: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Active_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Not_Premium_Conditional;
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter;
use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter;
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
* This class generates the metabox on the edit post / page as well as contains all page analysis functionality.
class WPSEO_Metabox extends WPSEO_Meta {
* Whether the social tab is enabled.
private $social_is_enabled;
* Helper to determine whether the SEO analysis is enabled.
* @var WPSEO_Metabox_Analysis_SEO
* Helper to determine whether the readability analysis is enabled.
* @var WPSEO_Metabox_Analysis_Readability
protected $readability_analysis;
* Helper to determine whether the inclusive language analysis is enabled.
* @var WPSEO_Metabox_Analysis_Inclusive_Language
protected $inclusive_language_analysis;
* The metabox editor object.
* @var WPSEO_Metabox_Editor
* Whether the advanced metadata is enabled.
protected $is_advanced_metadata_enabled;
public function __construct() {
if ( $this->is_internet_explorer() ) {
add_action( 'add_meta_boxes', [ $this, 'internet_explorer_metabox' ] );
add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
add_action( 'wp_insert_post', [ $this, 'save_postdata' ] );
add_action( 'edit_attachment', [ $this, 'save_postdata' ] );
add_action( 'add_attachment', [ $this, 'save_postdata' ] );
add_action( 'admin_init', [ $this, 'translate_meta_boxes' ] );
$this->editor = new WPSEO_Metabox_Editor();
$this->editor->register_hooks();
$this->social_is_enabled = WPSEO_Options::get( 'opengraph', false ) || WPSEO_Options::get( 'twitter', false );
$this->is_advanced_metadata_enabled = WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta' ) === false;
$this->seo_analysis = new WPSEO_Metabox_Analysis_SEO();
$this->readability_analysis = new WPSEO_Metabox_Analysis_Readability();
$this->inclusive_language_analysis = new WPSEO_Metabox_Analysis_Inclusive_Language();
* Checks whether the request comes from an IE 11 browser.
* @return bool Whether the request comes from an IE 11 browser.
public static function is_internet_explorer() {
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
$user_agent = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) );
if ( stripos( $user_agent, 'Trident/7.0' ) === false ) {
* Adds an alternative metabox for internet explorer users.
public function internet_explorer_metabox() {
$post_types = WPSEO_Post_Type::get_accessible_post_types();
$post_types = array_filter( $post_types, [ $this, 'display_metabox' ] );
if ( ! is_array( $post_types ) || $post_types === [] ) {
$product_title = $this->get_product_title();
foreach ( $post_types as $post_type ) {
add_filter( "postbox_classes_{$post_type}_wpseo_meta", [ $this, 'wpseo_metabox_class' ] );
[ $this, 'render_internet_explorer_notice' ],
apply_filters( 'wpseo_metabox_prio', 'high' ),
[ '__block_editor_compatible_meta_box' => true ]
* Renders the content for the internet explorer metabox.
public function render_internet_explorer_notice() {
/* translators: 1: Link start tag to the Firefox website, 2: Link start tag to the Chrome website, 3: Link start tag to the Edge website, 4: Link closing tag. */
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' ),
'<a href="https://www.mozilla.org/firefox/new/">',
'<a href="https://www.google.com/chrome/">',
'<a href="https://www.microsoft.com/windows/microsoft-edge">',
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped above.
echo new Alert_Presenter( $content );
* Translates text strings for use in the meta box.
* IMPORTANT: if you want to add a new string (option) somewhere, make sure you add that array key to
* the main meta box definition array in the class WPSEO_Meta() as well!!!!
public static function translate_meta_boxes() {
WPSEO_Meta::$meta_fields['general']['title']['title'] = __( 'SEO title', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['general']['metadesc']['title'] = __( 'Meta description', 'wordpress-seo' );
/* translators: %s expands to the post type name. */
WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['title'] = __( 'Allow search engines to show this %s in search results?', 'wordpress-seo' );
if ( (string) get_option( 'blog_public' ) === '0' ) {
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>';
/* translators: %1$s expands to Yes or No, %2$s expands to the post type name.*/
WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['0'] = __( 'Default for %2$s, currently: %1$s', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['2'] = __( 'Yes', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['1'] = __( 'No', 'wordpress-seo' );
/* translators: %1$s expands to the post type name.*/
WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['title'] = __( 'Should search engines follow links on this %1$s?', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['options']['0'] = __( 'Yes', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['options']['1'] = __( 'No', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['title'] = __( 'Meta robots advanced', 'wordpress-seo' );
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' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['noimageindex'] = __( 'No Image Index', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['noarchive'] = __( 'No Archive', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['nosnippet'] = __( 'No Snippet', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['bctitle']['title'] = __( 'Breadcrumbs Title', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['bctitle']['description'] = __( 'Title to use for this page in breadcrumb paths', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['canonical']['title'] = __( 'Canonical URL', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['canonical']['description'] = sprintf(
/* translators: 1: link open tag; 2: link close tag. */
__( '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' ),
'<a href="https://googlewebmastercentral.blogspot.com/2009/12/handling-legitimate-cross-domain.html" target="_blank" rel="noopener">',
WPSEO_Admin_Utils::get_new_tab_message() . '</a>'
WPSEO_Meta::$meta_fields['advanced']['redirect']['title'] = __( '301 Redirect', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['redirect']['description'] = __( 'The URL that this page should redirect to.', 'wordpress-seo' );
do_action( 'wpseo_tab_translate' );
* Determines whether the metabox should be shown for the passed identifier.
* By default the check is done for post types, but can also be used for taxonomies.
* @param string|null $identifier The identifier to check.
* @param string $type The type of object to check. Defaults to post_type.
* @return bool Whether or not the metabox should be displayed.
public function display_metabox( $identifier = null, $type = 'post_type' ) {
return WPSEO_Utils::is_metabox_active( $identifier, $type );
* Adds the Yoast SEO meta box to the edit boxes in the edit post, page,
* attachment, and custom post types pages.
public function add_meta_box() {
$post_types = WPSEO_Post_Type::get_accessible_post_types();
$post_types = array_filter( $post_types, [ $this, 'display_metabox' ] );
if ( ! is_array( $post_types ) || $post_types === [] ) {
$product_title = $this->get_product_title();
foreach ( $post_types as $post_type ) {
add_filter( "postbox_classes_{$post_type}_wpseo_meta", [ $this, 'wpseo_metabox_class' ] );
apply_filters( 'wpseo_metabox_prio', 'high' ),
[ '__block_editor_compatible_meta_box' => true ]
* Adds CSS classes to the meta box.
* @param string[] $classes An array of postbox CSS classes.
* @return string[] List of classes that will be applied to the editbox container.
public function wpseo_metabox_class( $classes ) {
$classes[] = 'yoast wpseo-metabox';
* Passes variables to js for use with the post-scraper.
* @return array<string,string|array<string|int|bool>|bool|int>
public function get_metabox_script_data() {
if ( is_object( $this->get_metabox_post() ) ) {
$permalink = get_sample_permalink( $this->get_metabox_post()->ID );
$permalink = $permalink[0];
$post_formatter = new WPSEO_Metabox_Formatter(
new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink )
$values = $post_formatter->get_values();
/** This filter is documented in admin/filters/class-cornerstone-filter.php. */
$post_types = apply_filters( 'wpseo_cornerstone_post_types', WPSEO_Post_Type::get_accessible_post_types() );
if ( $values['cornerstoneActive'] && ! in_array( $this->get_metabox_post()->post_type, $post_types, true ) ) {
$values['cornerstoneActive'] = false;
if ( $values['semrushIntegrationActive'] && $this->post->post_type === 'attachment' ) {
$values['semrushIntegrationActive'] = 0;
if ( $values['wincherIntegrationActive'] && $this->post->post_type === 'attachment' ) {
$values['wincherIntegrationActive'] = 0;
* Determines whether or not the current post type has registered taxonomies.
* @return bool Whether the current post type has taxonomies.
private function current_post_type_has_taxonomies() {
$post_taxonomies = get_object_taxonomies( get_post_type() );
return ! empty( $post_taxonomies );
* Determines the scope based on the post type.
* This can be used by the replacevar plugin to determine if a replacement needs to be executed.
* @return string String describing the current scope.
private function determine_scope() {
if ( $this->get_metabox_post()->post_type === 'page' ) {
public function meta_box() {
$this->render_hidden_fields();
* Renders the metabox hidden fields.
protected function render_hidden_fields() {
wp_nonce_field( 'yoast_free_metabox', 'yoast_free_metabox_nonce' );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'general' );
if ( $this->is_advanced_metadata_enabled ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'advanced' );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'schema', $this->get_metabox_post()->post_type );
if ( $this->social_is_enabled ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'social' );
* Filter: 'wpseo_content_meta_section_content' - Allow filtering the metabox content before outputting.
* @param string $post_content The metabox content string.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output should be escaped in the filter.
echo apply_filters( 'wpseo_content_meta_section_content', '' );
* Renders the metabox tabs.
protected function render_tabs() {
echo '<div class="wpseo-metabox-content">';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $this->get_product_title() returns a hard-coded string.
printf( '<div class="wpseo-metabox-menu"><ul role="tablist" class="yoast-aria-tabs" aria-label="%s">', $this->get_product_title() );
$tabs = $this->get_tabs();
foreach ( $tabs as $tab ) {
if ( $tab->name === 'premium' ) {
foreach ( $tabs as $tab ) {
* Returns the relevant metabox tabs for the current view.
* @return WPSEO_Metabox_Section[]
private function get_tabs() {
$label = __( 'SEO', 'wordpress-seo' );
if ( $this->seo_analysis->is_enabled() ) {
$label = '<span class="wpseo-score-icon-container" id="wpseo-seo-score-icon"></span>' . $label;
$tabs[] = new WPSEO_Metabox_Section_React( 'content', $label );
if ( $this->readability_analysis->is_enabled() ) {
$tabs[] = new WPSEO_Metabox_Section_Readability();
if ( $this->inclusive_language_analysis->is_enabled() ) {
$tabs[] = new WPSEO_Metabox_Section_Inclusive_Language();
if ( $this->is_advanced_metadata_enabled ) {
$tabs[] = new WPSEO_Metabox_Section_React(
'<span class="wpseo-schema-icon"></span>' . __( 'Schema', 'wordpress-seo' ),
if ( $this->social_is_enabled ) {
$tabs[] = new WPSEO_Metabox_Section_React(
'<span class="dashicons dashicons-share"></span>' . __( 'Social', 'wordpress-seo' ),
'html_after' => '<div id="wpseo-section-social"></div>',
$tabs = array_merge( $tabs, $this->get_additional_tabs() );
* Returns the metabox tabs that have been added by other plugins.
* @return WPSEO_Metabox_Section_Additional[]
protected function get_additional_tabs() {
* Private filter: 'yoast_free_additional_metabox_sections'.
* Meant for internal use only. Allows adding additional tabs to the Yoast SEO metabox.
* An array of arrays with tab specifications.
* @type string $name The name of the tab. Used in the HTML IDs, href and aria properties.
* @type string $link_content The content of the tab link.
* @type string $content The content of the tab.
* Optional. Extra options.
* @type string $link_class Optional. The class for the tab link.
* @type string $link_aria_label Optional. The aria label of the tab link.
$requested_tabs = apply_filters( 'yoast_free_additional_metabox_sections', [] );
foreach ( $requested_tabs as $tab ) {
if ( is_array( $tab ) && array_key_exists( 'name', $tab ) && array_key_exists( 'link_content', $tab ) && array_key_exists( 'content', $tab ) ) {
$options = array_key_exists( 'options', $tab ) ? $tab['options'] : [];
$tabs[] = new WPSEO_Metabox_Section_Additional(