illar_content = ''; $dashicon_format = ''; if ( is_singular( Helper::get_accessible_post_types() ) ) { if ( get_post_meta( get_the_ID(), 'rank_math_pillar_content', true ) === 'on' ) { $is_pillar_content = sprintf( $dashicon_format, 'yes' ); } $this->add_sub_menu( 'pillar-content', [ 'title' => $is_pillar_content . esc_html__( 'As Pillar Content', 'rank-math' ), 'href' => '#pillar_content', 'meta' => [ 'class' => 'mark-page-as' ], ], 'mark-me' ); } if ( Paper::get() ) { $robots = Paper::get()->get_robots(); $noindex_check = in_array( 'noindex', $robots, true ) ? sprintf( $dashicon_format, 'yes' ) : ''; $this->add_sub_menu( 'no-index', [ 'title' => $noindex_check . esc_html__( 'As NoIndex', 'rank-math' ), 'href' => '#noindex', 'meta' => [ 'class' => 'mark-page-as' ], ], 'mark-me' ); $nofollow_check = in_array( 'nofollow', $robots, true ) ? sprintf( $dashicon_format, 'yes' ) : ''; $this->add_sub_menu( 'no-follow', [ 'title' => $nofollow_check . esc_html__( 'As NoFollow', 'rank-math' ), 'href' => '#nofollow', 'meta' => [ 'class' => 'mark-page-as' ], ], 'mark-me' ); } } /** * Third party SEO Tools, like the Google Structured Data Testing Tool. */ private function add_seo_tools() { $this->add_sub_menu( 'third-party', [ 'title' => esc_html__( 'External Tools', 'rank-math' ), 'href' => '#', 'priority' => 200, ] ); $url = rawurlencode( Url::get_current_url() ); $items = [ 'google-pagespeed' => [ 'title' => esc_html__( 'Google PageSpeed', 'rank-math' ), 'href' => 'https://developers.google.com/speed/pagespeed/insights/?url=' . $url, 'meta' => [ 'title' => esc_html__( 'Google PageSpeed Insights', 'rank-math' ) ], ], 'google-richresults-mobile' => [ 'title' => esc_html__( 'Google Rich Results (Mobile)', 'rank-math' ), 'href' => 'https://search.google.com/test/rich-results?url=' . $url . '&user_agent=1', 'meta' => [ 'title' => esc_html__( 'Google Rich Results Test - Googlebot Smartphone', 'rank-math' ) ], ], 'google-richresults-desktop' => [ 'title' => esc_html__( 'Google Rich Results (Desktop)', 'rank-math' ), 'href' => 'https://search.google.com/test/rich-results?url=' . $url . '&user_agent=2', 'meta' => [ 'title' => esc_html__( 'Google Rich Results Test - Googlebot Desktop', 'rank-math' ) ], ], 'google-cache' => [ 'title' => esc_html__( 'Google Cache', 'rank-math' ), 'href' => 'https://webcache.googleusercontent.com/search?q=cache:' . $url, 'meta' => [ 'title' => esc_html__( 'See Google\'s cached version of your site', 'rank-math' ) ], ], 'fb-debugger' => [ 'title' => esc_html__( 'Facebook Debugger', 'rank-math' ), 'href' => 'https://developers.facebook.com/tools/debug/sharing/?q=' . $url, 'meta' => [ 'title' => esc_html__( 'Facebook Sharing Debugger', 'rank-math' ) ], ], ]; foreach ( $items as $id => $args ) { $args['meta']['target'] = '_blank'; $this->add_sub_menu( $id, $args, 'third-party' ); } } /** * Add sub menu item * * @param string $id Unique ID for the node. * @param array $args Arguments for adding a node. * @param string $parent Node parent. */ public function add_sub_menu( $id, $args, $parent = '' ) { $args['priority'] = isset( $args['priority'] ) ? $args['priority'] : 999; $args['id'] = 'rank-math-' . $id; $args['parent'] = '' !== $parent ? 'rank-math-' . $parent : self::MENU_IDENTIFIER; $this->items[ $id ] = $args; } /** * Can current user has capability for admin menu. * * @return bool */ private function can_add_menu() { return Helper::has_cap( 'admin_bar' ); } /** * Can add mark me menu. * * @return bool */ private function can_add_mark_menu() { return $this->is_front() && Helper::has_cap( 'onpage_general' ); } /** * Is frontend. * * @return bool */ private function is_front() { return ! is_admin() && ! is_preview(); } /** * Sort admin bar items callback. * * @param array $item1 Item A to compare. * @param array $item2 Item B to compare. * * @return integer */ private function sort_by_priority( $item1, $item2 ) { if ( $item1['priority'] === $item2['priority'] ) { return $item1['order'] < $item2['order'] ? -1 : 1; } return $item1['priority'] < $item2['priority'] ? -1 : 1; } /** * Get Rank Math icon. * * @param integer $width Width of the icon. * * @return string */ private function get_icon( $width = 20 ) { return ''; } }