[wp-trac] [WordPress Trac] #47646: Network wide activation variable is always failing for multisite

WordPress Trac noreply at wordpress.org
Wed Jul 3 18:16:46 UTC 2019


#47646: Network wide activation variable is always failing for multisite
--------------------------------+-----------------------------
 Reporter:  KestutisIT          |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Networks and Sites  |    Version:  5.2.2
 Severity:  blocker             |   Keywords:
  Focuses:  multisite           |
--------------------------------+-----------------------------
 So, I have multisite enabled. I go to network admin, find my plugin and
 click on 'network activate' link.
 But I get a fatal error of '**Regular activation (non-multisite or
 multisite's local activation).**'

 There was another person having the same issue more than a year ago, and
 appears the bug is still there, and I have no idea how to 'workaround-it'.

 https://wordpress.org/support/topic/network_wide-parameter-always-in-
 registered-activation-hook-function/

 So this is a **BLOCKER** for all network-enabled or multisite plugin
 developers.

 {{{#!php
 <?php
 final class MainController
 {
     // Configuration object reference
     private $confWithoutRouting         = NULL;
     private $conf                       = NULL;
     private $lang                       = NULL;
     private $canProcess                 = FALSE; // Have to be in main
 controller, as we don't use that for abstract controller
     private static $dependenciesLoaded  = FALSE;

     /**
      * NOTE: Here we must NOT support passing by reference, as it comes
 from static object
      * @param ConfigurationInterface $paramConfWithoutRouting
      */
     public function __construct(ConfigurationInterface
 $paramConfWithoutRouting)
     {
         // This is very important to set it here
         $this->canProcess = TRUE;

         // We assign it to variable to avoid passing by reference waring
 for non-variables
         $this->confWithoutRouting = $paramConfWithoutRouting;

         // 2. Autoloader registration code <..>

         //
         // 3. Activation Hooks
         //
         if(!is_null($this->confWithoutRouting))
         {
 register_activation_hook($this->confWithoutRouting->getPluginPathWithFilename(),
 array($this, 'networkOrSingleActivate'));
             // Other hooks

         }
     }

     /**
      * Activate (enable+install or enable only) plugin for across the
 whole network
      * @note - 'get_sites' function requires WordPress 4.6 or newer!
      * @param bool $networkWideActivation - if the activation is 'network
 enabled' or 'locally enabled' (even if multisite is enabled)
      */
     public function networkOrSingleActivate($networkWideActivation)
     {
         if(is_multisite() && $networkWideActivation)
         {
             // A workaround until WP will get fixed
             // SHOULD be 'networkActivate' but WordPress does not yet
 support that feature,
             // so this means as long as the 'MULTISITE' constant is
 defined in wp-config, we use that method
             trigger_error('Network wide activation', E_USER_ERROR);
             $this->multisiteActivate();
         } else
         {
             // A workaround until WP will get fixed
             trigger_error('Regular activation (non-multisite or
 multisite\'s local activation).', E_USER_ERROR);
             $this->activate();
         }
     }

     // Other methods <...>
 }
 }}}

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


More information about the wp-trac mailing list