[wp-trac] [WordPress Trac] #36406: $network_wide is unreliable
WordPress Trac
noreply at wordpress.org
Wed Oct 26 05:27:33 UTC 2016
#36406: $network_wide is unreliable
--------------------------+-----------------------------
Reporter: mensmaximus | Owner:
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: Future Release
Component: Plugins | Version: 3.0
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: multisite
--------------------------+-----------------------------
Changes (by jeremyfelt):
* keywords: has-patch needs-testing => needs-patch
* owner: jeremyfelt =>
* version: 4.4.2 => 3.0
* milestone: 4.7 => Future Release
Comment:
I think I've wrapped my head around what's possible and what's missing
here. Thanks for your patience @mensmaximus!
First, I don't think there's a way to short-circuit network activation of
a plugin and show a custom or configurable error message in our current
state. When the plugin's activation hook fires, WordPress expects to get
`null` back. If anything else is output, then a predetermined path to an
error condition occurs.
* If `echo 'error';` is used, an error explaining that unexpected
characters were output will appear. The plugin will still be activated
with just a warning to be cautious.
* If `exit()` is used, a fatal error will occur during activation and a
different error will be showing.
It's when this fatal error is show that the plugin goes through additional
validations and the plugin activation hook is run again with varying
`$network_wide` values. If the plugin is network activated with no error,
the activation hook fires once.
It's possible to work around the activation by using the
`activated_plugin` hook to reverse activation immediately after. Something
like this:
{{{
function remove_this_plugin( $plugin ) {
$current = get_site_option( 'active_sitewide_plugins', array() );
unset( $current[ $plugin ] );
update_site_option( 'active_sitewide_plugins', $current );
}
register_activation_hook( __FILE__, 'test_activation_hook' );
function test_activation_hook( $network_wide ) {
if ( $network_wide ) {
add_action( 'activated_plugin', 'remove_this_plugin' );
}
}
}}}
This works, but provides no feedback to the user that the plugin
activation was not successful.
It seems like there should be room for a filter that allows a plugin to
set the `WP_Error` message in a way that a proper error will be displayed.
I'm not yet sure if I'm missing anything in thinking that way.
I'm going to push this back to Future Release. We should continue
discussing possible approaches.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36406#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list