options = WPSEO_Options::get_options( array( 'wpseo', 'wpseo_social' ) );
// Check if on of the social settings is checked in the options, if so, initialize the social_admin object.
if ( $this->options['opengraph'] === true || $this->options['twitter'] === true ) {
$this->social_admin = new WPSEO_Social_Admin( $this->options );
}
$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']['snippetpreview']['title'] = __( 'Snippet editor', 'wordpress-seo' );
self::$meta_fields['general']['snippetpreview']['help'] = sprintf( __( 'This is a rendering of what this post might look like in Google\'s search results. %sLearn more about the Snippet Preview%s.', 'wordpress-seo' ), '', '' );
self::$meta_fields['general']['snippetpreview']['help-button'] = __( 'Show information about the snippet editor', 'wordpress-seo' );
self::$meta_fields['general']['pageanalysis']['title'] = __( 'Analysis', 'wordpress-seo' );
self::$meta_fields['general']['pageanalysis']['help'] = sprintf( __( 'This is the content analysis, a collection of content checks that analyze the content of your page. %sLearn more about the Content Analysis Tool%s.', 'wordpress-seo' ), '', '' );
self::$meta_fields['general']['pageanalysis']['help-button'] = __( 'Show information about the content analysis', 'wordpress-seo' );
self::$meta_fields['general']['focuskw_text_input']['title'] = __( 'Focus keyword', 'wordpress-seo' );
self::$meta_fields['general']['focuskw_text_input']['help'] = sprintf( __( 'Pick the main keyword or keyphrase that this post/page is about. %sLearn more about the Focus Keyword%s.', 'wordpress-seo' ), '', '' );
self::$meta_fields['general']['focuskw_text_input']['help-button'] = __( 'Show information about the focus keyword', 'wordpress-seo' );
self::$meta_fields['general']['title']['title'] = __( 'SEO Title', 'wordpress-seo' );
self::$meta_fields['general']['metadesc']['title'] = __( 'Meta description', 'wordpress-seo' );
self::$meta_fields['general']['metakeywords']['title'] = __( 'Meta keywords', 'wordpress-seo' );
self::$meta_fields['general']['metakeywords']['description'] = __( 'If you type something above it will override your %smeta keywords template%s.', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-noindex']['title'] = __( 'Meta Robots Index', 'wordpress-seo' );
if ( '0' == 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' ) . '
';
}
self::$meta_fields['advanced']['meta-robots-noindex']['options']['0'] = __( 'Default for this post type, currently: %s', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-noindex']['options']['2'] = 'Index';
self::$meta_fields['advanced']['meta-robots-noindex']['options']['1'] = 'Noindex';
self::$meta_fields['advanced']['meta-robots-nofollow']['title'] = __( 'Meta Robots Follow', 'wordpress-seo' );
self::$meta_fields['advanced']['meta-robots-nofollow']['options']['0'] = 'follow';
self::$meta_fields['advanced']['meta-robots-nofollow']['options']['1'] = 'nofollow';
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' );
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']['noodp'] = __( 'NO ODP', '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' );
self::$meta_fields['advanced']['canonical']['description'] = sprintf( __( 'The canonical URL that this page should point to, leave empty to default to permalink. %sCross domain canonical%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' );
}
/**
* Test whether the metabox should be hidden either by choice of the admin or because
* the post type is not a public post type
*
* @since 1.5.0
*
* @param string $post_type (optional) The post type to test, defaults to the current post post_type.
*
* @return bool Whether or not the meta box (and associated columns etc) should be hidden
*/
function is_metabox_hidden( $post_type = null ) {
if ( ! isset( $post_type ) && ( isset( $GLOBALS['post'] ) && ( is_object( $GLOBALS['post'] ) && isset( $GLOBALS['post']->post_type ) ) ) ) {
$post_type = $GLOBALS['post']->post_type;
}
if ( isset( $post_type ) ) {
// Don't make static as post_types may still be added during the run.
$cpts = get_post_types( array( 'public' => true ), 'names' );
$options = get_option( 'wpseo_titles' );
return ( ( isset( $options[ 'hideeditbox-' . $post_type ] ) && $options[ 'hideeditbox-' . $post_type ] === true ) || in_array( $post_type, $cpts ) === false );
}
return false;
}
/**
* 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->is_metabox_hidden() === true ) {
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 keyword 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 / cpt pages.
*/
public function add_meta_box() {
$post_types = get_post_types( array( 'public' => true ) );
if ( is_array( $post_types ) && $post_types !== array() ) {
foreach ( $post_types as $post_type ) {
if ( $this->is_metabox_hidden( $post_type ) === false ) {
$product_title = 'Yoast SEO';
if ( file_exists( WPSEO_PATH . 'premium/' ) ) {
$product_title .= ' Premium';
}
add_meta_box( 'wpseo_meta', $product_title, array(
$this,
'meta_box',
), $post_type, 'normal', apply_filters( 'wpseo_metabox_prio', 'high' ) );
}
}
}
}
/**
* 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, WPSEO_Options::get_option( 'wpseo_titles' ), $permalink )
);
return $post_formatter->get_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(),
'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 decribing 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, snippet preview, 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 ) {
?>
get_content_sections();
// Add Help Center to the metabox see #4701.
$tab_video_url = 'https://yoa.st/metabox-screencast';
include WPSEO_PATH . 'admin/views/partial-settings-tab-video.php';
echo '