WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

#47646 closed defect (bug) (duplicate)

Network wide activation variable is always failing for multisite

Reported by: KestutisIT Owned by:
Milestone: Priority: normal
Severity: blocker Version: 5.2.2
Component: Networks and Sites Keywords:
Focuses: multisite Cc:
PR Number:

Description

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
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 <...>
}

Change History (2)

#1 @KestutisIT
5 months ago

A note added to https://wordpress.org/support/topic/network_wide-parameter-always-in-registered-activation-hook-function/ moderator's answer - I just ran a test on absolutely fresh default newest (5.2.2) WordPress with my plugin only. So there is no other possible plugins to be impacting this, as he said in his reply.

Last edited 5 months ago by KestutisIT (previous) (diff)

#2 @SergeyBiryukov
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there,

Thanks for the report, we're already tracking this issue in #36406.

Note: See TracTickets for help on using tickets.