← All changes
|
jetpack_vendor/automattic/jetpack-masterbar/src/admin-menu/class-wpcom-admin-menu.php
+2
-175
13.7.2
→
16.3-beta
View file →
| @@ -6,9 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Masterbar; |
| 9 | 9 | |
| 10 | -use Automattic\Jetpack\Status; | |
| 11 | 10 | use Jetpack_Custom_CSS; |
| 12 | 11 | use JITM; |
| 13 | 12 | |
| 14 | 13 | require_once __DIR__ . '/class-admin-menu.php'; |
| @@ -17,15 +16,8 @@ | ||
| 17 | 16 | * Class WPcom_Admin_Menu. |
| 18 | 17 | */ |
| 19 | 18 | class WPcom_Admin_Menu extends Admin_Menu { |
| 20 | 19 | /** |
| 21 | - * Holds the current plan, set by get_current_plan(). | |
| 22 | - * | |
| 23 | - * @var array | |
| 24 | - */ | |
| 25 | - private $current_plan = array(); | |
| 26 | - | |
| 27 | - /** | |
| 28 | 20 | * WPcom_Admin_Menu constructor. |
| 29 | 21 | */ |
| 30 | 22 | protected function __construct() { |
| 31 | 23 | parent::__construct(); |
| @@ -31,10 +23,9 @@ | ||
| 31 | 23 | parent::__construct(); |
| 32 | 24 | |
| 33 | 25 | add_action( 'wp_ajax_sidebar_state', array( $this, 'ajax_sidebar_state' ) ); |
| 34 | 26 | add_action( 'wp_ajax_jitm_dismiss', array( $this, 'wp_ajax_jitm_dismiss' ) ); |
| 35 | - add_action( 'wp_ajax_upsell_nudge_jitm', array( $this, 'wp_ajax_upsell_nudge_jitm' ) ); | |
| 36 | - add_action( 'admin_enqueue_scripts', array( $this, 'wpcom_upsell_nudge_jitm_fix' ) ); | |
| 27 | + add_action( 'adminmenu', array( $this, 'render_upsell_nudge' ), 100 ); | |
| 37 | 28 | add_action( 'admin_init', array( $this, 'sync_sidebar_collapsed_state' ) ); |
| 38 | 29 | add_action( 'admin_menu', array( $this, 'remove_submenus' ), 140 ); // After hookpress hook at 130. |
| 39 | 30 | } |
| 40 | 31 | |
| @@ -43,20 +34,15 @@ | ||
| 43 | 34 | */ |
| 44 | 35 | public function reregister_menu_items() { |
| 45 | 36 | parent::reregister_menu_items(); |
| 46 | 37 | |
| 47 | - $this->add_my_home_menu(); | |
| 48 | - $this->add_my_mailboxes_menu(); | |
| 49 | 38 | $this->remove_gutenberg_menu(); |
| 50 | 39 | |
| 51 | 40 | // Not needed outside of wp-admin. |
| 52 | 41 | if ( ! $this->is_api_request ) { |
| 53 | - $this->add_site_card_menu(); | |
| 54 | 42 | $this->add_new_site_link(); |
| 55 | 43 | } |
| 56 | 44 | |
| 57 | - $this->add_woocommerce_installation_menu( $this->get_current_plan() ); | |
| 58 | - | |
| 59 | 45 | ksort( $GLOBALS['menu'] ); |
| 60 | 46 | } |
| 61 | 47 | |
| 62 | 48 | /** |
| @@ -133,83 +119,8 @@ | ||
| 133 | 119 | add_menu_page( __( 'Add New Site', 'jetpack-masterbar' ), __( 'Add New Site', 'jetpack-masterbar' ), 'read', 'https://wordpress.com/start?ref=calypso-sidebar', null, 'dashicons-plus-alt' ); |
| 134 | 120 | } |
| 135 | 121 | |
| 136 | 122 | /** |
| 137 | - * Adds site card component. | |
| 138 | - */ | |
| 139 | - public function add_site_card_menu() { | |
| 140 | - $default = plugins_url( 'globe-icon.svg', __FILE__ ); | |
| 141 | - $icon = get_site_icon_url( 32, $default ); | |
| 142 | - $blog_name = get_option( 'blogname' ) !== '' ? get_option( 'blogname' ) : $this->domain; | |
| 143 | - $status = new Status(); | |
| 144 | - $is_private_site = $status->is_private_site(); | |
| 145 | - $is_coming_soon = $status->is_coming_soon(); | |
| 146 | - | |
| 147 | - if ( $default === $icon && blavatar_exists( $this->domain ) ) { | |
| 148 | - $icon = blavatar_url( $this->domain, 'img', 32 ); | |
| 149 | - } | |
| 150 | - | |
| 151 | - $badge = ''; | |
| 152 | - if ( $is_private_site || $is_coming_soon ) { | |
| 153 | - $badge .= sprintf( | |
| 154 | - '<span class="site__badge site__badge-private">%s</span>', | |
| 155 | - $is_coming_soon ? esc_html__( 'Coming Soon', 'jetpack-masterbar' ) : esc_html__( 'Private', 'jetpack-masterbar' ) | |
| 156 | - ); | |
| 157 | - } | |
| 158 | - | |
| 159 | - if ( function_exists( 'is_simple_site_redirect' ) && is_simple_site_redirect( $this->domain ) ) { | |
| 160 | - $badge .= '<span class="site__badge site__badge-redirect">' . esc_html__( 'Redirect', 'jetpack-masterbar' ) . '</span>'; | |
| 161 | - } | |
| 162 | - | |
| 163 | - if ( ! empty( get_option( 'options' )['is_domain_only'] ) ) { | |
| 164 | - $badge .= '<span class="site__badge site__badge-domain-only">' . esc_html__( 'Domain', 'jetpack-masterbar' ) . '</span>'; | |
| 165 | - } | |
| 166 | - | |
| 167 | - $site_card = ' | |
| 168 | -<div class="site__info"> | |
| 169 | - <div class="site__title">%1$s</div> | |
| 170 | - <div class="site__domain">%2$s</div> | |
| 171 | - %3$s | |
| 172 | -</div>'; | |
| 173 | - | |
| 174 | - $site_card = sprintf( | |
| 175 | - $site_card, | |
| 176 | - $blog_name, | |
| 177 | - $this->domain, | |
| 178 | - $badge | |
| 179 | - ); | |
| 180 | - | |
| 181 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 182 | - add_menu_page( 'site-card', $site_card, 'read', get_home_url(), null, $icon, 1 ); | |
| 183 | - add_filter( 'add_menu_classes', array( $this, 'set_site_card_menu_class' ) ); | |
| 184 | - } | |
| 185 | - | |
| 186 | - /** | |
| 187 | - * Adds a custom element class and id for Site Card's menu item. | |
| 188 | - * | |
| 189 | - * @param array $menu Associative array of administration menu items. | |
| 190 | - * @return array | |
| 191 | - */ | |
| 192 | - public function set_site_card_menu_class( array $menu ) { | |
| 193 | - foreach ( $menu as $key => $menu_item ) { | |
| 194 | - if ( 'site-card' !== $menu_item[3] ) { | |
| 195 | - continue; | |
| 196 | - } | |
| 197 | - | |
| 198 | - $classes = ' toplevel_page_site-card'; | |
| 199 | - if ( blavatar_exists( $this->domain ) ) { | |
| 200 | - $classes .= ' has-site-icon'; | |
| 201 | - } | |
| 202 | - | |
| 203 | - $menu[ $key ][4] = $menu_item[4] . $classes; | |
| 204 | - $menu[ $key ][5] = 'toplevel_page_site_card'; | |
| 205 | - break; | |
| 206 | - } | |
| 207 | - | |
| 208 | - return $menu; | |
| 209 | - } | |
| 210 | - | |
| 211 | - /** | |
| 212 | 123 | * Returns the first available upsell nudge. |
| 213 | 124 | * |
| 214 | 125 | * @return array |
| 215 | 126 | */ |
| @@ -245,68 +156,8 @@ | ||
| 245 | 156 | } |
| 246 | 157 | } |
| 247 | 158 | |
| 248 | 159 | /** |
| 249 | - * Adds Stats menu. | |
| 250 | - */ | |
| 251 | - public function add_stats_menu() { | |
| 252 | - $menu_title = __( 'Stats', 'jetpack-masterbar' ); | |
| 253 | - | |
| 254 | - if ( ! $this->is_api_request ) { | |
| 255 | - $menu_title .= sprintf( | |
| 256 | - '<img class="sidebar-unified__sparkline" width="80" height="20" src="%1$s" alt="%2$s">', | |
| 257 | - esc_url( site_url( 'wp-includes/charts/admin-bar-hours-scale-2x.php?masterbar=1&s=' . get_current_blog_id() ) ), | |
| 258 | - esc_attr__( 'Hourly views', 'jetpack-masterbar' ) | |
| 259 | - ); | |
| 260 | - } | |
| 261 | - | |
| 262 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 263 | - add_menu_page( __( 'Stats', 'jetpack-masterbar' ), $menu_title, 'read', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 ); | |
| 264 | - } | |
| 265 | - | |
| 266 | - /** | |
| 267 | - * Gets the current plan and stores it in $this->current_plan so the database is only called once per request. | |
| 268 | - * | |
| 269 | - * @return array | |
| 270 | - */ | |
| 271 | - private function get_current_plan() { | |
| 272 | - if ( empty( $this->current_plan ) && class_exists( 'WPCOM_Store_API' ) ) { | |
| 273 | - $this->current_plan = \WPCOM_Store_API::get_current_plan( get_current_blog_id() ); | |
| 274 | - } | |
| 275 | - return $this->current_plan; | |
| 276 | - } | |
| 277 | - | |
| 278 | - /** | |
| 279 | - * Adds Upgrades menu. | |
| 280 | - * | |
| 281 | - * @param string $plan The current WPCOM plan of the blog. | |
| 282 | - */ | |
| 283 | - public function add_upgrades_menu( $plan = null ) { | |
| 284 | - $current_plan = $this->get_current_plan(); | |
| 285 | - if ( ! empty( $current_plan['product_name_short'] ) ) { | |
| 286 | - $plan = $current_plan['product_name_short']; | |
| 287 | - } | |
| 288 | - | |
| 289 | - parent::add_upgrades_menu( $plan ); | |
| 290 | - | |
| 291 | - $last_upgrade_submenu_position = $this->get_submenu_item_count( 'paid-upgrades.php' ); | |
| 292 | - | |
| 293 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 294 | - add_submenu_page( 'paid-upgrades.php', __( 'Domains', 'jetpack-masterbar' ), __( 'Domains', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/domains/manage/' . $this->domain, null, $last_upgrade_submenu_position - 1 ); | |
| 295 | - | |
| 296 | - /** This filter is already documented in modules/masterbar/admin-menu/class-atomic-admin-menu.php */ | |
| 297 | - if ( apply_filters( 'jetpack_show_wpcom_upgrades_email_menu', false ) ) { | |
| 298 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 299 | - add_submenu_page( 'paid-upgrades.php', __( 'Emails', 'jetpack-masterbar' ), __( 'Emails', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/email/' . $this->domain, null, $last_upgrade_submenu_position ); | |
| 300 | - } | |
| 301 | - | |
| 302 | - if ( defined( 'WPCOM_ENABLE_ADD_ONS_MENU_ITEM' ) && WPCOM_ENABLE_ADD_ONS_MENU_ITEM ) { | |
| 303 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 304 | - add_submenu_page( 'paid-upgrades.php', __( 'Add-Ons', 'jetpack-masterbar' ), __( 'Add-Ons', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/add-ons/' . $this->domain, null, 1 ); | |
| 305 | - } | |
| 306 | - } | |
| 307 | - | |
| 308 | - /** | |
| 309 | 160 | * Adds Appearance menu. |
| 310 | 161 | * |
| 311 | 162 | * @return string The Customizer URL. |
| 312 | 163 | */ |
| @@ -350,30 +201,11 @@ | ||
| 350 | 201 | $slug = current_user_can( 'list_users' ) ? 'users.php' : 'profile.php'; |
| 351 | 202 | $this->update_submenus( $slug, $submenus_to_update ); |
| 352 | 203 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. |
| 353 | 204 | add_submenu_page( 'users.php', esc_attr__( 'Add New User', 'jetpack-masterbar' ), __( 'Add New User', 'jetpack-masterbar' ), 'promote_users', 'https://wordpress.com/people/new/' . $this->domain, null, 1 ); |
| 354 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 355 | - add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack-masterbar' ), __( 'Subscribers', 'jetpack-masterbar' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null, 3 ); | |
| 356 | 205 | } |
| 357 | 206 | |
| 358 | 207 | /** |
| 359 | - * Adds Settings menu. | |
| 360 | - */ | |
| 361 | - public function add_options_menu() { | |
| 362 | - parent::add_options_menu(); | |
| 363 | - | |
| 364 | - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. | |
| 365 | - add_submenu_page( 'options-general.php', esc_attr__( 'Hosting Configuration', 'jetpack-masterbar' ), __( 'Hosting Configuration', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/hosting-config/' . $this->domain, null, 10 ); | |
| 366 | - } | |
| 367 | - | |
| 368 | - /** | |
| 369 | - * Adds My Home menu. | |
| 370 | - */ | |
| 371 | - public function add_my_home_menu() { | |
| 372 | - $this->update_menu( 'index.php', 'https://wordpress.com/home/' . $this->domain, __( 'My Home', 'jetpack-masterbar' ), 'read', 'dashicons-admin-home' ); | |
| 373 | - } | |
| 374 | - | |
| 375 | - /** | |
| 376 | 208 | * Also remove the Gutenberg plugin menu. |
| 377 | 209 | */ |
| 378 | 210 | public function remove_gutenberg_menu() { |
| 379 | 211 | // Always remove the Gutenberg menu. |
| @@ -418,9 +250,9 @@ | ||
| 418 | 250 | ); |
| 419 | 251 | |
| 420 | 252 | update_user_attribute( $user_id, 'calypso_preferences', $value ); |
| 421 | 253 | |
| 422 | - die(); | |
| 254 | + die( 0 ); | |
| 423 | 255 | } |
| 424 | 256 | |
| 425 | 257 | /** |
| 426 | 258 | * Handle ajax requests to dismiss a just-in-time-message |
| @@ -467,13 +299,8 @@ | ||
| 467 | 299 | |
| 468 | 300 | /* @see https://github.com/Automattic/wp-calypso/issues/49210 */ |
| 469 | 301 | remove_submenu_page( 'index.php', 'my-blogs' ); |
| 470 | 302 | $_registered_pages['admin_page_my-blogs'] = true; // phpcs:ignore |
| 471 | - | |
| 472 | - remove_submenu_page( 'paid-upgrades.php', 'premium-themes' ); | |
| 473 | - remove_submenu_page( 'paid-upgrades.php', 'domains' ); | |
| 474 | - remove_submenu_page( 'paid-upgrades.php', 'my-upgrades' ); | |
| 475 | - remove_submenu_page( 'paid-upgrades.php', 'billing-history' ); | |
| 476 | 303 | |
| 477 | 304 | remove_submenu_page( 'themes.php', 'customize.php?autofocus[panel]=amp_panel&return=' . rawurlencode( admin_url() ) ); |
| 478 | 305 | |
| 479 | 306 | remove_submenu_page( 'users.php', 'wpcom-invite-users' ); // Wpcom_Invite_Users::action_admin_menu. |