Two of Redux’s users reported a conflict with Maintenance Mode and Redux. Upon investigation, I found the problem with Maintenance Mode to be that it breaks compatibility with the entire pluggable architecture. Maintenance Mode probably breaks a lot more plugins then people realize, it’s just that most plugins don’t report the fact. That’s a nice feature inherited from Register Plus.
The offending code follows:
if (!function_exists('wp_get_current_user')) require (ABSPATH . WPINC . '/pluggable.php');
The plugin author was kind enough to explain the purpose of this code: “For current_user_can() -> “wp_get_current_user() in wp-includes\capabilities.php on line 969″. We need to include now since it is by default included AFTER plugins are being loaded.” So there was a problem with the current_user_can code not working. I’m surprised by that because current user_can is a pretty basic function for a plugin.
The following two posts in the WordPress Support Forum actually address the very problem Maintenance Mode must have been having…
http://wordpress.org/support/topic/current_user_can-in-the-_construct
http://wordpress.org/support/topic/using-current_user_can-breaks-plugin
Looking into it further, it appears the ApplyMaintenceMode function is the real culprit it makes a call to current_user_can() and to another function which in turn is dependent on current_user_can(). Regardless, all this is done in the constructor so it’s done pretty much immediately. We can fix this by changing the line $myMaMo->ApplyMaintenanceMode(); to add_action('plugins_loaded', array($myMaMo, 'ApplyMaintenanceMode')); and commenting out the if (!function_exists('wp_get_current_user')) require (ABSPATH . WPINC . '/pluggable.php'); line.
Thank you to pixelprohet for verifying these changes work!
Interesting reading. I use Maintenance Mode on a LOT of installs and have never seen any issues that I would account to this plugin but as you said…if nothing was reported, how would I know?
Aren’t there many other plugins that check for current_user like theme previews, etc? I wonder how these are (or are not affected)?
Anywho…let me know if you need any assistance with testing, I’m happy to help if I can.
Well, in regard to Maintenance Mode specifically, not a lot of plugins overwrite pluggable functions, so that makes for a lot less issues right out of the gate, also, I’m not sure what order WordPress reads the plugins, if WP read Redux before Maintenance Mode, that would have prevented the issue too. In fact, if there was a way to weight the load order of plugins and set Maintenance Mode weight very high, then that would be another fix. If I had to guess, I think WP reads them in alpha order, but I’ve never looked, although, that’s an interesting avenue of research.
In regard to other themes and plugins, most of them don’t call out to current_user_can() until after they are initialized. This is kind of specific to the way Maintenance Mode was written. I’m not sure if that’s good luck, good coding practice, or trial and error, but this doesn’t seem to be a common problem. So, I don’t blame WP, not to say I blame the author either, it’s just one of those things you learn from.
Now I just need someone to test my solution so I can present it to the author and make Maintenance Mode a good citizen of the plugin community.
Hey there radiok! I tested your solution and reported here. Sorry, no dice for me.
Now it works! (with the solution updates, as explained here) Goodly stuff
Thanks for testing that out! You’ve made the world a better place! Well, the digital world at least!
Thank you very much radiok! I’ve just fixed it and published version 5.3:
http://wordpress.org/extend/plugins/maintenance-mode/changelog/
Thank you, both of you!!
Found another conflicting plugin, this one is PDF24 Article to PDF. Sure enough, the very first thing it does is call pluggable.php. Will see about contacting the plugin author.
Thanks!
I love your plugin. The only problem I’m having, is the admin notification new user email is being sent to the wrong user. I have two administrators, and it is not being sent to either one. How can I change where the notification email is being sent? Thanks!
Beth, in the preview pane for the admin message, it should display the email address it will send admin emails to, is that either of the admins you intend to sent it to?
No, it shows the address where the email is going, but it is not to either of the Adminstrators. It is going to a Contributor.
OK Beth, the email address that Redux uses is found in the General Settings on your WordPress Control Panel, I’m not positive it will let you, but you can try to enter both email addresses with a comma separating them. If that does not work you will either need to choose one, or, create a forwarding email address via your web hosting control panel that forwards to both of your admins. Let me know how that works for you.
Very detailed post. There are quite a few maintenance scripts out there though.. what ones do you recommend using?
I’ve issues with a few in the past – any suggestions? Thanks!