Make WordPress Core

Opened 10 months ago

Last modified 9 months ago

#45779 new defect (bug)

probable issue in Plugin activation hook

Reported by: tazotodua Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Plugins Keywords:
Focuses: multisite Cc:
PR Number:


i.e. if we have a simplest plugin:

 * Plugin Name:	example-1

register_activation_hook(__FILE__, "my" );
function my($network_wide)
    if($network_wide || is_network_admin())
       die("Activation from Network");


and you try to activate it from Network, you get such empty screen:

Probably the reason, as far as I can understand, is that, as the plugin is activated within the external sandbox call, and if it sees an error, it returns with activation-failure and then in iframe, it tries to load the activated plugin in order to be able to see the error message. However, as I doubt, in the first call, the $newtork_wide || is_network_admin() is evaluated to true, causing the die to be triggered. however, while WP tries to show the iframe, then there is not seen the error, as i suspect that $newtork_wide || is_network_admin() is evaluated to false.
that makes some problems to plugin developers if they target activation from Network or Single-Site. Will be good if that will be addressed.

Change History (4)

#1 @tazotodua
10 months ago

that can be confirmed, if we put this code in my function:

function my($network_wide)
    $die=$network_wide || is_network_admin();
    file_put_contents(ABSPATH.'/aaa.txt', ($die ? "yes" : "no") ."\r\n", FILE_APPEND);
       die("Activation from Network");

#2 @tazotodua
10 months ago

and this is the temporary solution how i handle that problem at this moment:

	public function activate($network_wide){
		$die= $network_wide || is_network_admin();
		if(  get_option("opt1", false) ) {
		if($die) {
		if($show_die) {
			$text= '<h2>Hi, dont activate from NETWORK!!!!!!</h2>';
			die($text .'<script>alert("'.strip_tags($text).'");</script>');

#3 @swissspidy
10 months ago

Possible duplicate of #36406.

#4 @SergeyBiryukov
9 months ago

  • Component changed from General to Plugins
  • Focuses multisite added
Note: See TracTickets for help on using tickets.