is_internet_explorer() ) {
add_action( 'add_meta_boxes', [ $this, 'internet_explorer_metabox' ] );
return;
}
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'] ) ) {
return false;
}
$user_agent = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) );
if ( stripos( $user_agent, 'Trident/7.0' ) === false ) {
return false;
}
return true;
}
/**
* 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 === [] ) {
return;
}
$product_title = $this->get_product_title();
foreach ( $post_types as $post_type ) {
add_filter( "postbox_classes_{$post_type}_wpseo_meta", [ $this, 'wpseo_metabox_class' ] );
add_meta_box(
'wpseo_meta',
$product_title,
[ $this, 'render_internet_explorer_notice' ],
$post_type,
'normal',
apply_filters( 'wpseo_metabox_prio', 'high' ),
[ '__block_editor_compatible_meta_box' => true ]
);
}
}
/**
* Renders the content for the internet explorer metabox.
*
* @return void
*/
public function render_internet_explorer_notice() {
$content = sprintf(
/* 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' ),
'',
'',
'',
''
);
// 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'] = '' . __( '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' ) . '';
}
/* 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 meta 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' ),
'',
WPSEO_Admin_Utils::get_new_tab_message() . ''
);
/* translators: %s expands to the post type name. */
WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['title'] = __( 'Timestamp this %s', 'wordpress-seo' );
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' );
WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['options']['0'] = __( 'Off', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['options']['1'] = __( 'On', 'wordpress-seo' );
WPSEO_Meta::$meta_fields['advanced']['wordproof_timestamp']['type'] = 'hidden';
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.
*
* @return void
*/
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 === [] ) {
return;
}
$product_title = $this->get_product_title();
foreach ( $post_types as $post_type ) {
add_filter( "postbox_classes_{$post_type}_wpseo_meta", [ $this, 'wpseo_metabox_class' ] );
add_meta_box(
'wpseo_meta',
$product_title,
[ $this, 'meta_box' ],
$post_type,
'normal',
apply_filters( 'wpseo_metabox_prio', 'high' ),
[ '__block_editor_compatible_meta_box' => true ]
);
}
}
/**
* Adds CSS classes to the meta box.
*
* @param array $classes An array of postbox CSS classes.
*
* @return array List of classes that will be applied to the editbox container.
*/
public function wpseo_metabox_class( $classes ) {
$classes[] = 'yoast wpseo-metabox';
return $classes;
}
/**
* Passes variables to js for use with the post-scraper.
*
* @return array
*/
public function get_metabox_script_data() {
$permalink = '';
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;
}
return $values;
}
/**
* 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' ) {
return 'page';
}
return 'post';
}
/**
* Outputs the meta box.
*/
public function meta_box() {
$this->render_hidden_fields();
$this->render_tabs();
}
/**
* Renders the metabox hidden fields.
*
* @return void
*/
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.
*
* @api 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.
*
* @return void
*/
protected function render_tabs() {
echo '