fix(core): defer plugin load to plugins_loaded hook#936
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
WPCOM_Liveblog::load() was called directly at the bottom of liveblog.php, so it ran the instant PHP parsed the file, before other plugins had a chance to hook into filters like liveblog_features. Now it runs on plugins_loaded at priority 0 instead, so a normal add_filter call in another plugin is guaranteed to be registered in time, regardless of plugin load order. Fixes Automattic#602
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WPCOM_Liveblog::load()was called directly at the bottom ofliveblog.php, so it ran the instant PHP parsed the file, before other plugins had a chance to register callbacks. This meant theliveblog_featuresfilter fired too early for a normaladd_filter( 'liveblog_features', ... )call elsewhere to ever take effect, depending on plugin load order.Fixes #602
Changes
liveblog.php
Before:
After:
Why: hooking onto
plugins_loadedat priority 0 defersload()until after every active plugin has been included, so any plugin's own top-leveladd_filter()call is guaranteed to be registered by the time Liveblog applies its filters. Priority 0 keeps it running as early as possible on that hook, same as before relative toinit.tests/Integration/LiveblogLoadTest.php
New test asserting
WPCOM_Liveblog::loadis registered onplugins_loadedat priority0. Fails against the old code, whereload()was never registered as a callback at all.Testing
Test 1: liveblog_features filter now applies
add_filter( 'liveblog_features', function( $f ) { return array( 'commands', 'emojis', 'authors' ); } );(no hashtags), activated as a regular plugin.#somethingin the entry composer.Result: hashtag suggestion no longer triggers, other features (commands/emoji/authors) still work. Before the fix, the filter had no effect regardless of plugin activation order.
Test 2: automated suite
composer test:unit— 7/7 passingcomposer test:integration(viawp-env) — 158/158 passing, including the newLiveblogLoadTestcomposer lintandcomposer csclean on changed files