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

Yoast / wordpress-seo / 6638054992

25 Oct 2023 08:55AM UTC coverage: 49.106%. First build
6638054992

Pull #20653

github

vraja-pro
Merge remote-tracking branch 'origin/feature/upgrade-react-and-tests' into feature/upgrade-react-and-tests
Pull Request #20653: Feature/upgrade react and tests

64 of 157 new or added lines in 34 files covered. (40.76%)

13135 of 26748 relevant lines covered (49.11%)

3.96 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
        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(
×
91
                                __( 'Search Console', 'wordpress-seo' ),
×
92
                                'wpseo_search_console',
×
93
                                $search_console_callback
×
94
                        ),
95
                        $this->get_submenu_page( __( 'Tools', 'wordpress-seo' ), 'wpseo_tools' ),
×
96
                        $this->get_submenu_page( $this->get_license_page_title(), 'wpseo_licenses' ),
×
97
                ];
98

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

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

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

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

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

© 2025 Coveralls, Inc