From 0c4c12cae1afd50e518d8aee070ff46c75ddb0fe Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Sat, 24 Mar 2018 13:57:42 -0700 Subject: [PATCH 1/2] Load commands later so that apply_filters can be hooked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the `liveblog_active_commands` filter runs early so hooking into that filter from a theme won’t work. If we load this later, folks can hook into it from their themes to create custom commands. --- ...lass-wpcom-liveblog-entry-extend-feature-commands.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/classes/class-wpcom-liveblog-entry-extend-feature-commands.php b/classes/class-wpcom-liveblog-entry-extend-feature-commands.php index 971beebd5..3ff22f00e 100644 --- a/classes/class-wpcom-liveblog-entry-extend-feature-commands.php +++ b/classes/class-wpcom-liveblog-entry-extend-feature-commands.php @@ -56,7 +56,7 @@ public function load() { // Allow plugins, themes, etc. to change // the current command set. - $this->commands = apply_filters( 'liveblog_active_commands', $this->commands ); + add_action( 'after_setup_theme', array( $this, 'custom_commands' ), 10 ); // This is the regex used to revert the // generated author html back to the @@ -82,6 +82,13 @@ public function load() { add_action( 'liveblog_insert_entry', array( $this, 'do_action_per_type' ), 10, 2 ); } + /** + * Returns the custom commands and allows for customizing the command set + * + */ + public function custom_commands() { + $this->commands = apply_filters( 'liveblog_active_commands', $this->commands ); + } /** * Gets the autocomplete config. * From 61b30ebbdd5bec301601a70a39290ff7511375b9 Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Sat, 24 Mar 2018 13:58:03 -0700 Subject: [PATCH 2/2] Update `liveblog_active_commands` filter instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e4dc30c1..e51c3dd3f 100755 --- a/README.md +++ b/README.md @@ -57,10 +57,10 @@ New iPad announced, launching next week — more info to come. /key You can add new commands easily with a filter, the most basic command will add a class to entry, so you could do a simple `/highlight` which would add `type-highlight` to the entry container, letting you style the background color: ``` php -add_filter( 'liveblog_active_commands', array( __CLASS__, 'add_highlight_command' ), 10 ); +add_filter( 'liveblog_active_commands', 'add_highlight_command', 10 ); -public static function add_highlight_command( $commands ) { +function add_highlight_command( $commands ) { $commands[] = highlight; return $commands; }