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

Yoast / wordpress-seo / d6112f48a78380ef0e30c3424c33b8a053eaa052

14 Apr 2025 01:30PM UTC coverage: 52.454% (-2.1%) from 54.594%
d6112f48a78380ef0e30c3424c33b8a053eaa052

Pull #22077

github

web-flow
Merge 68bb84799 into b621a6397
Pull Request #22077: Drop compatibility with PHP 7.2 and 7.3

7827 of 13877 branches covered (56.4%)

Branch coverage included in aggregate %.

29025 of 56379 relevant lines covered (51.48%)

42277.18 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
/**
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
         * @return void
27
         */
28
        public function register_settings_page() {
×
29
                $manage_capability   = $this->get_manage_capability();
×
30
                $page_identifier     = $this->get_page_identifier();
×
31
                $admin_page_callback = $this->get_admin_page_callback();
×
32

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

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

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

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

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

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

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

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

81
                $search_console_callback = null;
×
82

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

89
                // Submenu pages.
90
                $submenu_pages = [
×
91
                        $this->get_submenu_page(
×
92
                                __( 'Search Console', 'wordpress-seo' ),
×
93
                                'wpseo_search_console',
×
94
                                $search_console_callback
×
95
                        ),
×
96
                        $this->get_submenu_page( __( 'Tools', 'wordpress-seo' ), 'wpseo_tools' ),
×
97
                        $this->get_submenu_page( $this->get_license_page_title(), 'wpseo_licenses' ),
×
98
                ];
×
99

100
                /**
101
                 * Filter: 'wpseo_submenu_pages' - Collects all submenus that need to be shown.
102
                 *
103
                 * @param array $submenu_pages List with all submenu pages.
104
                 */
105
                return (array) apply_filters( 'wpseo_submenu_pages', $submenu_pages );
×
106
        }
107

108
        /**
109
         * Returns the notification count in HTML format.
110
         *
111
         * @return string The notification count in HTML format.
112
         */
113
        protected function get_notification_counter() {
×
114
                $notification_center = Yoast_Notification_Center::get();
×
115
                $notification_count  = $notification_center->get_notification_count();
×
116

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

121
                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 );
×
122
        }
123

124
        /**
125
         * Returns the capability that is required to manage all options.
126
         *
127
         * @return string Capability to check against.
128
         */
129
        protected function get_manage_capability() {
×
130
                return 'wpseo_manage_options';
×
131
        }
132
}
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