From 8344ab42519b723b2a614c6c71d6ecdb6069f9f9 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 8 Oct 2018 17:41:18 +0530 Subject: [PATCH 1/4] Add support for other post types --- liveblog.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/liveblog.php b/liveblog.php index 44bc4c130..f51bb59c5 100644 --- a/liveblog.php +++ b/liveblog.php @@ -59,6 +59,7 @@ final class WPCOM_Liveblog { public static $auto_archive_days = null; public static $auto_archive_expiry_key = 'liveblog_autoarchive_expiry_date'; public static $latest_timestamp = false; + public static $supported_post_types = array(); /** Load Methods **********************************************************/ @@ -250,7 +251,11 @@ public static function init() { * Add liveblog support to the 'post' post type. This is done here so * we can possibly introduce this to other post types later. */ - add_post_type_support( 'post', self::KEY ); + $post_types = array( 'post' ); + self::$supported_post_types = apply_filters( 'liveblog_modify_supported_post_types', $post_types ); + foreach ( self::$supported_post_types as $post_type ) { + add_post_type_support( $post_type, self::key ); + } /** * Apply a Filter to Setup our Auto Archive Days. @@ -493,14 +498,14 @@ public static function is_liveblog_post( $post_id = null ) { * @return bool */ public static function is_viewing_liveblog_post() { - return (bool) ( is_single() && self::is_liveblog_post() ); + return (bool) ( is_singular( self::$supported_post_types ) && self::is_liveblog_post() ); } /** * One of: 'enable', 'archive', false. */ public static function get_liveblog_state( $post_id = null ) { - if ( ! is_single() && ! is_admin() && ! self::$is_rest_api_call ) { + if ( ! is_singular( self::$supported_post_types ) && ! is_admin() && ! self::$is_rest_api_call ) { return false; } if ( empty( $post_id ) ) { From 980245cac38c2841f82a0b7139aa2d3dbc5042ef Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 8 Oct 2018 17:54:14 +0530 Subject: [PATCH 2/4] Fix typo - self::KEY --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index f51bb59c5..75a4ca22e 100644 --- a/liveblog.php +++ b/liveblog.php @@ -254,7 +254,7 @@ public static function init() { $post_types = array( 'post' ); self::$supported_post_types = apply_filters( 'liveblog_modify_supported_post_types', $post_types ); foreach ( self::$supported_post_types as $post_type ) { - add_post_type_support( $post_type, self::key ); + add_post_type_support( $post_type, self::KEY ); } /** From 08ba42f40bdd59c218b46181e7760e1f01523d3d Mon Sep 17 00:00:00 2001 From: Shantanu Date: Tue, 9 Oct 2018 11:30:02 +0530 Subject: [PATCH 3/4] Document the filter - liveblog_supported_post_types --- liveblog.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index 75a4ca22e..8be089ab7 100644 --- a/liveblog.php +++ b/liveblog.php @@ -252,7 +252,16 @@ public static function init() { * we can possibly introduce this to other post types later. */ $post_types = array( 'post' ); - self::$supported_post_types = apply_filters( 'liveblog_modify_supported_post_types', $post_types ); + + /** + * Filters post types supported by liveblog. + * + * @since 2.0 + * + * @param array An array of supported post types. + */ + self::$supported_post_types = apply_filters( 'liveblog_supported_post_types', $post_types ); + foreach ( self::$supported_post_types as $post_type ) { add_post_type_support( $post_type, self::KEY ); } From 8ae06f104b2bc9dba9e6dafeca3398ad006ee76d Mon Sep 17 00:00:00 2001 From: Shantanu Date: Tue, 9 Oct 2018 15:49:10 +0530 Subject: [PATCH 4/4] Update the docblock for the supported post types filter --- liveblog.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liveblog.php b/liveblog.php index 8be089ab7..e9a270fe7 100644 --- a/liveblog.php +++ b/liveblog.php @@ -254,11 +254,11 @@ public static function init() { $post_types = array( 'post' ); /** - * Filters post types supported by liveblog. + * Filters post types supported by this plugin. * - * @since 2.0 + * @since 2.0.0 * - * @param array An array of supported post types. + * @param array Supported post types. */ self::$supported_post_types = apply_filters( 'liveblog_supported_post_types', $post_types );