| @@ -4,11 +4,9 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WPSEO\Admin |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -use Yoast\WP\SEO\Conditionals\Admin\Estimated_Reading_Time_Conditional; | |
| 9 | -use Yoast\WP\SEO\Conditionals\Admin\Post_Conditional; | |
| 10 | -use Yoast\WP\SEO\Helpers\Input_Helper; | |
| 8 | +use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository; | |
| 11 | 9 | use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter; |
| 12 | 10 | use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter; |
| 13 | 11 | |
| 14 | 12 | /** |
| @@ -16,9 +14,9 @@ | ||
| 16 | 14 | */ |
| 17 | 15 | class WPSEO_Metabox extends WPSEO_Meta { |
| 18 | 16 | |
| 19 | 17 | /** |
| 20 | - * Whether or not the social tab is enabled. | |
| 18 | + * Whether the social tab is enabled. | |
| 21 | 19 | * |
| 22 | 20 | * @var bool |
| 23 | 21 | */ |
| 24 | 22 | private $social_is_enabled; |
| @@ -23,9 +21,9 @@ | ||
| 23 | 21 | */ |
| 24 | 22 | private $social_is_enabled; |
| 25 | 23 | |
| 26 | 24 | /** |
| 27 | - * Helper to determine whether or not the SEO analysis is enabled. | |
| 25 | + * Helper to determine whether the SEO analysis is enabled. | |
| 28 | 26 | * |
| 29 | 27 | * @var WPSEO_Metabox_Analysis_SEO |
| 30 | 28 | */ |
| 31 | 29 | protected $seo_analysis; |
| @@ -30,9 +28,9 @@ | ||
| 30 | 28 | */ |
| 31 | 29 | protected $seo_analysis; |
| 32 | 30 | |
| 33 | 31 | /** |
| 34 | - * Helper to determine whether or not the readability analysis is enabled. | |
| 32 | + * Helper to determine whether the readability analysis is enabled. | |
| 35 | 33 | * |
| 36 | 34 | * @var WPSEO_Metabox_Analysis_Readability |
| 37 | 35 | */ |
| 38 | 36 | protected $readability_analysis; |
| @@ -37,8 +35,15 @@ | ||
| 37 | 35 | */ |
| 38 | 36 | protected $readability_analysis; |
| 39 | 37 | |
| 40 | 38 | /** |
| 39 | + * Helper to determine whether the inclusive language analysis is enabled. | |
| 40 | + * | |
| 41 | + * @var WPSEO_Metabox_Analysis_Inclusive_Language | |
| 42 | + */ | |
| 43 | + protected $inclusive_language_analysis; | |
| 44 | + | |
| 45 | + /** | |
| 41 | 46 | * The metabox editor object. |
| 42 | 47 | * |
| 43 | 48 | * @var WPSEO_Metabox_Editor |
| 44 | 49 | */ |
| @@ -46,14 +51,14 @@ | ||
| 46 | 51 | |
| 47 | 52 | /** |
| 48 | 53 | * The Metabox post. |
| 49 | 54 | * |
| 50 | - * @var WP_Post | |
| 55 | + * @var WP_Post|null | |
| 51 | 56 | */ |
| 52 | 57 | protected $post = null; |
| 53 | 58 | |
| 54 | 59 | /** |
| 55 | - * Whether or not the advanced metadata is enabled. | |
| 60 | + * Whether the advanced metadata is enabled. | |
| 56 | 61 | * |
| 57 | 62 | * @var bool |
| 58 | 63 | */ |
| 59 | 64 | protected $is_advanced_metadata_enabled; |
| @@ -58,20 +63,14 @@ | ||
| 58 | 63 | */ |
| 59 | 64 | protected $is_advanced_metadata_enabled; |
| 60 | 65 | |
| 61 | 66 | /** |
| 62 | - * Represents the estimated_reading_time_conditional. | |
| 63 | - * | |
| 64 | - * @var Estimated_Reading_Time_Conditional | |
| 65 | - */ | |
| 66 | - protected $estimated_reading_time_conditional; | |
| 67 | - | |
| 68 | - /** | |
| 69 | 67 | * Class constructor. |
| 70 | 68 | */ |
| 71 | 69 | public function __construct() { |
| 72 | 70 | if ( $this->is_internet_explorer() ) { |
| 73 | 71 | add_action( 'add_meta_boxes', [ $this, 'internet_explorer_metabox' ] ); |
| 72 | + | |
| 74 | 73 | return; |
| 75 | 74 | } |
| 76 | 75 | |
| 77 | 76 | add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] ); |
| @@ -78,23 +77,15 @@ | ||
| 78 | 77 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 79 | 78 | add_action( 'wp_insert_post', [ $this, 'save_postdata' ] ); |
| 80 | 79 | add_action( 'edit_attachment', [ $this, 'save_postdata' ] ); |
| 81 | 80 | add_action( 'add_attachment', [ $this, 'save_postdata' ] ); |
| 82 | - add_action( 'admin_init', [ $this, 'translate_meta_boxes' ] ); | |
| 83 | 81 | |
| 84 | - $this->editor = new WPSEO_Metabox_Editor(); | |
| 85 | - $this->editor->register_hooks(); | |
| 82 | + $this->social_is_enabled = WPSEO_Options::get( 'opengraph', false, [ 'wpseo_social' ] ) || WPSEO_Options::get( 'twitter', false, [ 'wpseo_social' ] ); | |
| 83 | + $this->is_advanced_metadata_enabled = WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta', null, [ 'wpseo' ] ) === false; | |
| 86 | 84 | |
| 87 | - $this->social_is_enabled = WPSEO_Options::get( 'opengraph', false ) || WPSEO_Options::get( 'twitter', false ); | |
| 88 | - $this->is_advanced_metadata_enabled = WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta' ) === false; | |
| 89 | - | |
| 90 | - $this->estimated_reading_time_conditional = new Estimated_Reading_Time_Conditional( | |
| 91 | - new Post_Conditional(), | |
| 92 | - new Input_Helper() | |
| 93 | - ); | |
| 94 | - | |
| 95 | - $this->seo_analysis = new WPSEO_Metabox_Analysis_SEO(); | |
| 96 | - $this->readability_analysis = new WPSEO_Metabox_Analysis_Readability(); | |
| 85 | + $this->seo_analysis = new WPSEO_Metabox_Analysis_SEO(); | |
| 86 | + $this->readability_analysis = new WPSEO_Metabox_Analysis_Readability(); | |
| 87 | + $this->inclusive_language_analysis = new WPSEO_Metabox_Analysis_Inclusive_Language(); | |
| 97 | 88 | } |
| 98 | 89 | |
| 99 | 90 | /** |
| 100 | 91 | * Checks whether the request comes from an IE 11 browser. |
| @@ -116,8 +107,10 @@ | ||
| 116 | 107 | } |
| 117 | 108 | |
| 118 | 109 | /** |
| 119 | 110 | * Adds an alternative metabox for internet explorer users. |
| 111 | + * | |
| 112 | + * @return void | |
| 120 | 113 | */ |
| 121 | 114 | public function internet_explorer_metabox() { |
| 122 | 115 | $post_types = WPSEO_Post_Type::get_accessible_post_types(); |
| 123 | 116 | $post_types = array_filter( $post_types, [ $this, 'display_metabox' ] ); |
| @@ -137,9 +130,9 @@ | ||
| 137 | 130 | [ $this, 'render_internet_explorer_notice' ], |
| 138 | 131 | $post_type, |
| 139 | 132 | 'normal', |
| 140 | 133 | apply_filters( 'wpseo_metabox_prio', 'high' ), |
| 141 | - [ '__block_editor_compatible_meta_box' => true ] | |
| 134 | + [ '__block_editor_compatible_meta_box' => true ], | |
| 142 | 135 | ); |
| 143 | 136 | } |
| 144 | 137 | } |
| 145 | 138 | |
| @@ -154,9 +147,9 @@ | ||
| 154 | 147 | esc_html__( 'The browser you are currently using is unfortunately rather dated. Since we strive to give you the best experience possible, we no longer support this browser. Instead, please use %1$sFirefox%4$s, %2$sChrome%4$s or %3$sMicrosoft Edge%4$s.', 'wordpress-seo' ), |
| 155 | 148 | '<a href="https://www.mozilla.org/firefox/new/">', |
| 156 | 149 | '<a href="https://www.google.com/chrome/">', |
| 157 | 150 | '<a href="https://www.microsoft.com/windows/microsoft-edge">', |
| 158 | - '</a>' | |
| 151 | + '</a>', | |
| 159 | 152 | ); |
| 160 | 153 | |
| 161 | 154 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped above. |
| 162 | 155 | echo new Alert_Presenter( $content ); |
| @@ -162,63 +155,8 @@ | ||
| 162 | 155 | echo new Alert_Presenter( $content ); |
| 163 | 156 | } |
| 164 | 157 | |
| 165 | 158 | /** |
| 166 | - * Translates text strings for use in the meta box. | |
| 167 | - * | |
| 168 | - * IMPORTANT: if you want to add a new string (option) somewhere, make sure you add that array key to | |
| 169 | - * the main meta box definition array in the class WPSEO_Meta() as well!!!! | |
| 170 | - */ | |
| 171 | - public static function translate_meta_boxes() { | |
| 172 | - WPSEO_Meta::$meta_fields['general']['title']['title'] = __( 'SEO title', 'wordpress-seo' ); | |
| 173 | - WPSEO_Meta::$meta_fields['general']['metadesc']['title'] = __( 'Meta description', 'wordpress-seo' ); | |
| 174 | - | |
| 175 | - /* translators: %s expands to the post type name. */ | |
| 176 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['title'] = __( 'Allow search engines to show this %s in search results?', 'wordpress-seo' ); | |
| 177 | - if ( (string) get_option( 'blog_public' ) === '0' ) { | |
| 178 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['description'] = '<span class="error-message">' . __( 'Warning: even though you can set the meta robots setting here, the entire site is set to noindex in the sitewide privacy settings, so these settings won\'t have an effect.', 'wordpress-seo' ) . '</span>'; | |
| 179 | - } | |
| 180 | - /* translators: %1$s expands to Yes or No, %2$s expands to the post type name.*/ | |
| 181 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['0'] = __( 'Default for %2$s, currently: %1$s', 'wordpress-seo' ); | |
| 182 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['2'] = __( 'Yes', 'wordpress-seo' ); | |
| 183 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['1'] = __( 'No', 'wordpress-seo' ); | |
| 184 | - | |
| 185 | - /* translators: %1$s expands to the post type name.*/ | |
| 186 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['title'] = __( 'Should search engines follow links on this %1$s?', 'wordpress-seo' ); | |
| 187 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['options']['0'] = __( 'Yes', 'wordpress-seo' ); | |
| 188 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['options']['1'] = __( 'No', 'wordpress-seo' ); | |
| 189 | - | |
| 190 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['title'] = __( 'Meta robots advanced', 'wordpress-seo' ); | |
| 191 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['description'] = __( 'If you want to apply advanced <code>meta</code> robots settings for this page, please define them in the following field.', 'wordpress-seo' ); | |
| 192 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['noimageindex'] = __( 'No Image Index', 'wordpress-seo' ); | |
| 193 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['noarchive'] = __( 'No Archive', 'wordpress-seo' ); | |
| 194 | - WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['nosnippet'] = __( 'No Snippet', 'wordpress-seo' ); | |
| 195 | - | |
| 196 | - WPSEO_Meta::$meta_fields['advanced']['bctitle']['title'] = __( 'Breadcrumbs Title', 'wordpress-seo' ); | |
| 197 | - WPSEO_Meta::$meta_fields['advanced']['bctitle']['description'] = __( 'Title to use for this page in breadcrumb paths', 'wordpress-seo' ); | |
| 198 | - | |
| 199 | - WPSEO_Meta::$meta_fields['advanced']['canonical']['title'] = __( 'Canonical URL', 'wordpress-seo' ); | |
| 200 | - | |
| 201 | - WPSEO_Meta::$meta_fields['advanced']['canonical']['description'] = sprintf( | |
| 202 | - /* translators: 1: link open tag; 2: link close tag. */ | |
| 203 | - __( 'The canonical URL that this page should point to. Leave empty to default to permalink. %1$sCross domain canonical%2$s supported too.', 'wordpress-seo' ), | |
| 204 | - '<a href="https://googlewebmastercentral.blogspot.com/2009/12/handling-legitimate-cross-domain.html" target="_blank" rel="noopener">', | |
| 205 | - WPSEO_Admin_Utils::get_new_tab_message() . '</a>' | |
| 206 | - ); | |
| 207 | - /* translators: %s expands to the post type name. */ | |
| 208 | - WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['title'] = __( 'Timestamp this %s', 'wordpress-seo' ); | |
| 209 | - WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['description'] = __( 'Use WordProof to timestamp this page to comply with legal regulations and join the fight for a more transparant and accountable internet.', 'wordpress-seo' ); | |
| 210 | - WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['options']['0'] = __( 'Off', 'wordpress-seo' ); | |
| 211 | - WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['options']['1'] = __( 'On', 'wordpress-seo' ); | |
| 212 | - WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['type'] = 'hidden'; | |
| 213 | - | |
| 214 | - WPSEO_Meta::$meta_fields['advanced']['redirect']['title'] = __( '301 Redirect', 'wordpress-seo' ); | |
| 215 | - WPSEO_Meta::$meta_fields['advanced']['redirect']['description'] = __( 'The URL that this page should redirect to.', 'wordpress-seo' ); | |
| 216 | - | |
| 217 | - do_action( 'wpseo_tab_translate' ); | |
| 218 | - } | |
| 219 | - | |
| 220 | - /** | |
| 221 | 159 | * Determines whether the metabox should be shown for the passed identifier. |
| 222 | 160 | * |
| 223 | 161 | * By default the check is done for post types, but can also be used for taxonomies. |
| 224 | 162 | * |
| @@ -256,9 +194,9 @@ | ||
| 256 | 194 | [ $this, 'meta_box' ], |
| 257 | 195 | $post_type, |
| 258 | 196 | 'normal', |
| 259 | 197 | apply_filters( 'wpseo_metabox_prio', 'high' ), |
| 260 | - [ '__block_editor_compatible_meta_box' => true ] | |
| 198 | + [ '__block_editor_compatible_meta_box' => true ], | |
| 261 | 199 | ); |
| 262 | 200 | } |
| 263 | 201 | } |
| 264 | 202 | |
| @@ -264,11 +202,11 @@ | ||
| 264 | 202 | |
| 265 | 203 | /** |
| 266 | 204 | * Adds CSS classes to the meta box. |
| 267 | 205 | * |
| 268 | - * @param array $classes An array of postbox CSS classes. | |
| 206 | + * @param string[] $classes An array of postbox CSS classes. | |
| 269 | 207 | * |
| 270 | - * @return array List of classes that will be applied to the editbox container. | |
| 208 | + * @return string[] List of classes that will be applied to the editbox container. | |
| 271 | 209 | */ |
| 272 | 210 | public function wpseo_metabox_class( $classes ) { |
| 273 | 211 | $classes[] = 'yoast wpseo-metabox'; |
| 274 | 212 | |
| @@ -277,24 +215,18 @@ | ||
| 277 | 215 | |
| 278 | 216 | /** |
| 279 | 217 | * Passes variables to js for use with the post-scraper. |
| 280 | 218 | * |
| 281 | - * @return array | |
| 219 | + * @return array<string, string|array<string|int|bool>|bool|int> | |
| 282 | 220 | */ |
| 283 | 221 | public function get_metabox_script_data() { |
| 284 | - $permalink = ''; | |
| 222 | + $permalink = $this->get_permalink(); | |
| 285 | 223 | |
| 286 | - if ( is_object( $this->get_metabox_post() ) ) { | |
| 287 | - $permalink = get_sample_permalink( $this->get_metabox_post()->ID ); | |
| 288 | - $permalink = $permalink[0]; | |
| 289 | - } | |
| 290 | - | |
| 291 | 224 | $post_formatter = new WPSEO_Metabox_Formatter( |
| 292 | - new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink ) | |
| 225 | + new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink ), | |
| 293 | 226 | ); |
| 294 | 227 | |
| 295 | 228 | $values = $post_formatter->get_values(); |
| 296 | - | |
| 297 | 229 | /** This filter is documented in admin/filters/class-cornerstone-filter.php. */ |
| 298 | 230 | $post_types = apply_filters( 'wpseo_cornerstone_post_types', WPSEO_Post_Type::get_accessible_post_types() ); |
| 299 | 231 | if ( $values['cornerstoneActive'] && ! in_array( $this->get_metabox_post()->post_type, $post_types, true ) ) { |
| 300 | 232 | $values['cornerstoneActive'] = false; |
| @@ -337,8 +269,10 @@ | ||
| 337 | 269 | } |
| 338 | 270 | |
| 339 | 271 | /** |
| 340 | 272 | * Outputs the meta box. |
| 273 | + * | |
| 274 | + * @return void | |
| 341 | 275 | */ |
| 342 | 276 | public function meta_box() { |
| 343 | 277 | $this->render_hidden_fields(); |
| 344 | 278 | $this->render_tabs(); |
| @@ -367,12 +301,27 @@ | ||
| 367 | 301 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class. |
| 368 | 302 | echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'social' ); |
| 369 | 303 | } |
| 370 | 304 | |
| 305 | + $is_block_editor = YoastSEO()->helpers->current_page->is_block_editor(); | |
| 306 | + if ( $is_block_editor && $this->get_metabox_post()->post_type === 'post' ) { | |
| 307 | + /** | |
| 308 | + * Filter: 'wpseo_enable_ai_content_planner_inline_banner' - Allows hiding the AI Content Planner inline banner site-wide. | |
| 309 | + * | |
| 310 | + * Returning false stops the hidden meta inputs from being rendered, which the editor JS treats as "banner disabled". | |
| 311 | + * | |
| 312 | + * @param bool $enabled Whether the inline banner should be available in the editor. Default true. | |
| 313 | + */ | |
| 314 | + if ( apply_filters( 'wpseo_enable_ai_content_planner_inline_banner', true ) ) { | |
| 315 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class. | |
| 316 | + echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'content_planner' ); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + | |
| 371 | 320 | /** |
| 372 | 321 | * Filter: 'wpseo_content_meta_section_content' - Allow filtering the metabox content before outputting. |
| 373 | 322 | * |
| 374 | - * @api string $post_content The metabox content string. | |
| 323 | + * @param string $post_content The metabox content string. | |
| 375 | 324 | */ |
| 376 | 325 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output should be escaped in the filter. |
| 377 | 326 | echo apply_filters( 'wpseo_content_meta_section_content', '' ); |
| 378 | 327 | } |
| @@ -423,13 +372,17 @@ | ||
| 423 | 372 | if ( $this->readability_analysis->is_enabled() ) { |
| 424 | 373 | $tabs[] = new WPSEO_Metabox_Section_Readability(); |
| 425 | 374 | } |
| 426 | 375 | |
| 376 | + if ( $this->inclusive_language_analysis->is_enabled() ) { | |
| 377 | + $tabs[] = new WPSEO_Metabox_Section_Inclusive_Language(); | |
| 378 | + } | |
| 379 | + | |
| 427 | 380 | if ( $this->is_advanced_metadata_enabled ) { |
| 428 | 381 | $tabs[] = new WPSEO_Metabox_Section_React( |
| 429 | 382 | 'schema', |
| 430 | 383 | '<span class="wpseo-schema-icon"></span>' . __( 'Schema', 'wordpress-seo' ), |
| 431 | - '' | |
| 384 | + '', | |
| 432 | 385 | ); |
| 433 | 386 | } |
| 434 | 387 | |
| 435 | 388 | if ( $this->social_is_enabled ) { |
| @@ -438,9 +391,9 @@ | ||
| 438 | 391 | '<span class="dashicons dashicons-share"></span>' . __( 'Social', 'wordpress-seo' ), |
| 439 | 392 | '', |
| 440 | 393 | [ |
| 441 | 394 | 'html_after' => '<div id="wpseo-section-social"></div>', |
| 442 | - ] | |
| 395 | + ], | |
| 443 | 396 | ); |
| 444 | 397 | } |
| 445 | 398 | |
| 446 | 399 | $tabs = array_merge( $tabs, $this->get_additional_tabs() ); |
| @@ -489,9 +442,9 @@ | ||
| 489 | 442 | $tabs[] = new WPSEO_Metabox_Section_Additional( |
| 490 | 443 | $tab['name'], |
| 491 | 444 | $tab['link_content'], |
| 492 | 445 | $tab['content'], |
| 493 | - $options | |
| 446 | + $options, | |
| 494 | 447 | ); |
| 495 | 448 | } |
| 496 | 449 | } |
| 497 | 450 | |
| @@ -498,208 +451,8 @@ | ||
| 498 | 451 | return $tabs; |
| 499 | 452 | } |
| 500 | 453 | |
| 501 | 454 | /** |
| 502 | - * Adds a line in the meta box. | |
| 503 | - * | |
| 504 | - * @todo [JRF] Check if $class is added appropriately everywhere. | |
| 505 | - * | |
| 506 | - * @param array $meta_field_def Contains the vars based on which output is generated. | |
| 507 | - * @param string $key Internal key (without prefix). | |
| 508 | - * | |
| 509 | - * @return string | |
| 510 | - */ | |
| 511 | - public function do_meta_box( $meta_field_def, $key = '' ) { | |
| 512 | - $content = ''; | |
| 513 | - $esc_form_key = esc_attr( WPSEO_Meta::$form_prefix . $key ); | |
| 514 | - $meta_value = WPSEO_Meta::get_value( $key, $this->get_metabox_post()->ID ); | |
| 515 | - | |
| 516 | - $class = ''; | |
| 517 | - if ( isset( $meta_field_def['class'] ) && $meta_field_def['class'] !== '' ) { | |
| 518 | - $class = ' ' . $meta_field_def['class']; | |
| 519 | - } | |
| 520 | - | |
| 521 | - $placeholder = ''; | |
| 522 | - if ( isset( $meta_field_def['placeholder'] ) && $meta_field_def['placeholder'] !== '' ) { | |
| 523 | - $placeholder = $meta_field_def['placeholder']; | |
| 524 | - } | |
| 525 | - | |
| 526 | - $aria_describedby = ''; | |
| 527 | - $description = ''; | |
| 528 | - if ( isset( $meta_field_def['description'] ) ) { | |
| 529 | - $aria_describedby = ' aria-describedby="' . $esc_form_key . '-desc"'; | |
| 530 | - $description = '<p id="' . $esc_form_key . '-desc" class="yoast-metabox__description">' . $meta_field_def['description'] . '</p>'; | |
| 531 | - } | |
| 532 | - | |
| 533 | - // Add a hide_on_pages option that returns nothing when the field is rendered on a page. | |
| 534 | - if ( isset( $meta_field_def['hide_on_pages'] ) && $meta_field_def['hide_on_pages'] && get_post_type() === 'page' ) { | |
| 535 | - return ''; | |
| 536 | - } | |
| 537 | - | |
| 538 | - switch ( $meta_field_def['type'] ) { | |
| 539 | - case 'text': | |
| 540 | - $ac = ''; | |
| 541 | - if ( isset( $meta_field_def['autocomplete'] ) && $meta_field_def['autocomplete'] === false ) { | |
| 542 | - $ac = 'autocomplete="off" '; | |
| 543 | - } | |
| 544 | - if ( $placeholder !== '' ) { | |
| 545 | - $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"'; | |
| 546 | - } | |
| 547 | - $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" ' . $ac . 'name="' . $esc_form_key . '" value="' . esc_attr( $meta_value ) . '" class="large-text' . $class . '"' . $aria_describedby . '/>'; | |
| 548 | - break; | |
| 549 | - | |
| 550 | - case 'url': | |
| 551 | - if ( $placeholder !== '' ) { | |
| 552 | - $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"'; | |
| 553 | - } | |
| 554 | - $content .= '<input type="url"' . $placeholder . ' id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr( urldecode( $meta_value ) ) . '" class="large-text' . $class . '"' . $aria_describedby . '/>'; | |
| 555 | - break; | |
| 556 | - | |
| 557 | - case 'textarea': | |
| 558 | - $rows = 3; | |
| 559 | - if ( isset( $meta_field_def['rows'] ) && $meta_field_def['rows'] > 0 ) { | |
| 560 | - $rows = $meta_field_def['rows']; | |
| 561 | - } | |
| 562 | - $content .= '<textarea class="large-text' . $class . '" rows="' . esc_attr( $rows ) . '" id="' . $esc_form_key . '" name="' . $esc_form_key . '"' . $aria_describedby . '>' . esc_textarea( $meta_value ) . '</textarea>'; | |
| 563 | - break; | |
| 564 | - | |
| 565 | - case 'hidden': | |
| 566 | - $default = ''; | |
| 567 | - if ( isset( $meta_field_def['default'] ) ) { | |
| 568 | - $default = sprintf( ' data-default="%s"', esc_attr( $meta_field_def['default'] ) ); | |
| 569 | - } | |
| 570 | - $content .= '<input type="hidden" id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr( $meta_value ) . '"' . $default . '/>' . "\n"; | |
| 571 | - break; | |
| 572 | - case 'select': | |
| 573 | - if ( isset( $meta_field_def['options'] ) && is_array( $meta_field_def['options'] ) && $meta_field_def['options'] !== [] ) { | |
| 574 | - $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '" class="yoast' . $class . '">'; | |
| 575 | - foreach ( $meta_field_def['options'] as $val => $option ) { | |
| 576 | - $selected = selected( $meta_value, $val, false ); | |
| 577 | - $content .= '<option ' . $selected . ' value="' . esc_attr( $val ) . '">' . esc_html( $option ) . '</option>'; | |
| 578 | - } | |
| 579 | - unset( $val, $option, $selected ); | |
| 580 | - $content .= '</select>'; | |
| 581 | - } | |
| 582 | - break; | |
| 583 | - | |
| 584 | - case 'multiselect': | |
| 585 | - if ( isset( $meta_field_def['options'] ) && is_array( $meta_field_def['options'] ) && $meta_field_def['options'] !== [] ) { | |
| 586 | - | |
| 587 | - // Set $meta_value as $selected_arr. | |
| 588 | - $selected_arr = $meta_value; | |
| 589 | - | |
| 590 | - // If the multiselect field is 'meta-robots-adv' we should explode on ,. | |
| 591 | - if ( $key === 'meta-robots-adv' ) { | |
| 592 | - $selected_arr = explode( ',', $meta_value ); | |
| 593 | - } | |
| 594 | - | |
| 595 | - if ( ! is_array( $selected_arr ) ) { | |
| 596 | - $selected_arr = (array) $selected_arr; | |
| 597 | - } | |
| 598 | - | |
| 599 | - $options_count = count( $meta_field_def['options'] ); | |
| 600 | - | |
| 601 | - // This select now uses Select2. | |
| 602 | - $content .= '<select multiple="multiple" size="' . esc_attr( $options_count ) . '" name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="yoast' . $class . '"' . $aria_describedby . '>'; | |
| 603 | - foreach ( $meta_field_def['options'] as $val => $option ) { | |
| 604 | - $selected = ''; | |
| 605 | - if ( in_array( $val, $selected_arr, true ) ) { | |
| 606 | - $selected = ' selected="selected"'; | |
| 607 | - } | |
| 608 | - $content .= '<option ' . $selected . ' value="' . esc_attr( $val ) . '">' . esc_html( $option ) . '</option>'; | |
| 609 | - } | |
| 610 | - $content .= '</select>'; | |
| 611 | - unset( $val, $option, $selected, $selected_arr, $options_count ); | |
| 612 | - } | |
| 613 | - break; | |
| 614 | - | |
| 615 | - case 'checkbox': | |
| 616 | - $checked = checked( $meta_value, 'on', false ); | |
| 617 | - $expl = ( isset( $meta_field_def['expl'] ) ) ? esc_html( $meta_field_def['expl'] ) : ''; | |
| 618 | - $content .= '<input type="checkbox" id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . ' value="on" class="yoast' . $class . '"' . $aria_describedby . '/> <label for="' . $esc_form_key . '">' . $expl . '</label>'; | |
| 619 | - unset( $checked, $expl ); | |
| 620 | - break; | |
| 621 | - | |
| 622 | - case 'radio': | |
| 623 | - if ( isset( $meta_field_def['options'] ) && is_array( $meta_field_def['options'] ) && $meta_field_def['options'] !== [] ) { | |
| 624 | - foreach ( $meta_field_def['options'] as $val => $option ) { | |
| 625 | - $checked = checked( $meta_value, $val, false ); | |
| 626 | - $content .= '<input type="radio" ' . $checked . ' id="' . $esc_form_key . '_' . esc_attr( $val ) . '" name="' . $esc_form_key . '" value="' . esc_attr( $val ) . '"/> <label for="' . $esc_form_key . '_' . esc_attr( $val ) . '">' . esc_html( $option ) . '</label> '; | |
| 627 | - } | |
| 628 | - unset( $val, $option, $checked ); | |
| 629 | - } | |
| 630 | - break; | |
| 631 | - | |
| 632 | - case 'upload': | |
| 633 | - $content .= '<input' . | |
| 634 | - ' id="' . $esc_form_key . '"' . | |
| 635 | - ' type="text"' . | |
| 636 | - ' size="36"' . | |
| 637 | - ' class="' . $class . '"' . | |
| 638 | - ' name="' . $esc_form_key . '"' . | |
| 639 | - ' value="' . esc_attr( $meta_value ) . '"' . $aria_describedby . | |
| 640 | - ' readonly="readonly"' . | |
| 641 | - ' /> '; | |
| 642 | - $content .= '<input' . | |
| 643 | - ' id="' . esc_attr( $esc_form_key ) . '_button"' . | |
| 644 | - ' class="wpseo_image_upload_button button"' . | |
| 645 | - ' data-target="' . esc_attr( $esc_form_key ) . '"' . | |
| 646 | - ' data-target-id="' . esc_attr( $esc_form_key ) . '-id"' . | |
| 647 | - ' type="button"' . | |
| 648 | - ' value="' . esc_attr__( 'Upload Image', 'wordpress-seo' ) . '"' . | |
| 649 | - ' /> '; | |
| 650 | - $content .= '<input' . | |
| 651 | - ' class="wpseo_image_remove_button button"' . | |
| 652 | - ' type="button"' . | |
| 653 | - ' value="' . esc_attr__( 'Clear Image', 'wordpress-seo' ) . '"' . | |
| 654 | - ' />'; | |
| 655 | - break; | |
| 656 | - } | |
| 657 | - | |
| 658 | - $html = ''; | |
| 659 | - if ( $content === '' ) { | |
| 660 | - $content = apply_filters( 'wpseo_do_meta_box_field_' . $key, $content, $meta_value, $esc_form_key, $meta_field_def, $key ); | |
| 661 | - } | |
| 662 | - | |
| 663 | - if ( $content !== '' ) { | |
| 664 | - | |
| 665 | - $title = esc_html( $meta_field_def['title'] ); | |
| 666 | - | |
| 667 | - // By default, use the field title as a label element. | |
| 668 | - $label = '<label for="' . $esc_form_key . '">' . $title . '</label>'; | |
| 669 | - | |
| 670 | - // Set the inline help and help panel, if any. | |
| 671 | - $help_button = ''; | |
| 672 | - $help_panel = ''; | |
| 673 | - if ( isset( $meta_field_def['help'] ) && $meta_field_def['help'] !== '' ) { | |
| 674 | - $help = new WPSEO_Admin_Help_Panel( $key, $meta_field_def['help-button'], $meta_field_def['help'] ); | |
| 675 | - $help_button = $help->get_button_html(); | |
| 676 | - $help_panel = $help->get_panel_html(); | |
| 677 | - } | |
| 678 | - | |
| 679 | - // If it's a set of radio buttons, output proper fieldset and legend. | |
| 680 | - if ( $meta_field_def['type'] === 'radio' ) { | |
| 681 | - return '<fieldset><legend>' . $title . '</legend>' . $help_button . $help_panel . $content . $description . '</fieldset>'; | |
| 682 | - } | |
| 683 | - | |
| 684 | - // If it's a single checkbox, ignore the title. | |
| 685 | - if ( $meta_field_def['type'] === 'checkbox' ) { | |
| 686 | - $label = ''; | |
| 687 | - } | |
| 688 | - | |
| 689 | - // Other meta box content or form fields. | |
| 690 | - if ( $meta_field_def['type'] === 'hidden' ) { | |
| 691 | - $html = $content; | |
| 692 | - } | |
| 693 | - else { | |
| 694 | - $html = $label . $description . $help_button . $help_panel . $content; | |
| 695 | - } | |
| 696 | - } | |
| 697 | - | |
| 698 | - return $html; | |
| 699 | - } | |
| 700 | - | |
| 701 | - /** | |
| 702 | 455 | * Saves the WP SEO metadata for posts. |
| 703 | 456 | * |
| 704 | 457 | * {@internal $_POST parameters are validated via sanitize_post_meta().}} |
| 705 | 458 | * |
| @@ -754,11 +507,16 @@ | ||
| 754 | 507 | $meta_boxes, |
| 755 | 508 | WPSEO_Meta::get_meta_field_defs( 'general', $post->post_type ), |
| 756 | 509 | WPSEO_Meta::get_meta_field_defs( 'advanced' ), |
| 757 | 510 | $social_fields, |
| 758 | - WPSEO_Meta::get_meta_field_defs( 'schema', $post->post_type ) | |
| 511 | + WPSEO_Meta::get_meta_field_defs( 'schema', $post->post_type ), | |
| 759 | 512 | ); |
| 760 | 513 | |
| 514 | + // We can't detect in save_postdata whether the request is coming from the block editor, so we gate the content_planner fields on post type only. | |
| 515 | + if ( $post->post_type === 'post' ) { | |
| 516 | + $meta_boxes = array_merge( $meta_boxes, WPSEO_Meta::get_meta_field_defs( 'content_planner' ) ); | |
| 517 | + } | |
| 518 | + | |
| 761 | 519 | foreach ( $meta_boxes as $key => $meta_box ) { |
| 762 | 520 | |
| 763 | 521 | // If analysis is disabled remove that analysis score value from the DB. |
| 764 | 522 | if ( $this->is_meta_value_disabled( $key ) ) { |
| @@ -808,9 +566,9 @@ | ||
| 808 | 566 | * |
| 809 | 567 | * @return bool Whether the given meta value key is disabled. |
| 810 | 568 | */ |
| 811 | 569 | public function is_meta_value_disabled( $key ) { |
| 812 | - if ( $key === 'linkdex' && ! $this->seo_analysis->is_enabled() ) { | |
| 570 | + if ( in_array( $key, [ 'linkdex', 'seo_title_score', 'meta_description_score' ], true ) && ! $this->seo_analysis->is_enabled() ) { | |
| 813 | 571 | return true; |
| 814 | 572 | } |
| 815 | 573 | |
| 816 | 574 | if ( $key === 'content_score' && ! $this->readability_analysis->is_enabled() ) { |
| @@ -816,8 +574,12 @@ | ||
| 816 | 574 | if ( $key === 'content_score' && ! $this->readability_analysis->is_enabled() ) { |
| 817 | 575 | return true; |
| 818 | 576 | } |
| 819 | 577 | |
| 578 | + if ( $key === 'inclusive_language_score' && ! $this->inclusive_language_analysis->is_enabled() ) { | |
| 579 | + return true; | |
| 580 | + } | |
| 581 | + | |
| 820 | 582 | return false; |
| 821 | 583 | } |
| 822 | 584 | |
| 823 | 585 | /** |
| @@ -823,32 +585,35 @@ | ||
| 823 | 585 | /** |
| 824 | 586 | * Enqueues all the needed JS and CSS. |
| 825 | 587 | * |
| 826 | 588 | * @todo [JRF => whomever] Create css/metabox-mp6.css file and add it to the below allowed colors array when done. |
| 589 | + * | |
| 590 | + * @return void | |
| 827 | 591 | */ |
| 828 | 592 | public function enqueue() { |
| 829 | 593 | global $pagenow; |
| 830 | 594 | |
| 595 | + if ( $this->readability_analysis->is_enabled() ) { | |
| 596 | + $this->editor = new WPSEO_Metabox_Editor(); | |
| 597 | + $this->editor->register_hooks(); | |
| 598 | + } | |
| 599 | + | |
| 831 | 600 | $asset_manager = new WPSEO_Admin_Asset_Manager(); |
| 832 | 601 | |
| 833 | - $is_editor = self::is_post_overview( $pagenow ) || self::is_post_edit( $pagenow ); | |
| 834 | - | |
| 835 | 602 | if ( self::is_post_overview( $pagenow ) ) { |
| 836 | - $asset_manager->enqueue_style( 'edit-page' ); | |
| 837 | - $asset_manager->enqueue_script( 'edit-page' ); | |
| 838 | - | |
| 839 | 603 | return; |
| 840 | 604 | } |
| 841 | 605 | |
| 842 | 606 | /* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */ |
| 843 | - if ( ( $is_editor === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || $this->display_metabox() === false ) { | |
| 607 | + if ( ( self::is_post_edit( $pagenow ) === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || $this->display_metabox() === false ) { | |
| 844 | 608 | return; |
| 845 | 609 | } |
| 846 | 610 | |
| 847 | 611 | $post_id = get_queried_object_id(); |
| 848 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 849 | - if ( empty( $post_id ) && isset( $_GET['post'] ) ) { | |
| 850 | - $post_id = sanitize_text_field( filter_input( INPUT_GET, 'post' ) ); | |
| 612 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 613 | + if ( empty( $post_id ) && isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) { | |
| 614 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 615 | + $post_id = sanitize_text_field( wp_unslash( $_GET['post'] ) ); | |
| 851 | 616 | } |
| 852 | 617 | |
| 853 | 618 | if ( $post_id !== 0 ) { |
| 854 | 619 | // Enqueue files needed for upload functionality. |
| @@ -855,13 +620,16 @@ | ||
| 855 | 620 | wp_enqueue_media( [ 'post' => $post_id ] ); |
| 856 | 621 | } |
| 857 | 622 | |
| 858 | 623 | $asset_manager->enqueue_style( 'metabox-css' ); |
| 859 | - $asset_manager->enqueue_style( 'scoring' ); | |
| 860 | - $asset_manager->enqueue_style( 'select2' ); | |
| 624 | + if ( $this->readability_analysis->is_enabled() ) { | |
| 625 | + $asset_manager->enqueue_style( 'scoring' ); | |
| 626 | + } | |
| 861 | 627 | $asset_manager->enqueue_style( 'monorepo' ); |
| 628 | + $asset_manager->enqueue_style( 'ai-generator' ); | |
| 629 | + $asset_manager->enqueue_style( 'ai-fix-assessments' ); | |
| 862 | 630 | |
| 863 | - $is_block_editor = WP_Screen::get()->is_block_editor(); | |
| 631 | + $is_block_editor = YoastSEO()->helpers->current_page->is_block_editor(); | |
| 864 | 632 | $post_edit_handle = 'post-edit'; |
| 865 | 633 | if ( ! $is_block_editor ) { |
| 866 | 634 | $post_edit_handle = 'post-edit-classic'; |
| 867 | 635 | } |
| @@ -877,9 +645,8 @@ | ||
| 877 | 645 | $asset_manager->localize_script( $post_edit_handle, 'wpseoAdminL10n', WPSEO_Utils::get_admin_l10n() ); |
| 878 | 646 | |
| 879 | 647 | $plugins_script_data = [ |
| 880 | 648 | 'replaceVars' => [ |
| 881 | - 'no_parent_text' => __( '(no parent)', 'wordpress-seo' ), | |
| 882 | 649 | 'replace_vars' => $this->get_replace_vars(), |
| 883 | 650 | 'hidden_replace_vars' => $this->get_hidden_replace_vars(), |
| 884 | 651 | 'recommended_replace_vars' => $this->get_recommended_replace_vars(), |
| 885 | 652 | 'scope' => $this->determine_scope(), |
| @@ -885,10 +652,10 @@ | ||
| 885 | 652 | 'scope' => $this->determine_scope(), |
| 886 | 653 | 'has_taxonomies' => $this->current_post_type_has_taxonomies(), |
| 887 | 654 | ], |
| 888 | 655 | 'shortcodes' => [ |
| 656 | + 'wpseo_shortcode_tags' => $this->get_valid_shortcode_tags(), | |
| 889 | 657 | 'wpseo_filter_shortcodes_nonce' => wp_create_nonce( 'wpseo-filter-shortcodes' ), |
| 890 | - 'wpseo_shortcode_tags' => $this->get_valid_shortcode_tags(), | |
| 891 | 658 | ], |
| 892 | 659 | ]; |
| 893 | 660 | |
| 894 | 661 | $worker_script_data = [ |
| @@ -897,44 +664,49 @@ | ||
| 897 | 664 | 'keywords_assessment_url' => YoastSEO()->helpers->asset->get_asset_url( 'yoast-seo-used-keywords-assessment' ), |
| 898 | 665 | 'log_level' => WPSEO_Utils::get_analysis_worker_log_level(), |
| 899 | 666 | ]; |
| 900 | 667 | |
| 901 | - $alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class ); | |
| 902 | - $dismissed_alerts = $alert_dismissal_action->all_dismissed(); | |
| 668 | + $page_on_front = (int) get_option( 'page_on_front' ); | |
| 669 | + $homepage_is_page = get_option( 'show_on_front' ) === 'page'; | |
| 670 | + $is_front_page = $homepage_is_page && $page_on_front === (int) $post_id; | |
| 903 | 671 | |
| 904 | 672 | $script_data = [ |
| 905 | - // @todo replace this translation with JavaScript translations. | |
| 906 | - 'media' => [ 'choose_image' => __( 'Use Image', 'wordpress-seo' ) ], | |
| 907 | - 'metabox' => $this->get_metabox_script_data(), | |
| 908 | - 'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ), | |
| 909 | - 'isPost' => true, | |
| 910 | - 'isBlockEditor' => $is_block_editor, | |
| 911 | - 'postStatus' => get_post_status( $post_id ), | |
| 912 | - 'analysis' => [ | |
| 913 | - 'plugins' => $plugins_script_data, | |
| 914 | - 'worker' => $worker_script_data, | |
| 915 | - 'estimatedReadingTimeEnabled' => $this->estimated_reading_time_conditional->is_met(), | |
| 673 | + 'metabox' => $this->get_metabox_script_data(), | |
| 674 | + 'isPost' => true, | |
| 675 | + 'isBlockEditor' => $is_block_editor, | |
| 676 | + 'postId' => $post_id, | |
| 677 | + 'postStatus' => get_post_status( $post_id ), | |
| 678 | + 'postType' => get_post_type( $post_id ), | |
| 679 | + 'isPage' => get_post_type( $post_id ) === 'page', | |
| 680 | + 'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ), | |
| 681 | + 'analysis' => [ | |
| 682 | + 'plugins' => $plugins_script_data, | |
| 683 | + 'worker' => $worker_script_data, | |
| 916 | 684 | ], |
| 917 | - 'dismissedAlerts' => $dismissed_alerts, | |
| 685 | + 'isFrontPage' => $is_front_page, | |
| 918 | 686 | ]; |
| 919 | 687 | |
| 920 | - if ( post_type_supports( get_post_type(), 'thumbnail' ) ) { | |
| 688 | + /** | |
| 689 | + * The website information repository. | |
| 690 | + * | |
| 691 | + * @var Website_Information_Repository $repo | |
| 692 | + */ | |
| 693 | + $repo = YoastSEO()->classes->get( Website_Information_Repository::class ); | |
| 694 | + $site_information = $repo->get_post_site_information(); | |
| 695 | + $site_information->set_permalink( $this->get_permalink() ); | |
| 696 | + $script_data = array_merge_recursive( $site_information->get_legacy_site_information(), $script_data ); | |
| 697 | + | |
| 698 | + if ( ! $is_block_editor && post_type_supports( get_post_type(), 'thumbnail' ) ) { | |
| 921 | 699 | $asset_manager->enqueue_style( 'featured-image' ); |
| 922 | - | |
| 923 | - // @todo replace this translation with JavaScript translations. | |
| 924 | - $script_data['featuredImage'] = [ | |
| 925 | - 'featured_image_notice' => __( 'SEO issue: The featured image should be at least 200 by 200 pixels to be picked up by Facebook and other social media sites.', 'wordpress-seo' ), | |
| 926 | - ]; | |
| 927 | 700 | } |
| 928 | 701 | |
| 929 | 702 | $asset_manager->localize_script( $post_edit_handle, 'wpseoScriptData', $script_data ); |
| 930 | - $asset_manager->enqueue_user_language_script(); | |
| 931 | 703 | } |
| 932 | 704 | |
| 933 | 705 | /** |
| 934 | 706 | * Returns post in metabox context. |
| 935 | 707 | * |
| 936 | - * @return WP_Post|array | |
| 708 | + * @return WP_Post|array<string|int|bool> | |
| 937 | 709 | */ |
| 938 | 710 | protected function get_metabox_post() { |
| 939 | 711 | if ( $this->post !== null ) { |
| 940 | 712 | return $this->post; |
| @@ -939,11 +711,12 @@ | ||
| 939 | 711 | if ( $this->post !== null ) { |
| 940 | 712 | return $this->post; |
| 941 | 713 | } |
| 942 | 714 | |
| 943 | - $post = filter_input( INPUT_GET, 'post' ); | |
| 944 | - if ( ! empty( $post ) ) { | |
| 945 | - $post_id = (int) WPSEO_Utils::validate_int( $post ); | |
| 715 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 716 | + if ( isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) { | |
| 717 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, Sanitization happens in the validate_int function. | |
| 718 | + $post_id = (int) WPSEO_Utils::validate_int( wp_unslash( $_GET['post'] ) ); | |
| 946 | 719 | |
| 947 | 720 | $this->post = get_post( $post_id ); |
| 948 | 721 | |
| 949 | 722 | return $this->post; |
| @@ -960,9 +733,9 @@ | ||
| 960 | 733 | |
| 961 | 734 | /** |
| 962 | 735 | * Returns an array with shortcode tags for all registered shortcodes. |
| 963 | 736 | * |
| 964 | - * @return array | |
| 737 | + * @return string[] | |
| 965 | 738 | */ |
| 966 | 739 | private function get_valid_shortcode_tags() { |
| 967 | 740 | $shortcode_tags = []; |
| 968 | 741 | |
| @@ -975,9 +748,9 @@ | ||
| 975 | 748 | |
| 976 | 749 | /** |
| 977 | 750 | * Prepares the replace vars for localization. |
| 978 | 751 | * |
| 979 | - * @return array Replace vars. | |
| 752 | + * @return string[] Replace vars. | |
| 980 | 753 | */ |
| 981 | 754 | private function get_replace_vars() { |
| 982 | 755 | $cached_replacement_vars = []; |
| 983 | 756 | |
| @@ -1024,9 +797,9 @@ | ||
| 1024 | 797 | |
| 1025 | 798 | /** |
| 1026 | 799 | * Prepares the recommended replace vars for localization. |
| 1027 | 800 | * |
| 1028 | - * @return array Recommended replacement variables. | |
| 801 | + * @return array<string[]> Recommended replacement variables. | |
| 1029 | 802 | */ |
| 1030 | 803 | private function get_recommended_replace_vars() { |
| 1031 | 804 | $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars(); |
| 1032 | 805 | |
| @@ -1040,9 +813,9 @@ | ||
| 1040 | 813 | * Gets the custom replace variables for custom taxonomies and fields. |
| 1041 | 814 | * |
| 1042 | 815 | * @param WP_Post $post The post to check for custom taxonomies and fields. |
| 1043 | 816 | * |
| 1044 | - * @return array Array containing all the replacement variables. | |
| 817 | + * @return array<string[]> Array containing all the replacement variables. | |
| 1045 | 818 | */ |
| 1046 | 819 | private function get_custom_replace_vars( $post ) { |
| 1047 | 820 | return [ |
| 1048 | 821 | 'custom_fields' => $this->get_custom_fields_replace_vars( $post ), |
| @@ -1054,9 +827,9 @@ | ||
| 1054 | 827 | * Gets the custom replace variables for custom taxonomies. |
| 1055 | 828 | * |
| 1056 | 829 | * @param WP_Post $post The post to check for custom taxonomies. |
| 1057 | 830 | * |
| 1058 | - * @return array Array containing all the replacement variables. | |
| 831 | + * @return array<string[]> Array containing all the replacement variables. | |
| 1059 | 832 | */ |
| 1060 | 833 | private function get_custom_taxonomies_replace_vars( $post ) { |
| 1061 | 834 | $taxonomies = get_object_taxonomies( $post, 'objects' ); |
| 1062 | 835 | $custom_replace_vars = []; |
| @@ -1085,9 +858,9 @@ | ||
| 1085 | 858 | * Gets the custom replace variables for custom fields. |
| 1086 | 859 | * |
| 1087 | 860 | * @param WP_Post $post The post to check for custom fields. |
| 1088 | 861 | * |
| 1089 | - * @return array Array containing all the replacement variables. | |
| 862 | + * @return array<string[]> Array containing all the replacement variables. | |
| 1090 | 863 | */ |
| 1091 | 864 | private function get_custom_fields_replace_vars( $post ) { |
| 1092 | 865 | $custom_replace_vars = []; |
| 1093 | 866 | |
| @@ -1102,8 +875,25 @@ | ||
| 1102 | 875 | if ( ! is_array( $custom_fields ) ) { |
| 1103 | 876 | return $custom_replace_vars; |
| 1104 | 877 | } |
| 1105 | 878 | |
| 879 | + $meta = YoastSEO()->meta->for_post( $post->ID ); | |
| 880 | + | |
| 881 | + if ( ! $meta ) { | |
| 882 | + return $custom_replace_vars; | |
| 883 | + } | |
| 884 | + | |
| 885 | + // Simply concatenate all fields containing replace vars so we can handle them all with a single regex find. | |
| 886 | + $replace_vars_fields = implode( | |
| 887 | + ' ', | |
| 888 | + [ | |
| 889 | + $meta->presentation->title, | |
| 890 | + $meta->presentation->meta_description, | |
| 891 | + ], | |
| 892 | + ); | |
| 893 | + | |
| 894 | + preg_match_all( '/%%cf_([A-Za-z0-9_]+)%%/', $replace_vars_fields, $matches ); | |
| 895 | + $fields_to_include = $matches[1]; | |
| 1106 | 896 | foreach ( $custom_fields as $custom_field_name => $custom_field ) { |
| 1107 | 897 | // Skip private custom fields. |
| 1108 | 898 | if ( substr( $custom_field_name, 0, 1 ) === '_' ) { |
| 1109 | 899 | continue; |
| @@ -1108,8 +898,13 @@ | ||
| 1108 | 898 | if ( substr( $custom_field_name, 0, 1 ) === '_' ) { |
| 1109 | 899 | continue; |
| 1110 | 900 | } |
| 1111 | 901 | |
| 902 | + // Skip custom fields that are not used, new ones will be fetched dynamically. | |
| 903 | + if ( ! in_array( $custom_field_name, $fields_to_include, true ) ) { | |
| 904 | + continue; | |
| 905 | + } | |
| 906 | + | |
| 1112 | 907 | // Skip custom field values that are serialized. |
| 1113 | 908 | if ( is_serialized( $custom_field[0] ) ) { |
| 1114 | 909 | continue; |
| 1115 | 910 | } |
| @@ -1149,6 +944,22 @@ | ||
| 1149 | 944 | * @return string The product title. |
| 1150 | 945 | */ |
| 1151 | 946 | protected function get_product_title() { |
| 1152 | 947 | return YoastSEO()->helpers->product->get_product_name(); |
| 948 | + } | |
| 949 | + | |
| 950 | + /** | |
| 951 | + * Gets the permalink. | |
| 952 | + * | |
| 953 | + * @return string | |
| 954 | + */ | |
| 955 | + protected function get_permalink() { | |
| 956 | + $permalink = ''; | |
| 957 | + | |
| 958 | + if ( is_object( $this->get_metabox_post() ) ) { | |
| 959 | + $permalink = get_sample_permalink( $this->get_metabox_post()->ID ); | |
| 960 | + $permalink = $permalink[0]; | |
| 961 | + } | |
| 962 | + | |
| 963 | + return $permalink; | |
| 1153 | 964 | } |
| 1154 | 965 | } |