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.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / vendor / automattic / jetpack-admin-ui / src / class-admin-menu.php
woocommerce / vendor / automattic / jetpack-admin-ui / src Last commit date
class-admin-menu.php 1 year ago
class-admin-menu.php
209 lines
1 <?php
2 /**
3 * Admin Menu Registration
4 *
5 * @package automattic/jetpack-admin-ui
6 */
7
8 namespace Automattic\Jetpack\Admin_UI;
9
10 /**
11 * This class offers a wrapper to add_submenu_page and makes sure stand-alone plugin's menu items are always added under the Jetpack top level menu.
12 * If the Jetpack top level was not previously registered by other plugin, it will be registered here.
13 */
14 class Admin_Menu {
15
16 const PACKAGE_VERSION = '0.5.1';
17
18 /**
19 * Whether this class has been initialized
20 *
21 * @var boolean
22 */
23 private static $initialized = false;
24
25 /**
26 * List of menu items enqueued to be added
27 *
28 * @var array
29 */
30 private static $menu_items = array();
31
32 /**
33 * Initialize the class and set up the main hook
34 *
35 * @return void
36 */
37 public static function init() {
38 if ( ! self::$initialized ) {
39 self::$initialized = true;
40 self::handle_akismet_menu();
41 add_action( 'admin_menu', array( __CLASS__, 'admin_menu_hook_callback' ), 1000 ); // Jetpack uses 998.
42 add_action( 'network_admin_menu', array( __CLASS__, 'admin_menu_hook_callback' ), 1000 ); // Jetpack uses 998.
43 }
44 }
45
46 /**
47 * Handles the Akismet menu item when used alongside other stand-alone plugins
48 *
49 * When Jetpack plugin is present, Akismet menu item is moved under the Jetpack top level menu, but if Akismet is active alongside other stand-alone plugins,
50 * we use this method to move the menu item.
51 */
52 private static function handle_akismet_menu() {
53 if ( class_exists( 'Akismet_Admin' ) ) {
54 add_action(
55 'admin_menu',
56 function () {
57 // Prevent Akismet from adding a menu item.
58 remove_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 );
59
60 // Add an Anti-spam menu item for Jetpack.
61 self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ), 6 );
62 },
63 4
64 );
65
66 }
67 }
68
69 /**
70 * Callback to the admin_menu and network_admin_menu hooks that will register the enqueued menu items
71 *
72 * @return void
73 */
74 public static function admin_menu_hook_callback() {
75 $can_see_toplevel_menu = true;
76 $jetpack_plugin_present = class_exists( 'Jetpack_React_Page' );
77 $icon = method_exists( '\Automattic\Jetpack\Assets\Logo', 'get_base64_logo' )
78 ? ( new \Automattic\Jetpack\Assets\Logo() )->get_base64_logo()
79 : 'dashicons-admin-plugins';
80
81 if ( ! $jetpack_plugin_present ) {
82 add_menu_page(
83 'Jetpack',
84 'Jetpack',
85 'edit_posts',
86 'jetpack',
87 '__return_null',
88 $icon,
89 3
90 );
91
92 // If Jetpack plugin is not present, user will only be able to see this menu if they have enough capability to at least one of the sub menus being added.
93 $can_see_toplevel_menu = false;
94 }
95
96 /**
97 * The add_sub_menu function has a bug and will not keep the right order of menu items.
98 *
99 * @see https://core.trac.wordpress.org/ticket/52035
100 * Let's order the items before registering them.
101 * Since this all happens after the Jetpack plugin menu items were added, all items will be added after Jetpack plugin items - unless position is very low number (smaller than the number of menu items present in Jetpack plugin).
102 */
103 usort(
104 self::$menu_items,
105 function ( $a, $b ) {
106 $position_a = empty( $a['position'] ) ? 0 : $a['position'];
107 $position_b = empty( $b['position'] ) ? 0 : $b['position'];
108 $result = $position_a <=> $position_b;
109
110 if ( 0 === $result ) {
111 $result = strcmp( $a['menu_title'], $b['menu_title'] );
112 }
113
114 return $result;
115 }
116 );
117
118 foreach ( self::$menu_items as $menu_item ) {
119 if ( ! current_user_can( $menu_item['capability'] ) ) {
120 continue;
121 }
122
123 $can_see_toplevel_menu = true;
124
125 add_submenu_page(
126 'jetpack',
127 $menu_item['page_title'],
128 $menu_item['menu_title'],
129 $menu_item['capability'],
130 $menu_item['menu_slug'],
131 $menu_item['function'],
132 $menu_item['position']
133 );
134 }
135
136 if ( ! $jetpack_plugin_present ) {
137 remove_submenu_page( 'jetpack', 'jetpack' );
138 }
139
140 if ( ! $can_see_toplevel_menu ) {
141 remove_menu_page( 'jetpack' );
142 }
143 }
144
145 /**
146 * Adds a new submenu to the Jetpack Top level menu
147 *
148 * The parameters this method accepts are the same as @see add_submenu_page. This class will
149 * aggreagate all menu items registered by stand-alone plugins and make sure they all go under the same
150 * Jetpack top level menu. It will also handle the top level menu registration in case the Jetpack plugin is not present.
151 *
152 * @param string $page_title The text to be displayed in the title tags of the page when the menu
153 * is selected.
154 * @param string $menu_title The text to be used for the menu.
155 * @param string $capability The capability required for this menu to be displayed to the user.
156 * @param string $menu_slug The slug name to refer to this menu by. Should be unique for this menu
157 * and only include lowercase alphanumeric, dashes, and underscores characters
158 * to be compatible with sanitize_key().
159 * @param callable $function The function to be called to output the content for this page.
160 * @param int $position The position in the menu order this item should appear. Leave empty typically.
161 *
162 * @return string The resulting page's hook_suffix
163 */
164 public static function add_menu( $page_title, $menu_title, $capability, $menu_slug, $function, $position = null ) {
165 self::init();
166 self::$menu_items[] = compact( 'page_title', 'menu_title', 'capability', 'menu_slug', 'function', 'position' );
167
168 /**
169 * Let's return the page hook so consumers can use.
170 * We know all pages will be under Jetpack top level menu page, so we can hardcode the first part of the string.
171 * Using get_plugin_page_hookname here won't work because the top level page is not registered yet.
172 */
173 return 'jetpack_page_' . $menu_slug;
174 }
175
176 /**
177 * Gets the slug for the first item under the Jetpack top level menu
178 *
179 * @return string|null
180 */
181 public static function get_top_level_menu_item_slug() {
182 global $submenu;
183 if ( ! empty( $submenu['jetpack'] ) ) {
184 $item = reset( $submenu['jetpack'] );
185 if ( isset( $item[2] ) ) {
186 return $item[2];
187 }
188 }
189 }
190
191 /**
192 * Gets the URL for the first item under the Jetpack top level menu
193 *
194 * @param string $fallback If Jetpack menu is not there or no children is found, return this fallback instead. Default to admin_url().
195 * @return string
196 */
197 public static function get_top_level_menu_item_url( $fallback = false ) {
198 $slug = self::get_top_level_menu_item_slug();
199
200 if ( $slug ) {
201 $url = menu_page_url( $slug, false );
202 return $url;
203 }
204
205 $url = $fallback ? $fallback : admin_url();
206 return $url;
207 }
208 }
209