Code Monkey home page Code Monkey logo

Comments (4)

lucatume avatar lucatume commented on June 3, 2024

Hooking at muplugins_loaded is a fairly common practice and one honoring WordPress real loading sequence. To point out some authoritative test code: posts-to-posts bootstrap file.
Furthermore the standard WordPress component loading flow loads plugins right after mu-plugins as can be seen in the wp-settings.php file.
Delaying that call would mean creating artificial conditions for the plugin existing in the test environment only.
There is, though, something happening between the muplugins_loaded and the plugins_loaded hook and it might be worth exploring the possibility to have the plugins loaded in a similar fashion

tests_add_filter( 'plugins_loaded', [ $this, `activatePlugins` ], PHP_INT_MIN );

aka "very very early in the hook".

from wp-browser.

barryhughes avatar barryhughes commented on June 3, 2024

Just to clarify, my suggestion wasn't to change when plugins are loaded - it was to change the hook on which they are activated.

I'd also agree wp may not be the best action either (though it works) - wp_loaded is probably better. Here's my take on the expected sequence of events when a plugin is activated:

  • wp-load.php bootstraps WordPress
  • wp-config.php is included by wp-load.php
  • wp-settings.php is included by wp-config.php
    • muplugins_loaded fires
    • plugins_loaded fires
    • Various key objects are now instantiated (including the $wp_rewrite global)
    • wp_loaded fires (at this point, we're right at the end of wp-settings.php)
  • The next thing we are interested in is the call to activate_plugin(...) which is responsible for firing the activate_{plugin} hook

So it's not unreasonable for a plugin to want to interact with things like $wp_rewrite when the activation hook runs - directly or indirectly (ie, by registering a post type). All I'm really saying is, yep let's load the plugins as we're currently doing (or on plugins_loaded) - but activation ought to move forward, as it would if we weren't in a test environment.

Does that make more sense?

from wp-browser.

lucatume avatar lucatume commented on June 3, 2024

It makes total sense and I think you are right.
I'm looking into it and will address this shortly, thanks for pointing it out.

from wp-browser.

lucatume avatar lucatume commented on June 3, 2024

I've updated the code to move the plugin activation to the wp_install hook. This should take care of the plugin activation issue and give activating plugins the environment those need.

from wp-browser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.