From cd814f198e292ac0124938128e5c75202dd29a60 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 14 Jan 2018 19:06:47 +0530 Subject: [PATCH 01/17] Add nbproject to git ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c03c179a0..b4faeed47 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ yarn-error.log .svn composer.lock vendor/ +/nbproject # Editor directories and files .idea From 43dd4deba4b5f8e916a13a7f7e416866800341a0 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 14 Jan 2018 19:08:05 +0530 Subject: [PATCH 02/17] Add post type support for page, attachment and revision in init() of the core plugin file --- liveblog.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/liveblog.php b/liveblog.php index 7d2ad5a63..fe9f49045 100644 --- a/liveblog.php +++ b/liveblog.php @@ -240,6 +240,9 @@ public static function init() { * we can possibly introduce this to other post types later. */ add_post_type_support( 'post', self::key ); + add_post_type_support( 'page', self::key ); + add_post_type_support( 'attachment', self::key ); + add_post_type_support( 'revision', self::key ); /** * Apply a Filter to Setup our Auto Archive Days. From b7a457e030049f9dc7e05c4fa3ac31c4d3f35b32 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 14 Jan 2018 19:56:00 +0530 Subject: [PATCH 03/17] Add checks for page and attachment when checking for liveblog post --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index fe9f49045..45667b42e 100644 --- a/liveblog.php +++ b/liveblog.php @@ -454,7 +454,7 @@ 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_single() || is_page() || is_attachment() ) && self::is_liveblog_post() ); } /** From a8876f0ece51cf2bc489655cd8a8a1a44885272d Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 14 Jan 2018 20:05:21 +0530 Subject: [PATCH 04/17] Use is_singular instead of multiple is_* checks --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index 45667b42e..aef86f370 100644 --- a/liveblog.php +++ b/liveblog.php @@ -454,7 +454,7 @@ public static function is_liveblog_post( $post_id = null ) { * @return bool */ public static function is_viewing_liveblog_post() { - return (bool) ( ( is_single() || is_page() || is_attachment() ) && self::is_liveblog_post() ); + return (bool) ( is_singular() && self::is_liveblog_post() ); } /** From 6e8d31c6e8263a5532a64679dc48e7d23f916b84 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 14 Jan 2018 20:05:51 +0530 Subject: [PATCH 05/17] Update get_liveblog_state --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index aef86f370..21d59955f 100644 --- a/liveblog.php +++ b/liveblog.php @@ -461,7 +461,7 @@ public static function is_viewing_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() && ! is_admin() && ! self::$is_rest_api_call) { return false; } if ( empty( $post_id ) ) { From 094727aee790dd5b2db9403d52063b6ca0e6bbd6 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Wed, 17 Jan 2018 12:34:28 +0530 Subject: [PATCH 06/17] Remove support for revision type --- liveblog.php | 1 - 1 file changed, 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index 21d59955f..9f5435c23 100644 --- a/liveblog.php +++ b/liveblog.php @@ -242,7 +242,6 @@ public static function init() { add_post_type_support( 'post', self::key ); add_post_type_support( 'page', self::key ); add_post_type_support( 'attachment', self::key ); - add_post_type_support( 'revision', self::key ); /** * Apply a Filter to Setup our Auto Archive Days. From 6cfe3942cce39acf8a1b7c5cad02e1dc2fc07933 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Thu, 18 Jan 2018 09:58:30 +0530 Subject: [PATCH 07/17] Remove support for attachment type --- liveblog.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/liveblog.php b/liveblog.php index 9f5435c23..d1787ab17 100644 --- a/liveblog.php +++ b/liveblog.php @@ -241,8 +241,7 @@ public static function init() { */ add_post_type_support( 'post', self::key ); add_post_type_support( 'page', self::key ); - add_post_type_support( 'attachment', self::key ); - + /** * Apply a Filter to Setup our Auto Archive Days. * NULL is classed as disabled. From 6ea2457af67fd2be6e8915b9b5bc4c445b5fe520 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Thu, 18 Jan 2018 10:04:29 +0530 Subject: [PATCH 08/17] Add a new filter to allow the user to filter the supported post types --- liveblog.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/liveblog.php b/liveblog.php index d1787ab17..b061bf536 100644 --- a/liveblog.php +++ b/liveblog.php @@ -57,6 +57,8 @@ final class WPCOM_Liveblog { public static $is_rest_api_call = false; public static $auto_archive_days = null; public static $auto_archive_expiry_key = 'liveblog_autoarchive_expiry_date'; + + public $supported_post_types = array(); /** Load Methods **********************************************************/ @@ -236,11 +238,18 @@ private static function register_embed_handlers() { */ 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 liveblog support to the 'post' and 'page' post type. + */ + $post_types = array( 'post', 'page' ); + + /** + * This allows the users to filter their supported post types. */ - add_post_type_support( 'post', self::key ); - add_post_type_support( 'page', self::key ); + $this->supported_post_types = apply_filters( 'modify_supported_post_types', $post_types ); + + foreach ( $this->supported_post_types as $post_type) { + add_post_type_support($post_type, self::key); + } /** * Apply a Filter to Setup our Auto Archive Days. From b08da6c984a43694626aac877426e2c06dcd6141 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Thu, 18 Jan 2018 10:11:23 +0530 Subject: [PATCH 09/17] Fix declarations --- liveblog.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liveblog.php b/liveblog.php index b061bf536..179e35512 100644 --- a/liveblog.php +++ b/liveblog.php @@ -58,7 +58,7 @@ final class WPCOM_Liveblog { public static $auto_archive_days = null; public static $auto_archive_expiry_key = 'liveblog_autoarchive_expiry_date'; - public $supported_post_types = array(); + public static $supported_post_types = array(); /** Load Methods **********************************************************/ @@ -245,9 +245,9 @@ public static function init() { /** * This allows the users to filter their supported post types. */ - $this->supported_post_types = apply_filters( 'modify_supported_post_types', $post_types ); + self::$supported_post_types = apply_filters( 'modify_supported_post_types', $post_types ); - foreach ( $this->supported_post_types as $post_type) { + foreach ( self::$supported_post_types as $post_type) { add_post_type_support($post_type, self::key); } From 66755640352d7275efefa9e3d62d689c5efdab55 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Thu, 18 Jan 2018 15:15:38 +0530 Subject: [PATCH 10/17] Add ruleset --- phpcs.xml.dist | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..4f1d0e5cf --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,17 @@ + + + Generally-applicable sniffs for WordPress plugins + + + + + + + . + + + + + */node_modules/* + */vendor/* + From b69ec27dd9ffb63acc1fa439c3c3c5f7c9db1a73 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Thu, 18 Jan 2018 15:20:08 +0530 Subject: [PATCH 11/17] Try adding a conditional to the url endpoint --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index 179e35512..d4bc7203c 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1063,7 +1063,7 @@ private static function get_entries_endpoint_url() { $url = WPCOM_Liveblog_Rest_Api::build_endpoint_base() . self::$post_id . '/'; } else { $post_permalink = get_permalink( self::$post_id ); - if ( false !== strpos( $post_permalink, '?p=' ) ) { + if ( ( false !== strpos( $post_permalink, '?p=' ) ) || ( false !== strpos( $post_permalink, '?page_id=' ) ) ) { $url = add_query_arg( self::url_endpoint, '', $post_permalink ) . '='; // returns something like ?p=1&liveblog= } else { $url = trailingslashit( trailingslashit( $post_permalink ) . self::url_endpoint ); // returns something like /2012/01/01/post/liveblog/ From 0c42d8c028fb8163e1be96503d8cb9c2a0eae1a2 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Thu, 18 Jan 2018 15:23:26 +0530 Subject: [PATCH 12/17] Revert last commit --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index d4bc7203c..179e35512 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1063,7 +1063,7 @@ private static function get_entries_endpoint_url() { $url = WPCOM_Liveblog_Rest_Api::build_endpoint_base() . self::$post_id . '/'; } else { $post_permalink = get_permalink( self::$post_id ); - if ( ( false !== strpos( $post_permalink, '?p=' ) ) || ( false !== strpos( $post_permalink, '?page_id=' ) ) ) { + if ( false !== strpos( $post_permalink, '?p=' ) ) { $url = add_query_arg( self::url_endpoint, '', $post_permalink ) . '='; // returns something like ?p=1&liveblog= } else { $url = trailingslashit( trailingslashit( $post_permalink ) . self::url_endpoint ); // returns something like /2012/01/01/post/liveblog/ From 69bafc4b39b0865eeae7036a75561b5e89b2cb93 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 22 Jan 2018 10:47:44 +0530 Subject: [PATCH 13/17] Remove /nbproject from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index b4faeed47..c03c179a0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ yarn-error.log .svn composer.lock vendor/ -/nbproject # Editor directories and files .idea From 3773a49fc23a18263f3c653a72b7a079596a7efe Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 22 Jan 2018 10:49:35 +0530 Subject: [PATCH 14/17] Add a 'liveblog' prefix to the filter name --- liveblog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index 179e35512..3b79465b8 100644 --- a/liveblog.php +++ b/liveblog.php @@ -245,7 +245,7 @@ public static function init() { /** * This allows the users to filter their supported post types. */ - self::$supported_post_types = apply_filters( 'modify_supported_post_types', $post_types ); + 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); From becefb7c7cf41683b9c31c8ec922b67444f1dad4 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 22 Jan 2018 11:02:27 +0530 Subject: [PATCH 15/17] Remove phpcs.xml.dist which was added by mistake --- phpcs.xml.dist | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 phpcs.xml.dist diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 4f1d0e5cf..000000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,17 +0,0 @@ - - - Generally-applicable sniffs for WordPress plugins - - - - - - - . - - - - - */node_modules/* - */vendor/* - From 7bc535fa118a4328a4c01a14282fd14f46b0f5e2 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 22 Jan 2018 14:42:46 +0530 Subject: [PATCH 16/17] Refine the is_singular() conditional --- liveblog.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liveblog.php b/liveblog.php index 3b79465b8..8804799f4 100644 --- a/liveblog.php +++ b/liveblog.php @@ -461,14 +461,14 @@ public static function is_liveblog_post( $post_id = null ) { * @return bool */ public static function is_viewing_liveblog_post() { - return (bool) ( is_singular() && 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_singular() && ! 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 7ee23c4868ee6243d3bdda06b2cd3025a57de188 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Mon, 22 Jan 2018 14:47:06 +0530 Subject: [PATCH 17/17] Fix formatting --- liveblog.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liveblog.php b/liveblog.php index 8804799f4..63378e340 100644 --- a/liveblog.php +++ b/liveblog.php @@ -461,14 +461,14 @@ public static function is_liveblog_post( $post_id = null ) { * @return bool */ public static function is_viewing_liveblog_post() { - return (bool) ( is_singular(self::$supported_post_types) && 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_singular(self::$supported_post_types) && ! 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 ) ) {