NTIFIER,
'title' => __( 'SEO Settings', 'wordpress-seo' ),
'meta' => [ 'tabindex' => '0' ],
];
$wp_admin_bar->add_menu( $menu_args );
foreach ( $submenu_pages as $submenu_page ) {
if ( ! current_user_can( $submenu_page[3] ) ) {
continue;
}
$id = 'wpseo-' . str_replace( '_', '-', str_replace( 'wpseo_', '', $submenu_page[4] ) );
if ( $id === 'wpseo-dashboard' ) {
$id = 'wpseo-general';
}
$menu_args = [
'parent' => self::NETWORK_SETTINGS_SUBMENU_IDENTIFIER,
'id' => $id,
'title' => $submenu_page[2],
'href' => network_admin_url( 'admin.php?page=' . urlencode( $submenu_page[4] ) ),
];
$wp_admin_bar->add_menu( $menu_args );
}
}
/**
* Gets the menu title markup.
*
* @return string Admin bar title markup.
*/
protected function get_title() {
return '
' . __( 'SEO', 'wordpress-seo' ) . '
';
}
/**
* Gets the current post if in a singular post context.
*
* @global string $pagenow Current page identifier.
* @global WP_Post|null $post Current post object, or null if none available.
*
* @return WP_Post|null Post object, or null if not in singular context.
*/
protected function get_singular_post() {
global $pagenow, $post;
if ( ! is_singular() && ( ! is_blog_admin() || ! WPSEO_Metabox::is_post_edit( $pagenow ) ) ) {
return null;
}
if ( ! isset( $post ) || ! is_object( $post ) || ! $post instanceof WP_Post ) {
return null;
}
return $post;
}
/**
* Gets the focus keyword for a given post.
*
* @param WP_Post $post Post object to get its focus keyword.
*
* @return string Focus keyword, or empty string if none available.
*/
protected function get_post_focus_keyword( $post ) {
if ( ! is_object( $post ) || ! property_exists( $post, 'ID' ) ) {
return '';
}
/**
* Filter: 'wpseo_use_page_analysis' Determines if the analysis should be enabled.
*
* @api bool Determines if the analysis should be enabled.
*/
if ( apply_filters( 'wpseo_use_page_analysis', true ) !== true ) {
return '';
}
return WPSEO_Meta::get_value( 'focuskw', $post->ID );
}
/**
* Gets the score for a given post.
*
* @param WP_Post $post Post object to get its score.
*
* @return string Score markup, or empty string if none available.
*/
protected function get_post_score( $post ) {
if ( ! is_object( $post ) || ! property_exists( $post, 'ID' ) ) {
return '';
}
if ( apply_filters( 'wpseo_use_page_analysis', true ) !== true ) {
return '';
}
$analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$analysis_readability = new WPSEO_Metabox_Analysis_Readability();
if ( $analysis_seo->is_enabled() ) {
return $this->get_score( WPSEO_Meta::get_value( 'linkdex', $post->ID ) );
}
if ( $analysis_readability->is_enabled() ) {
return $this->get_score( WPSEO_Meta::get_value( 'content_score', $post->ID ) );
}
return '';
}
/**
* Gets the current term if in a singular term context.
*
* @global string $pagenow Current page identifier.
* @global WP_Query $wp_query Current query object.
* @global WP_Term|null $tag Current term object, or null if none available.
*
* @return WP_Term|null Term object, or null if not in singular context.
*/
protected function get_singular_term() {
global $pagenow, $wp_query, $tag;
if ( is_category() || is_tag() || is_tax() ) {
return $wp_query->get_queried_object();
}
if ( WPSEO_Taxonomy::is_term_edit( $pagenow ) && ! WPSEO_Taxonomy::is_term_overview( $pagenow ) && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) {
return get_term( $tag->term_id );
}
return null;
}
/**
* Gets the score for a given term.
*
* @param WP_Term $term Term object to get its score.
*
* @return string Score markup, or empty string if none available.
*/
protected function get_term_score( $term ) {
if ( ! is_object( $term ) || ! property_exists( $term, 'term_id' ) || ! property_exists( $term, 'taxonomy' ) ) {
return '';
}
$analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$analysis_readability = new WPSEO_Metabox_Analysis_Readability();
if ( $analysis_seo->is_enabled() ) {
return $this->get_score( WPSEO_Taxonomy_Meta::get_term_meta( $term->term_id, $term->taxonomy, 'linkdex' ) );
}
if ( $analysis_readability->is_enabled() ) {
return $this->get_score( WPSEO_Taxonomy_Meta::get_term_meta( $term->term_id, $term->taxonomy, 'content_score' ) );
}
return '';
}
/**
* Takes the SEO score and makes the score icon for the admin bar for it.
*
* @param int $score The 0-100 rating of the score. Can be either SEO score or content score.
*
* @return string Score markup.
*/
protected function get_score( $score ) {
$score_class = WPSEO_Utils::translate_score( $score );
$translated_score = WPSEO_Utils::translate_score( $score, false );
/* translators: %s expands to the SEO score. */
$screen_reader_text = sprintf( __( 'SEO score: %s', 'wordpress-seo' ), $translated_score );
$score_adminbar_element = '' . $screen_reader_text . '
';
return $score_adminbar_element;
}
/**
* Gets the URL to the main admin settings page.
*
* @return string Admin settings page URL.
*/
protected function get_settings_page_url() {
return self_admin_url( 'admin.php?page=' . WPSEO_Admin::PAGE_IDENTIFIER );
}
/**
* Gets the notification counter if in a valid context.
*
* @return string Notification counter markup, or empty string if not available.
*/
protected function get_notification_counter() {
$notification_center = Yoast_Notification_Center::get();
$notification_count = $notification_center->get_notification_count();
if ( ! $notification_count ) {
return '';
}
/* translators: %s: number of notifications */
$counter_screen_reader_text = sprintf( _n( '%s notification', '%s notifications', $notification_count, 'wordpress-seo' ), number_format_i18n( $notification_count ) );
return sprintf( ' %d%s
', $notification_count, $counter_screen_reader_text );
}
/**
* Gets the notification popup if in a valid context.
*
* @return string Notification popup markup, or empty string if not available.
*/
protected function get_notification_popup() {
$notification_center = Yoast_Notification_Center::get();
$new_notifications = $notification_center->get_new_notifications();
$new_notifications_count = count( $new_notifications );
if ( ! $new_notifications_count ) {
return '';
}
$notification = sprintf(
_n(
'There is a new notification.',
'There are new notifications.',
$new_notifications_count,
'wordpress-seo'
),
$new_notifications_count
);
return '' . $notification . '
';
}
/**
* Checks whether the current user can manage options in the current context.
*
* @return bool True if capabilities are sufficient, false otherwise.
*/
protected function can_manage_options() {
return is_network_admin() && current_user_can( 'wpseo_manage_network_options' ) || ! is_network_admin() && WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' );
}
}