[wp-trac] [WordPress Trac] #33215: Main plugin file loaded multiple times under special circumstances on Network Activate

WordPress Trac noreply at wordpress.org
Fri Jul 31 10:06:04 UTC 2015


#33215: Main plugin file loaded multiple times under special circumstances on
Network Activate
---------------------------------------+-----------------------------
 Reporter:  ccprog                     |      Owner:
     Type:  defect (bug)               |     Status:  new
 Priority:  normal                     |  Milestone:  Awaiting Review
Component:  Plugins                    |    Version:  4.2.3
 Severity:  normal                     |   Keywords:
  Focuses:  administration, multisite  |
---------------------------------------+-----------------------------
 Consider the following code in the main plugin file:
 {{{
 function test_plugin_install ( $network_wide = null ) {
     if ( $network_wide ) {
         trigger_error( 'Please activate individually.', E_USER_ERROR );
     }
 }
 register_activation_hook( __FILE__, 'test_plugin_install' );
 }}}

 and a multisite setup with
 * mysite.intern as main site
 * one.mysite.intern, two.mysite.intern, etc. as blog sites

 Now, if you first activate the plugin ''individually'' on mysite.intern,
 and then select "Network Activate", the following is logged:
 {{{
 PHP Fatal error:  Please activate individually. in test_plugin.php on line
 17
 PHP Fatal error:  Cannot redeclare test_plugin_install() (previously
 declared in test_plugin.php:15) in test_plugin.php on line 15
 PHP Fatal error:  Cannot redeclare test_plugin_install() (previously
 declared in test_plugin.php:15) in test_plugin.php on line 15
 }}}
 and only the last error is displayed on the admin page.

 If the plugin is first activated on another blog site or isn't activated
 individually anywhere, only the expected "Please activate individually"
 error is thrown and displayed on network activation, as expected.

 Wrapping the function test_plugin_install in a conditional only results in
 the next function in the plugin file triggering the redeclaration error.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33215>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list