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