social_admin = new WPSEO_Social_Admin();
}
$this->editor = new WPSEO_Metabox_Editor();
$this->editor->register_hooks();
$this->analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$this->analysis_readability = new WPSEO_Metabox_Analysis_Readability();
}
/**
* Translate 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() {
self::$meta_fields['general']['title']['title'] = __( 'SEO title', 'wordpress-seo' );
self::$meta_fields['general']['metadesc']['title'] = __( 'Meta description', 'wordpress-seo' );
/* translators: %s expands to the post type name. */
self::$meta_fields['advanced']['meta-robots-noindex']['title'] = __( 'Allow search engines to show this %s in search results?', 'wordpress-seo' );
if ( '0' === (string) get_option( 'blog_public' ) ) {
self::$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.*/
self::$meta_fields['advanced']['meta-robots-noindex']['options']['0'] = __( 'Default for %2$s, currently: %1$s', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-noindex']['options']['2'] = __( 'Yes', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-noindex']['options']['1'] = __( 'No', 'wordpress-seo' );
/* translators: %1$s expands to the post type name.*/
self::$meta_fields['advanced']['meta-robots-nofollow']['title'] = __( 'Should search engines follow links on this %1$s?', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-nofollow']['options']['0'] = __( 'Yes', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-nofollow']['options']['1'] = __( 'No', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-adv']['title'] = __( 'Meta robots advanced', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-adv']['description'] = __( 'Advanced meta robots settings for this page.', 'wordpress-seo' );
/* translators: %s expands to the advanced robots settings default as set in the site-wide settings.*/
self::$meta_fields['advanced']['meta-robots-adv']['options']['-'] = __( 'Site-wide default: %s', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-adv']['options']['none'] = __( 'None', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-adv']['options']['noimageindex'] = __( 'No Image Index', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-adv']['options']['noarchive'] = __( 'No Archive', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-adv']['options']['nosnippet'] = __( 'No Snippet', 'wordpress-seo' );
self::$meta_fields['advanced']['bctitle']['title'] = __( 'Breadcrumbs Title', 'wordpress-seo' );
self::$meta_fields['advanced']['bctitle']['description'] = __( 'Title to use for this page in breadcrumb paths', 'wordpress-seo' );
self::$meta_fields['advanced']['canonical']['title'] = __( 'Canonical URL', 'wordpress-seo' );
/* translators: 1: link open tag; 2: link close tag. */
self::$meta_fields['advanced']['canonical']['description'] = sprintf( __( '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' ), '', '' );
self::$meta_fields['advanced']['redirect']['title'] = __( '301 Redirect', 'wordpress-seo' );
self::$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 );
}
/**
* Sets up all the functionality related to the prominence of the page analysis functionality.
*/
public function setup_page_analysis() {
if ( apply_filters( 'wpseo_use_page_analysis', true ) === true ) {
add_action( 'post_submitbox_start', array( $this, 'publish_box' ) );
}
}
/**
* Outputs the page analysis score in the Publish Box.
*/
public function publish_box() {
if ( $this->display_metabox() === false ) {
return;
}
$post = $this->get_metabox_post();
if ( self::get_value( 'meta-robots-noindex', $post->ID ) === '1' ) {
$score_label = 'noindex';
$title = __( 'Post is set to noindex.', 'wordpress-seo' );
$score_title = $title;
}
else {
$score = self::get_value( 'linkdex', $post->ID );
if ( $score === '' ) {
$score_label = 'na';
$title = __( 'No focus keyphrase set.', 'wordpress-seo' );
}
else {
$score_label = WPSEO_Utils::translate_score( $score );
}
$score_title = WPSEO_Utils::translate_score( $score, false );
if ( ! isset( $title ) ) {
$title = $score_title;
}
}
}
/**
* 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();
if ( ! is_array( $post_types ) || $post_types === array() ) {
return;
}
$tab_registered = false;
foreach ( $post_types as $post_type ) {
if ( $this->display_metabox( $post_type ) === false ) {
continue;
}
$product_title = 'Yoast SEO';
if ( file_exists( WPSEO_PATH . 'premium/' ) ) {
$product_title .= ' Premium';
}
if ( get_current_screen() !== null ) {
$screen_id = get_current_screen()->id;
add_filter( "postbox_classes_{$screen_id}_wpseo_meta", array( $this, 'wpseo_metabox_class' ) );
}
if ( ! $tab_registered ) {
// Add template variables tab to the Help Center.
$tab = new WPSEO_Help_Center_Template_Variables_Tab();
$tab->register_hooks();
$tab_registered = true;
}
add_meta_box( 'wpseo_meta', $product_title, array(
$this,
'meta_box',
), $post_type, 'normal', apply_filters( 'wpseo_metabox_prio', 'high' ) );
}
}
/**
* 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;
}
/**
* Pass variables to js for use with the post-scraper.
*
* @return array
*/
public function localize_post_scraper_script() {
$post = $this->get_metabox_post();
$permalink = '';
if ( is_object( $post ) ) {
$permalink = get_sample_permalink( $post->ID );
$permalink = $permalink[0];
}
$post_formatter = new WPSEO_Metabox_Formatter(
new WPSEO_Post_Metabox_Formatter( $post, array(), $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( $post->post_type, $post_types, true ) ) {
$values['cornerstoneActive'] = false;
}
return $values;
}
/**
* Pass some variables to js for replacing variables.
*/
public function localize_replace_vars_script() {
return array(
'no_parent_text' => __( '(no parent)', 'wordpress-seo' ),
'replace_vars' => $this->get_replace_vars(),
'recommended_replace_vars' => $this->get_recommended_replace_vars(),
'scope' => $this->determine_scope(),
);
}
/**
* 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() {
$post_type = get_post_type( $this->get_metabox_post() );
if ( $post_type === 'page' ) {
return 'page';
}
return 'post';
}
/**
* Pass some variables to js for the edit / post page overview, etc.
*
* @return array
*/
public function localize_shortcode_plugin_script() {
return array(
'wpseo_filter_shortcodes_nonce' => wp_create_nonce( 'wpseo-filter-shortcodes' ),
'wpseo_shortcode_tags' => $this->get_valid_shortcode_tags(),
);
}
/**
* Output a tab in the Yoast SEO Metabox.
*
* @param string $id CSS ID of the tab.
* @param string $heading Heading for the tab.
* @param string $content Content of the tab. This content should be escaped.
*/
public function do_tab( $id, $heading, $content ) {
?>