exists() ) { $this->product_name = $theme_object->get( 'Name' ); $this->product_version = $theme_object->get( 'Version' ); $this->product_slug = $theme_object->get_template(); } } elseif ( 'plugin' === $mode ) { $plugin_details = Helper::get_plugin_information( $slug ); if ( ! empty( $plugin_details ) ) { $this->product_name = $plugin_details['Name']; $this->product_version = $plugin_details['Version']; $this->product_slug = $slug; } } } /** * Run now. * * @since 1.0.0 */ public function run() { if ( empty( $this->page ) ) { return; } if ( empty( $this->product_slug ) ) { return; } if ( count( $this->tabs ) > 1 ) { $this->tab_status = true; } // Create admin page. add_action( 'admin_menu', array( $this, 'create_menu_page' ) ); if ( ! empty( $this->admin_notice ) ) { // Update notice dismiss status. add_action( 'admin_head', array( $this, 'update_notice_status' ) ); // Admin notice. add_action( 'admin_notices', array( $this, 'add_admin_notice' ) ); } // AJAX callbacks. add_action( 'wp_ajax_nopriv_wpw_plugin_installer', array( Ajax::class, 'install_plugin' ) ); add_action( 'wp_ajax_wpw_plugin_installer', array( Ajax::class, 'install_plugin' ) ); add_action( 'wp_ajax_nopriv_wpw_plugin_activation', array( Ajax::class, 'activate_plugin' ) ); add_action( 'wp_ajax_wpw_plugin_activation', array( Ajax::class, 'activate_plugin' ) ); } /** * Add admin notice. * * @since 1.0.0 */ public function add_admin_notice() { add_action( 'admin_notices', array( $this, 'display_admin_notice' ), 99 ); } /** * Update user notice dismiss status. * * @since 1.0.0 */ public function update_notice_status() { if ( isset( $_GET[ 'wpw-dismiss-' . $this->product_slug ] ) && check_admin_referer( 'wpw-dismiss-' . get_current_user_id() ) ) { update_user_meta( get_current_user_id(), "wpw_dismissed_{$this->product_slug}", 1 ); } } /** * Display admin notice. * * @since 1.0.0 */ public function display_admin_notice() { $screen_id = null; $current_screen = get_current_screen(); if ( $current_screen ) { $screen_id = $current_screen->id; } $dismiss_status = get_user_meta( get_current_user_id(), "wpw_dismissed_{$this->product_slug}", true ); if ( current_user_can( $this->page['capability'] ) && in_array( $screen_id, $this->admin_notice['screens'], true ) && 1 !== absint( $dismiss_status ) ) { echo '
' . wp_kses_post( $this->admin_notice['message'] ) . '
'; echo '' . esc_html( $this->admin_notice['button_text'] ) . ' ' . esc_html__( 'Dismiss this notice', 'wp-welcome' ) . '
'; } /** * Set page settings. * * @since 1.0.0 * * @param array $args Page arguments. */ public function set_page( $args = array() ) { $defaults = array( /* translators: 1: Name 2: Version */ 'page_title' => sprintf( esc_html__( 'Welcome to %1$s - %2$s', 'wp-welcome' ), esc_html( $this->product_name ), esc_html( $this->product_version ) ), /* translators: 1: Name */ 'page_subtitle' => sprintf( esc_html__( '%1$s is now installed and ready to use. Thank you for choosing %1$s, cheers!', 'wp-welcome' ), esc_html( $this->product_name ) ), 'menu_title' => esc_html__( 'Admin Dashboard', 'wp-welcome' ), 'capability' => 'edit_theme_options', 'menu_slug' => 'wp-welcome', 'menu_icon' => '', 'top_level_menu' => false, 'parent_page' => 'options-general.php', ); $this->page = wp_parse_args( $args, $defaults ); $this->top_level_menu = $this->page['top_level_menu']; $this->parent_page = $this->page['parent_page']; } /** * Set admin notice. * * @since 1.0.0 * * @param array $args Notice arguments. */ public function set_admin_notice( $args = array() ) { $defaults = array( 'type' => 'success', /* translators: 1: Name */ 'message' => sprintf( esc_html__( 'Welcome! %1$s is now installed and ready to use. Thank you for choosing %1$s.', 'wp-welcome' ), esc_html( $this->product_name ) ), /* translators: 1: Name */ 'button_text' => sprintf( esc_html__( 'Get started with %1$s', 'wp-welcome' ), $this->product_name ), 'screens' => array( 'dashboard' ), ); $this->admin_notice = wp_parse_args( $args, $defaults ); } /** * Set quick links. * * @since 1.0.0 * * @param array $links Quick links array. */ public function set_quick_links( $links ) { $output = array(); if ( empty( $links ) ) { return $output; } foreach ( $links as $link ) { $defaults = array( 'text' => esc_html__( 'Link', 'wp-welcome' ), 'url' => '#', 'type' => 'primary', ); $output[] = wp_parse_args( $link, $defaults ); } $this->quick_links = $output; } /** * Create menu page. * * @since 1.0.0 */ public function create_menu_page() { if ( true === $this->top_level_menu ) { add_menu_page( $this->page['page_title'], $this->page['menu_title'], $this->page['capability'], $this->page['menu_slug'], array( $this, 'render_page' ), $this->page['menu_icon'] ); } else { add_submenu_page( $this->parent_page, $this->page['page_title'], $this->page['menu_title'], $this->page['capability'], $this->page['menu_slug'], array( $this, 'render_page' ) ); } } /** * Render page. * * @since 1.0.0 */ public function render_page() { if ( ! current_user_can( $this->page['capability'] ) ) { return; } echo '