config = $config; 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/theme-info/images/pt-logo.png'; $this->logo_link = isset( $this->config['logo_link'] ) ? $this->config['logo_link'] : 'https://cyclonethemes.com/'; $this->tabs = isset( $this->config['tabs'] ) ? $this->config['tabs'] : array(); $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.', 'fire-blog' ), $this->theme_name, '', '' ) . '

' . sprintf( esc_html__( 'Get started with %s', 'fire-blog' ), $this->theme_name ) . '' . esc_html__( 'Hide this notice', 'fire-blog' ) . '

' ); } /** * 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 ( ! empty( $welcome_content ) ) { echo '
' . wp_kses_post( $welcome_content ) . '
'; } if ( $this->logo_url && $this->logo_link ) { echo ''; } $this->render_quick_links(); // Display tabs. if ( ! empty( $this->tabs ) ) { $active_tab = isset( $_GET['tab'] ) ? wp_unslash( $_GET['tab'] ) : 'getting_started'; 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 ) ) { 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 theme is activated then show the admin message if( !empty( $_GET['fire-blog-theme_show_optin'] ) ){ update_option( 'fire_blog_hide_msg', false ); } // Hide fire blog admin message if( !empty( $_GET['status'] ) && $_GET['status'] == 'fire_blog_hide_msg' ){ update_option( 'fire_blog_hide_msg', true ); } if ( !empty( $this->notification ) && get_option( 'fire_blog_hide_msg' ) != true ) { 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( 'blog-way-about', get_template_directory_uri() . '/inc/theme-info/css/about.css', array(), '1.0.0' ); wp_enqueue_script( 'blog-way-about', get_template_directory_uri() . '/inc/theme-info/js/about.js', array( 'jquery' ), '1.0.0' ); $js_vars = array( 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), ); wp_localize_script( 'blog-way-about', 'BlogWayAboutObject', $js_vars ); } } /** * Render getting started tab. * * @since 1.0.0 */ public function getting_started() { if ( ! empty( $this->config['getting_started'] ) ) { $getting_started = $this->config['getting_started']; if ( ! empty( $getting_started ) ) { echo '
'; foreach ( $getting_started as $getting_started_item ) { echo '
'; if ( ! empty( $getting_started_item['title'] ) ) { echo '

' . esc_html( $getting_started_item['title'] ) . '

'; } if ( ! empty( $getting_started_item['text'] ) ) { echo '

' . esc_html( $getting_started_item['text'] ) . '

'; } if ( ! empty( $getting_started_item['button_link'] ) && ! empty( $getting_started_item['button_label'] ) ) { echo '

'; $button_class = ''; if ( $getting_started_item['is_button'] ) { $button_class = 'button button-primary'; } $count = $this->get_total_recommended_actions(); if ( $getting_started_item['recommended_actions'] && isset( $count ) ) { if ( 0 === $count ) { echo ''; } else { echo ''; } } $button_new_tab = '_self'; if ( isset( $getting_started_item['is_new_tab'] ) ) { if ( $getting_started_item['is_new_tab'] ) { $button_new_tab = '_blank'; } } echo '' . esc_html( $getting_started_item['button_label'] ) . ''; echo '

'; } echo '
'; } // End foreach(). echo '
'; } // End if(). } // End if(). } /** * 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 '