Completed
Push — try/wpcom-nav-package ( c38648 )
by
unknown
12:50 queued 02:43
created

P2_Admin_Menu   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reregister_menu_items() 0 5 1
A remove_menus() 0 36 5
A add_p2_editor_menu() 0 11 3
1
<?php
2
/**
3
 * P2 Admin Menu file.
4
 *
5
 * @package Jetpack
6
 */
7
8
namespace Automattic\Jetpack;
9
10
/**
11
 * Class P2_Admin_Menu.
12
 */
13
class P2_Admin_Menu extends Simple_Admin_Menu {
14
15
	/**
16
	 * Create the desired menu output.
17
	 */
18
	public function reregister_menu_items() {
19
		parent::reregister_menu_items();
20
		$this->remove_menus();
21
		$this->add_p2_editor_menu();
22
	}
23
24
	/**
25
	 * Remove menu items not applicable for P2 sites.
26
	 */
27
	public function remove_menus() {
28
		if (
29
			defined( 'IS_WPCOM' ) && IS_WPCOM &&
30
			function_exists( 'require_lib' )
31
		) {
32
			require_lib( 'wpforteams' );
33
34
			if ( \WPForTeams\Workspace\is_part_of_active_workspace( get_current_blog_id() ) ) {
35
				remove_menu_page( 'https://wordpress.com/plans/' . $this->domain );
36
			}
37
		}
38
39
		remove_menu_page( 'link-manager.php' );
40
		remove_menu_page( 'edit.php?post_type=feedback' );
41
		remove_menu_page( 'plugins.php' );
42
		remove_menu_page( 'https://wordpress.com/plugins/' . $this->domain );
43
		remove_submenu_page( 'plugins.php', 'plugins.php' );
44
45
		remove_submenu_page( 'https://wordpress.com/plans/' . $this->domain, 'https://wordpress.com/domains/manage/' . $this->domain );
46
47
		$themes_slug = 'https://wordpress.com/themes/' . $this->domain;
48
		remove_submenu_page( $themes_slug, $themes_slug );
49
50
		$tools_slug = 'https://wordpress.com/marketing/tools/' . $this->domain;
51
		remove_submenu_page( $tools_slug, 'https://wordpress.com/marketing/tools/' . $this->domain );
52
		remove_submenu_page( $tools_slug, 'https://wordpress.com/earn/' . $this->domain );
53
54
		remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'sharing' );
55
		remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'polls&action=options' );
56
		remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'ratings&action=options' );
57
		remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'https://wordpress.com/hosting-config/' . $this->domain );
58
		remove_submenu_page(
59
			'https://wordpress.com/settings/general/' . $this->domain,
60
			'https://wordpress.com/marketing/sharing-buttons/' . $this->domain
61
		);
62
	}
63
64
	/**
65
	 * Adds the P2 Editor menu.
66
	 */
67
	public function add_p2_editor_menu() {
68
		/** This action is documented in `wp-content/plugins/p2-editor/classes/p2-editor-admin.php` */
69
		if ( apply_filters( 'p2tenberg_admin_patterns', apply_filters( 'p2editor_admin_patterns', true ) ) !== true ) {
70
			return;
71
		}
72
73
		// Add the menu only in Calypso (it already exists in WP Admin).
74
		if ( $this->is_api_request ) {
75
			add_menu_page( esc_attr__( 'P2 Editor', 'jetpack' ), __( 'P2 Editor', 'jetpack' ), 'manage_options', 'p2editor', '', 'dashicons-admin-multisite' );
76
		}
77
	}
78
}
79