PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | modules/seo-tools/class-jetpack-seo-titles.php +18 -2 12.0.3 → 16.3-beta View file →
@@ -96,10 +96,17 @@
96 96 if ( ! Jetpack_SEO_Utils::is_enabled_jetpack_seo() ) {
97 97 return $default_title;
98 98 }
99 99
100 - // If it's a singular -- page or post -- check for a meta title override.
101 - if ( 'pages' === $page_type || 'posts' === $page_type ) {
100 + // If it's a singular -- page or post -- check for a meta title override. Also
101 + // check a static front page, where get_post() returns that page. On a latest-posts
102 + // homepage it would instead return the first post in the loop, letting the newest
103 + // post's SEO title hijack the homepage title.
104 + $check_post_meta = 'pages' === $page_type
105 + || 'posts' === $page_type
106 + || ( 'front_page' === $page_type && 'page' === get_option( 'show_on_front' ) );
107 +
108 + if ( $check_post_meta ) {
102 109 $post = get_post();
103 110 if ( $post instanceof WP_Post ) {
104 111 $custom_title = get_post_meta( $post->ID, Jetpack_SEO_Posts::HTML_TITLE_META_KEY, true );
105 112 if ( ! empty( trim( $custom_title ) ) ) {
@@ -301,8 +308,14 @@
301 308 * @return array The sanitized array.
302 309 */
303 310 public static function sanitize_title_formats( $title_formats ) {
304 311 foreach ( $title_formats as &$format_array ) {
312 + // The API accepts an empty string as "clear this page type"; store it as
313 + // the empty list every reader expects, and don't iterate a string.
314 + if ( ! is_array( $format_array ) ) {
315 + $format_array = array();
316 + continue;
317 + }
305 318 foreach ( $format_array as &$item ) {
306 319 if ( 'string' === $item['type'] ) {
307 320 // From `wp_strip_all_tags`, but omitting the `trim` portion since we want spacing preserved.
308 321 $item['value'] = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $item['value'] );
@@ -336,9 +349,12 @@
336 349 'groups' => array(),
337 350 'archives' => array(),
338 351 );
339 352
353 + // Sanitize the stored formats too: a page type saved as '' before this guard
354 + // existed would otherwise survive every partial save from Calypso.
340 355 $previous_formats = self::get_custom_title_formats();
356 + $previous_formats = is_array( $previous_formats ) ? self::sanitize_title_formats( $previous_formats ) : array();
341 357
342 358 $result = array_merge( $empty_formats, $previous_formats, $new_formats );
343 359
344 360 if ( update_option( self::TITLE_FORMATS_OPTION, $result ) ) {