config = $config; self::$instance->setup_config(); self::$instance->setup_actions(); } } } /** * Setup the class props based on the config array. */ 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->menu_name = isset( $this->config['menu_name'] ) ? $this->config['menu_name'] : 'About ' . $this->theme_name; $this->page_name = isset( $this->config['page_name'] ) ? $this->config['page_name'] : 'About ' . $this->theme_name; $this->notification = isset( $this->config['notification'] ) ? $this->config['notification'] : ( '

' . sprintf( '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.', $this->theme_name, '', '' ) . '

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

' ); $this->tabs = isset( $this->config['tabs'] ) ? $this->config['tabs'] : array(); } /** * Setup the actions used for this page. */ public function setup_actions() { add_action( 'admin_menu', array( $this, 'register' ) ); /* activation notice */ add_action( 'load-themes.php', array( $this, 'activation_admin_notice' ) ); /* enqueue script and style for about page */ add_action( 'admin_enqueue_scripts', array( $this, 'style_and_scripts' ) ); /* ajax callback for dismissable required actions */ add_action( 'wp_ajax_ct_about_page_dismiss_required_action', array( $this, 'dismiss_required_action_callback' ) ); add_action( 'wp_ajax_nopriv_ct_about_page_dismiss_required_action', array( $this, 'dismiss_required_action_callback' ) ); } /** * Hide required tab if no actions present. * * @return bool Either hide the tab or not. */ public function hide_required( $value, $tab ) { if ( $tab != 'recommended_actions' ) { return $value; } $required = $this->get_required_actions(); if ( count( $required ) == 0 ) { return false; } else { return true; } } /** * Register the menu page under Appearance menu. */ function register() { if ( ! empty( $this->menu_name ) && ! empty( $this->page_name ) ) { $count = 0; $actions_count = $this->get_required_actions(); if ( ! empty( $actions_count ) ) { $count = count( $actions_count ); } $title = $count > 0 ? $this->page_name . '' . esc_html( $count ) . '' : $this->page_name; add_theme_page( $this->menu_name, $title, 'activate_plugins', $this->theme_slug . '-welcome', array( $this, 'Coothemes_about_page_render', ) ); } } /** * Adds an admin notice upon successful activation. */ public function activation_admin_notice() { global $pagenow; if ( is_admin() && ( 'themes.php' == $pagenow ) && isset( $_GET['activated'] ) ) { add_action( 'admin_notices', array( $this, 'Coothemes_about_page_welcome_admin_notice' ), 99 ); } } /** * Display an admin notice linking to the about page */ public function Coothemes_about_page_welcome_admin_notice() { if ( ! empty( $this->notification ) ) { echo '
'; echo wp_kses_post( $this->notification ); echo '
'; } } /** * Render the main content page. */ public function Coothemes_about_page_render() { 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 ) . '
'; } echo ''; /* 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(). } /** * Call plugin api */ public function call_plugin_api( $slug ) { include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); $call_api = get_transient( 'ct_about_plugin_info_' . $slug ); if ( false === $call_api ) { $call_api = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'downloaded' => false, 'rating' => false, 'description' => false, 'short_description' => true, 'donate_link' => false, 'tags' => false, 'sections' => true, 'homepage' => true, 'added' => false, 'last_updated' => false, 'compatibility' => false, 'tested' => false, 'requires' => false, 'downloadlink' => false, 'icons' => true, ), ) ); set_transient( 'ct_about_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS ); } return $call_api; } /** * Check if plugin is active * * @param plugin-slug $slug the plugin slug. * @return array */ public function check_if_plugin_active( $slug ) { if ( ( $slug == 'intergeo-maps' ) || ( $slug == 'visualizer' ) ) { $plugin_root_file = 'index'; } elseif ( $slug == 'adblock-notify-by-bweb' ) { $plugin_root_file = 'adblock-notify'; } else { $plugin_root_file = $slug; } $path = WPMU_PLUGIN_DIR . '/' . $slug . '/' . $plugin_root_file . '.php'; if ( ! file_exists( $path ) ) { $path = WP_PLUGIN_DIR . '/' . $slug . '/' . $plugin_root_file . '.php'; if ( ! file_exists( $path ) ) { $path = false; } } if ( file_exists( $path ) ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $needs = is_plugin_active( $slug . '/' . $plugin_root_file . '.php' ) ? 'deactivate' : 'activate'; return array( 'status' => is_plugin_active( $slug . '/' . $plugin_root_file . '.php' ), 'needs' => $needs, ); } return array( 'status' => false, 'needs' => 'install', ); } /** * Get icon of wordpress.org plugin * * @param array $arr array of image formats. * * @return mixed */ public function get_plugin_icon( $arr ) { if ( ! empty( $arr['svg'] ) ) { $plugin_icon_url = $arr['svg']; } elseif ( ! empty( $arr['2x'] ) ) { $plugin_icon_url = $arr['2x']; } elseif ( ! empty( $arr['1x'] ) ) { $plugin_icon_url = $arr['1x']; } else { $plugin_icon_url = get_template_directory_uri() . '/ct-about-page/images/placeholder_plugin.png'; } return $plugin_icon_url; } /** * Function that crates the action link for install/activate/deactivate. * * @param Plugin-state $state the plugin state (uninstalled/active/inactive). * @param Plugin-slug $slug the plugin slug. * * @return string */ public function create_action_link( $state, $slug ) { if ( ( $slug == 'intergeo-maps' ) || ( $slug == 'visualizer' ) ) { $plugin_root_file = 'index'; } elseif ( $slug == 'adblock-notify-by-bweb' ) { $plugin_root_file = 'adblock-notify'; } else { $plugin_root_file = $slug; } switch ( $state ) { case 'install': return wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $slug, ), network_admin_url( 'update.php' ) ), 'install-plugin_' . $slug ); break; case 'deactivate': return add_query_arg( array( 'action' => 'deactivate', 'plugin' => rawurlencode( $slug . '/' . $plugin_root_file . '.php' ), 'plugin_status' => 'all', 'paged' => '1', '_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $slug . '/' . $plugin_root_file . '.php' ), ), network_admin_url( 'plugins.php' ) ); break; case 'activate': return add_query_arg( array( 'action' => 'activate', 'plugin' => rawurlencode( $slug . '/' . $plugin_root_file . '.php' ), 'plugin_status' => 'all', 'paged' => '1', '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $slug . '/' . $plugin_root_file . '.php' ), ), network_admin_url( 'plugins.php' ) ); break; }// End switch(). } /** * Getting started tab */ 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 '

