Completed
Push — update/admin-menu-sso-disabled ( 2f5af7...39bf4b )
by
unknown
86:28 queued 75:57
created

Test_Atomic_Admin_Menu::test_add_page_menu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Tests for Atomic_Admin_Menu class.
4
 *
5
 * @package automattic/jetpack
6
 */
7
8
use Automattic\Jetpack\Dashboard_Customizations\Atomic_Admin_Menu;
9
use Automattic\Jetpack\Status;
10
11
require_jetpack_file( 'modules/masterbar/admin-menu/class-atomic-admin-menu.php' );
12
require_jetpack_file( 'tests/php/modules/masterbar/data/admin-menu.php' );
13
14
/**
15
 * Class Test_Atomic_Admin_Menu.
16
 *
17
 * @coversDefaultClass Automattic\Jetpack\Dashboard_Customizations\Atomic_Admin_Menu
18
 */
19
class Test_Atomic_Admin_Menu extends WP_UnitTestCase {
20
21
	/**
22
	 * Menu data fixture.
23
	 *
24
	 * @var array
25
	 */
26
	public static $menu_data;
27
28
	/**
29
	 * Submenu data fixture.
30
	 *
31
	 * @var array
32
	 */
33
	public static $submenu_data;
34
35
	/**
36
	 * Test domain.
37
	 *
38
	 * @var string
39
	 */
40
	public static $domain;
41
42
	/**
43
	 * Whether this testsuite is run on WP.com.
44
	 *
45
	 * @var bool
46
	 */
47
	public static $is_wpcom;
48
49
	/**
50
	 * Admin menu instance.
51
	 *
52
	 * @var Atomic_Admin_Menu
53
	 */
54
	public static $admin_menu;
55
56
	/**
57
	 * Mock user ID.
58
	 *
59
	 * @var int
60
	 */
61
	private static $user_id = 0;
62
63
	/**
64
	 * Create shared fixtures.
65
	 *
66
	 * @param WP_UnitTest_Factory $factory Fixture factory.
67
	 */
68 View Code Duplication
	public static function wpSetUpBeforeClass( $factory ) {
69
		static::$domain       = ( new Status() )->get_site_suffix();
70
		static::$user_id      = $factory->user->create( array( 'role' => 'administrator' ) );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
71
		static::$menu_data    = get_wpcom_menu_fixture();
72
		static::$submenu_data = get_submenu_fixture();
73
	}
74
75
	/**
76
	 * Set up data.
77
	 */
78 View Code Duplication
	public function setUp() {
79
		parent::setUp();
80
		global $menu, $submenu;
81
82
		// Initialize in setUp so it registers hooks for every test.
83
		static::$admin_menu = Atomic_Admin_Menu::get_instance();
84
85
		$menu    = static::$menu_data;
86
		$submenu = static::$submenu_data;
87
88
		wp_set_current_user( static::$user_id );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
89
90
		\Jetpack::activate_module( 'sso' );
91
		$this->disable_api_request();
92
	}
93
94
	/**
95
	 * Test get_instance.
96
	 *
97
	 * @covers ::get_instance
98
	 * @covers ::__construct
99
	 */
100 View Code Duplication
	public function test_get_instance() {
101
		$instance = Atomic_Admin_Menu::get_instance();
102
103
		$this->assertInstanceOf( Atomic_Admin_Menu::class, $instance );
104
		$this->assertSame( $instance, static::$admin_menu );
105
106
		$this->assertSame( 99998, has_action( 'admin_menu', array( $instance, 'reregister_menu_items' ) ) );
107
		$this->assertSame( 11, has_action( 'admin_enqueue_scripts', array( $instance, 'enqueue_scripts' ) ) );
108
	}
109
110
	/**
111
	 * Tests add_browse_sites_link.
112
	 *
113
	 * @covers ::add_browse_sites_link
114
	 */
115
	public function test_add_browse_sites_link() {
116
		global $menu;
117
118
		// No output when executed in single site mode.
119
		static::$admin_menu->add_browse_sites_link();
120
		$this->assertArrayNotHasKey( 0, $menu );
121
	}
122
123
	/**
124
	 * Tests add_browse_sites_link.
125
	 *
126
	 * @covers ::add_browse_sites_link
127
	 */
128
	public function test_add_browse_sites_link_multisite() {
129
		if ( ! is_multisite() ) {
130
			$this->markTestSkipped( 'Only used on multisite' );
131
		}
132
133
		global $menu;
134
135
		// No output when user has just one site.
136
		static::$admin_menu->add_browse_sites_link();
137
		$this->assertArrayNotHasKey( 0, $menu );
138
139
		// Give user a second site.
140
		update_user_option( static::$user_id, 'wpcom_site_count', 2 );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
141
142
		static::$admin_menu->add_browse_sites_link();
143
144
		$browse_sites_menu_item = array(
145
			'Browse sites',
146
			'read',
147
			'https://wordpress.com/home',
148
			'site-switcher',
149
			'menu-top toplevel_page_https://wordpress.com/home',
150
			'toplevel_page_https://wordpress.com/home',
151
			'dashicons-arrow-left-alt2',
152
		);
153
		$this->assertSame( $menu[0], $browse_sites_menu_item );
154
155
		delete_user_option( static::$user_id, 'wpcom_site_count' );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
156
	}
157
158
	/**
159
	 * Tests add_new_site_link.
160
	 *
161
	 * @covers ::add_new_site_link
162
	 */
163
	public function test_add_new_site_link() {
164
		global $menu;
165
166
		// Set jetpack user data.
167
		update_user_option( static::$user_id, 'wpcom_site_count', 1 );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
168
169
		static::$admin_menu->add_new_site_link();
170
171
		$new_site_menu_item = array(
172
			'Add New Site',
173
			'read',
174
			'https://wordpress.com/start?ref=calypso-sidebar',
175
			'Add New Site',
176
			'menu-top toplevel_page_https://wordpress.com/start?ref=calypso-sidebar',
177
			'toplevel_page_https://wordpress.com/start?ref=calypso-sidebar',
178
			'dashicons-plus-alt',
179
		);
180
		$this->assertSame( array_pop( $menu ), $new_site_menu_item );
181
182
		delete_user_option( static::$user_id, 'wpcom_site_count' );
0 ignored issues
show
Bug introduced by
Since $user_id is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $user_id to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
183
	}
184
185
	/**
186
	 * Tests add_site_card_menu
187
	 *
188
	 * @covers ::add_site_card_menu
189
	 */
190
	public function test_add_site_card_menu() {
191
		global $menu;
192
193
		if ( ! function_exists( 'site_is_private' ) ) {
194
			function site_is_private() { // phpcs:ignore
195
				return false;
196
			}
197
		}
198
		static::$admin_menu->add_site_card_menu();
199
200
		$home_url            = home_url();
201
		$site_card_menu_item = array(
202
			// phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
203
			'
204
<div class="site__info">
205
	<div class="site__title">' . get_option( 'blogname' ) . '</div>
206
	<div class="site__domain">' . static::$domain . "</div>\n\t\n</div>",
207
			'read',
208
			$home_url,
209
			'site-card',
210
			'menu-top toplevel_page_' . $home_url,
211
			'toplevel_page_' . $home_url,
212
			'data:image/svg+xml,%3Csvg%20class%3D%22gridicon%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Ctitle%3EGlobe%3C%2Ftitle%3E%3Crect%20fill-opacity%3D%220%22%20x%3D%220%22%20width%3D%2224%22%20height%3D%2224%22%2F%3E%3Cg%3E%3Cpath%20fill%3D%22%23fff%22%20d%3D%22M12%202C6.477%202%202%206.477%202%2012s4.477%2010%2010%2010%2010-4.477%2010-10S17.523%202%2012%202zm0%2018l2-2%201-1v-2h-2v-1l-1-1H9v3l2%202v1.93c-3.94-.494-7-3.858-7-7.93l1%201h2v-2h2l3-3V6h-2L9%205v-.41C9.927%204.21%2010.94%204%2012%204s2.073.212%203%20.59V6l-1%201v2l1%201%203.13-3.13c.752.897%201.304%201.964%201.606%203.13H18l-2%202v2l1%201h2l.286.286C18.03%2018.06%2015.24%2020%2012%2020z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E',
213
		);
214
215
		$this->assertEquals( $menu[1], $site_card_menu_item );
216
	}
217
218
	/**
219
	 * Tests set_site_card_menu_class
220
	 *
221
	 * @covers ::set_site_card_menu_class
222
	 */
223
	public function test_set_site_card_menu_class() {
224
		global $menu;
225
226
		if ( ! function_exists( 'site_is_private' ) ) {
227
			function site_is_private() { // phpcs:ignore
0 ignored issues
show
Best Practice introduced by
The function site_is_private() has been defined more than once; this definition is ignored, only the first definition in this file (L194-196) is considered.

This check looks for functions that have already been defined in the same file.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
228
				return false;
229
			}
230
		}
231
232
		static::$admin_menu->add_site_card_menu();
233
234
		$menu = static::$admin_menu->set_site_card_menu_class( $menu );
235
		$this->assertNotContains( 'has-site-icon', $menu[1][4] );
236
237
		// Atomic fallback site icon counts as no site icon.
238
		add_filter( 'get_site_icon_url', array( $this, 'wpcomsh_site_icon_url' ) );
239
		$menu = static::$admin_menu->set_site_card_menu_class( $menu );
240
		remove_filter( 'get_site_icon_url', array( $this, 'wpcomsh_site_icon_url' ) );
241
		$this->assertNotContains( 'has-site-icon', $menu[1][4] );
242
243
		// Custom site icon triggers CSS class.
244
		add_filter( 'get_site_icon_url', array( $this, 'custom_site_icon_url' ) );
245
		$menu = static::$admin_menu->set_site_card_menu_class( $menu );
246
		remove_filter( 'get_site_icon_url', array( $this, 'custom_site_icon_url' ) );
247
		$this->assertContains( 'has-site-icon', $menu[1][4] );
248
	}
249
250
	/**
251
	 * Shim wpcomsh fallback site icon.
252
	 *
253
	 * @return string
254
	 */
255
	public function wpcomsh_site_icon_url() {
256
		return 'https://s0.wp.com/i/webclip.png';
257
	}
258
259
	/**
260
	 * Custom site icon.
261
	 *
262
	 * @return string
263
	 */
264
	public function custom_site_icon_url() {
265
		return 'https://s0.wp.com/i/jetpack.png';
266
	}
267
268
	/**
269
	 * Tests add_posts_menu
270
	 *
271
	 * @covers ::add_posts_menu
272
	 */
273 View Code Duplication
	public function test_add_posts_menu() {
274
		global $submenu;
275
276
		// Make sure menu items link to WP Admin.
277
		static::$admin_menu->add_posts_menu( false );
278
		$this->assertSame( 'edit.php', $submenu['edit.php'][5][2] );
279
		$this->assertSame( 'post-new.php', $submenu['edit.php'][10][2] );
280
281
		// Reset.
282
		$submenu = static::$submenu_data;
283
284
		// Make sure menu items link to Calypso for API requests when SSO is disabled.
285
		$this->enable_api_request();
286
		\Jetpack::deactivate_module( 'sso' );
287
		static::$admin_menu->add_posts_menu( true );
288
		$this->assertSame( 'https://wordpress.com/posts/' . static::$domain, $submenu['edit.php'][0][2] );
289
		$this->assertSame( 'https://wordpress.com/post/' . static::$domain, $submenu['edit.php'][1][2] );
290
	}
291
292
	/**
293
	 * Tests add_page_menu
294
	 *
295
	 * @covers ::add_page_menu
296
	 */
297 View Code Duplication
	public function test_add_page_menu() {
298
		global $submenu;
299
300
		// Make sure menu items link to WP Admin.
301
		static::$admin_menu->add_page_menu( false );
302
		$this->assertSame( 'edit.php?post_type=page', $submenu['edit.php?post_type=page'][5][2] );
303
		$this->assertSame( 'post-new.php?post_type=page', $submenu['edit.php?post_type=page'][10][2] );
304
305
		// Reset.
306
		$submenu = static::$submenu_data;
307
308
		// Make sure menu items link to Calypso for API requests when SSO is disabled.
309
		$this->enable_api_request();
310
		\Jetpack::deactivate_module( 'sso' );
311
		static::$admin_menu->add_page_menu( true );
312
		$this->assertSame( 'https://wordpress.com/pages/' . static::$domain, $submenu['edit.php?post_type=page'][0][2] );
313
		$this->assertSame( 'https://wordpress.com/page/' . static::$domain, $submenu['edit.php?post_type=page'][1][2] );
314
	}
315
316
	/**
317
	 * Tests add_upgrades_menu
318
	 *
319
	 * @covers ::add_upgrades_menu
320
	 */
321 View Code Duplication
	public function test_add_upgrades_menu() {
322
		global $submenu;
323
324
		static::$admin_menu->add_upgrades_menu();
325
326
		$this->assertSame( 'https://wordpress.com/plans/my-plan/' . static::$domain, $submenu['paid-upgrades.php'][1][2] );
327
		$this->assertSame( 'https://wordpress.com/domains/manage/' . static::$domain, $submenu['paid-upgrades.php'][2][2] );
328
329
		/** This filter is already documented in modules/masterbar/admin-menu/class-atomic-admin-menu.php */
330
		if ( apply_filters( 'jetpack_show_wpcom_upgrades_email_menu', false ) ) {
331
			$this->assertSame( 'https://wordpress.com/email/' . static::$domain, $submenu['paid-upgrades.php'][3][2] );
332
			$this->assertSame( 'https://wordpress.com/purchases/subscriptions/' . static::$domain, $submenu['paid-upgrades.php'][4][2] );
333
		} else {
334
			$this->assertSame( 'https://wordpress.com/purchases/subscriptions/' . static::$domain, $submenu['paid-upgrades.php'][3][2] );
335
		}
336
	}
337
338
	/**
339
	 * Tests add_tools_menu
340
	 *
341
	 * @covers ::add_tools_menu
342
	 */
343
	public function test_add_tools_menu() {
344
		global $submenu;
345
346
		static::$admin_menu->add_tools_menu();
347
348
		// Check Export menu item always links to WP Admin.
349
		$this->assertSame( 'export.php', $submenu['tools.php'][5][2] );
350
	}
351
352
	/**
353
	 * Tests add_options_menu
354
	 *
355
	 * @covers ::add_options_menu
356
	 */
357
	public function test_add_options_menu() {
358
		global $submenu;
359
360
		static::$admin_menu->add_options_menu();
361
		$this->assertSame( 'https://wordpress.com/hosting-config/' . static::$domain, $submenu['options-general.php'][6][2] );
362
		$this->assertSame( 'options-writing.php', array_pop( $submenu['options-general.php'] )[2] );
363
364
		// Reset.
365
		$submenu = static::$submenu_data;
366
367
		static::$admin_menu->add_options_menu( true );
368
		$last_submenu = array_pop( $submenu['options-general.php'] );
369
		$this->assertNotSame( 'options-writing.php', $last_submenu[2] );
370
371
		// Reset.
372
		$submenu = static::$submenu_data;
373
374
		$this->enable_api_request();
375
		\Jetpack::deactivate_module( 'sso' );
376
		$last_submenu = array_pop( $submenu['options-general.php'] );
377
		$this->assertNotSame( 'options-writing.php', $last_submenu[2] );
378
	}
379
380
	/**
381
	 * Tests add_plugins_menu
382
	 *
383
	 * @covers ::add_plugins_menu
384
	 */
385
	public function test_add_plugins_menu() {
386
		global $menu;
387
388
		static::$admin_menu->add_plugins_menu( false );
389
390
		// Check Plugins menu always links to WP Admin.
391
		$this->assertSame( 'plugins.php', $menu[65][2] );
392
	}
393
394
	/**
395
	 * Tests add_appearance_menu
396
	 *
397
	 * @covers ::add_appearance_menu
398
	 */
399
	public function test_add_appearance_menu() {
400
		global $submenu;
401
402
		static::$admin_menu->add_appearance_menu();
403
404
		// Multisite users don't have the `install_themes` capability by default,
405
		// so we have to make a dynamic check based on whether the current user can
406
		// install themes.
407
		if ( current_user_can( 'install_themes' ) ) {
408
			$this->assertSame( 'theme-install.php', $submenu['themes.php'][1][2] );
409
			// Check Customize menu always links to WP Admin.
410
			$this->assertSame( 'customize.php?return', $submenu['themes.php'][3][2] );
411
		} else {
412
			// Check Customize menu always links to WP Admin.
413
			$this->assertSame( 'customize.php?return', $submenu['themes.php'][2][2] );
414
		}
415
416
		// Reset.
417
		$submenu = static::$submenu_data;
418
419
		$this->enable_api_request();
420
		\Jetpack::deactivate_module( 'sso' );
421
		$this->assertArrayNotHasKey( 1, $submenu['themes.php'] );
422
	}
423
424
	/**
425
	 * Tests add_users_menu
426
	 *
427
	 * @covers ::add_users_menu
428
	 */
429
	public function test_add_users_menu() {
430
		global $submenu;
431
432
		static::$admin_menu->add_users_menu();
433
		$this->assertSame( 'users.php', $submenu['users.php'][2][2] );
434
435
		// Reset.
436
		$submenu = static::$submenu_data;
437
438
		$this->enable_api_request();
439
		\Jetpack::deactivate_module( 'sso' );
440
		$this->assertArrayNotHasKey( 2, $submenu['users.php'] );
441
	}
442
443
	/**
444
	 * Tests add_comments_menu
445
	 *
446
	 * @covers ::add_comments_menu
447
	 */
448
	public function test_add_comments_menu() {
449
		global $menu;
450
451
		// Make sure menu items link to WP Admin.
452
		static::$admin_menu->add_comments_menu( false );
453
		$this->assertSame( 'edit-comments.php', $menu[25][2] );
454
455
		// Reset.
456
		$menu = static::$menu_data;
457
458
		// Make sure menu items link to Calypso for API requests when SSO is disabled.
459
		$this->enable_api_request();
460
		\Jetpack::deactivate_module( 'sso' );
461
		static::$admin_menu->add_comments_menu( true );
462
		$this->assertSame( 'https://wordpress.com/comments/all/' . static::$domain, $menu[25][2] );
463
464
	}
465
466
	/**
467
	 * Tests add_gutenberg_menus
468
	 *
469
	 * @covers ::add_gutenberg_menus
470
	 */
471
	public function test_add_gutenberg_menus() {
472
		global $menu;
473
		static::$admin_menu->add_gutenberg_menus( false );
474
475
		// Gutenberg plugin menu should not be visible.
476
		$this->assertArrayNotHasKey( 101, $menu );
477
	}
478
479
	/**
480
	 * Makes the admin class think the menu is requested by an API request.
481
	 */
482 View Code Duplication
	public function enable_api_request() {
483
		$admin_menu     = new ReflectionClass( static::$admin_menu );
484
		$is_api_request = $admin_menu->getProperty( 'is_api_request' );
485
		$is_api_request->setAccessible( true );
486
		$is_api_request->setValue( static::$admin_menu, true );
487
	}
488
489
	/**
490
	 * Makes the admin class think the menu is requested by an API request.
491
	 */
492 View Code Duplication
	public function disable_api_request() {
493
		$admin_menu     = new ReflectionClass( static::$admin_menu );
494
		$is_api_request = $admin_menu->getProperty( 'is_api_request' );
495
		$is_api_request->setAccessible( true );
496
		$is_api_request->setValue( static::$admin_menu, false );
497
	}
498
}
499