• Resolved sdwire

    (@sdwire)


    I have a bit of a weird situation that’s causing the install of this plugin to fail.

    I run a multi-site network where users are allowed to create their own sites with wp-signup.php. I also hook into the wp-initialize-site to automatically activate certain plugins.

    Unfortunately, trying to activate Media Library Organizer during the wp-initialize-site action generates a fatal error because it tries to run the installer, but the installer class is added only when the plugin believes it’s running in an admin page. When someone creates their own site using wp-signup, WP_ADMIN is not set when the wp-initialize-site action happens. Because the installer class isn’t set up, line 18 of includes/admin/activation.php fails.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor wpmedialibrary

    (@wpmedialibrary)

    Understand the point, but would need to see your code that you’re using to hook into wp_initialize_site() here, as that’s a very early action to use.

    Can then confirm if we will modify Plugin accordingly.

    Thanks.

    Thread Starter sdwire

    (@sdwire)

    My code is a private derivative of https://github.com/wpmudev/pro-sites/blob/master/pro-sites-files/modules/premium-plugins.php

    My version of line 51 uses the wp_insert_site action, which replaces the deprecated wpmu_new_blog used in this public repository. I misspoke earlier. I thought I was using the wp_initialize_site action, but it’s actually using the wp_insert_site action, which is the recommended replacement. (And wp_initialize_site and wp_insert_site happen one right after the other anyway.)

    Line 393 is where the plugin activation happens. This is inside the function that handles the wp_insert_site action.

    The whole point of my code (and the module in the public repository from which it’s derived) is to activate a collection of plugins when a user creates a new blog using the self-signup process for a Multi-Site network. This new blog creation process does not happen within the context of an admin page, so it doesn’t really matter what action I try to use or how late it is in the blog creation process. It will never be in an admin context, so the install routine of MLO will always fail as long as the install class only gets initialized for admin pages.

    Thread Starter sdwire

    (@sdwire)

    As an experiment, I have also tried network-activating Media Library Organizer rather than conditionally activating it with my own code.

    Media Library Organizer’s own code hooks the wpmu_new_blog action to call media_library_organizer_activate_new_site(). When a new user self-registers a new site on the network using wp-signup.php, that wpmu_new_blog action is triggered, but not from an admin page.

    Even when processing its own registered action, MLO is throwing an exception when it tries to activate the new site, because the install class was not instantiated because is_admin() returned false.

    Plugin Contributor wpmedialibrary

    (@wpmedialibrary)

    Resolving in next update. No ETA at this time, so feel free to review more suitable alternatives given your urgency here. Thanks!

    Plugin Contributor wpmedialibrary

    (@wpmedialibrary)

    Resolving in 1.4.0, releasing Thursday 3rd March 2022 23:59 UTC.

    Proof of concept used to confirm correct working functionality in 1.4.0 can be found at https://gist.github.com/n7studios/32bf54a4b7acfac409767ad391b2867d

    Thank you.

    Thread Starter sdwire

    (@sdwire)

    Excellent! Thanks for the quick response.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Can’t activate during self-signup’ is closed to new replies.