diff options
Diffstat (limited to 'plugins/jetpack/modules/masterbar/admin-menu/class-admin-menu.php')
-rw-r--r-- | plugins/jetpack/modules/masterbar/admin-menu/class-admin-menu.php | 133 |
1 files changed, 48 insertions, 85 deletions
diff --git a/plugins/jetpack/modules/masterbar/admin-menu/class-admin-menu.php b/plugins/jetpack/modules/masterbar/admin-menu/class-admin-menu.php index 46b7f8bf..f49a6a5b 100644 --- a/plugins/jetpack/modules/masterbar/admin-menu/class-admin-menu.php +++ b/plugins/jetpack/modules/masterbar/admin-menu/class-admin-menu.php @@ -108,68 +108,6 @@ class Admin_Menu extends Base_Admin_Menu { } /** - * Adds upsell nudge as a menu. - * - * @param object $nudge The $nudge object containing the content, CTA, link and tracks. - */ - public function add_upsell_nudge( $nudge ) { - $dismiss_button = ''; - if ( $nudge['dismissible'] ) { - $dismiss_button = '<svg xmlns="http://www.w3.org/2000/svg" data-feature_class="%1$s" data-feature_id="%2$s" viewBox="0 0 24 24" class="gridicon gridicons-cross dismissible-card__close-icon" height="24" width="24"><g><path d="M18.36 19.78L12 13.41l-6.36 6.37-1.42-1.42L10.59 12 4.22 5.64l1.42-1.42L12 10.59l6.36-6.36 1.41 1.41L13.41 12l6.36 6.36z"></path></g></svg>'; - $dismiss_button = sprintf( $dismiss_button, esc_attr( $nudge['feature_class'] ), esc_attr( $nudge['id'] ) ); - } - - $message = ' -<div class="upsell_banner"> - <div class="banner__info"> - <div class="banner__title">%1$s</div> - </div> - <div class="banner__action"> - <button type="button" class="button">%2$s</button> - </div>%3$s -</div>'; - - $message = sprintf( - $message, - wp_kses( $nudge['content'], array() ), - wp_kses( $nudge['cta'], array() ), - $dismiss_button - ); - - $menu_slug = $nudge['link']; - if ( wp_startswith( $menu_slug, '/' ) ) { - $menu_slug = 'https://wordpress.com' . $menu_slug; - } - - add_menu_page( 'site-notices', $message, 'read', $menu_slug, null, null, 1 ); - add_filter( 'add_menu_classes', array( $this, 'set_site_notices_menu_class' ) ); - } - - /** - * Adds a custom element class and id for Site Notices's menu item. - * - * @param array $menu Associative array of administration menu items. - * @return array - */ - public function set_site_notices_menu_class( array $menu ) { - foreach ( $menu as $key => $menu_item ) { - if ( 'site-notices' !== $menu_item[3] ) { - continue; - } - - $classes = ' toplevel_page_site-notices'; - - if ( isset( $menu_item[4] ) ) { - $menu[ $key ][4] = $menu_item[4] . $classes; - $menu[ $key ][5] = 'toplevel_page_site-notices'; - break; - } - } - - return $menu; - } - - /** * Adds Inbox menu. */ public function add_inbox_menu() { @@ -510,33 +448,58 @@ class Admin_Menu extends Base_Admin_Menu { } /** - * Prepend a dashboard swithcer to the "Screen Options" box of the current page. - * Callback for the 'screen_settings' filter (available in WP 3.0 and up). - * - * @param string $current The currently added panels in screen options. - * - * @return string The HTML code to append to "Screen Options" + * AJAX handler for retrieving the upsell nudge. */ - public function register_dashboard_switcher( $current ) { - $menu_mappings = require __DIR__ . '/menu-mappings.php'; - $screen = $this->get_current_screen(); + public function wp_ajax_upsell_nudge_jitm() { + check_ajax_referer( 'upsell_nudge_jitm' ); - // Let's show the switcher only in screens that we have a Calypso mapping to switch to. - if ( ! isset( $menu_mappings[ $screen ] ) ) { - return; + $nudge = $this->get_upsell_nudge(); + if ( ! $nudge ) { + wp_die(); } - $contents = sprintf( - '<div id="dashboard-switcher"><h5>%s</h5><p class="dashboard-switcher-text">%s</p><a class="button button-primary dashboard-switcher-button" href="%s">%s</a></div>', - __( 'Screen features', 'jetpack' ), - __( 'Currently you are seeing the classic WP-Admin view of this page. Would you like to see the default WordPress.com view?', 'jetpack' ), - add_query_arg( 'preferred-view', 'default' ), - __( 'Use WordPress.com view', 'jetpack' ) - ); - - // Prepend the Dashboard swither to the other custom panels. - $current = $contents . $current; + $link = $nudge['link']; + if ( substr( $link, 0, 1 ) === '/' ) { + $link = 'https://wordpress.com' . $link; + } + ?> + <li class="wp-not-current-submenu menu-top menu-icon-generic toplevel_page_site-notices" id="toplevel_page_site-notices"> + <a href="<?php echo esc_url( $link ); ?>" class="wp-not-current-submenu menu-top menu-icon-generic toplevel_page_site-notices"> + <div class="wp-menu-arrow"> + <div></div> + </div> + <div class="wp-menu-image dashicons-before dashicons-admin-generic" aria-hidden="true"><br></div> + <div class="wp-menu-name"> + <div class="upsell_banner"> + <div class="banner__info"> + <div class="banner__title"> + <?php echo wp_kses( $nudge['content'], array() ); ?> + </div> + </div> + <div class="banner__action"> + <button type="button" class="button"> + <?php echo wp_kses( $nudge['cta'], array() ); ?> + </button> + </div> + <?php if ( $nudge['dismissible'] ) : ?> + <svg xmlns="http://www.w3.org/2000/svg" data-feature_class="<?php echo esc_attr( $nudge['feature_class'] ); ?>" data-feature_id="<?php echo esc_attr( $nudge['id'] ); ?>" viewBox="0 0 24 24" class="gridicon gridicons-cross dismissible-card__close-icon" height="24" width="24"><g><path d="M18.36 19.78L12 13.41l-6.36 6.37-1.42-1.42L10.59 12 4.22 5.64l1.42-1.42L12 10.59l6.36-6.36 1.41 1.41L13.41 12l6.36 6.36z"></path></g></svg> + <?php endif; ?> + </div> + </div> + </a> + </li> + <?php + wp_die(); + } - return $current; + /** + * Returns the first available upsell nudge. + * Needs to be implemented separately for each child menu class. + * Empty by default. + * + * @return array + */ + public function get_upsell_nudge() { + return array(); } } |