config = $config; self::$instance->setup_config(); self::$instance->setup_actions(); } } } /** * Setup theme information. */ public function setup_config() { $theme = wp_get_theme(); if ( is_child_theme() ) { if ( method_exists( $theme->parent(), 'get' ) ) { $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'] : ( apply_filters( 'tg_welcome_notice_filter', ( '

' . 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(); } /** * Hooks. */ public function setup_actions() { add_action( 'admin_menu', array( $this, 'register' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); } /** * Add about page in admin. */ public function register() { if ( ! empty( $this->menu_name ) && ! empty( $this->page_name ) ) { $title = $this->page_name; add_theme_page( $this->menu_name, $title, 'activate_plugins', $this->theme_slug . '-about', array( $this, 'about_page_render', ) ); } } /** * Enqueue scripts. */ public function enqueue() { $current_screen = get_current_screen(); wp_enqueue_script( 'zakra-plugin-install-helper', ZAKRA_PARENT_INC_URI . '/admin/js/plugin-handle.js', array( 'jquery' ), ZAKRA_THEME_VERSION, true ); wp_localize_script( 'zakra-plugin-install-helper', 'zakra_plugin_helper', array( 'activating' => esc_html__( 'Activating ', 'zakra' ), ) ); if ( ! isset( $current_screen->id ) || ( 'appearance_page_' . $this->theme_slug . '-about' !== $current_screen->id ) ) { return; } wp_enqueue_style( 'zakra-about-page-css', get_template_directory_uri() . '/inc/admin/css/about-page.css', array(), ZAKRA_THEME_VERSION ); wp_enqueue_script( 'zakra-about-page-js', get_template_directory_uri() . '/inc/admin/js/about-page.js', array( 'jquery', 'jquery-ui-tabs', ), ZAKRA_THEME_VERSION, true ); wp_enqueue_script( 'updates' ); wp_localize_script( 'zakra-about-page-js', 'zakraAboutPageObject', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'template_directory' => get_template_directory_uri(), 'activating_string' => esc_html__( 'Activating', 'zakra' ), ) ); } /** * Render HTML contents for about page. */ public function about_page_render() { $this->render_header(); $this->render_tabs(); } /** * Render header part. */ private function render_header() { if ( ! empty( $this->config['welcome_title'] ) ) { $title = $this->config['welcome_title']; } if ( ! empty( $this->config['welcome_content'] ) ) { $content = $this->config['welcome_content']; } if ( empty( $title ) && empty( $content ) ) { return; } echo '
'; echo '
'; echo '
'; if ( ! empty( $title ) ) { echo '

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

'; } if ( ! empty( $content ) ) { echo '
' . wp_kses_post( $content ) . '
'; } echo ''; echo '
'; } /** * Render tabs. */ private function render_tabs() { if ( empty( $this->tabs ) ) { return; } $count = 0; ?>
tabs as $tab_id => $tab_name ) { ?>
config['getting_started'] ) ) { $getting_started = $this->config['getting_started']; if ( ! empty( $getting_started ) ) { echo '
'; foreach ( $getting_started as $key => $getting_started_item ) { echo '
'; if ( ! empty( $getting_started_item['title'] ) ) { echo '

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

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

'; if ( isset( $getting_started_item['install_button'] ) && true === $getting_started_item['install_button'] ) { ?>

display_button( $getting_started_item ); } echo '

'; } echo '
'; } echo '
'; } } } /** * Render Recommended Plugins tab content. */ public function recommended_plugins_render() { $recommended_plugins = $this->config['recommended_plugins']; if ( empty( $recommended_plugins['content'] ) || ! is_array( $recommended_plugins['content'] ) ) { return; } echo ''; } /** * Render Support tab content. */ public function support_render() { if ( ! empty( $this->config['support'] ) ) { $support = $this->config['support']; if ( ! empty( $support ) ) { echo '
'; foreach ( $support as $support_item ) { echo '
'; if ( ! empty( $support_item['title'] ) ) { echo '

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

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

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

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

'; if ( isset( $support_item['install_button'] ) && true === $support_item['install_button'] ) { echo Zakra_Plugin_Install_Helper::instance()->get_button_html( $support_item['button_link'] ); // WPCS: XSS OK. } else { $this->display_button( $support_item ); } echo '

'; } echo '
'; } echo '
'; } } } /** * Render Site Library tab content. */ public function site_library_render() { if ( ! empty( $this->config['site_library'] ) ) { $site_library = $this->config['site_library']; if ( ! empty( $site_library ) ) { ?>

get_contents( $changelog_file ); $changelog_list = $this->parse_changelog( $changelog ); echo wp_kses_post( $changelog_list ); } ?>
'; foreach ( $changes as $index => $line ) { $changelog .= wp_kses_post( preg_replace( '~(=\s*Version\s*(\d+(?:\.\d+)+)\s*=|$)~Uis', '${1}', $line ) ); } $changelog .= ''; } return wp_kses_post( $changelog ); } /** * Get plugin's information. * * @param string $slug Plugin's slug. * * @return array|mixed|object|\WP_Error */ public function call_plugin_api( $slug ) { include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); $call_api = get_transient( 'zakra_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, 'banners' => true, ), ) ); set_transient( 'zakra_about_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS ); } return $call_api; } /** * Output button. * * @param array $data Button's information. */ public function display_button( $data ) { $button_new_tab = '_self'; $button_class = ''; if ( isset( $tab_data['is_new_tab'] ) ) { if ( $data['is_new_tab'] ) { $button_new_tab = '_blank'; } } if ( $data['is_button'] ) { $button_class = 'button button-primary'; } echo '' . esc_html( $data['button_label'] ) . ''; } /** * Check if plugin is active * * @param plugin-slug $slug the plugin slug. * * @return array */ public function check_if_plugin_active( $slug ) { $plugin_link_suffix = Zakra_Plugin_Install_Helper::get_plugin_path( $slug ); $path = WPMU_PLUGIN_DIR . '/' . $plugin_link_suffix; if ( ! file_exists( $path ) ) { $path = WP_PLUGIN_DIR . '/' . $plugin_link_suffix; if ( ! file_exists( $path ) ) { $path = false; } } if ( file_exists( $path ) ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $needs = is_plugin_active( $plugin_link_suffix ) ? 'deactivate' : 'activate'; return array( 'status' => is_plugin_active( $plugin_link_suffix ), 'needs' => $needs, ); } return array( 'status' => false, 'needs' => 'install', ); } }