PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
← All changes | inc/options/class-wpseo-option-titles.php +74 -91 18.6 → trunk View file →
@@ -25,9 +25,9 @@
25 25 * Shouldn't be requested directly, use $this->get_defaults();
26 26 *
27 27 * {@internal Note: Some of the default values are added via the translate_defaults() method.}}
28 28 *
29 - * @var array
29 + * @var string[]
30 30 */
31 31 protected $defaults = [
32 32 // Form fields.
33 33 'forcerewritetitle' => false,
@@ -69,9 +69,9 @@
69 69 'breadcrumbs-enable' => true,
70 70 'breadcrumbs-home' => '', // Text field.
71 71 'breadcrumbs-prefix' => '', // Text field.
72 72 'breadcrumbs-searchprefix' => '', // Text field.
73 - 'breadcrumbs-sep' => '»', // Text field.
73 + 'breadcrumbs-sep' => '»', // Text field.
74 74
75 75 'website_name' => '',
76 76 'person_name' => '',
77 77 'person_logo' => '',
@@ -81,8 +81,9 @@
81 81 'company_logo_id' => 0,
82 82 'company_logo_meta' => false,
83 83 'person_logo_meta' => false,
84 84 'company_name' => '',
85 + 'company_alternate_name' => '',
85 86 'company_or_person' => 'company',
86 87 'company_or_person_user_id' => false,
87 88
88 89 'stripcategorybase' => false,
@@ -91,8 +92,30 @@
91 92 'open_graph_frontpage_desc' => '', // Text field.
92 93 'open_graph_frontpage_image' => '', // Text field.
93 94 'open_graph_frontpage_image_id' => 0,
94 95
96 + 'publishing_principles_id' => 0,
97 + 'ownership_funding_info_id' => 0,
98 + 'actionable_feedback_policy_id' => 0,
99 + 'corrections_policy_id' => 0,
100 + 'ethics_policy_id' => 0,
101 + 'diversity_policy_id' => 0,
102 + 'diversity_staffing_report_id' => 0,
103 +
104 + 'org-description' => '',
105 + 'org-email' => '',
106 + 'org-phone' => '',
107 + 'org-legal-name' => '',
108 + 'org-founding-date' => '',
109 + 'org-number-employees' => '',
110 +
111 + 'org-vat-id' => '',
112 + 'org-tax-id' => '',
113 + 'org-iso' => '',
114 + 'org-duns' => '',
115 + 'org-leicode' => '',
116 + 'org-naics' => '',
117 +
95 118 /*
96 119 * Uses enrich_defaults to add more along the lines of:
97 120 * - 'title-' . $pt->name => ''; // Text field.
98 121 * - 'metadesc-' . $pt->name => ''; // Text field.
@@ -116,9 +139,9 @@
116 139
117 140 /**
118 141 * Used for "caching" during pageload.
119 142 *
120 - * @var array
143 + * @var string[]|null
121 144 */
122 145 protected $enriched_defaults = null;
123 146
124 147 /**
@@ -123,9 +146,9 @@
123 146
124 147 /**
125 148 * Array of variable option name patterns for the option.
126 149 *
127 - * @var array
150 + * @var string[]
128 151 */
129 152 protected $variable_array_key_patterns = [
130 153 'title-',
131 154 'metadesc-',
@@ -139,14 +162,15 @@
139 162 'social-title-',
140 163 'social-description-',
141 164 'social-image-url-',
142 165 'social-image-id-',
166 + 'org-',
143 167 ];
144 168
145 169 /**
146 170 * Array of sub-options which should not be overloaded with multi-site defaults.
147 171 *
148 - * @var array
172 + * @var string[]
149 173 */
150 174 public $ms_exclude = [
151 175 'forcerewritetitle',
152 176 ];
@@ -172,8 +196,10 @@
172 196 }
173 197
174 198 /**
175 199 * Make sure we can recognize the right action for the double cleaning.
200 + *
201 + * @return void
176 202 */
177 203 public function end_of_init() {
178 204 do_action( 'wpseo_double_clean_titles' );
179 205 }
@@ -193,9 +219,9 @@
193 219
194 220 /**
195 221 * Get the available separator options.
196 222 *
197 - * @return array
223 + * @return string[]
198 224 */
199 225 public function get_separator_options() {
200 226 $separators = wp_list_pluck( self::get_separator_option_list(), 'option' );
201 227
@@ -201,9 +227,9 @@
201 227
202 228 /**
203 229 * Allow altering the array with separator options.
204 230 *
205 - * @api array $separator_options Array with the separator options.
231 + * @param array $separator_options Array with the separator options.
206 232 */
207 233 $filtered_separators = apply_filters( 'wpseo_separator_options', $separators );
208 234
209 235 if ( is_array( $filtered_separators ) && $filtered_separators !== [] ) {
@@ -215,9 +241,9 @@
215 241
216 242 /**
217 243 * Get the available separator options aria-labels.
218 244 *
219 - * @return array Array with the separator options aria-labels.
245 + * @return string[] Array with the separator options aria-labels.
220 246 */
221 247 public function get_separator_options_for_display() {
222 248 $separators = $this->get_separator_options();
223 249 $separator_list = self::get_separator_option_list();
@@ -224,9 +250,9 @@
224 250
225 251 $separator_options = [];
226 252
227 253 foreach ( $separators as $key => $label ) {
228 - $aria_label = isset( $separator_list[ $key ]['label'] ) ? $separator_list[ $key ]['label'] : '';
254 + $aria_label = ( $separator_list[ $key ]['label'] ?? '' );
229 255
230 256 $separator_options[ $key ] = [
231 257 'label' => $label,
232 258 'aria_label' => $aria_label,
@@ -329,11 +355,9 @@
329 355 $enriched_defaults[ 'social-description-tax-' . $tax->name ] = ''; // Text area.
330 356 $enriched_defaults[ 'social-image-url-tax-' . $tax->name ] = ''; // Hidden input field.
331 357 $enriched_defaults[ 'social-image-id-tax-' . $tax->name ] = 0; // Hidden input field.
332 358
333 - if ( ! $tax->_builtin ) {
334 - $enriched_defaults[ 'taxonomy-' . $tax->name . '-ptparent' ] = 0; // Select box;.
335 - }
359 + $enriched_defaults[ 'taxonomy-' . $tax->name . '-ptparent' ] = 0; // Select box;.
336 360 }
337 361 }
338 362
339 363 $this->enriched_defaults = $enriched_defaults;
@@ -355,13 +379,13 @@
355 379
356 380 /**
357 381 * Validate the option.
358 382 *
359 - * @param array $dirty New value for the option.
360 - * @param array $clean Clean value for the option, normally the defaults.
361 - * @param array $old Old value of the option.
383 + * @param string[] $dirty New value for the option.
384 + * @param string[] $clean Clean value for the option, normally the defaults.
385 + * @param string[] $old Old value of the option.
362 386 *
363 - * @return array Validated clean value for the option to be saved to the database.
387 + * @return string[] Validated clean value for the option to be saved to the database.
364 388 */
365 389 protected function validate_option( $dirty, $clean, $old ) {
366 390 $allowed_post_types = $this->get_allowed_post_types();
367 391
@@ -405,8 +429,9 @@
405 429 * 'social-title-tax-' . $tax->name
406 430 * 'social-title-author-wpseo', 'social-title-archive-wpseo'
407 431 * 'open_graph_frontpage_title'
408 432 */
433 + case 'org-':
409 434 case 'website_name':
410 435 case 'alternate_website_name':
411 436 case 'title-':
412 437 case 'social-title-':
@@ -468,8 +493,9 @@
468 493 */
469 494 case 'metadesc-':
470 495 case 'bctitle-ptarchive-':
471 496 case 'company_name':
497 + case 'company_alternate_name':
472 498 case 'person_name':
473 499 case 'social-description-':
474 500 case 'open_graph_frontpage_desc':
475 501 if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
@@ -516,9 +542,9 @@
516 542 $this->group_name, // Slug title of the setting.
517 543 $key, // Suffix-id for the error message box.
518 544 /* translators: %s expands to a post type. */
519 545 sprintf( __( 'Please select a valid taxonomy for post type "%s"', 'wordpress-seo' ), $post_type ), // The error message.
520 - 'error' // Message type.
546 + 'error', // Message type.
521 547 );
522 548 }
523 549 }
524 550 elseif ( isset( $old[ $key ] ) ) {
@@ -554,9 +580,9 @@
554 580 $this->group_name, // Slug title of the setting.
555 581 '_' . $tax, // Suffix-ID for the error message box.
556 582 /* translators: %s expands to a taxonomy slug. */
557 583 sprintf( __( 'Please select a valid post type for taxonomy "%s"', 'wordpress-seo' ), $tax ), // The error message.
558 - 'error' // Message type.
584 + 'error', // Message type.
559 585 );
560 586 unset( $tax );
561 587 }
562 588 }
@@ -578,8 +604,15 @@
578 604 case 'company_logo_id':
579 605 case 'person_logo_id':
580 606 case 'social-image-id-':
581 607 case 'open_graph_frontpage_image_id':
608 + case 'publishing_principles_id':
609 + case 'ownership_funding_info_id':
610 + case 'actionable_feedback_policy_id':
611 + case 'corrections_policy_id':
612 + case 'ethics_policy_id':
613 + case 'diversity_policy_id':
614 + case 'diversity_staffing_report_id':
582 615 if ( isset( $dirty[ $key ] ) ) {
583 616 $int = WPSEO_Utils::validate_int( $dirty[ $key ] );
584 617 if ( $int !== false && $int >= 0 ) {
585 618 $clean[ $key ] = $int;
@@ -591,9 +624,8 @@
591 624 $clean[ $key ] = $int;
592 625 }
593 626 }
594 627 break;
595 -
596 628 /* Separator field - Radio. */
597 629 case 'separator':
598 630 if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
599 631
@@ -625,9 +657,9 @@
625 657 * Filter: 'wpseo_schema_article_types' - Allow developers to filter the available article types.
626 658 *
627 659 * Make sure when you filter this to also filter `wpseo_schema_article_types_labels`.
628 660 *
629 - * @api array $schema_article_types The available schema article types.
661 + * @param array $schema_article_types The available schema article types.
630 662 */
631 663 if ( array_key_exists( $dirty[ $key ], apply_filters( 'wpseo_schema_article_types', Schema_Types::ARTICLE_TYPES ) ) ) {
632 664 $clean[ $key ] = $dirty[ $key ];
633 665 }
@@ -679,9 +711,9 @@
679 711 * Helper method for validation.
680 712 *
681 713 * {@internal Don't make static as new types may still be registered.}}
682 714 *
683 - * @return array
715 + * @return string[]
684 716 */
685 717 protected function get_allowed_post_types() {
686 718 $allowed_post_types = [];
687 719
@@ -707,16 +739,13 @@
707 739
708 740 /**
709 741 * Clean a given option value.
710 742 *
711 - * @param array $option_value Old (not merged with defaults or filtered) option value to
712 - * clean according to the rules for this option.
713 - * @param string|null $current_version Optional. Version from which to upgrade, if not set,
714 - * version specific upgrades will be disregarded.
715 - * @param array|null $all_old_option_values Optional. Only used when importing old options to have
716 - * access to the real old values, in contrast to the saved ones.
743 + * @param string[] $option_value Old (not merged with defaults or filtered) option value to clean according to the rules for this option.
744 + * @param string[]|null $current_version Optional. Version from which to upgrade, if not set, version specific upgrades will be disregarded.
745 + * @param string[]|null $all_old_option_values Optional. Only used when importing old options to have access to the real old values, in contrast to the saved ones.
717 746 *
718 - * @return array Cleaned option.
747 + * @return string[] Cleaned option.
719 748 */
720 749 protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) {
721 750 static $original = null;
722 751
@@ -763,15 +792,13 @@
763 792 unset( $move, $old, $new );
764 793 }
765 794 unset( $old_option );
766 795
767 -
768 796 // Fix wrongness created by buggy version 1.2.2.
769 797 if ( isset( $option_value['title-home'] ) && $option_value['title-home'] === '%%sitename%% - %%sitedesc%% - 12345' ) {
770 798 $option_value['title-home-wpseo'] = '%%sitename%% - %%sitedesc%%';
771 799 }
772 800
773 -
774 801 /*
775 802 * Renaming these options to avoid ever overwritting these if a (bloody stupid) user /
776 803 * programmer would use any of the following as a custom post type or custom taxonomy:
777 804 * 'home', 'author', 'archive', 'search', '404', 'subpages'.
@@ -798,20 +825,18 @@
798 825 }
799 826 }
800 827 unset( $rename, $old, $new );
801 828
802 -
803 829 /*
804 830 * {@internal This clean-up action can only be done effectively once the taxonomies
805 831 * and post_types have been registered, i.e. at the end of the init action.}}
806 832 */
807 - if ( isset( $original ) && current_filter() === 'wpseo_double_clean_titles' || did_action( 'wpseo_double_clean_titles' ) > 0 ) {
833 + if ( ( isset( $original ) && current_filter() === 'wpseo_double_clean_titles' ) || did_action( 'wpseo_double_clean_titles' ) > 0 ) {
808 834 $rename = [
809 835 'title-' => 'title-tax-',
810 836 'metadesc-' => 'metadesc-tax-',
811 837 'noindex-' => 'noindex-tax-',
812 838 'tax-hideeditbox-' => 'hideeditbox-tax-',
813 -
814 839 ];
815 840
816 841 $taxonomy_names = get_taxonomies( [ 'public' => true ], 'names' );
817 842 $post_type_names = get_post_types( [ 'public' => true ], 'names' );
@@ -833,12 +858,10 @@
833 858 */
834 859 if ( ! isset( $post_type_names[ $tax ] ) && isset( $option_value[ $old_prefix . $tax ] ) ) {
835 860 unset( $option_value[ $old_prefix . $tax ] );
836 861 }
837 - else {
838 - if ( isset( $post_type_names[ $tax ] ) && ! isset( $option_value[ $old_prefix . $tax ] ) ) {
839 - $option_value[ $old_prefix . $tax ] = $original[ $old_prefix . $tax ];
840 - }
862 + elseif ( isset( $post_type_names[ $tax ] ) && ! isset( $option_value[ $old_prefix . $tax ] ) ) {
863 + $option_value[ $old_prefix . $tax ] = $original[ $old_prefix . $tax ];
841 864 }
842 865
843 866 if ( $old_prefix === 'tax-hideeditbox-' ) {
844 867 unset( $option_value[ $old_prefix . $tax ] );
@@ -849,48 +872,8 @@
849 872 }
850 873 unset( $rename, $taxonomy_names, $post_type_names, $defaults, $tax, $old_prefix, $new_prefix );
851 874 }
852 875
853 - /*
854 - * Make sure the values of the variable option key options are cleaned as they
855 - * may be retained and would not be cleaned/validated then.
856 - */
857 - if ( is_array( $option_value ) && $option_value !== [] ) {
858 - foreach ( $option_value as $key => $value ) {
859 - $switch_key = $this->get_switch_key( $key );
860 -
861 - // Similar to validation routine - any changes made there should be made here too.
862 - switch ( $switch_key ) {
863 - /* Text fields. */
864 - case 'title-':
865 - case 'metadesc-':
866 - case 'bctitle-ptarchive-':
867 - $option_value[ $key ] = WPSEO_Utils::sanitize_text_field( $value );
868 - break;
869 -
870 - case 'separator':
871 - if ( ! array_key_exists( $value, $this->get_separator_options() ) ) {
872 - $option_value[ $key ] = false;
873 - }
874 - break;
875 -
876 - /*
877 - * Boolean fields.
878 - */
879 -
880 - /*
881 - * Covers:
882 - * 'noindex-'
883 - * 'hideeditbox-'
884 - */
885 - default:
886 - $option_value[ $key ] = WPSEO_Utils::validate_bool( $value );
887 - break;
888 - }
889 - }
890 - unset( $key, $value, $switch_key );
891 - }
892 -
893 876 return $option_value;
894 877 }
895 878
896 879 /**
@@ -900,14 +883,14 @@
900 883 * {@internal Overrule the abstract class version of this to make sure one extra renamed
901 884 * variable key does not get removed. IMPORTANT: keep this method in line with
902 885 * the parent on which it is based!}}
903 886 *
904 - * @param array $dirty Original option as retrieved from the database.
905 - * @param array $clean Filtered option where any options which shouldn't be in our option
887 + * @param string[] $dirty Original option as retrieved from the database.
888 + * @param string[] $clean Filtered option where any options which shouldn't be in our option
906 889 * have already been removed and any options which weren't set
907 890 * have been set to their defaults.
908 891 *
909 - * @return array
892 + * @return string[]
910 893 */
911 894 protected function retain_variable_keys( $dirty, $clean ) {
912 895 if ( ( is_array( $this->variable_array_key_patterns ) && $this->variable_array_key_patterns !== [] ) && ( is_array( $dirty ) && $dirty !== [] ) ) {
913 896
@@ -917,9 +900,9 @@
917 900
918 901 /**
919 902 * Allow altering the array with variable array key patterns.
920 903 *
921 - * @api array $patterns Array with the variable array key patterns.
904 + * @param array $patterns Array with the variable array key patterns.
922 905 */
923 906 $patterns = apply_filters( 'wpseo_option_titles_variable_array_key_patterns', $patterns );
924 907
925 908 foreach ( $dirty as $key => $value ) {
@@ -943,9 +926,9 @@
943 926
944 927 /**
945 928 * Retrieves a list of separator options.
946 929 *
947 - * @return array An array of the separator options.
930 + * @return string[] An array of the separator options.
948 931 */
949 932 protected static function get_separator_option_list() {
950 933 $separators = [
951 934 'sc-dash' => [
@@ -952,13 +935,13 @@
952 935 'option' => '-',
953 936 'label' => __( 'Dash', 'wordpress-seo' ),
954 937 ],
955 938 'sc-ndash' => [
956 - 'option' => '–',
939 + 'option' => '–',
957 940 'label' => __( 'En dash', 'wordpress-seo' ),
958 941 ],
959 942 'sc-mdash' => [
960 - 'option' => '—',
943 + 'option' => '—',
961 944 'label' => __( 'Em dash', 'wordpress-seo' ),
962 945 ],
963 946 'sc-colon' => [
964 947 'option' => ':',
@@ -964,13 +947,13 @@
964 947 'option' => ':',
965 948 'label' => __( 'Colon', 'wordpress-seo' ),
966 949 ],
967 950 'sc-middot' => [
968 - 'option' => '·',
951 + 'option' => '·',
969 952 'label' => __( 'Middle dot', 'wordpress-seo' ),
970 953 ],
971 954 'sc-bull' => [
972 - 'option' => '•',
955 + 'option' => '•',
973 956 'label' => __( 'Bullet', 'wordpress-seo' ),
974 957 ],
975 958 'sc-star' => [
976 959 'option' => '*',
@@ -988,21 +971,21 @@
988 971 'option' => '~',
989 972 'label' => __( 'Small tilde', 'wordpress-seo' ),
990 973 ],
991 974 'sc-laquo' => [
992 - 'option' => '«',
975 + 'option' => '«',
993 976 'label' => __( 'Left angle quotation mark', 'wordpress-seo' ),
994 977 ],
995 978 'sc-raquo' => [
996 - 'option' => '»',
979 + 'option' => '»',
997 980 'label' => __( 'Right angle quotation mark', 'wordpress-seo' ),
998 981 ],
999 982 'sc-lt' => [
1000 - 'option' => '<',
983 + 'option' => '>',
1001 984 'label' => __( 'Less than sign', 'wordpress-seo' ),
1002 985 ],
1003 986 'sc-gt' => [
1004 - 'option' => '>',
987 + 'option' => '<',
1005 988 'label' => __( 'Greater than sign', 'wordpress-seo' ),
1006 989 ],
1007 990 ];
1008 991
@@ -1008,9 +991,9 @@
1008 991
1009 992 /**
1010 993 * Allows altering the separator options array.
1011 994 *
1012 - * @api array $separators Array with the separator options.
995 + * @param array $separators Array with the separator options.
1013 996 */
1014 997 $separator_list = apply_filters( 'wpseo_separator_option_list', $separators );
1015 998
1016 999 if ( ! is_array( $separator_list ) ) {