' . $getting_started_item['title'] . '

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

' . $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 = 0; $actions_count = $this->get_required_actions(); if ( ! empty( $actions_count ) ) { $count = count( $actions_count ); } if ( $getting_started_item['recommended_actions'] && isset( $count ) ) { if ( $count == 0 ) { 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 '' . $getting_started_item['button_label'] . ''; echo '

'; } echo '
'; }// End foreach(). echo '
'; }// End if(). }// End if(). } /** * Recommended Actions tab */ public function recommended_actions() { $recommended_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array(); if ( ! empty( $recommended_actions ) ) { echo '
'; $actions = array(); $req_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array(); foreach ( $req_actions['content'] as $req_action ) { $actions[] = $req_action; } if ( ! empty( $actions ) && is_array( $actions ) ) { $ct_about_page_show_required_actions = get_option( $this->theme_slug . '_required_actions' ); $hooray = true; foreach ( $actions as $action_key => $action_value ) { $hidden = false; if ( $ct_about_page_show_required_actions[ $action_value['id'] ] === false ) { $hidden = true; } if ( $action_value['check'] ) { continue; } echo '
'; if ( ! $hidden ) { echo ''; } else { echo ''; } if ( ! empty( $action_value['title'] ) ) { echo '

' . wp_kses_post( $action_value['title'] ) . '

'; } if ( ! empty( $action_value['description'] ) ) { echo '

' . wp_kses_post( $action_value['description'] ) . '

'; } if ( ! empty( $action_value['plugin_slug'] ) ) { $active = $this->check_if_plugin_active( $action_value['plugin_slug'] ); $url = $this->create_action_link( $active['needs'], $action_value['plugin_slug'] ); $label = ''; switch ( $active['needs'] ) { case 'install': $class = 'install-now button'; if ( ! empty( $this->config['recommended_actions']['install_label'] ) ) { $label = $this->config['recommended_actions']['install_label']; } break; case 'activate': $class = 'activate-now button button-primary'; if ( ! empty( $this->config['recommended_actions']['activate_label'] ) ) { $label = $this->config['recommended_actions']['activate_label']; } break; case 'deactivate': $class = 'deactivate-now button'; if ( ! empty( $this->config['recommended_actions']['deactivate_label'] ) ) { $label = $this->config['recommended_actions']['deactivate_label']; } break; } ?>

'; }// End foreach(). }// End if(). echo '
'; }// End if(). } /** * Recommended plugins tab */ public function recommended_plugins() { $recommended_plugins = $this->config['recommended_plugins']; if ( ! empty( $recommended_plugins ) ) { if ( ! empty( $recommended_plugins['content'] ) && is_array( $recommended_plugins['content'] ) ) { echo '