| @@ -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 ); |
| @@ -166,10 +159,17 @@ | ||
| 166 | 159 | * Translates text strings for use in the meta box. |
| 167 | 160 | * |
| 168 | 161 | * IMPORTANT: if you want to add a new string (option) somewhere, make sure you add that array key to |
| 169 | 162 | * the main meta box definition array in the class WPSEO_Meta() as well!!!! |
| 163 | + * | |
| 164 | + * @deprecated 23.5 | |
| 165 | + * @codeCoverageIgnore | |
| 166 | + * | |
| 167 | + * @return void | |
| 170 | 168 | */ |
| 171 | 169 | public static function translate_meta_boxes() { |
| 170 | + _deprecated_function( __METHOD__, 'Yoast SEO 23.5' ); | |
| 171 | + | |
| 172 | 172 | WPSEO_Meta::$meta_fields['general']['title']['title'] = __( 'SEO title', 'wordpress-seo' ); |
| 173 | 173 | WPSEO_Meta::$meta_fields['general']['metadesc']['title'] = __( 'Meta description', 'wordpress-seo' ); |
| 174 | 174 | |
| 175 | 175 | /* translators: %s expands to the post type name. */ |
| @@ -201,15 +201,15 @@ | ||
| 201 | 201 | WPSEO_Meta::$meta_fields['advanced']['canonical']['description'] = sprintf( |
| 202 | 202 | /* translators: 1: link open tag; 2: link close tag. */ |
| 203 | 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 | 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>' | |
| 205 | + WPSEO_Admin_Utils::get_new_tab_message() . '</a>', | |
| 206 | 206 | ); |
| 207 | 207 | |
| 208 | 208 | WPSEO_Meta::$meta_fields['advanced']['redirect']['title'] = __( '301 Redirect', 'wordpress-seo' ); |
| 209 | 209 | WPSEO_Meta::$meta_fields['advanced']['redirect']['description'] = __( 'The URL that this page should redirect to.', 'wordpress-seo' ); |
| 210 | 210 | |
| 211 | - do_action( 'wpseo_tab_translate' ); | |
| 211 | + do_action_deprecated( 'wpseo_tab_translate', [], 'Yoast SEO 23.5', '', 'WPSEO_Metabox::translate_meta_boxes is deprecated.' ); | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | 215 | * Determines whether the metabox should be shown for the passed identifier. |
| @@ -250,9 +250,9 @@ | ||
| 250 | 250 | [ $this, 'meta_box' ], |
| 251 | 251 | $post_type, |
| 252 | 252 | 'normal', |
| 253 | 253 | apply_filters( 'wpseo_metabox_prio', 'high' ), |
| 254 | - [ '__block_editor_compatible_meta_box' => true ] | |
| 254 | + [ '__block_editor_compatible_meta_box' => true ], | |
| 255 | 255 | ); |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| @@ -258,11 +258,11 @@ | ||
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Adds CSS classes to the meta box. |
| 261 | 261 | * |
| 262 | - * @param array $classes An array of postbox CSS classes. | |
| 262 | + * @param string[] $classes An array of postbox CSS classes. | |
| 263 | 263 | * |
| 264 | - * @return array List of classes that will be applied to the editbox container. | |
| 264 | + * @return string[] List of classes that will be applied to the editbox container. | |
| 265 | 265 | */ |
| 266 | 266 | public function wpseo_metabox_class( $classes ) { |
| 267 | 267 | $classes[] = 'yoast wpseo-metabox'; |
| 268 | 268 | |
| @@ -271,24 +271,18 @@ | ||
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Passes variables to js for use with the post-scraper. |
| 274 | 274 | * |
| 275 | - * @return array | |
| 275 | + * @return array<string, string|array<string|int|bool>|bool|int> | |
| 276 | 276 | */ |
| 277 | 277 | public function get_metabox_script_data() { |
| 278 | - $permalink = ''; | |
| 278 | + $permalink = $this->get_permalink(); | |
| 279 | 279 | |
| 280 | - if ( is_object( $this->get_metabox_post() ) ) { | |
| 281 | - $permalink = get_sample_permalink( $this->get_metabox_post()->ID ); | |
| 282 | - $permalink = $permalink[0]; | |
| 283 | - } | |
| 284 | - | |
| 285 | 280 | $post_formatter = new WPSEO_Metabox_Formatter( |
| 286 | - new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink ) | |
| 281 | + new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink ), | |
| 287 | 282 | ); |
| 288 | 283 | |
| 289 | 284 | $values = $post_formatter->get_values(); |
| 290 | - | |
| 291 | 285 | /** This filter is documented in admin/filters/class-cornerstone-filter.php. */ |
| 292 | 286 | $post_types = apply_filters( 'wpseo_cornerstone_post_types', WPSEO_Post_Type::get_accessible_post_types() ); |
| 293 | 287 | if ( $values['cornerstoneActive'] && ! in_array( $this->get_metabox_post()->post_type, $post_types, true ) ) { |
| 294 | 288 | $values['cornerstoneActive'] = false; |
| @@ -331,8 +325,10 @@ | ||
| 331 | 325 | } |
| 332 | 326 | |
| 333 | 327 | /** |
| 334 | 328 | * Outputs the meta box. |
| 329 | + * | |
| 330 | + * @return void | |
| 335 | 331 | */ |
| 336 | 332 | public function meta_box() { |
| 337 | 333 | $this->render_hidden_fields(); |
| 338 | 334 | $this->render_tabs(); |
| @@ -361,12 +357,27 @@ | ||
| 361 | 357 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class. |
| 362 | 358 | echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'social' ); |
| 363 | 359 | } |
| 364 | 360 | |
| 361 | + $is_block_editor = YoastSEO()->helpers->current_page->is_block_editor(); | |
| 362 | + if ( $is_block_editor && $this->get_metabox_post()->post_type === 'post' ) { | |
| 363 | + /** | |
| 364 | + * Filter: 'wpseo_enable_ai_content_planner_inline_banner' - Allows hiding the AI Content Planner inline banner site-wide. | |
| 365 | + * | |
| 366 | + * Returning false stops the hidden meta inputs from being rendered, which the editor JS treats as "banner disabled". | |
| 367 | + * | |
| 368 | + * @param bool $enabled Whether the inline banner should be available in the editor. Default true. | |
| 369 | + */ | |
| 370 | + if ( apply_filters( 'wpseo_enable_ai_content_planner_inline_banner', true ) ) { | |
| 371 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class. | |
| 372 | + echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'content_planner' ); | |
| 373 | + } | |
| 374 | + } | |
| 375 | + | |
| 365 | 376 | /** |
| 366 | 377 | * Filter: 'wpseo_content_meta_section_content' - Allow filtering the metabox content before outputting. |
| 367 | 378 | * |
| 368 | - * @api string $post_content The metabox content string. | |
| 379 | + * @param string $post_content The metabox content string. | |
| 369 | 380 | */ |
| 370 | 381 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output should be escaped in the filter. |
| 371 | 382 | echo apply_filters( 'wpseo_content_meta_section_content', '' ); |
| 372 | 383 | } |
| @@ -417,13 +428,17 @@ | ||
| 417 | 428 | if ( $this->readability_analysis->is_enabled() ) { |
| 418 | 429 | $tabs[] = new WPSEO_Metabox_Section_Readability(); |
| 419 | 430 | } |
| 420 | 431 | |
| 432 | + if ( $this->inclusive_language_analysis->is_enabled() ) { | |
| 433 | + $tabs[] = new WPSEO_Metabox_Section_Inclusive_Language(); | |
| 434 | + } | |
| 435 | + | |
| 421 | 436 | if ( $this->is_advanced_metadata_enabled ) { |
| 422 | 437 | $tabs[] = new WPSEO_Metabox_Section_React( |
| 423 | 438 | 'schema', |
| 424 | 439 | '<span class="wpseo-schema-icon"></span>' . __( 'Schema', 'wordpress-seo' ), |
| 425 | - '' | |
| 440 | + '', | |
| 426 | 441 | ); |
| 427 | 442 | } |
| 428 | 443 | |
| 429 | 444 | if ( $this->social_is_enabled ) { |
| @@ -432,9 +447,9 @@ | ||
| 432 | 447 | '<span class="dashicons dashicons-share"></span>' . __( 'Social', 'wordpress-seo' ), |
| 433 | 448 | '', |
| 434 | 449 | [ |
| 435 | 450 | 'html_after' => '<div id="wpseo-section-social"></div>', |
| 436 | - ] | |
| 451 | + ], | |
| 437 | 452 | ); |
| 438 | 453 | } |
| 439 | 454 | |
| 440 | 455 | $tabs = array_merge( $tabs, $this->get_additional_tabs() ); |
| @@ -483,9 +498,9 @@ | ||
| 483 | 498 | $tabs[] = new WPSEO_Metabox_Section_Additional( |
| 484 | 499 | $tab['name'], |
| 485 | 500 | $tab['link_content'], |
| 486 | 501 | $tab['content'], |
| 487 | - $options | |
| 502 | + $options, | |
| 488 | 503 | ); |
| 489 | 504 | } |
| 490 | 505 | } |
| 491 | 506 | |
| @@ -494,16 +509,19 @@ | ||
| 494 | 509 | |
| 495 | 510 | /** |
| 496 | 511 | * Adds a line in the meta box. |
| 497 | 512 | * |
| 498 | - * @todo [JRF] Check if $class is added appropriately everywhere. | |
| 513 | + * @deprecated 23.5 | |
| 514 | + * @codeCoverageIgnore | |
| 499 | 515 | * |
| 500 | - * @param array $meta_field_def Contains the vars based on which output is generated. | |
| 501 | - * @param string $key Internal key (without prefix). | |
| 516 | + * @param string[] $meta_field_def Contains the vars based on which output is generated. | |
| 517 | + * @param string $key Internal key (without prefix). | |
| 502 | 518 | * |
| 503 | 519 | * @return string |
| 504 | 520 | */ |
| 505 | 521 | public function do_meta_box( $meta_field_def, $key = '' ) { |
| 522 | + _deprecated_function( __METHOD__, 'Yoast SEO 23.5' ); | |
| 523 | + | |
| 506 | 524 | $content = ''; |
| 507 | 525 | $esc_form_key = esc_attr( WPSEO_Meta::$form_prefix . $key ); |
| 508 | 526 | $meta_value = WPSEO_Meta::get_value( $key, $this->get_metabox_post()->ID ); |
| 509 | 527 | |
| @@ -591,9 +609,8 @@ | ||
| 591 | 609 | } |
| 592 | 610 | |
| 593 | 611 | $options_count = count( $meta_field_def['options'] ); |
| 594 | 612 | |
| 595 | - // This select now uses Select2. | |
| 596 | 613 | $content .= '<select multiple="multiple" size="' . esc_attr( $options_count ) . '" name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="yoast' . $class . '"' . $aria_describedby . '>'; |
| 597 | 614 | foreach ( $meta_field_def['options'] as $val => $option ) { |
| 598 | 615 | $selected = ''; |
| 599 | 616 | if ( in_array( $val, $selected_arr, true ) ) { |
| @@ -621,38 +638,13 @@ | ||
| 621 | 638 | } |
| 622 | 639 | unset( $val, $option, $checked ); |
| 623 | 640 | } |
| 624 | 641 | break; |
| 625 | - | |
| 626 | - case 'upload': | |
| 627 | - $content .= '<input' . | |
| 628 | - ' id="' . $esc_form_key . '"' . | |
| 629 | - ' type="text"' . | |
| 630 | - ' size="36"' . | |
| 631 | - ' class="' . $class . '"' . | |
| 632 | - ' name="' . $esc_form_key . '"' . | |
| 633 | - ' value="' . esc_attr( $meta_value ) . '"' . $aria_describedby . | |
| 634 | - ' readonly="readonly"' . | |
| 635 | - ' /> '; | |
| 636 | - $content .= '<input' . | |
| 637 | - ' id="' . esc_attr( $esc_form_key ) . '_button"' . | |
| 638 | - ' class="wpseo_image_upload_button button"' . | |
| 639 | - ' data-target="' . esc_attr( $esc_form_key ) . '"' . | |
| 640 | - ' data-target-id="' . esc_attr( $esc_form_key ) . '-id"' . | |
| 641 | - ' type="button"' . | |
| 642 | - ' value="' . esc_attr__( 'Upload Image', 'wordpress-seo' ) . '"' . | |
| 643 | - ' /> '; | |
| 644 | - $content .= '<input' . | |
| 645 | - ' class="wpseo_image_remove_button button"' . | |
| 646 | - ' type="button"' . | |
| 647 | - ' value="' . esc_attr__( 'Clear Image', 'wordpress-seo' ) . '"' . | |
| 648 | - ' />'; | |
| 649 | - break; | |
| 650 | 642 | } |
| 651 | 643 | |
| 652 | 644 | $html = ''; |
| 653 | 645 | if ( $content === '' ) { |
| 654 | - $content = apply_filters( 'wpseo_do_meta_box_field_' . $key, $content, $meta_value, $esc_form_key, $meta_field_def, $key ); | |
| 646 | + $content = apply_filters_deprecated( 'wpseo_do_meta_box_field_' . $key, [ $content, $meta_value, $esc_form_key, $meta_field_def, $key ], 'Yoast SEO 23.5', '', 'do_meta_box is deprecated' ); | |
| 655 | 647 | } |
| 656 | 648 | |
| 657 | 649 | if ( $content !== '' ) { |
| 658 | 650 | |
| @@ -748,11 +740,16 @@ | ||
| 748 | 740 | $meta_boxes, |
| 749 | 741 | WPSEO_Meta::get_meta_field_defs( 'general', $post->post_type ), |
| 750 | 742 | WPSEO_Meta::get_meta_field_defs( 'advanced' ), |
| 751 | 743 | $social_fields, |
| 752 | - WPSEO_Meta::get_meta_field_defs( 'schema', $post->post_type ) | |
| 744 | + WPSEO_Meta::get_meta_field_defs( 'schema', $post->post_type ), | |
| 753 | 745 | ); |
| 754 | 746 | |
| 747 | + // 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. | |
| 748 | + if ( $post->post_type === 'post' ) { | |
| 749 | + $meta_boxes = array_merge( $meta_boxes, WPSEO_Meta::get_meta_field_defs( 'content_planner' ) ); | |
| 750 | + } | |
| 751 | + | |
| 755 | 752 | foreach ( $meta_boxes as $key => $meta_box ) { |
| 756 | 753 | |
| 757 | 754 | // If analysis is disabled remove that analysis score value from the DB. |
| 758 | 755 | if ( $this->is_meta_value_disabled( $key ) ) { |
| @@ -802,9 +799,9 @@ | ||
| 802 | 799 | * |
| 803 | 800 | * @return bool Whether the given meta value key is disabled. |
| 804 | 801 | */ |
| 805 | 802 | public function is_meta_value_disabled( $key ) { |
| 806 | - if ( $key === 'linkdex' && ! $this->seo_analysis->is_enabled() ) { | |
| 803 | + if ( in_array( $key, [ 'linkdex', 'seo_title_score', 'meta_description_score' ], true ) && ! $this->seo_analysis->is_enabled() ) { | |
| 807 | 804 | return true; |
| 808 | 805 | } |
| 809 | 806 | |
| 810 | 807 | if ( $key === 'content_score' && ! $this->readability_analysis->is_enabled() ) { |
| @@ -810,8 +807,12 @@ | ||
| 810 | 807 | if ( $key === 'content_score' && ! $this->readability_analysis->is_enabled() ) { |
| 811 | 808 | return true; |
| 812 | 809 | } |
| 813 | 810 | |
| 811 | + if ( $key === 'inclusive_language_score' && ! $this->inclusive_language_analysis->is_enabled() ) { | |
| 812 | + return true; | |
| 813 | + } | |
| 814 | + | |
| 814 | 815 | return false; |
| 815 | 816 | } |
| 816 | 817 | |
| 817 | 818 | /** |
| @@ -817,32 +818,35 @@ | ||
| 817 | 818 | /** |
| 818 | 819 | * Enqueues all the needed JS and CSS. |
| 819 | 820 | * |
| 820 | 821 | * @todo [JRF => whomever] Create css/metabox-mp6.css file and add it to the below allowed colors array when done. |
| 822 | + * | |
| 823 | + * @return void | |
| 821 | 824 | */ |
| 822 | 825 | public function enqueue() { |
| 823 | 826 | global $pagenow; |
| 824 | 827 | |
| 828 | + if ( $this->readability_analysis->is_enabled() ) { | |
| 829 | + $this->editor = new WPSEO_Metabox_Editor(); | |
| 830 | + $this->editor->register_hooks(); | |
| 831 | + } | |
| 832 | + | |
| 825 | 833 | $asset_manager = new WPSEO_Admin_Asset_Manager(); |
| 826 | 834 | |
| 827 | - $is_editor = self::is_post_overview( $pagenow ) || self::is_post_edit( $pagenow ); | |
| 828 | - | |
| 829 | 835 | if ( self::is_post_overview( $pagenow ) ) { |
| 830 | - $asset_manager->enqueue_style( 'edit-page' ); | |
| 831 | - $asset_manager->enqueue_script( 'edit-page' ); | |
| 832 | - | |
| 833 | 836 | return; |
| 834 | 837 | } |
| 835 | 838 | |
| 836 | 839 | /* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */ |
| 837 | - if ( ( $is_editor === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || $this->display_metabox() === false ) { | |
| 840 | + if ( ( self::is_post_edit( $pagenow ) === false && apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false ) || $this->display_metabox() === false ) { | |
| 838 | 841 | return; |
| 839 | 842 | } |
| 840 | 843 | |
| 841 | 844 | $post_id = get_queried_object_id(); |
| 842 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 843 | - if ( empty( $post_id ) && isset( $_GET['post'] ) ) { | |
| 844 | - $post_id = sanitize_text_field( filter_input( INPUT_GET, 'post' ) ); | |
| 845 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 846 | + if ( empty( $post_id ) && isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) { | |
| 847 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 848 | + $post_id = sanitize_text_field( wp_unslash( $_GET['post'] ) ); | |
| 845 | 849 | } |
| 846 | 850 | |
| 847 | 851 | if ( $post_id !== 0 ) { |
| 848 | 852 | // Enqueue files needed for upload functionality. |
| @@ -849,13 +853,16 @@ | ||
| 849 | 853 | wp_enqueue_media( [ 'post' => $post_id ] ); |
| 850 | 854 | } |
| 851 | 855 | |
| 852 | 856 | $asset_manager->enqueue_style( 'metabox-css' ); |
| 853 | - $asset_manager->enqueue_style( 'scoring' ); | |
| 854 | - $asset_manager->enqueue_style( 'select2' ); | |
| 857 | + if ( $this->readability_analysis->is_enabled() ) { | |
| 858 | + $asset_manager->enqueue_style( 'scoring' ); | |
| 859 | + } | |
| 855 | 860 | $asset_manager->enqueue_style( 'monorepo' ); |
| 861 | + $asset_manager->enqueue_style( 'ai-generator' ); | |
| 862 | + $asset_manager->enqueue_style( 'ai-fix-assessments' ); | |
| 856 | 863 | |
| 857 | - $is_block_editor = WP_Screen::get()->is_block_editor(); | |
| 864 | + $is_block_editor = YoastSEO()->helpers->current_page->is_block_editor(); | |
| 858 | 865 | $post_edit_handle = 'post-edit'; |
| 859 | 866 | if ( ! $is_block_editor ) { |
| 860 | 867 | $post_edit_handle = 'post-edit-classic'; |
| 861 | 868 | } |
| @@ -871,9 +878,8 @@ | ||
| 871 | 878 | $asset_manager->localize_script( $post_edit_handle, 'wpseoAdminL10n', WPSEO_Utils::get_admin_l10n() ); |
| 872 | 879 | |
| 873 | 880 | $plugins_script_data = [ |
| 874 | 881 | 'replaceVars' => [ |
| 875 | - 'no_parent_text' => __( '(no parent)', 'wordpress-seo' ), | |
| 876 | 882 | 'replace_vars' => $this->get_replace_vars(), |
| 877 | 883 | 'hidden_replace_vars' => $this->get_hidden_replace_vars(), |
| 878 | 884 | 'recommended_replace_vars' => $this->get_recommended_replace_vars(), |
| 879 | 885 | 'scope' => $this->determine_scope(), |
| @@ -879,10 +885,10 @@ | ||
| 879 | 885 | 'scope' => $this->determine_scope(), |
| 880 | 886 | 'has_taxonomies' => $this->current_post_type_has_taxonomies(), |
| 881 | 887 | ], |
| 882 | 888 | 'shortcodes' => [ |
| 889 | + 'wpseo_shortcode_tags' => $this->get_valid_shortcode_tags(), | |
| 883 | 890 | 'wpseo_filter_shortcodes_nonce' => wp_create_nonce( 'wpseo-filter-shortcodes' ), |
| 884 | - 'wpseo_shortcode_tags' => $this->get_valid_shortcode_tags(), | |
| 885 | 891 | ], |
| 886 | 892 | ]; |
| 887 | 893 | |
| 888 | 894 | $worker_script_data = [ |
| @@ -891,44 +897,49 @@ | ||
| 891 | 897 | 'keywords_assessment_url' => YoastSEO()->helpers->asset->get_asset_url( 'yoast-seo-used-keywords-assessment' ), |
| 892 | 898 | 'log_level' => WPSEO_Utils::get_analysis_worker_log_level(), |
| 893 | 899 | ]; |
| 894 | 900 | |
| 895 | - $alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class ); | |
| 896 | - $dismissed_alerts = $alert_dismissal_action->all_dismissed(); | |
| 901 | + $page_on_front = (int) get_option( 'page_on_front' ); | |
| 902 | + $homepage_is_page = get_option( 'show_on_front' ) === 'page'; | |
| 903 | + $is_front_page = $homepage_is_page && $page_on_front === (int) $post_id; | |
| 897 | 904 | |
| 898 | 905 | $script_data = [ |
| 899 | - // @todo replace this translation with JavaScript translations. | |
| 900 | - 'media' => [ 'choose_image' => __( 'Use Image', 'wordpress-seo' ) ], | |
| 901 | - 'metabox' => $this->get_metabox_script_data(), | |
| 902 | - 'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ), | |
| 903 | - 'isPost' => true, | |
| 904 | - 'isBlockEditor' => $is_block_editor, | |
| 905 | - 'postStatus' => get_post_status( $post_id ), | |
| 906 | - 'analysis' => [ | |
| 907 | - 'plugins' => $plugins_script_data, | |
| 908 | - 'worker' => $worker_script_data, | |
| 909 | - 'estimatedReadingTimeEnabled' => $this->estimated_reading_time_conditional->is_met(), | |
| 906 | + 'metabox' => $this->get_metabox_script_data(), | |
| 907 | + 'isPost' => true, | |
| 908 | + 'isBlockEditor' => $is_block_editor, | |
| 909 | + 'postId' => $post_id, | |
| 910 | + 'postStatus' => get_post_status( $post_id ), | |
| 911 | + 'postType' => get_post_type( $post_id ), | |
| 912 | + 'isPage' => get_post_type( $post_id ) === 'page', | |
| 913 | + 'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ), | |
| 914 | + 'analysis' => [ | |
| 915 | + 'plugins' => $plugins_script_data, | |
| 916 | + 'worker' => $worker_script_data, | |
| 910 | 917 | ], |
| 911 | - 'dismissedAlerts' => $dismissed_alerts, | |
| 918 | + 'isFrontPage' => $is_front_page, | |
| 912 | 919 | ]; |
| 913 | 920 | |
| 914 | - if ( post_type_supports( get_post_type(), 'thumbnail' ) ) { | |
| 921 | + /** | |
| 922 | + * The website information repository. | |
| 923 | + * | |
| 924 | + * @var Website_Information_Repository $repo | |
| 925 | + */ | |
| 926 | + $repo = YoastSEO()->classes->get( Website_Information_Repository::class ); | |
| 927 | + $site_information = $repo->get_post_site_information(); | |
| 928 | + $site_information->set_permalink( $this->get_permalink() ); | |
| 929 | + $script_data = array_merge_recursive( $site_information->get_legacy_site_information(), $script_data ); | |
| 930 | + | |
| 931 | + if ( ! $is_block_editor && post_type_supports( get_post_type(), 'thumbnail' ) ) { | |
| 915 | 932 | $asset_manager->enqueue_style( 'featured-image' ); |
| 916 | - | |
| 917 | - // @todo replace this translation with JavaScript translations. | |
| 918 | - $script_data['featuredImage'] = [ | |
| 919 | - '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' ), | |
| 920 | - ]; | |
| 921 | 933 | } |
| 922 | 934 | |
| 923 | 935 | $asset_manager->localize_script( $post_edit_handle, 'wpseoScriptData', $script_data ); |
| 924 | - $asset_manager->enqueue_user_language_script(); | |
| 925 | 936 | } |
| 926 | 937 | |
| 927 | 938 | /** |
| 928 | 939 | * Returns post in metabox context. |
| 929 | 940 | * |
| 930 | - * @return WP_Post|array | |
| 941 | + * @return WP_Post|array<string|int|bool> | |
| 931 | 942 | */ |
| 932 | 943 | protected function get_metabox_post() { |
| 933 | 944 | if ( $this->post !== null ) { |
| 934 | 945 | return $this->post; |
| @@ -933,11 +944,12 @@ | ||
| 933 | 944 | if ( $this->post !== null ) { |
| 934 | 945 | return $this->post; |
| 935 | 946 | } |
| 936 | 947 | |
| 937 | - $post = filter_input( INPUT_GET, 'post' ); | |
| 938 | - if ( ! empty( $post ) ) { | |
| 939 | - $post_id = (int) WPSEO_Utils::validate_int( $post ); | |
| 948 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. | |
| 949 | + if ( isset( $_GET['post'] ) && is_string( $_GET['post'] ) ) { | |
| 950 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, Sanitization happens in the validate_int function. | |
| 951 | + $post_id = (int) WPSEO_Utils::validate_int( wp_unslash( $_GET['post'] ) ); | |
| 940 | 952 | |
| 941 | 953 | $this->post = get_post( $post_id ); |
| 942 | 954 | |
| 943 | 955 | return $this->post; |
| @@ -954,9 +966,9 @@ | ||
| 954 | 966 | |
| 955 | 967 | /** |
| 956 | 968 | * Returns an array with shortcode tags for all registered shortcodes. |
| 957 | 969 | * |
| 958 | - * @return array | |
| 970 | + * @return string[] | |
| 959 | 971 | */ |
| 960 | 972 | private function get_valid_shortcode_tags() { |
| 961 | 973 | $shortcode_tags = []; |
| 962 | 974 | |
| @@ -969,9 +981,9 @@ | ||
| 969 | 981 | |
| 970 | 982 | /** |
| 971 | 983 | * Prepares the replace vars for localization. |
| 972 | 984 | * |
| 973 | - * @return array Replace vars. | |
| 985 | + * @return string[] Replace vars. | |
| 974 | 986 | */ |
| 975 | 987 | private function get_replace_vars() { |
| 976 | 988 | $cached_replacement_vars = []; |
| 977 | 989 | |
| @@ -1018,9 +1030,9 @@ | ||
| 1018 | 1030 | |
| 1019 | 1031 | /** |
| 1020 | 1032 | * Prepares the recommended replace vars for localization. |
| 1021 | 1033 | * |
| 1022 | - * @return array Recommended replacement variables. | |
| 1034 | + * @return array<string[]> Recommended replacement variables. | |
| 1023 | 1035 | */ |
| 1024 | 1036 | private function get_recommended_replace_vars() { |
| 1025 | 1037 | $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars(); |
| 1026 | 1038 | |
| @@ -1034,9 +1046,9 @@ | ||
| 1034 | 1046 | * Gets the custom replace variables for custom taxonomies and fields. |
| 1035 | 1047 | * |
| 1036 | 1048 | * @param WP_Post $post The post to check for custom taxonomies and fields. |
| 1037 | 1049 | * |
| 1038 | - * @return array Array containing all the replacement variables. | |
| 1050 | + * @return array<string[]> Array containing all the replacement variables. | |
| 1039 | 1051 | */ |
| 1040 | 1052 | private function get_custom_replace_vars( $post ) { |
| 1041 | 1053 | return [ |
| 1042 | 1054 | 'custom_fields' => $this->get_custom_fields_replace_vars( $post ), |
| @@ -1048,9 +1060,9 @@ | ||
| 1048 | 1060 | * Gets the custom replace variables for custom taxonomies. |
| 1049 | 1061 | * |
| 1050 | 1062 | * @param WP_Post $post The post to check for custom taxonomies. |
| 1051 | 1063 | * |
| 1052 | - * @return array Array containing all the replacement variables. | |
| 1064 | + * @return array<string[]> Array containing all the replacement variables. | |
| 1053 | 1065 | */ |
| 1054 | 1066 | private function get_custom_taxonomies_replace_vars( $post ) { |
| 1055 | 1067 | $taxonomies = get_object_taxonomies( $post, 'objects' ); |
| 1056 | 1068 | $custom_replace_vars = []; |
| @@ -1079,9 +1091,9 @@ | ||
| 1079 | 1091 | * Gets the custom replace variables for custom fields. |
| 1080 | 1092 | * |
| 1081 | 1093 | * @param WP_Post $post The post to check for custom fields. |
| 1082 | 1094 | * |
| 1083 | - * @return array Array containing all the replacement variables. | |
| 1095 | + * @return array<string[]> Array containing all the replacement variables. | |
| 1084 | 1096 | */ |
| 1085 | 1097 | private function get_custom_fields_replace_vars( $post ) { |
| 1086 | 1098 | $custom_replace_vars = []; |
| 1087 | 1099 | |
| @@ -1096,8 +1108,25 @@ | ||
| 1096 | 1108 | if ( ! is_array( $custom_fields ) ) { |
| 1097 | 1109 | return $custom_replace_vars; |
| 1098 | 1110 | } |
| 1099 | 1111 | |
| 1112 | + $meta = YoastSEO()->meta->for_post( $post->ID ); | |
| 1113 | + | |
| 1114 | + if ( ! $meta ) { | |
| 1115 | + return $custom_replace_vars; | |
| 1116 | + } | |
| 1117 | + | |
| 1118 | + // Simply concatenate all fields containing replace vars so we can handle them all with a single regex find. | |
| 1119 | + $replace_vars_fields = implode( | |
| 1120 | + ' ', | |
| 1121 | + [ | |
| 1122 | + $meta->presentation->title, | |
| 1123 | + $meta->presentation->meta_description, | |
| 1124 | + ], | |
| 1125 | + ); | |
| 1126 | + | |
| 1127 | + preg_match_all( '/%%cf_([A-Za-z0-9_]+)%%/', $replace_vars_fields, $matches ); | |
| 1128 | + $fields_to_include = $matches[1]; | |
| 1100 | 1129 | foreach ( $custom_fields as $custom_field_name => $custom_field ) { |
| 1101 | 1130 | // Skip private custom fields. |
| 1102 | 1131 | if ( substr( $custom_field_name, 0, 1 ) === '_' ) { |
| 1103 | 1132 | continue; |
| @@ -1102,8 +1131,13 @@ | ||
| 1102 | 1131 | if ( substr( $custom_field_name, 0, 1 ) === '_' ) { |
| 1103 | 1132 | continue; |
| 1104 | 1133 | } |
| 1105 | 1134 | |
| 1135 | + // Skip custom fields that are not used, new ones will be fetched dynamically. | |
| 1136 | + if ( ! in_array( $custom_field_name, $fields_to_include, true ) ) { | |
| 1137 | + continue; | |
| 1138 | + } | |
| 1139 | + | |
| 1106 | 1140 | // Skip custom field values that are serialized. |
| 1107 | 1141 | if ( is_serialized( $custom_field[0] ) ) { |
| 1108 | 1142 | continue; |
| 1109 | 1143 | } |
| @@ -1143,6 +1177,22 @@ | ||
| 1143 | 1177 | * @return string The product title. |
| 1144 | 1178 | */ |
| 1145 | 1179 | protected function get_product_title() { |
| 1146 | 1180 | return YoastSEO()->helpers->product->get_product_name(); |
| 1181 | + } | |
| 1182 | + | |
| 1183 | + /** | |
| 1184 | + * Gets the permalink. | |
| 1185 | + * | |
| 1186 | + * @return string | |
| 1187 | + */ | |
| 1188 | + protected function get_permalink() { | |
| 1189 | + $permalink = ''; | |
| 1190 | + | |
| 1191 | + if ( is_object( $this->get_metabox_post() ) ) { | |
| 1192 | + $permalink = get_sample_permalink( $this->get_metabox_post()->ID ); | |
| 1193 | + $permalink = $permalink[0]; | |
| 1194 | + } | |
| 1195 | + | |
| 1196 | + return $permalink; | |
| 1147 | 1197 | } |
| 1148 | 1198 | } |