can_be_displayed() ) { return; } add_action( 'admin_print_styles', array( $this, 'admin_banner_styles' ) ); add_action( 'admin_notices', array( $this, 'render_banner' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_banner_scripts' ) ); } /** * Can we display the banner? */ private function can_be_displayed() { if ( ! Jetpack_Wizard::can_be_displayed() ) { return false; } // Only the dashboard and plugins pages should see the banner. if ( ! in_array( get_current_screen()->id, array( 'dashboard', 'plugins' ), true ) ) { return false; } if ( ! current_user_can( 'jetpack_manage_modules' ) ) { return false; } // Kill if banner has been dismissed. if ( Jetpack_Options::get_option( 'dismissed_wizard_banner' ) ) { return false; } if ( ! in_array( Jetpack_Options::get_option( 'setup_wizard_status', 'not-started' ), array( 'not-started', 'intro-page' ), true ) ) { return false; } return true; } /** * Enqueue JavaScript files. */ public function enqueue_banner_scripts() { wp_enqueue_script( 'jetpack-wizard-banner-js', Assets::get_file_url_for_environment( '_inc/build/jetpack-wizard-banner.min.js', '_inc/jetpack-wizard-banner.js' ), array( 'jquery' ), JETPACK__VERSION, true ); wp_localize_script( 'jetpack-wizard-banner-js', 'jp_banner', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'wizardBannerNonce' => wp_create_nonce( 'jp-wizard-banner-nonce' ), ) ); } /** * Include the needed styles */ public function admin_banner_styles() { wp_enqueue_style( 'jetpack-wizard-banner', Assets::get_file_url_for_environment( 'css/jetpack-wizard-banner.min.css', 'css/jetpack-wizard-banner.css' ), array(), JETPACK__VERSION ); } /** * AJAX callback */ public static function ajax_callback() { check_ajax_referer( 'jp-wizard-banner-nonce', 'nonce' ); $tracking = new Tracking(); if ( isset( $_REQUEST['personal'] ) ) { $tracking->record_user_event( 'setup_wizard_banner_click', array( 'button' => 'personal' ) ); } if ( isset( $_REQUEST['business'] ) ) { $tracking->record_user_event( 'setup_wizard_banner_click', array( 'button' => 'business' ) ); } if ( isset( $_REQUEST['skip'] ) ) { $tracking->record_user_event( 'setup_wizard_banner_click', array( 'button' => 'skip' ) ); } if ( current_user_can( 'jetpack_manage_modules' ) && isset( $_REQUEST['dismissBanner'] ) ) { Jetpack_Options::update_option( 'dismissed_wizard_banner', 1 ); $tracking->record_user_event( 'setup_wizard_banner_dismiss' ); wp_send_json_success(); } wp_die(); } /** * Renders the Wizard Banner * * Since this HTML replicates the contents of _inc/client/setup-wizard/intro-page/index.jsx, * every time one is changed, the other should also be. */ public function render_banner() { $jetpack_logo = new Jetpack_Logo(); $powering_up_logo = plugins_url( 'images/jetpack-powering-up.svg', JETPACK__PLUGIN_FILE ); ?>