class-p2-admin-menu.php
6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* P2 Admin Menu file.
*
* @package Jetpack
*/
namespace Automattic\Jetpack\Dashboard_Customizations;
require_once __DIR__ . '/class-wpcom-admin-menu.php';
/**
* Class P2_Admin_Menu.
*/
class P2_Admin_Menu extends WPcom_Admin_Menu {
/**
* Slug for the "Appearance" menu item.
*
* @var string
*/
private $appearance_slug = 'themes.php';
/**
* Slug for the "Jetpack" menu item.
*
* @var string
*/
private $jetpack_slug = 'jetpack';
/**
* Slug for the "Upgrades" menu item.
*
* @var string
*/
private $upgrades_slug = 'paid-upgrades.php';
/**
* Slug for the "Plugins" menu item.
*
* @var string
*/
private $plugins_slug = 'plugins.php';
/**
* Slug for the "Tools" menu item.
*
* @var string
*/
private $tools_slug = 'tools.php';
/**
* Whether or not the P2 is a hub.
*
* @var bool
*/
private $is_hub = false;
/**
* Whether or not the P2 has a paid plan.
*
* @var bool
*/
private $is_paid = false;
/**
* P2_Admin_Menu constructor.
*/
protected function __construct() {
parent::__construct();
if (
defined( 'IS_WPCOM' ) && IS_WPCOM &&
function_exists( 'require_lib' )
) {
require_lib( 'wpforteams' );
$current_blog_id = get_current_blog_id();
$this->is_hub = \WPForTeams\Workspace\is_workspace_hub( $current_blog_id );
$this->is_paid = \WPForTeams\has_p2_plus_plan( \WPForTeams\Workspace\get_hub_blog_id_from_blog_id( $current_blog_id ) );
}
// Appearance -> AMP. This needs to be called here in the constructor.
// Running it from reregister_menu_items is not early enough.
remove_action( 'admin_menu', 'amp_add_customizer_link' );
}
/**
* Create the desired menu output.
*/
public function reregister_menu_items() {
parent::reregister_menu_items();
if ( ! $this->is_hub ) {
$this->remove_menus_for_p2_space();
} else {
$this->remove_menus_for_hub();
}
$this->remove_menus_for_all_p2s();
}
/**
* Remove menu items that are not applicable for P2 workspace sites.
*/
private function remove_menus_for_p2_space() {
// Non-hub P2s can't have plans at all.
remove_menu_page( $this->upgrades_slug );
// Jetpack -> Backup.
remove_submenu_page( $this->jetpack_slug, 'https://wordpress.com/backup/' . $this->domain );
// Appearance -> Themes.
remove_submenu_page( $this->appearance_slug, 'https://wordpress.com/themes/' . $this->domain );
// Appearance -> Additional CSS.
$customize_custom_css_url = add_query_arg(
array( 'autofocus' => array( 'section' => 'css_nudge' ) ),
'https://wordpress.com/customize/' . $this->domain
);
remove_submenu_page( $this->appearance_slug, $customize_custom_css_url );
// Tools
remove_submenu_page( $this->tools_slug, 'https://wordpress.com/marketing/tools/' . $this->domain );
remove_submenu_page( $this->tools_slug, 'https://wordpress.com/earn/' . $this->domain );
}
/**
* Remove menu items that are not applicable for P2 hubs.
*/
private function remove_menus_for_hub() {
// Hubs can have plans, but not domain and email products.
remove_submenu_page( $this->upgrades_slug, 'https://wordpress.com/domains/manage/' . $this->domain );
remove_submenu_page( $this->upgrades_slug, 'https://wordpress.com/email/' . $this->domain );
// Stats.
remove_menu_page( 'https://wordpress.com/stats/day/' . $this->domain );
// Hide posts.
remove_menu_page( 'edit.php' );
// Hide pages.
remove_menu_page( 'edit.php?post_type=page' );
// Hide media.
remove_menu_page( 'https://wordpress.com/media/' . $this->domain );
// Hide comments.
remove_menu_page( 'https://wordpress.com/comments/all/' . $this->domain );
// Hide appearance.
remove_menu_page( $this->appearance_slug );
// Tools.
remove_submenu_page( $this->tools_slug, 'https://wordpress.com/marketing/tools/' . $this->domain );
remove_submenu_page( $this->tools_slug, 'https://wordpress.com/earn/' . $this->domain );
remove_submenu_page( $this->tools_slug, 'https://wordpress.com/import/' . $this->domain );
remove_submenu_page( $this->tools_slug, 'https://wordpress.com/export/' . $this->domain );
add_submenu_page( $this->tools_slug, __( 'Integrations', 'jetpack' ), __( 'Integrations', 'jetpack' ), 'manage_options', 'https://wordpress.com/marketing/connections/' . $this->domain, null, 0 );
// Hide settings.
remove_submenu_page( 'options-general.php', 'options-reading.php' );
remove_submenu_page( 'options-general.php', 'options-writing.php' );
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
}
/**
* Remove menu items that are not applicable for all P2s.
*/
private function remove_menus_for_all_p2s() {
// Remove Jetpack menu item.
remove_menu_page( $this->jetpack_slug );
// The following menu items are hidden for both hubs and P2 sites.
remove_menu_page( 'link-manager.php' );
remove_menu_page( 'feedback' );
remove_menu_page( $this->plugins_slug );
remove_menu_page( 'https://wordpress.com/plugins/' . $this->domain );
remove_menu_page( 'https://wordpress.com/inbox/' . $this->domain );
remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'sharing' );
remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'polls&action=options' );
remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'ratings&action=options' );
remove_submenu_page(
'options-general.php',
'https://wordpress.com/hosting-config/' . $this->domain
);
remove_submenu_page(
'https://wordpress.com/settings/general/' . $this->domain,
'https://wordpress.com/marketing/sharing-buttons/' . $this->domain
);
/** This action is documented in `wp-content/plugins/p2-editor/classes/p2-editor-admin.php` */
if ( apply_filters( 'p2tenberg_admin_patterns', apply_filters( 'p2editor_admin_patterns', true ) ) !== true ) {
remove_menu_page( 'edit.php?post_type=p2_pattern' );
}
remove_submenu_page(
'edit.php?post_type=p2_pattern',
'edit-tags.php?taxonomy=post_tag&post_type=p2_pattern'
);
// Hide performance settings.
remove_submenu_page( 'options-general.php', 'https://wordpress.com/settings/performance/' . $this->domain );
}
/**
* Override, don't add the woocommerce installation menu on any p2s.
*
* @param array|null $current_plan The site's plan.
*/
public function add_woocommerce_installation_menu( $current_plan = null ) {} // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
}