config = $importconfig; self::$instance->setup_config(); self::$instance->setup_actions(); } } } /** * Setup the class props based on the config array. * * @since 1.0.0 */ public function setup_config() { $theme = wp_get_theme(); if ( is_child_theme() ) { $this->theme_name = $theme->parent()->get( 'Name' ); $this->theme = $theme->parent(); } else { $this->theme_name = $theme->get( 'Name' ); $this->theme = $theme->parent(); } $this->theme_version = $theme->get( 'Version' ); $this->theme_slug = $theme->get_template(); $this->page_slug = $this->theme_slug . '-about'; $this->action_key = $this->theme_slug . '-recommended_actions'; $this->menu_name = isset( $this->config['menu_name'] ) ? $this->config['menu_name'] : $this->theme_name; $this->page_name = isset( $this->config['page_name'] ) ? $this->config['page_name'] : $this->theme_name; $this->logo_url = isset( $this->config['logo_url'] ) ? $this->config['logo_url'] : get_template_directory_uri() . '/inc/mytheme/images/logopostmag.png'; $this->logo_link = isset( $this->config['logo_link'] ) ? $this->config['logo_link'] : 'https://www.postmagthemes.com/'; $this->tabs = isset( $this->config['tabs'] ) ? $this->config['tabs'] : array(); /* translators: %1$s is replaced with "string" */ /* translators: %2$s is replaced with "string" */ /* translators: %3$s is replaced with "string" */ /* translators: %s is replaced with "string" */ /* translators: %s: get started */ $this->notification = isset( $this->config['notification'] ) ? $this->config['notification'] : ( '

' . sprintf( esc_html__( 'Welcome! Thank you for choosing %1$s! To fully take advantage of the best our theme can offer please make sure you visit our %2$swelcome page%3$s.', 'postmag' ), $this->theme_name, '', '' ) . '

' . sprintf( esc_html__( 'Get started with %s', 'postmag' ), $this->theme_name ) . '

' ); } /** * Setup actions. * * @since 1.0.0 */ public function setup_actions() { add_action( 'admin_menu', array( $this, 'register' ) ); add_action( 'load-themes.php', array( $this, 'activation_admin_notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'load_assets' ) ); add_action( 'wp_ajax_pt_about_action_dismiss_recommended_action', array( $this, 'dismiss_recommended_action_callback' ) ); add_action( 'wp_ajax_nopriv_pt_about_action_dismiss_recommended_action', array( $this, 'dismiss_recommended_action_callback' ) ); } /** * Register the page under Appearance. * * @since 1.0.0 */ public function register() { if ( ! empty( $this->menu_name ) && ! empty( $this->page_name ) ) { $count = $this->get_total_recommended_actions(); $title = $this->page_name; if ( $count > 0 ) { $title .= '' . esc_html( $count ) . ''; } add_theme_page( $this->menu_name, $title, 'edit_theme_options', $this->page_slug, array( $this, 'render_about_page' ) ); } } /** * Get total recommended actions count. * * @since 1.0.0 * * @return int Total count. */ private function get_total_recommended_actions() { $actions = $this->get_recommended_actions(); return count( $actions ); } /** * Return valid array of recommended actions. * * @return array Valid array of recommended actions. */ private function get_recommended_actions() { $saved_actions = get_option( $this->action_key ); if ( ! is_array( $saved_actions ) ) { $saved_actions = array(); } $valid = array(); $action_config = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array(); if ( ! empty( $action_config['content'] ) ) { foreach ( $action_config['content'] as $item ) { if ( isset( $item['check'] ) && true === $item['check'] ) { continue; } if ( isset( $saved_actions[ $item['id'] ] ) && false === $saved_actions[ $item['id'] ] ) { continue; } $valid[] = $item; } } return $valid; } /** * Render quick links. * * @since 1.0.0 */ public function render_quick_links() { $quick_links = ( isset( $this->config['quick_links'] ) ) ? $this->config['quick_links'] : array(); if ( empty( $quick_links ) ) { return; } echo '

'; foreach ( $quick_links as $link ) { $link_class = 'button'; if ( isset( $link['button'] ) ) { $link_class .= ' button-' . esc_attr( $link['button'] ); } echo '' . esc_html( $link['text'] ) . '  '; } echo '

'; } /** * Render main page. * * @since 1.0.0 */ public function render_about_page() { if ( ! empty( $this->config['welcome_title'] ) ) { $welcome_title = $this->config['welcome_title']; } if ( ! empty( $this->config['welcome_content'] ) ) { $welcome_content = $this->config['welcome_content']; } if ( ! empty( $welcome_title ) || ! empty( $welcome_content ) || ! empty( $this->tabs ) ) { echo '
'; if ( ! empty( $welcome_title ) ) { echo '

'; echo esc_html( $welcome_title ); if ( ! empty( $this->theme_version ) ) { echo esc_html( $this->theme_version ); } echo '

'; } if ( $this->logo_url && $this->logo_link ) { echo ''; } $this->render_quick_links(); // Display tabs. if ( ! empty( $this->tabs ) ) { $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] )) : 'recommended_actions'; echo ''; // Display content for current tab. if ( method_exists( $this, $active_tab ) ) { $this->$active_tab(); } } // End if(). echo '
'; } // End if(). } /** * Adds an admin notice upon successful activation. * * @since 1.0.0 */ public function activation_admin_notice() { global $pagenow; if ( is_admin() && ( 'themes.php' === $pagenow ) && isset( $_GET['activated'] ) ) { add_action( 'admin_notices', array( $this, 'welcome_admin_notice' ), 99 ); } } /** * Display an admin notice linking to the about page. * * @since 1.0.0 */ public function welcome_admin_notice() { if ( ! empty( $this->notification ) ) { echo '
'; echo wp_kses_post( $this->notification ); echo '
'; } } /** * Load assets. * * @since 1.0.0 * * @param string $hook Hook name. */ public function load_assets( $hook ) { $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; $custom_css = '.badge-action-count { padding: 0 6px; display: inline-block; background-color: #d54e21; color: #fff; font-size: 9px; line-height: 17px; font-weight: 600; margin: 1px 0 0 2px; vertical-align: top; border-radius: 10px; z-index: 26; margin-top: 5px; margin-left: 5px; } .wp-submenu .badge-action-count { margin-top: 0; }'; wp_add_inline_style( 'admin-menu', $custom_css ); if ( 'appearance_page_' . $this->page_slug === $hook ) { wp_enqueue_style( 'plugin-install' ); wp_enqueue_script( 'plugin-install' ); wp_enqueue_script( 'updates' ); wp_enqueue_style( 'Postmag-about', get_template_directory_uri() . '/inc/theme-info/css/about.css', array(), '1.0.0' ); } } /** * Render recommended actions tab. * * @since 1.0.0 */ public function recommended_actions() { $recommended_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array(); if ( ! empty( $recommended_actions ) ) { echo '