From 59855fdfd41d2dcc9ac4c03b6451ac4cc36b4fe3 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 11:48:04 +0100 Subject: [PATCH 01/13] Schema: Refactor array to object conversion Work with the plain array data for as long as possible, and then recursively convert at the end. --- classes/class-wpcom-liveblog-amp.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index 4b9a2b1aa..db8dbdc58 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -206,26 +206,26 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { $publisher_organization = $metadata['publisher']['type']; } - $blog_item = (object) array( + $blog_item = array( '@type' => 'BlogPosting', 'headline' => self::get_entry_title( $entry ), 'url' => $entry->share_link, 'datePublished' => date( 'c', $entry->entry_time ), 'dateModified' => date( 'c', $entry->timestamp ), - 'author' => (object) array( + 'author' => array( '@type' => 'Person', 'name' => $entry->authors[0]['name'], ), - 'articleBody' => (object) array( + 'articleBody' => array( '@type' => 'Text', ), - 'publisher' => (object) array( + 'publisher' => array( '@type' => $publisher_organization, 'name' => $publisher_name, ), ); - array_push( $blog_updates, $blog_item ); + array_push( $blog_updates, json_decode( json_encode( $blog_item ) ) ); } $metadata['@type'] = 'LiveBlogPosting'; From 75bec388893d3713a8fa0b7972b6f9c932053ae0 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 11:50:17 +0100 Subject: [PATCH 02/13] Schema: Return early when there are no entries --- classes/class-wpcom-liveblog-amp.php | 68 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index db8dbdc58..ba18daca2 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -195,43 +195,45 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { $blog_updates = []; - if ( isset( $entries['entries'] ) && is_array( $entries['entries'] ) ) { - foreach ( $entries['entries'] as $key => $entry ) { - - if ( isset( $metadata['publisher']['name'] ) ) { - $publisher_name = $metadata['publisher']['name']; - } - - if ( isset( $metadata['publisher']['type'] ) ) { - $publisher_organization = $metadata['publisher']['type']; - } - - $blog_item = array( - '@type' => 'BlogPosting', - 'headline' => self::get_entry_title( $entry ), - 'url' => $entry->share_link, - 'datePublished' => date( 'c', $entry->entry_time ), - 'dateModified' => date( 'c', $entry->timestamp ), - 'author' => array( - '@type' => 'Person', - 'name' => $entry->authors[0]['name'], - ), - 'articleBody' => array( - '@type' => 'Text', - ), - 'publisher' => array( - '@type' => $publisher_organization, - 'name' => $publisher_name, - ), - ); - - array_push( $blog_updates, json_decode( json_encode( $blog_item ) ) ); + if ( ! isset( $entries[ 'entries' ] ) || ! is_array( $entries[ 'entries' ] ) ) { + return $metadata; + } + + foreach ( $entries[ 'entries' ] as $key => $entry ) { + + if ( isset( $metadata[ 'publisher' ][ 'name' ] ) ) { + $publisher_name = $metadata[ 'publisher' ][ 'name' ]; } - $metadata['@type'] = 'LiveBlogPosting'; - $metadata['liveBlogUpdate'] = $blog_updates; + if ( isset( $metadata[ 'publisher' ][ 'type' ] ) ) { + $publisher_organization = $metadata[ 'publisher' ][ 'type' ]; + } + + $blog_item = [ + '@type' => 'BlogPosting', + 'headline' => self::get_entry_title( $entry ), + 'url' => $entry->share_link, + 'datePublished' => date( 'c', $entry->entry_time ), + 'dateModified' => date( 'c', $entry->timestamp ), + 'author' => [ + '@type' => 'Person', + 'name' => $entry->authors[ 0 ][ 'name' ], + ], + 'articleBody' => [ + '@type' => 'Text', + ], + 'publisher' => [ + '@type' => $publisher_organization, + 'name' => $publisher_name, + ], + ]; + + array_push( $blog_updates, json_decode( json_encode( $blog_item ) ) ); } + $metadata[ '@type' ] = 'LiveBlogPosting'; + $metadata[ 'liveBlogUpdate' ] = $blog_updates; + return $metadata; } From d6a10f251615be3410234136c10dd7f7be070f6e Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 12:01:04 +0100 Subject: [PATCH 03/13] Schema: Consolidate publisher extraction Can't have publisher type without a name, and can't have a name without a type, so consolidate into a single conditional Also checks if the publisher even exists before adding what could otherwise be empty values. --- classes/class-wpcom-liveblog-amp.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index ba18daca2..98734688e 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -188,9 +188,6 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { $request = self::get_request_data(); - $publisher_organization = ''; - $publisher_name = ''; - $entries = WPCOM_Liveblog::get_entries_paged( $request->page, $request->last ); $blog_updates = []; @@ -200,15 +197,6 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { } foreach ( $entries[ 'entries' ] as $key => $entry ) { - - if ( isset( $metadata[ 'publisher' ][ 'name' ] ) ) { - $publisher_name = $metadata[ 'publisher' ][ 'name' ]; - } - - if ( isset( $metadata[ 'publisher' ][ 'type' ] ) ) { - $publisher_organization = $metadata[ 'publisher' ][ 'type' ]; - } - $blog_item = [ '@type' => 'BlogPosting', 'headline' => self::get_entry_title( $entry ), @@ -222,12 +210,15 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { 'articleBody' => [ '@type' => 'Text', ], - 'publisher' => [ - '@type' => $publisher_organization, - 'name' => $publisher_name, - ], ]; + if ( isset( $metadata['publisher'], $metadata['publisher']['name'], $metadata['publisher']['@type'] ) ) { + $blog_item['publisher'] = [ + '@type' => $metadata['publisher']['@type'], + 'name' => $metadata['publisher']['name'] + ]; + } + array_push( $blog_updates, json_decode( json_encode( $blog_item ) ) ); } From 21c770b2347daee35886012fe0c2d8eeaad7e94d Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 12:07:11 +0100 Subject: [PATCH 04/13] Schema: Add support for publisher logo on liveblog If the site icon (in Customizer) is populated, then it is passed through from AMP and added to liveblog entry schema data. See #506. --- classes/class-wpcom-liveblog-amp.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index 98734688e..a0281121c 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -217,6 +217,10 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { '@type' => $metadata['publisher']['@type'], 'name' => $metadata['publisher']['name'] ]; + + if ( isset( $metadata['publisher']['logo'] ) ) { + $blog_item['publisher']['logo'] = $metadata['publisher']['logo']; + } } array_push( $blog_updates, json_decode( json_encode( $blog_item ) ) ); From b99f26d59af0de4ca6d39959affec8dae0560ef9 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 12:18:46 +0100 Subject: [PATCH 05/13] Schema: Avoid array_push() since it is slow --- classes/class-wpcom-liveblog-amp.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index a0281121c..d29dc3eed 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -223,11 +223,11 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { } } - array_push( $blog_updates, json_decode( json_encode( $blog_item ) ) ); + $blog_updates[] = json_decode( json_encode( $blog_item ) ); } - $metadata[ '@type' ] = 'LiveBlogPosting'; - $metadata[ 'liveBlogUpdate' ] = $blog_updates; + $metadata['@type'] = 'LiveBlogPosting'; + $metadata['liveBlogUpdate'] = $blog_updates; return $metadata; } From a5338674bc9e43fcb70acab5e0654530b7aa77c1 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 12:20:06 +0100 Subject: [PATCH 06/13] Schema: Add mainEntityOfPage to liveblog entry This is a recommended property for BlogPosting. See #506. --- classes/class-wpcom-liveblog-amp.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index d29dc3eed..23faf7fb1 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -198,16 +198,17 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { foreach ( $entries[ 'entries' ] as $key => $entry ) { $blog_item = [ - '@type' => 'BlogPosting', - 'headline' => self::get_entry_title( $entry ), - 'url' => $entry->share_link, - 'datePublished' => date( 'c', $entry->entry_time ), - 'dateModified' => date( 'c', $entry->timestamp ), - 'author' => [ + '@type' => 'BlogPosting', + 'headline' => self::get_entry_title( $entry ), + 'url' => $entry->share_link, + 'mainEntityOfPage' => $entry->share_link, + 'datePublished' => date( 'c', $entry->entry_time ), + 'dateModified' => date( 'c', $entry->timestamp ), + 'author' => [ '@type' => 'Person', 'name' => $entry->authors[ 0 ][ 'name' ], ], - 'articleBody' => [ + 'articleBody' => [ '@type' => 'Text', ], ]; From 6b5b1d2bc44d64d371131b51a98cca330283ba09 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 7 Aug 2018 12:53:29 +0100 Subject: [PATCH 07/13] Schema: Simplify publisher data Just use the AMP-supplied publisher data as is, if it exists (which it should, to be valid in AMP). --- classes/class-wpcom-liveblog-amp.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index 23faf7fb1..69fc9532f 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -213,15 +213,8 @@ public static function append_liveblog_to_metadata( $metadata, $post ) { ], ]; - if ( isset( $metadata['publisher'], $metadata['publisher']['name'], $metadata['publisher']['@type'] ) ) { - $blog_item['publisher'] = [ - '@type' => $metadata['publisher']['@type'], - 'name' => $metadata['publisher']['name'] - ]; - - if ( isset( $metadata['publisher']['logo'] ) ) { - $blog_item['publisher']['logo'] = $metadata['publisher']['logo']; - } + if ( isset( $metadata['publisher'] ) ) { + $blog_item['publisher'] = $metadata['publisher']; } $blog_updates[] = json_decode( json_encode( $blog_item ) ); From 66922c04609d1e0c56336b0390145a1905c76cf3 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 12 Aug 2018 13:47:07 +0100 Subject: [PATCH 08/13] Schema: Abstract out the metadata generation and apply to non-AMP liveblogs Moves the actual generation of the Liveblog metadata into it's own helper function in the main WPCOM_Liveblog class and then uses that function to output the metadata in both the AMP and non-AMP versions of a Liveblog. --- classes/class-wpcom-liveblog-amp.php | 46 +++-------------- liveblog.php | 75 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 40 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index 69fc9532f..5aa4a5474 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -181,48 +181,14 @@ public static function get_entry_image( $entry ) { */ public static function append_liveblog_to_metadata( $metadata, $post ) { - // If we are not viewing a liveblog post then exist the filter. - if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { - return $metadata; + // Only append metadata to Liveblogs. + if ( false !== WPCOM_Liveblog::is_liveblog_post( $post->ID ) ) { + /** + * This filter is documented in liveblog.php + */ + $metadata = WPCOM_Liveblog::get_liveblog_metadata(); } - $request = self::get_request_data(); - - $entries = WPCOM_Liveblog::get_entries_paged( $request->page, $request->last ); - - $blog_updates = []; - - if ( ! isset( $entries[ 'entries' ] ) || ! is_array( $entries[ 'entries' ] ) ) { - return $metadata; - } - - foreach ( $entries[ 'entries' ] as $key => $entry ) { - $blog_item = [ - '@type' => 'BlogPosting', - 'headline' => self::get_entry_title( $entry ), - 'url' => $entry->share_link, - 'mainEntityOfPage' => $entry->share_link, - 'datePublished' => date( 'c', $entry->entry_time ), - 'dateModified' => date( 'c', $entry->timestamp ), - 'author' => [ - '@type' => 'Person', - 'name' => $entry->authors[ 0 ][ 'name' ], - ], - 'articleBody' => [ - '@type' => 'Text', - ], - ]; - - if ( isset( $metadata['publisher'] ) ) { - $blog_item['publisher'] = $metadata['publisher']; - } - - $blog_updates[] = json_decode( json_encode( $blog_item ) ); - } - - $metadata['@type'] = 'LiveBlogPosting'; - $metadata['liveBlogUpdate'] = $blog_updates; - return $metadata; } diff --git a/liveblog.php b/liveblog.php index 420623a71..d353953f7 100644 --- a/liveblog.php +++ b/liveblog.php @@ -173,6 +173,7 @@ private static function add_actions() { add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) ); add_action( 'wp_ajax_set_liveblog_state_for_post', array( __CLASS__, 'admin_ajax_set_liveblog_state_for_post' ) ); add_action( 'pre_get_posts', array( __CLASS__, 'add_custom_post_type_support' ) ); + add_action( 'wp_head', array( __CLASS__, 'print_liveblog_metadata' ) ); } /** @@ -1771,6 +1772,80 @@ public static function get_refresh_interval() { return $refresh_interval; } + /** + * Generates metadata for a single liveblog + * + * @param array $metadata Metadata. + * @param WP_Post $post Current Post. + * @return array Updated Meta + */ + public static function get_liveblog_metadata() { + + // If we are not viewing a liveblog post then exist the filter. + if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { + return $metadata; + } + + $request = self::get_request_data(); + + $entries = WPCOM_Liveblog::get_entries_paged( $request->page, $request->last ); + + $blog_updates = []; + + if ( ! isset( $entries[ 'entries' ] ) || ! is_array( $entries[ 'entries' ] ) ) { + return $metadata; + } + + foreach ( $entries[ 'entries' ] as $key => $entry ) { + $blog_item = [ + '@type' => 'BlogPosting', + 'headline' => self::get_entry_title( $entry ), + 'url' => $entry->share_link, + 'mainEntityOfPage' => $entry->share_link, + 'datePublished' => date( 'c', $entry->entry_time ), + 'dateModified' => date( 'c', $entry->timestamp ), + 'author' => [ + '@type' => 'Person', + 'name' => $entry->authors[ 0 ][ 'name' ], + ], + 'articleBody' => [ + '@type' => 'Text', + ], + ]; + + if ( isset( $metadata['publisher'] ) ) { + $blog_item['publisher'] = $metadata['publisher']; + } + + $blog_updates[] = json_decode( json_encode( $blog_item ) ); + } + + $metadata['@type'] = 'LiveBlogPosting'; + $metadata['liveBlogUpdate'] = $blog_updates; + + apply_filters( 'liveblog_metadata', $metadata, $post ); + + return $metadata; + } + + public function print_liveblog_metadata() { + + // Bail if we are not viewing a liveblog. + if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { + return; + } + + $metadata = self::get_liveblog_metadata(); + if ( empty( $metadata ) ) { + return; + } + + ?> + + Date: Sun, 12 Aug 2018 13:52:08 +0100 Subject: [PATCH 09/13] Schema: Abstract out the request data getter. --- classes/class-wpcom-liveblog-amp.php | 17 ++--------------- liveblog.php | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index 5aa4a5474..c9ca28be4 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -124,7 +124,7 @@ public static function social_meta_tags() { return; } - $request = self::get_request_data(); + $request = WPCOM_Liveblog::get_request_data(); // If no entry id set then not on single entry. if ( false === $request->id ) { @@ -205,7 +205,7 @@ public static function append_liveblog_to_content( $content ) { return $content; } - $request = self::get_request_data(); + $request = WPCOM_Liveblog::get_request_data(); if ( $request->id ) { $entries = WPCOM_Liveblog::get_entries_paged( false, false, $request->id ); @@ -436,19 +436,6 @@ public static function build_single_entry_permalink( $permalink, $id ) { ); } - /** - * Get Page and Last known entry from the request. - * - * @return object Request Data. - */ - public static function get_request_data() { - return (object) array( - 'page' => get_query_var( 'liveblog_page', 1 ), - 'last' => get_query_var( 'liveblog_last', false ), - 'id' => get_query_var( 'liveblog_id', false ), - ); - } - /** * Get template. * diff --git a/liveblog.php b/liveblog.php index d353953f7..9c15f1255 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1781,6 +1781,8 @@ public static function get_refresh_interval() { */ public static function get_liveblog_metadata() { + global $post; + // If we are not viewing a liveblog post then exist the filter. if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { return $metadata; @@ -1828,14 +1830,16 @@ public static function get_liveblog_metadata() { return $metadata; } - public function print_liveblog_metadata() { + public static function print_liveblog_metadata() { + + global $post; // Bail if we are not viewing a liveblog. if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { return; } - $metadata = self::get_liveblog_metadata(); + $metadata = WPCOM_Liveblog::get_liveblog_metadata(); if ( empty( $metadata ) ) { return; } @@ -1846,6 +1850,19 @@ public function print_liveblog_metadata() { } + /** + * Get Page and Last known entry from the request. + * + * @return object Request Data. + */ + public static function get_request_data() { + return (object) array( + 'page' => get_query_var( 'liveblog_page', 1 ), + 'last' => get_query_var( 'liveblog_last', false ), + 'id' => get_query_var( 'liveblog_id', false ), + ); + } + } WPCOM_Liveblog::load(); From 38e11dbfc2299a704c0e243cd1b40e5ff77ea953 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 12 Aug 2018 13:54:27 +0100 Subject: [PATCH 10/13] Schema: Abstract out get_entry_title() --- classes/class-wpcom-liveblog-amp.php | 12 +----------- classes/class-wpcom-liveblog-entry.php | 11 +++++++++++ liveblog.php | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/classes/class-wpcom-liveblog-amp.php b/classes/class-wpcom-liveblog-amp.php index c9ca28be4..c6e99b3cb 100644 --- a/classes/class-wpcom-liveblog-amp.php +++ b/classes/class-wpcom-liveblog-amp.php @@ -132,7 +132,7 @@ public static function social_meta_tags() { } $entry = self::get_entry( $request->id, $post->ID ); - $title = self::get_entry_title( $entry ); + $title = WPCOM_Liveblog_Entry::get_entry_title( $entry ); $description = strip_tags( $entry->content ); $url = self::build_single_entry_permalink( amp_get_permalink( $post->ID ), $entry->id ); $image = self::get_entry_image( $entry ); @@ -365,16 +365,6 @@ public static function get_entry_date( $entry ) { return date_i18n( $date_format, strtotime( $utc_offset, $entry->entry_time ) ); } - /** - * Work out Entry title - * - * @param object $entry Entry. - * @return string Title - */ - public static function get_entry_title( $entry ) { - return wp_trim_words( $entry->content, 10, '...' ); - } - /** * Gets Pagination Links (First, Last, Next, Previous) * diff --git a/classes/class-wpcom-liveblog-entry.php b/classes/class-wpcom-liveblog-entry.php index f07b57d5a..90c3f94b1 100644 --- a/classes/class-wpcom-liveblog-entry.php +++ b/classes/class-wpcom-liveblog-entry.php @@ -492,6 +492,17 @@ public static function get_authors( $comment_id ) { return array_merge( $author, $contributors ); } + + /** + * Work out Entry title + * + * @param object $entry Entry. + * @return string Title + */ + public static function get_entry_title( $entry ) { + return wp_trim_words( $entry->content, 10, '...' ); + } + } WPCOM_Liveblog_Entry::generate_allowed_tags_for_entry(); diff --git a/liveblog.php b/liveblog.php index 9c15f1255..86b456bea 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1801,7 +1801,7 @@ public static function get_liveblog_metadata() { foreach ( $entries[ 'entries' ] as $key => $entry ) { $blog_item = [ '@type' => 'BlogPosting', - 'headline' => self::get_entry_title( $entry ), + 'headline' => WPCOM_Liveblog_Entry::get_entry_title( $entry ), 'url' => $entry->share_link, 'mainEntityOfPage' => $entry->share_link, 'datePublished' => date( 'c', $entry->entry_time ), From c1ff769fa86ed6cf7a5eff5657df5a168a23dff4 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sun, 12 Aug 2018 14:02:37 +0100 Subject: [PATCH 11/13] Schema: Document the filter. Also make sure it's actually used! --- liveblog.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/liveblog.php b/liveblog.php index 86b456bea..8bc5254cf 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1825,7 +1825,17 @@ public static function get_liveblog_metadata() { $metadata['@type'] = 'LiveBlogPosting'; $metadata['liveBlogUpdate'] = $blog_updates; - apply_filters( 'liveblog_metadata', $metadata, $post ); + /** + * Filters lhe Liveblog metadata. + * + * Allows plugins and themes to adapt the metadata printed by the + * liveblog into the head, describing the liveblog and it's entries. + * + * @since 1.9 + * + * @param array $metadata An array of metadata. + */ + $metadata = apply_filters( 'liveblog_metadata', $metadata, $post ); return $metadata; } From 56012aab6e4849f9b11ae1c449d12d520a3b8079 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 8 Sep 2018 11:02:09 +0100 Subject: [PATCH 12/13] Fix spelling mistakes. --- liveblog.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liveblog.php b/liveblog.php index 8bc5254cf..ce51c1b38 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1783,7 +1783,7 @@ public static function get_liveblog_metadata() { global $post; - // If we are not viewing a liveblog post then exist the filter. + // If we are not viewing a liveblog post then exit the filter. if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { return $metadata; } @@ -1826,7 +1826,7 @@ public static function get_liveblog_metadata() { $metadata['liveBlogUpdate'] = $blog_updates; /** - * Filters lhe Liveblog metadata. + * Filters the Liveblog metadata. * * Allows plugins and themes to adapt the metadata printed by the * liveblog into the head, describing the liveblog and it's entries. From a633b1f8653f1cb5938b9d9e81ce7a6edcd8063a Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 8 Sep 2018 11:07:41 +0100 Subject: [PATCH 13/13] Use get_the_ID() rather than grabbing the `$post` global. --- liveblog.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/liveblog.php b/liveblog.php index ce51c1b38..99f650528 100644 --- a/liveblog.php +++ b/liveblog.php @@ -1842,10 +1842,8 @@ public static function get_liveblog_metadata() { public static function print_liveblog_metadata() { - global $post; - // Bail if we are not viewing a liveblog. - if ( WPCOM_Liveblog::is_liveblog_post( $post->ID ) === false ) { + if ( WPCOM_Liveblog::is_liveblog_post( get_the_ID() ) === false ) { return; }