Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#21612 closed defect (bug)

wp-settings loads plugins before pluggable.php is included — at Initial Version

Reported by: kingjeffrey Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: General Keywords:
Focuses: Cc:


When manually initializing WordPress (like in a page that handles AJAX requests) to access all WordPress functions, it is typical to begin the file with:


require($_SERVERDOCUMENT_ROOT? . '/wp-blog-header.php');


However, if a plugin calls the get_userdata() function, the page will deliver this fatal error:


Fatal error: Call to undefined function get_userdata() in [...]/wp-includes/user.php on line 1402


The "Maintenance" plugin is an example of one that causes this issue.

When the plugin is loaded in wp-settings.php line 198, it calls the get_userdata() function. But the get_userdata() function is not defined until wp-includes/pluggable.php is included on line 202 of wp-settings.

So this issue is not limited to calling get_userdata(), but any function defined in wp-includes/pluggable.php.

A simple fix to this, assuming wp-includes/pluggable.php does not depend on the plugins being loaded (which it very may well), is to swap the order of loading in wp-settings.php

Change History (0)

Note: See TracTickets for help on using tickets.