| @@ -308,8 +308,14 @@ | ||
| 308 | 308 | * @return array The sanitized array. |
| 309 | 309 | */ |
| 310 | 310 | public static function sanitize_title_formats( $title_formats ) { |
| 311 | 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 | + } | |
| 312 | 318 | foreach ( $format_array as &$item ) { |
| 313 | 319 | if ( 'string' === $item['type'] ) { |
| 314 | 320 | // From `wp_strip_all_tags`, but omitting the `trim` portion since we want spacing preserved. |
| 315 | 321 | $item['value'] = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $item['value'] ); |
| @@ -343,9 +349,12 @@ | ||
| 343 | 349 | 'groups' => array(), |
| 344 | 350 | 'archives' => array(), |
| 345 | 351 | ); |
| 346 | 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. | |
| 347 | 355 | $previous_formats = self::get_custom_title_formats(); |
| 356 | + $previous_formats = is_array( $previous_formats ) ? self::sanitize_title_formats( $previous_formats ) : array(); | |
| 348 | 357 | |
| 349 | 358 | $result = array_merge( $empty_formats, $previous_formats, $new_formats ); |
| 350 | 359 | |
| 351 | 360 | if ( update_option( self::TITLE_FORMATS_OPTION, $result ) ) { |