• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 4c5f9780cef7c22b7f9bfbace943d71badc638ed

08 Oct 2024 09:39AM UTC coverage: 54.494% (-0.04%) from 54.538%
4c5f9780cef7c22b7f9bfbace943d71badc638ed

push

github

YoastBot
Bump version to 23.6 on free

7502 of 13498 branches covered (55.58%)

Branch coverage included in aggregate %.

29530 of 54458 relevant lines covered (54.23%)

41951.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/admin/menu/class-admin-menu.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Menu
6
 */
7

8
use Yoast\WP\SEO\Conditionals\New_Dashboard_Ui_Conditional;
9
/**
10
 * Registers the admin menu on the left of the admin area.
11
 */
12
class WPSEO_Admin_Menu extends WPSEO_Base_Menu {
13

14
        /**
15
         * Registers all hooks to WordPress.
16
         *
17
         * @return void
18
         */
19
        public function register_hooks() {
×
20
                // Needs the lower than default priority so other plugins can hook underneath it without issue.
21
                add_action( 'admin_menu', [ $this, 'register_settings_page' ], 5 );
×
22
        }
23

24
        /**
25
         * Registers the menu item submenus.
26
         *
27
         * @return void
28
         */
29
        public function register_settings_page() {
×
30
                $manage_capability   = $this->get_manage_capability();
×
31
                $page_identifier     = $this->get_page_identifier();
×
32
                $admin_page_callback = $this->get_admin_page_callback();
×
33

34
                // Get all submenu pages.
35
                $submenu_pages = $this->get_submenu_pages();
×
36

37
                foreach ( $submenu_pages as $submenu_page ) {
×
38
                        if ( WPSEO_Capability_Utils::current_user_can( $submenu_page[3] ) ) {
×
39
                                $manage_capability   = $submenu_page[3];
×
40
                                $page_identifier     = $submenu_page[4];
×
41
                                $admin_page_callback = $submenu_page[5];
×
42
                                break;
×
43
                        }
44
                }
45

46
                foreach ( $submenu_pages as $index => $submenu_page ) {
×
47
                        $submenu_pages[ $index ][0] = $page_identifier;
×
48
                }
49

50
                /*
51
                 * The current user has the capability to control anything.
52
                 * This means that all submenus and dashboard can be shown.
53
                 */
54
                global $admin_page_hooks;
×
55

56
                add_menu_page(
×
57
                        'Yoast SEO: ' . __( 'Dashboard', 'wordpress-seo' ),
×
58
                        'Yoast SEO ' . $this->get_notification_counter(),
×
59
                        $manage_capability,
×
60
                        $page_identifier,
×
61
                        $admin_page_callback,
×
62
                        $this->get_icon_svg(),
×
63
                        99
×
64
                );
65

66
                // Wipe notification bits from hooks.
67
                // phpcs:ignore WordPress.WP.GlobalVariablesOverride -- This is a deliberate action.
68
                $admin_page_hooks[ $page_identifier ] = 'seo';
×
69

70
                // Add submenu items to the main menu if possible.
71
                $this->register_submenu_pages( $submenu_pages );
×
72
        }
73

74
        /**
75
         * Returns the list of registered submenu pages.
76
         *
77
         * @return array List of registered submenu pages.
78
         */
79
        public function get_submenu_pages() {
×
80
                global $wpseo_admin;
×
81

82
                $search_console_callback = null;
×
83

84
                // Account for when the available submenu pages are requested from outside the admin.
85
                if ( isset( $wpseo_admin ) ) {
×
86
                        $google_search_console   = new WPSEO_GSC();
×
87
                        $search_console_callback = [ $google_search_console, 'display' ];
×
88
                }
89

90
                // Submenu pages.
91
                $submenu_pages = [
92
                        $this->get_submenu_page(
×
93
                                __( 'Search Console', 'wordpress-seo' ),
×
94
                                'wpseo_search_console',
×
95
                                $search_console_callback
×
96
                        ),
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
                if ( ! ( new New_Dashboard_Ui_Conditional() )->is_met() ) {
×
102
                        array_unshift( $submenu_pages, $this->get_submenu_page( __( 'General', 'wordpress-seo' ), $this->get_page_identifier() ) );
×
103
                }
104

105
                /**
106
                 * Filter: 'wpseo_submenu_pages' - Collects all submenus that need to be shown.
107
                 *
108
                 * @param array $submenu_pages List with all submenu pages.
109
                 */
110
                return (array) apply_filters( 'wpseo_submenu_pages', $submenu_pages );
×
111
        }
112

113
        /**
114
         * Returns the notification count in HTML format.
115
         *
116
         * @return string The notification count in HTML format.
117
         */
118
        protected function get_notification_counter() {
×
119
                $notification_center = Yoast_Notification_Center::get();
×
120
                $notification_count  = $notification_center->get_notification_count();
×
121

122
                // Add main page.
123
                /* translators: Hidden accessibility text; %s: number of notifications. */
124
                $notifications = sprintf( _n( '%s notification', '%s notifications', $notification_count, 'wordpress-seo' ), number_format_i18n( $notification_count ) );
×
125

126
                return 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 );
×
127
        }
128

129
        /**
130
         * Returns the capability that is required to manage all options.
131
         *
132
         * @return string Capability to check against.
133
         */
134
        protected function get_manage_capability() {
×
135
                return 'wpseo_manage_options';
×
136
        }
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc