[wp-trac] [WordPress Trac] #36406: $network_wide is unreliable
WordPress Trac
noreply at wordpress.org
Sun Apr 3 09:20:35 UTC 2016
#36406: $network_wide is unreliable
--------------------------+-----------------------------
Reporter: mensmaximus | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 4.4.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
This issue may be related to ticket #31104
Scenario:
In a WordPress network an admin decides a plugin must not be network
activated. Only a per site or even a site specific activation shall be
allowed.
Idea:
Conditional check during plugin activation and die with an error message
if $network_wide is true.
Result:
Plugin does not get activated but the custom error message is not
displayed
Assume the following function run during activation (it is simplified and
the real activation sequence does not have echos!)
{{{
function test_activation_hook( $network_wide ) {
echo '<span>1 | </span>';
// exit( 1 );
if ( is_multisite() ) {
echo '<span>2: | </span>';
// exit( 2 );
if ( $network_wide ) {
echo '<span>3: | </span>';
// exit( 3 );
} else {
echo '<span>4: | </span>';
// exit( 4 );
}
} else {
echo '<span>5: | </span>';
// exit( 5 );
}
echo '<span>6: | </span>';
exit( 6 );
}
}}}
If you exit after if(is_multisite) the message displayed will be '1 | 2 |'
If you exit after if($network_wide) during a networkwide activation the
message displayed is '1 | 2 | 4 | 6' instead of '1 | 2| 3|'
Exiting at 4, 5, or 6 will display '1 | 2| 4|', '1 | 2| 5|' and '1 | 2|
6|' as expected.
After many hours of debuging I realized the function (the action filter
'activate_' . $plugin) gets executed 3 times if you exit it early. And
only the first call has the argument $network_wide set to true if it is an
network_wide activation.
If you like to exit at 3, that is you do not want a network activation,
the flow is therefore as follows:
- The first run (click on network activate) has $network_wide set to true
and will exit at 3
- the second run (no idea why) has $network_wide set to false and will
pass 1 | 2 | 4 | 6
- the third run (no idea why) has $network_wide set to false and will pass
1 | 2 | 4 | 6
Imho calling the activation function (or the code) three times in case you
exit it (better say terminate because you cant end a plugin installiton
clean) is wrong at all. However if this is by design then $network_wide
must be reliably set to true if it originally was.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36406>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list