Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error if not logged in and accessing wp-admin #4828

Closed
tanthammar opened this issue Apr 7, 2018 · 5 comments
Closed

Fatal error if not logged in and accessing wp-admin #4828

tanthammar opened this issue Apr 7, 2018 · 5 comments
Assignees
Labels
Status: Need User Feedback Waiting on feedback from user who reported issue Type: Bug
Milestone

Comments

@tanthammar
Copy link

Issue Overview

I forgot to log in and tried to access wp-admin.
This caused a fatal error.

Expected Behavior

No error

Current Behavior

Fatal error: Uncaught Error: Call to undefined function get_current_screen() in /home/bokamark/staging.bokamarknad.se/wp-content/plugins/pods/classes/PodsInit.php:304 Stack trace: #0 /home/bokamark/staging.bokamarknad.se/wp-includes/class-wp-hook.php(286): PodsInit->register_assets(‘’) #1 /home/bokamark/staging.bokamarknad.se/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #2 /home/bokamark/staging.bokamarknad.se/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/bokamark/staging.bokamarknad.se/wp-includes/script-loader.php(1435): do_action(‘wp_enqueue_scri...‘) #4 /home/bokamark/staging.bokamarknad.se/wp-includes/class-wp-hook.php(286): wp_enqueue_scripts(‘’) #5 /home/bokamark/staging.bokamarknad.se/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #6 /home/bokamark/staging.bokamarknad.se/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #7 /home/bokamark/staging.bokamarknad.se/wp-includes/general-template.php(2614): do_action(‘wp_head’) #8 /home/bokamark/st in /home/bokamark/staging.bokamarknad.se/wp-content/plugins/pods/classes/PodsInit.php on line 304

Possible Solution

Add an if-statement to check if user is logged in.
Update line 304 in Podsinit.php to;
if (is_user_logged_in() && is_admin()) {...}

Steps to Reproduce (for bugs)

See issue Overview

@therealgilles
Copy link
Contributor

I believe the better fix would be:

if ( is_admin() && function_exists('get_current_screen') ) {...}

@jimtrue
Copy link
Contributor

jimtrue commented May 20, 2018

@tanthammar and @therealgilles I'm actually not able to reproduce this error locally. If I attempt to access the wp-admin and I'm not logged in, I'm re-routed to the login screen. Is that not the case with your installations? There is a reason we ask for Steps to Reproduce (for bugs). Your issue overview is not sufficient enough to reproduce the bug.

@jimtrue
Copy link
Contributor

jimtrue commented May 20, 2018

Additional forum post for reference from @therealgilles https://wordpress.org/support/topic/problem-with-ajax-requests/

@jimtrue jimtrue added Status: Need User Feedback Waiting on feedback from user who reported issue Type: Bug labels May 20, 2018
@therealgilles
Copy link
Contributor

therealgilles commented May 21, 2018

In my case, I am using the login-with-ajax plugin. Therefore I am guessing that it's an ajax request that's creating the problem. When doing an ajax request, is_admin() returns true.

I also read this from the get_current_screen page:

This function is defined on most admin pages, but not all. Thus there are cases where is_admin() will return true, but attempting to call get_current_screen() will result in a fatal error because it is not defined.

So again I reckon it would be better to qualify the if statement by checking if the function is defined when the code is reached.

@pglewis
Copy link
Contributor

pglewis commented May 21, 2018

PR: #4947

pglewis added a commit that referenced this issue Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Need User Feedback Waiting on feedback from user who reported issue Type: Bug
Projects
None yet
Development

No branches or pull requests

4 participants