| @@ -50,29 +50,30 @@ | ||
| 50 | 50 | * |
| 51 | 51 | * @var array |
| 52 | 52 | */ |
| 53 | 53 | public static $defaults_per_term = [ |
| 54 | - 'wpseo_title' => '', | |
| 55 | - 'wpseo_desc' => '', | |
| 56 | - 'wpseo_canonical' => '', | |
| 57 | - 'wpseo_bctitle' => '', | |
| 58 | - 'wpseo_noindex' => 'default', | |
| 59 | - 'wpseo_focuskw' => '', | |
| 60 | - 'wpseo_linkdex' => '', | |
| 61 | - 'wpseo_content_score' => '', | |
| 62 | - 'wpseo_focuskeywords' => '[]', | |
| 63 | - 'wpseo_keywordsynonyms' => '[]', | |
| 64 | - 'wpseo_is_cornerstone' => '0', | |
| 54 | + 'wpseo_title' => '', | |
| 55 | + 'wpseo_desc' => '', | |
| 56 | + 'wpseo_canonical' => '', | |
| 57 | + 'wpseo_bctitle' => '', | |
| 58 | + 'wpseo_noindex' => 'default', | |
| 59 | + 'wpseo_focuskw' => '', | |
| 60 | + 'wpseo_linkdex' => '', | |
| 61 | + 'wpseo_content_score' => '', | |
| 62 | + 'wpseo_inclusive_language_score' => '', | |
| 63 | + 'wpseo_focuskeywords' => '[]', | |
| 64 | + 'wpseo_keywordsynonyms' => '[]', | |
| 65 | + 'wpseo_is_cornerstone' => '0', | |
| 65 | 66 | |
| 66 | 67 | // Social fields. |
| 67 | - 'wpseo_opengraph-title' => '', | |
| 68 | - 'wpseo_opengraph-description' => '', | |
| 69 | - 'wpseo_opengraph-image' => '', | |
| 70 | - 'wpseo_opengraph-image-id' => '', | |
| 71 | - 'wpseo_twitter-title' => '', | |
| 72 | - 'wpseo_twitter-description' => '', | |
| 73 | - 'wpseo_twitter-image' => '', | |
| 74 | - 'wpseo_twitter-image-id' => '', | |
| 68 | + 'wpseo_opengraph-title' => '', | |
| 69 | + 'wpseo_opengraph-description' => '', | |
| 70 | + 'wpseo_opengraph-image' => '', | |
| 71 | + 'wpseo_opengraph-image-id' => '', | |
| 72 | + 'wpseo_twitter-title' => '', | |
| 73 | + 'wpseo_twitter-description' => '', | |
| 74 | + 'wpseo_twitter-image' => '', | |
| 75 | + 'wpseo_twitter-image-id' => '', | |
| 75 | 76 | ]; |
| 76 | 77 | |
| 77 | 78 | /** |
| 78 | 79 | * Available index options. |
| @@ -117,8 +118,10 @@ | ||
| 117 | 118 | } |
| 118 | 119 | |
| 119 | 120 | /** |
| 120 | 121 | * Add extra default options received from a filter. |
| 122 | + * | |
| 123 | + * @return void | |
| 121 | 124 | */ |
| 122 | 125 | public function enrich_defaults() { |
| 123 | 126 | $extra_defaults_per_term = apply_filters( 'wpseo_add_extra_taxmeta_term_defaults', [] ); |
| 124 | 127 | if ( is_array( $extra_defaults_per_term ) ) { |
| @@ -233,9 +236,11 @@ | ||
| 233 | 236 | |
| 234 | 237 | case 'wpseo_keywordsynonyms': |
| 235 | 238 | if ( isset( $meta_data[ $key ] ) && is_string( $meta_data[ $key ] ) ) { |
| 236 | 239 | // The data is stringified JSON. Use `json_decode` and `json_encode` around the sanitation. |
| 237 | - $input = json_decode( $meta_data[ $key ], true ); | |
| 240 | + $input = json_decode( $meta_data[ $key ], true ); | |
| 241 | + // If something is wrong with the JSON make sure this cannot break. | |
| 242 | + $input ??= []; | |
| 238 | 243 | $sanitized = array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], $input ); |
| 239 | 244 | $clean[ $key ] = WPSEO_Utils::format_json_encode( $sanitized ); |
| 240 | 245 | } |
| 241 | 246 | elseif ( isset( $old_meta[ $key ] ) ) { |
| @@ -289,9 +294,9 @@ | ||
| 289 | 294 | } |
| 290 | 295 | break; |
| 291 | 296 | } |
| 292 | 297 | |
| 293 | - $clean[ $key ] = apply_filters( 'wpseo_sanitize_tax_meta_' . $key, $clean[ $key ], ( isset( $meta_data[ $key ] ) ? $meta_data[ $key ] : null ), ( isset( $old_meta[ $key ] ) ? $old_meta[ $key ] : null ) ); | |
| 298 | + $clean[ $key ] = apply_filters( 'wpseo_sanitize_tax_meta_' . $key, $clean[ $key ], ( $meta_data[ $key ] ?? null ), ( $old_meta[ $key ] ?? null ) ); | |
| 294 | 299 | } |
| 295 | 300 | |
| 296 | 301 | // Only save the non-default values. |
| 297 | 302 | return array_diff_assoc( $clean, self::$defaults_per_term ); |
| @@ -407,9 +412,8 @@ | ||
| 407 | 412 | if ( ! isset( $meta ) ) { |
| 408 | 413 | return $tax_meta; |
| 409 | 414 | } |
| 410 | 415 | |
| 411 | - | |
| 412 | 416 | if ( isset( $tax_meta[ 'wpseo_' . $meta ] ) ) { |
| 413 | 417 | return $tax_meta[ 'wpseo_' . $meta ]; |
| 414 | 418 | } |
| 415 | 419 | |
| @@ -437,8 +441,10 @@ | ||
| 437 | 441 | * |
| 438 | 442 | * @param int $term_id ID of the term to save data for. |
| 439 | 443 | * @param string $taxonomy The taxonomy the term belongs to. |
| 440 | 444 | * @param array $meta_values The values that will be saved. |
| 445 | + * | |
| 446 | + * @return void | |
| 441 | 447 | */ |
| 442 | 448 | public static function set_values( $term_id, $taxonomy, array $meta_values ) { |
| 443 | 449 | /* Validate the post values */ |
| 444 | 450 | $old = self::get_term_meta( $term_id, $taxonomy ); |
| @@ -453,8 +459,10 @@ | ||
| 453 | 459 | * @param int $term_id ID of the term to save data for. |
| 454 | 460 | * @param string $taxonomy The taxonomy the term belongs to. |
| 455 | 461 | * @param string $meta_key The target meta key to store the value in. |
| 456 | 462 | * @param string $meta_value The value of the target meta key. |
| 463 | + * | |
| 464 | + * @return void | |
| 457 | 465 | */ |
| 458 | 466 | public static function set_value( $term_id, $taxonomy, $meta_key, $meta_value ) { |
| 459 | 467 | |
| 460 | 468 | if ( substr( strtolower( $meta_key ), 0, 6 ) !== 'wpseo_' ) { |
| @@ -475,9 +483,8 @@ | ||
| 475 | 483 | */ |
| 476 | 484 | public static function get_keyword_usage( $keyword, $current_term_id, $current_taxonomy ) { |
| 477 | 485 | $tax_meta = self::get_tax_meta(); |
| 478 | 486 | |
| 479 | - | |
| 480 | 487 | $found = []; |
| 481 | 488 | // @todo Check for terms of all taxonomies, not only the current taxonomy. |
| 482 | 489 | foreach ( $tax_meta as $taxonomy_name => $terms ) { |
| 483 | 490 | foreach ( $terms as $term_id => $meta_values ) { |
| @@ -496,8 +503,10 @@ | ||
| 496 | 503 | * |
| 497 | 504 | * @param int $term_id ID of the term to save data for. |
| 498 | 505 | * @param string $taxonomy The taxonomy the term belongs to. |
| 499 | 506 | * @param array $clean Array with clean values. |
| 507 | + * | |
| 508 | + * @return void | |
| 500 | 509 | */ |
| 501 | 510 | private static function save_clean_values( $term_id, $taxonomy, array $clean ) { |
| 502 | 511 | $tax_meta = self::get_tax_meta(); |
| 503 | 512 | |
| @@ -520,9 +529,9 @@ | ||
| 520 | 529 | |
| 521 | 530 | /** |
| 522 | 531 | * Getting the meta from the options. |
| 523 | 532 | * |
| 524 | - * @return void|array | |
| 533 | + * @return array|void | |
| 525 | 534 | */ |
| 526 | 535 | private static function get_tax_meta() { |
| 527 | 536 | return get_option( self::$name ); |
| 528 | 537 | } |
| @@ -530,8 +539,10 @@ | ||
| 530 | 539 | /** |
| 531 | 540 | * Saving the tax meta values to the database. |
| 532 | 541 | * |
| 533 | 542 | * @param array $tax_meta Array with the meta values for taxonomy. |
| 543 | + * | |
| 544 | + * @return void | |
| 534 | 545 | */ |
| 535 | 546 | private static function save_tax_meta( $tax_meta ) { |
| 536 | 547 | update_option( self::$name, $tax_meta ); |
| 537 | 548 | } |