Skip to content

fix(core): defer plugin load to plugins_loaded hook#936

Open
faisalahammad wants to merge 1 commit into
Automattic:developfrom
faisalahammad:fix/602-liveblog-features-filter-timing
Open

fix(core): defer plugin load to plugins_loaded hook#936
faisalahammad wants to merge 1 commit into
Automattic:developfrom
faisalahammad:fix/602-liveblog-features-filter-timing

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

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 register callbacks. This meant the liveblog_features filter fired too early for a normal add_filter( 'liveblog_features', ... ) call elsewhere to ever take effect, depending on plugin load order.
Fixes #602

Changes

liveblog.php

Before:

	}
	WPCOM_Liveblog::load();

	/** Plupload Helpers */

After:

	}

	// Hooked instead of called directly so that other plugins get a chance to
	// register their own callbacks (e.g. on `liveblog_features`) before we run.
	add_action( 'plugins_loaded', array( 'WPCOM_Liveblog', 'load' ), 0 );

	/** Plupload Helpers */

Why: hooking onto plugins_loaded at priority 0 defers load() until after every active plugin has been included, so any plugin's own top-level add_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 to init.

tests/Integration/LiveblogLoadTest.php

New test asserting WPCOM_Liveblog::load is registered on plugins_loaded at priority 0. Fails against the old code, where load() was never registered as a callback at all.

Testing

Test 1: liveblog_features filter now applies

  1. Added a small test plugin with add_filter( 'liveblog_features', function( $f ) { return array( 'commands', 'emojis', 'authors' ); } ); (no hashtags), activated as a regular plugin.
  2. Opened a post with an active liveblog and typed #something in 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 passing
  • composer test:integration (via wp-env) — 158/158 passing, including the new LiveblogLoadTest
  • composer lint and composer cs clean on changed files

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
@faisalahammad faisalahammad requested a review from a team as a code owner July 4, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

liveblog_features filter appears not to run

1 participant