PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / menu / class-admin-menu.php

class-admin-menu.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at admin/menu/class-admin-menu.php

136 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin\Menu
6 */
7
8 /**
9 * Registers the admin menu on the left of the admin area.
10 */
11 class WPSEO_Admin_Menu extends WPSEO_Base_Menu {
12
13 /**
14 * Registers all hooks to WordPress.
15 *
16 * @return void
17 */
18 public function register_hooks() {
19 // Needs the lower than default priority so other plugins can hook underneath it without issue.
20 add_action( 'admin_menu', [ $this, 'register_settings_page' ], 5 );
21 }
22
23 /**
24 * Registers the menu item submenus.
25 */
26 public function register_settings_page() {
27 $manage_capability = $this->get_manage_capability();
28 $page_identifier = $this->get_page_identifier();
29 $admin_page_callback = $this->get_admin_page_callback();
30
31 // Get all submenu pages.
32 $submenu_pages = $this->get_submenu_pages();
33
34 foreach ( $submenu_pages as $submenu_page ) {
35 if ( WPSEO_Capability_Utils::current_user_can( $submenu_page[3] ) ) {
36 $manage_capability = $submenu_page[3];
37 $page_identifier = $submenu_page[4];
38 $admin_page_callback = $submenu_page[5];
39 break;
40 }
41 }
42
43 foreach ( $submenu_pages as $index => $submenu_page ) {
44 $submenu_pages[ $index ][0] = $page_identifier;
45 }
46
47 /*
48 * The current user has the capability to control anything.
49 * This means that all submenus and dashboard can be shown.
50 */
51 global $admin_page_hooks;
52
53 add_menu_page(
54 'Yoast SEO: ' . __( 'Dashboard', 'wordpress-seo' ),
55 'Yoast SEO ' . $this->get_notification_counter(),
56 $manage_capability,
57 $page_identifier,
58 $admin_page_callback,
59 $this->get_icon_svg(),
60 99
61 );
62
63 // Wipe notification bits from hooks.
64 // phpcs:ignore WordPress.WP.GlobalVariablesOverride -- This is a deliberate action.
65 $admin_page_hooks[ $page_identifier ] = 'seo';
66
67 // Add submenu items to the main menu if possible.
68 $this->register_submenu_pages( $submenu_pages );
69 }
70
71 /**
72 * Returns the list of registered submenu pages.
73 *
74 * @return array List of registered submenu pages.
75 */
76 public function get_submenu_pages() {
77 global $wpseo_admin;
78
79 $search_console_callback = null;
80
81 // Account for when the available submenu pages are requested from outside the admin.
82 if ( isset( $wpseo_admin ) ) {
83 $google_search_console = new WPSEO_GSC();
84 $search_console_callback = [ $google_search_console, 'display' ];
85 }
86
87 // Submenu pages.
88 $submenu_pages = [
89 $this->get_submenu_page( __( 'General', 'wordpress-seo' ), $this->get_page_identifier() ),
90 $this->get_submenu_page( __( 'Search Appearance', 'wordpress-seo' ), 'wpseo_titles' ),
91 $this->get_submenu_page(
92 __( 'Search Console', 'wordpress-seo' ),
93 'wpseo_search_console',
94 $search_console_callback
95 ),
96 $this->get_submenu_page( __( 'Social', 'wordpress-seo' ), 'wpseo_social' ),
97 $this->get_submenu_page( __( 'Tools', 'wordpress-seo' ), 'wpseo_tools' ),
98 $this->get_submenu_page( $this->get_license_page_title(), 'wpseo_licenses' ),
99 ];
100
101 /**
102 * Filter: 'wpseo_submenu_pages' - Collects all submenus that need to be shown.
103 *
104 * @api array $submenu_pages List with all submenu pages.
105 */
106 return (array) apply_filters( 'wpseo_submenu_pages', $submenu_pages );
107 }
108
109 /**
110 * Returns the notification count in HTML format.
111 *
112 * @return string The notification count in HTML format.
113 */
114 protected function get_notification_counter() {
115 $notification_center = Yoast_Notification_Center::get();
116 $notification_count = $notification_center->get_notification_count();
117
118 // Add main page.
119 /* translators: %s: number of notifications */
120 $notifications = sprintf( _n( '%s notification', '%s notifications', $notification_count, 'wordpress-seo' ), number_format_i18n( $notification_count ) );
121
122 $counter = sprintf( '<span class="update-plugins count-%1$d"><span class="plugin-count" aria-hidden="true">%1$d</span><span class="screen-reader-text">%2$s</span></span>', $notification_count, $notifications );
123
124 return $counter;
125 }
126
127 /**
128 * Returns the capability that is required to manage all options.
129 *
130 * @return string Capability to check against.
131 */
132 protected function get_manage_capability() {
133 return 'wpseo_manage_options';
134 }
135 }
136