Hello, after a few hair pulling days I've finally determined the cause of problems I've been experiencing, as well as a tedious workaround.
Problem:
When the NicePage and Woocommerce plugins are both active, the WP Admin page is completely broken, giving the following error:
Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /var/www/wp-content/plugins/woocommerce/includes/wc-user-functions.php:403 Stack trace: #0 /var/www/wp-content/plugins/woocommerce/includes/wc-user-functions.php(525): wc_current_user_has_role('administrator') #1 /var/www/wp-includes/class-wp-hook.php(308): wc_modify_editable_roles(Array) #2 /var/www/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #3 /var/www/wp-admin/includes/user.php(272): apply_filters('editable_roles', Array) #4 /var/www/wp-content/plugins/zant_technologies/includes/class-np-role-manager.php(19): get_editable_roles() #5 /var/www/wp-content/plugins/zant_technologies/includes/class-np-role-manager.php(186): NpRoleManager::init() #6 /var/www/wp-content/plugins/zant_technologies/zant_technologies.php(48): include_once('/var/www/wp-con...') #7 /var/www/wp-settings.php(447): include_once('/var/www/wp-con...') #8 /var/www/wp-config.php(104): require_once('/var/www/wp-set...') #9 /var/www/wp-load.php(50): require_once('/var/www/wp-con...') #10 /var/www/wp-admin/admin.php(34): require_once('/var/www/wp-loa...') #11 /var/www/wp-admin/options-general.php(10): require_once('/var/www/wp-adm...') #12 {main} thrown in /var/www/wp-content/plugins/woocommerce/includes/wc-user-functions.php on line 403
Reproduction Steps
The critical step to reproducing this issue, is to give the whitelabeled Theme/Plugin a name that comes after WooCommerce alphabetically. Then inside a WP site, install and activate both plugins in any order. Once both are enabled the error will appear in the WP Admin page.
Root Cause
It appears the NicePage WordPress plugin does not properly use hooks as it should, and as WooCommerce does. As a result, if WooCommerce is loaded first (as plugins are loaded alphabetically by default), it will set up some hooks that get triggered too early during the NicePage plugins initialization causing the error above.
Long Term Solution for NicePage
Updating the NicePage WP Export to correctly use hooks will avoid this and other similar compatibility issues.
Workaround for WP Site Managers
1. Edit the wp-content/plugins/[PluginNameHere]/[PluginNameHere].php (i.e. wp-content/plugins/zant_technologies/zant_technologies.php)
2. Comment out the following line (line #48 in my case): include_once dirname(FILE) . '/includes/class-np-role-manager.php';
3. Activate both your Whitelabeled NicePage plugin and the WooCommerce plugin. (It will work at this step, except for the role manager portion of the nicepage plugin in the admin panel.)
4. Install a plugin that can modify the load order. (I'm using "Plugins Load Order")
5. Using the load order plugin, ensure the Whitelabeled NicePage plugin is loaded before WooCommerce.
6. Go back to the file modified in step 1, and undo the change made in step 2.
Hopefully NicePage can get a long term solution, but in the meantime maybe someone else will find this workaround helpful.
Hello, after a few hair pulling days I've finally determined the cause of problems I've been experiencing, as well as a tedious workaround. **Problem:** When the NicePage and Woocommerce plugins are both active, the WP Admin page is completely broken, giving the following error: Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /var/www/wp-content/plugins/woocommerce/includes/wc-user-functions.php:403 Stack trace: #0 /var/www/wp-content/plugins/woocommerce/includes/wc-user-functions.php(525): wc_current_user_has_role('administrator') #1 /var/www/wp-includes/class-wp-hook.php(308): wc_modify_editable_roles(Array) #2 /var/www/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #3 /var/www/wp-admin/includes/user.php(272): apply_filters('editable_roles', Array) #4 /var/www/wp-content/plugins/zant_technologies/includes/class-np-role-manager.php(19): get_editable_roles() #5 /var/www/wp-content/plugins/zant_technologies/includes/class-np-role-manager.php(186): NpRoleManager::init() #6 /var/www/wp-content/plugins/zant_technologies/zant_technologies.php(48): include_once('/var/www/wp-con...') #7 /var/www/wp-settings.php(447): include_once('/var/www/wp-con...') #8 /var/www/wp-config.php(104): require_once('/var/www/wp-set...') #9 /var/www/wp-load.php(50): require_once('/var/www/wp-con...') #10 /var/www/wp-admin/admin.php(34): require_once('/var/www/wp-loa...') #11 /var/www/wp-admin/options-general.php(10): require_once('/var/www/wp-adm...') #12 {main} thrown in /var/www/wp-content/plugins/woocommerce/includes/wc-user-functions.php on line 403 **Reproduction Steps** The critical step to reproducing this issue, is to give the whitelabeled Theme/Plugin a name that comes after WooCommerce alphabetically. Then inside a WP site, install and activate both plugins in any order. Once both are enabled the error will appear in the WP Admin page. **Root Cause** It appears the NicePage WordPress plugin does not properly use hooks as it should, and as WooCommerce does. As a result, if WooCommerce is loaded first (as plugins are loaded alphabetically by default), it will set up some hooks that get triggered too early during the NicePage plugins initialization causing the error above. **Long Term Solution for NicePage** Updating the NicePage WP Export to correctly use hooks will avoid this and other similar compatibility issues. **Workaround for WP Site Managers** 1. Edit the wp-content/plugins/[PluginNameHere]/[PluginNameHere].php (i.e. wp-content/plugins/zant_technologies/zant_technologies.php) 2. Comment out the following line (line #48 in my case): *include_once dirname(__FILE__) . '/includes/class-np-role-manager.php';* 3. Activate both your Whitelabeled NicePage plugin and the WooCommerce plugin. (It will work at this step, except for the role manager portion of the nicepage plugin in the admin panel.) 4. Install a plugin that can modify the load order. (I'm using "Plugins Load Order") 5. Using the load order plugin, ensure the Whitelabeled NicePage plugin is loaded before WooCommerce. 6. Go back to the file modified in step 1, and undo the change made in step 2. Hopefully NicePage can get a long term solution, but in the meantime maybe someone else will find this workaround helpful.