Completed
Push — jetpack/branch-9.7 ( 8eeea3...2cff2c )
by Jeremy
10:32
created

Base_Admin_Menu::is_item_visible()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Base Admin Menu file.
4
 *
5
 * @package automattic/jetpack
6
 */
7
8
namespace Automattic\Jetpack\Dashboard_Customizations;
9
10
use Automattic\Jetpack\Status;
11
12
/**
13
 * Class Base_Admin_Menu
14
 */
15
abstract class Base_Admin_Menu {
16
	/**
17
	 * Holds class instances.
18
	 *
19
	 * @var array
20
	 */
21
	protected static $instances;
22
23
	/**
24
	 * Whether the current request is a REST API request.
25
	 *
26
	 * @var bool
27
	 */
28
	protected $is_api_request = false;
29
30
	/**
31
	 * Domain of the current site.
32
	 *
33
	 * @var string
34
	 */
35
	protected $domain;
36
37
	/**
38
	 * The CSS classes used to hide the submenu items in navigation.
39
	 *
40
	 * @var string
41
	 */
42
	const HIDE_CSS_CLASS = 'hide-if-js';
43
44
	/**
45
	 * Base_Admin_Menu constructor.
46
	 */
47
	protected function __construct() {
48
		add_action( 'admin_menu', array( $this, 'set_is_api_request' ), 99997 );
49
		add_action( 'admin_menu', array( $this, 'reregister_menu_items' ), 99998 );
50
51
		add_action( 'admin_menu', array( $this, 'hide_parent_of_hidden_submenus' ), 99999 );
52
53
		add_filter( 'admin_menu', array( $this, 'override_svg_icons' ), 99999 );
54
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
55
		add_action( 'admin_head', array( $this, 'set_site_icon_inline_styles' ) );
56
		add_filter( 'rest_request_before_callbacks', array( $this, 'rest_api_init' ), 11 );
57
58
		$this->domain = ( new Status() )->get_site_suffix();
59
	}
60
61
	/**
62
	 * Determine if the current request is from API
63
	 */
64
	public function set_is_api_request() {
65
		// Constant is not defined until parse_request.
66
		if ( ! $this->is_api_request ) {
67
			$this->is_api_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
68
		}
69
	}
70
71
	/**
72
	 * Returns class instance.
73
	 *
74
	 * @return Admin_Menu
75
	 */
76
	public static function get_instance() {
77
		$class = get_called_class();
78
79
		if ( empty( static::$instances[ $class ] ) ) {
80
			static::$instances[ $class ] = new $class();
81
		}
82
83
		return static::$instances[ $class ];
84
	}
85
86
	/**
87
	 * Sets up class properties for REST API requests.
88
	 *
89
	 * @param \WP_REST_Response $response Response from the endpoint.
90
	 */
91
	public function rest_api_init( $response ) {
92
		$this->is_api_request = true;
93
94
		return $response;
95
	}
96
97
	/**
98
	 * Updates the menu data of the given menu slug.
99
	 *
100
	 * @param string $slug Slug of the menu to update.
101
	 * @param string $url New menu URL.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $url not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
102
	 * @param string $title New menu title.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $title not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
103
	 * @param string $cap New menu capability.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cap not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
104
	 * @param string $icon New menu icon.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $icon not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
105
	 * @param int    $position New menu position.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $position not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
106
	 * @return bool Whether the menu has been updated.
107
	 */
108
	public function update_menu( $slug, $url = null, $title = null, $cap = null, $icon = null, $position = null ) {
109
		global $menu, $submenu;
110
111
		$menu_item     = null;
112
		$menu_position = null;
113
114
		foreach ( $menu as $i => $item ) {
115
			if ( $slug === $item[2] ) {
116
				$menu_item     = $item;
117
				$menu_position = $i;
118
				break;
119
			}
120
		}
121
122
		if ( ! $menu_item ) {
123
			return false;
124
		}
125
126
		if ( $title ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $title of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
127
			$menu_item[0] = $title;
128
			$menu_item[3] = esc_attr( $title );
129
		}
130
131
		if ( $cap ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cap of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
132
			$menu_item[1] = $cap;
133
		}
134
135
		// Change parent slug only if there are no submenus (the slug of the 1st submenu will be used if there are submenus).
136
		if ( $url ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $url of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
137
			$this->hide_submenu_page( $slug, $slug );
138
139
			if ( ! isset( $submenu[ $slug ] ) || ! $this->has_visible_items( $submenu[ $slug ] ) ) {
140
				$menu_item[2] = $url;
141
			}
142
		}
143
144
		if ( $icon ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $icon of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
145
			$menu_item[4] = 'menu-top';
146
			$menu_item[6] = $icon;
147
		}
148
149
		// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
150
		unset( $menu[ $menu_position ] );
151
		if ( $position ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $position of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
152
			$menu_position = $position;
153
		}
154
		$this->set_menu_item( $menu_item, $menu_position );
155
156
		// Only add submenu when there are other submenu items.
157
		if ( $url && isset( $submenu[ $slug ] ) && $this->has_visible_items( $submenu[ $slug ] ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $url of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
158
			add_submenu_page( $slug, $menu_item[3], $menu_item[0], $menu_item[1], $url, null, 0 );
159
		}
160
161
		return true;
162
	}
163
164
	/**
165
	 * Updates the submenus of the given menu slug.
166
	 *
167
	 * It hides the menu by adding the `hide-if-js` css class and duplicates the submenu with the new slug.
168
	 *
169
	 * @param string $slug Menu slug.
170
	 * @param array  $submenus_to_update Array of new submenu slugs.
171
	 */
172
	public function update_submenus( $slug, $submenus_to_update ) {
173
		global $submenu;
174
175
		if ( ! isset( $submenu[ $slug ] ) ) {
176
			return;
177
		}
178
179
		// This is needed for cases when the submenus to update have the same new slug.
180
		$submenus_to_update = array_filter(
181
			$submenus_to_update,
182
			static function ( $item, $old_slug ) {
183
				return $item !== $old_slug;
184
			},
185
			ARRAY_FILTER_USE_BOTH
186
		);
187
188
		/**
189
		 * Iterate over all submenu items and add the hide the submenus with CSS classes.
190
		 * This is done separately of the second foreach because the position of the submenu might change.
191
		 */
192
		foreach ( $submenu[ $slug ] as $index => $item ) {
193
			if ( ! array_key_exists( $item[2], $submenus_to_update ) ) {
194
				continue;
195
			}
196
197
			$this->hide_submenu_element( $index, $slug, $item );
198
		}
199
200
		$submenu_items = array_values( $submenu[ $slug ] );
201
202
		/**
203
		 * Iterate again over the submenu array. We need a copy of the array because add_submenu_page will add new elements
204
		 * to submenu array that might cause an infinite loop.
205
		 */
206
		foreach ( $submenu_items as $i => $submenu_item ) {
207
			if ( ! array_key_exists( $submenu_item[2], $submenus_to_update ) ) {
208
				continue;
209
			}
210
211
			add_submenu_page(
212
				$slug,
213
				isset( $submenu_item[3] ) ? $submenu_item[3] : '',
214
				isset( $submenu_item[0] ) ? $submenu_item[0] : '',
215
				isset( $submenu_item[1] ) ? $submenu_item[1] : 'read',
216
				$submenus_to_update[ $submenu_item[2] ],
217
				'',
218
				$i
219
			);
220
		}
221
	}
222
223
	/**
224
	 * Adds a menu separator.
225
	 *
226
	 * @param int    $position The position in the menu order this item should appear.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $position not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
227
	 * @param string $cap Optional. The capability required for this menu to be displayed to the user.
228
	 *                         Default: 'read'.
229
	 */
230
	public function add_admin_menu_separator( $position = null, $cap = 'read' ) {
231
		$menu_item = array(
232
			'',                                  // Menu title (ignored).
233
			$cap,                                // Required capability.
234
			wp_unique_id( 'separator-custom-' ), // URL or file (ignored, but must be unique).
235
			'',                                  // Page title (ignored).
236
			'wp-menu-separator',                 // CSS class. Identifies this item as a separator.
237
		);
238
239
		$this->set_menu_item( $menu_item, $position );
240
	}
241
242
	/**
243
	 * Enqueues scripts and styles.
244
	 */
245
	public function enqueue_scripts() {
246
		$is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM;
247
248
		if ( $this->is_rtl() ) {
249
			if ( $is_wpcom ) {
250
				$css_path = 'rtl/admin-menu-rtl.css';
251
			} else {
252
				$css_path = 'admin-menu-rtl.css';
253
			}
254
		} else {
255
			$css_path = 'admin-menu.css';
256
		}
257
258
		wp_enqueue_style(
259
			'jetpack-admin-menu',
260
			plugins_url( $css_path, __FILE__ ),
261
			array(),
262
			JETPACK__VERSION
263
		);
264
265
		wp_enqueue_script(
266
			'jetpack-admin-menu',
267
			plugins_url( 'admin-menu.js', __FILE__ ),
268
			array(),
269
			JETPACK__VERSION,
270
			true
271
		);
272
	}
273
274
	/**
275
	 * Injects inline-styles for site icon for when third-party plugins remove enqueued stylesheets.
276
	 * Unable to use wp_add_inline_style as plugins remove styles from all non-standard handles
277
	 */
278
	public function set_site_icon_inline_styles() {
279
		echo '<style>
280
			#adminmenu .toplevel_page_site-card .wp-menu-image,
281
			#adminmenu .toplevel_page_site-card .wp-menu-image img {
282
				height: 32px;
283
				width: 32px;
284
			}
285
		</style>';
286
	}
287
288
	/**
289
	 * Hide the submenu page based on slug and return the item that was hidden.
290
	 *
291
	 * Instead of actually removing the submenu item, a safer approach is to hide it and filter it in the API response.
292
	 * In this manner we'll avoid breaking third-party plugins depending on items that no longer exist.
293
	 *
294
	 * A false|array value is returned to be consistent with remove_submenu_page() function
295
	 *
296
	 * @param string $menu_slug The parent menu slug.
297
	 * @param string $submenu_slug The submenu slug that should be hidden.
298
	 * @return false|array
299
	 */
300
	public function hide_submenu_page( $menu_slug, $submenu_slug ) {
301
		global $submenu;
302
303
		if ( ! isset( $submenu[ $menu_slug ] ) ) {
304
			return false;
305
		}
306
307
		foreach ( $submenu[ $menu_slug ] as $i => $item ) {
308
			if ( $submenu_slug !== $item[2] ) {
309
				continue;
310
			}
311
312
			$this->hide_submenu_element( $i, $menu_slug, $item );
313
314
			return $item;
315
		}
316
317
		return false;
318
	}
319
320
	/**
321
	 * Apply the hide-if-js CSS class to a submenu item.
322
	 *
323
	 * @param int    $index The position of a submenu item in the submenu array.
324
	 * @param string $parent_slug The parent slug.
325
	 * @param array  $item The submenu item.
326
	 */
327
	public function hide_submenu_element( $index, $parent_slug, $item ) {
328
		global $submenu;
329
330
		$css_classes = empty( $item[4] ) ? self::HIDE_CSS_CLASS : $item[4] . ' ' . self::HIDE_CSS_CLASS;
331
332
		// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
333
		$submenu [ $parent_slug ][ $index ][4] = $css_classes;
334
	}
335
336
	/**
337
	 * Check if the menu has submenu items visible
338
	 *
339
	 * @param array $submenu_items The submenu items.
340
	 * @return bool
341
	 */
342
	public function has_visible_items( $submenu_items ) {
343
		$visible_items = array_filter(
344
			$submenu_items,
345
			array( $this, 'is_item_visible' )
346
		);
347
348
		return array() !== $visible_items;
349
	}
350
351
	/**
352
	 * Return the number of existing submenu items under the supplied parent slug.
353
	 *
354
	 * @param string $parent_slug The slug of the parent menu.
355
	 * @return int The number of submenu items under $parent_slug.
356
	 */
357
	public function get_submenu_item_count( $parent_slug ) {
358
		global $submenu;
359
360
		if ( empty( $parent_slug ) || empty( $submenu[ $parent_slug ] ) || ! is_array( $submenu[ $parent_slug ] ) ) {
361
			return 0;
362
		}
363
364
		return count( $submenu[ $parent_slug ] );
365
	}
366
367
	/**
368
	 * Adds the given menu item in the specified position.
369
	 *
370
	 * @param array $item The menu item to add.
371
	 * @param int   $position The position in the menu order this item should appear.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $position not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
372
	 */
373
	public function set_menu_item( $item, $position = null ) {
374
		global $menu;
375
376
		// Handle position (avoids overwriting menu items already populated in the given position).
377
		// Inspired by https://core.trac.wordpress.org/browser/trunk/src/wp-admin/menu.php?rev=49837#L160.
378
		if ( null === $position ) {
379
			$menu[] = $item; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
380
		} elseif ( isset( $menu[ "$position" ] ) ) {
381
			$position            = $position + substr( base_convert( md5( $item[2] . $item[0] ), 16, 10 ), -5 ) * 0.00001;
382
			$menu[ "$position" ] = $item; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
383
		} else {
384
			$menu[ $position ] = $item; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
385
		}
386
	}
387
388
	/**
389
	 * Determines whether the current locale is right-to-left (RTL).
390
	 */
391
	public function is_rtl() {
392
		return is_rtl();
393
	}
394
395
	/**
396
	 * Checks for any SVG icons in the menu, and overrides things so that
397
	 * we can display the icon in the correct colour for the theme.
398
	 */
399
	public function override_svg_icons() {
400
		global $menu;
401
402
		// Only do this if we're not in an API request, as we override the $menu global.
403
		if ( $this->is_api_request ) {
404
			return;
405
		}
406
407
		$svg_items = array();
408
		foreach ( $menu as $idx => $menu_item ) {
409
			// Menu items that don't have icons, for example separators, have less than 7
410
			// elements, partly because the 7th is the icon. So, if we have less than 7,
411
			// let's skip it.
412
			if ( count( $menu_item ) < 7 ) {
413
				continue;
414
			}
415
416
			// If the hookname contain a URL than sanitize it by replacing invalid characters.
417
			if ( false !== strpos( $menu_item[5], '://' ) ) {
418
				$menu_item[5] = preg_replace( '![:/.]+!', '_', $menu_item[5] );
419
			}
420
421
			if ( 0 === strpos( $menu_item[6], 'data:image/svg+xml' ) && 'site-card' !== $menu_item[3] ) {
422
				$svg_items[]   = array(
423
					'icon' => $menu_item[6],
424
					'id'   => $menu_item[5],
425
				);
426
				$menu_item[4] .= ' menu-svg-icon';
427
				$menu_item[6]  = 'none';
428
			}
429
			// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
430
			$menu[ $idx ] = $menu_item;
431
		}
432
		if ( count( $svg_items ) > 0 ) {
433
			$styles = '.menu-svg-icon .wp-menu-image { background-repeat: no-repeat; background-position: center center } ';
434
			foreach ( $svg_items as $svg_item ) {
435
				$styles .= sprintf( '#%s .wp-menu-image { background-image: url( "%s" ) }', $svg_item['id'], $svg_item['icon'] );
436
			}
437
			$styles .= '@supports ( mask-image: none ) or ( -webkit-mask-image: none ) { ';
438
			$styles .= '.menu-svg-icon .wp-menu-image { background-image: none; } ';
439
			$styles .= '.menu-svg-icon .wp-menu-image::before { background-color: currentColor; ';
440
			$styles .= 'mask-size: contain; mask-position: center center; mask-repeat: no-repeat; ';
441
			$styles .= '-webkit-mask-size: contain; -webkit-mask-position: center center; -webkit-mask-repeat: no-repeat; content:"" } ';
442
			foreach ( $svg_items as $svg_item ) {
443
				$styles .= sprintf(
444
					'#%s .wp-menu-image { background-image: none; } #%s .wp-menu-image::before{ mask-image: url( "%s" ); -webkit-mask-image: url( "%s" ) }',
445
					$svg_item['id'],
446
					$svg_item['id'],
447
					$svg_item['icon'],
448
					$svg_item['icon']
449
				);
450
			}
451
			$styles .= '}';
452
453
			wp_register_style( 'svg-menu-overrides', false, array(), '20210331' );
454
			wp_enqueue_style( 'svg-menu-overrides' );
455
			wp_add_inline_style( 'svg-menu-overrides', $styles );
456
		}
457
	}
458
459
	/**
460
	 * Hide menus that are unauthorized and don't have visible submenus and cases when the menu has the same slug
461
	 * as the first submenu item.
462
	 *
463
	 * This must be done at the end of menu and submenu manipulation in order to avoid performing this check each time
464
	 * the submenus are altered.
465
	 */
466
	public function hide_parent_of_hidden_submenus() {
467
		global $menu, $submenu;
468
469
		$this->sort_hidden_submenus();
470
471
		foreach ( $menu as $menu_index => $menu_item ) {
472
			$has_submenus = isset( $submenu[ $menu_item[2] ] );
473
474
			// Skip if the menu doesn't have submenus.
475
			if ( ! $has_submenus ) {
476
				continue;
477
			}
478
479
			// If the first submenu item is hidden then we should also hide the parent.
480
			// Since the submenus are ordered by self::HIDE_CSS_CLASS (hidden submenus should be at the end of the array),
481
			// we can say that if the first submenu is hidden then we should also hide the menu.
482
			$first_submenu_item       = array_values( $submenu[ $menu_item[2] ] )[0];
483
			$is_first_submenu_visible = $this->is_item_visible( $first_submenu_item );
484
485
			// if the user does not have access to the menu and the first submenu is hidden, then hide the menu.
486
			if ( ! current_user_can( $menu_item[1] ) && ! $is_first_submenu_visible ) {
487
				// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
488
				$menu[ $menu_index ][4] = self::HIDE_CSS_CLASS;
489
			}
490
491
			// if the menu has the same slug as the first submenu then hide the submenu.
492
			if ( $menu_item[2] === $first_submenu_item[2] && ! $is_first_submenu_visible ) {
493
				// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
494
				$menu[ $menu_index ][4] = self::HIDE_CSS_CLASS;
495
			}
496
		}
497
	}
498
499
	/**
500
	 * Sort the hidden submenus by moving them at the end of the array in order to avoid WP using them as default URLs.
501
	 *
502
	 * This operation has to be done at the end of submenu manipulation in order to guarantee that the hidden submenus
503
	 * are at the end of the array.
504
	 */
505
	public function sort_hidden_submenus() {
506
		global $submenu;
507
508
		foreach ( $submenu as $menu_slug => $submenu_items ) {
509
			foreach ( $submenu_items as $submenu_index => $submenu_item ) {
510
				if ( $this->is_item_visible( $submenu_item ) ) {
511
					continue;
512
				}
513
514
				unset( $submenu[ $menu_slug ][ $submenu_index ] );
515
				// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
516
				$submenu[ $menu_slug ][] = $submenu_item;
517
			}
518
		}
519
	}
520
521
	/**
522
	 * Check if the given item is visible or not in the admin menu.
523
	 *
524
	 * @param array $item A menu or submenu array.
525
	 */
526
	public function is_item_visible( $item ) {
527
		return ! isset( $item[4] ) || false === strpos( $item[4], self::HIDE_CSS_CLASS );
528
	}
529
530
	/**
531
	 * Whether to use wp-admin pages rather than Calypso.
532
	 *
533
	 * Options:
534
	 * false - Calypso (Default).
535
	 * true  - wp-admin.
536
	 *
537
	 * @return bool
538
	 */
539
	abstract public function should_link_to_wp_admin();
540
541
	/**
542
	 * Create the desired menu output.
543
	 */
544
	abstract public function reregister_menu_items();
545
}
546