theme = $theme_args; $this->tabs = $data; $this->about_page = $about_page; if ( isset( $this->tabs['custom_tabs'] ) ) { $this->custom_tabs = $data['custom_tabs']; unset( $this->tabs['custom_tabs'] ); } $this->render(); } /** * The main render function */ private function render() { if ( empty( $this->tabs ) ) { return; } echo '
'; $this->render_header(); echo '
'; $this->render_tabs_list(); $this->render_tabs_content(); echo '
'; $this->render_footer(); echo '
'; } /** * Render the header */ private function render_header() { ?>

Welcome to theme['name'] ); ?>! - Version theme['version'] ); ?>

'; foreach ( $this->tabs as $slug => $tab_data ) { if( ! array_key_exists( 'type', $tab_data ) ){ continue; } if ( $tab_data['type'] === 'recommended_actions' && $this->about_page->get_recommended_actions_left() === 0 ) { continue; } if ( $slug === 'welcome_notice' || $slug === 'footer_messages' ) { continue; } echo '
  • '; echo '' . esc_html( $tab_data['title'] ) . ''; echo '
  • '; } foreach ( $this->custom_tabs as $slug => $tab_data ) { echo '
  • '; echo '' . esc_html( $tab_data['title'] ) . ''; echo '
  • '; } echo ''; } /** * Render tab content */ private function render_tabs_content() { foreach ( $this->tabs as $slug => $tab_data ) { if( ! array_key_exists( 'type', $tab_data ) ){ continue; } if ( $slug === 'recommended_actions' && $this->about_page->get_recommended_actions_left() === 0 ) { continue; } if ( $slug === 'welcome_notice' || $slug === 'footer_messages' ) { continue; } echo '
    '; switch ( $tab_data['type'] ) { case 'recommended_actions': $this->render_recommended_actions( $tab_data['plugins'] ); break; case 'plugins': $this->render_plugins_tab( $tab_data['plugins'] ); break; case 'changelog': $this->render_changelog(); break; default: $this->render_default_tab( $tab_data['content'] ); break; } echo '
    '; } foreach ( $this->custom_tabs as $slug => $tab_data ) { echo '
    '; call_user_func( $tab_data['render_callback'] ); echo '
    '; } } /** * Render recommended actions * * @param array $plugins_list - recommended plugins. */ private function render_recommended_actions( $plugins_list ) { if ( empty( $plugins_list ) || $this->about_page->get_recommended_actions_left() === 0 ) { return; } $recommended_plugins_visbility = get_option( 'ti_about_recommended_plugins' ); foreach ( $plugins_list as $slug => $plugin ) { if ( $recommended_plugins_visbility[ $slug ] === 'hidden' || Ti_About_Plugin_Helper::instance()->check_plugin_state( $slug ) === 'deactivate' ) { continue; } echo '
    '; echo ''; echo '

    ' . $plugin['name'] . '

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

    ' . $plugin['description'] . '

    '; } else { $plugin_description = $this->call_plugin_api( $slug ); echo '

    ' . $plugin_description->short_description . '

    '; } echo Ti_About_Plugin_Helper::instance()->get_button_html( $slug, array( 'redirect' => add_query_arg( 'page', $this->theme['slug'] . '-welcome', admin_url( 'themes.php#recommended_actions' ) ) ) ); echo '
    '; } } /** * Call plugin api * * @param string $slug plugin slug. * * @return array|mixed|object */ private function call_plugin_api( $slug ) { include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); $call_api = get_transient( 'ti_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( 'ti_about_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS ); } return $call_api; } /** * Render plugins tab content. * * @param array $plugins_list - list of useful plugins */ private function render_plugins_tab( $plugins_list ) { if ( empty( $plugins_list ) ) { return; } echo ''; } /** * Render changelog */ private function render_changelog() { $changelog = $this->parse_changelog(); if ( ! empty( $changelog ) ) { echo ''; } } /** * Return the releases changes array. * * @return array $releases - changelog. */ private function parse_changelog() { WP_Filesystem(); global $wp_filesystem; $changelog = $wp_filesystem->get_contents( get_template_directory() . '/CHANGELOG.md' ); if ( is_wp_error( $changelog ) ) { $changelog = ''; } $changelog = explode( PHP_EOL, $changelog ); $releases = array(); foreach ( $changelog as $changelog_line ) { if ( strpos( $changelog_line, '**Changes:**' ) !== false || empty( $changelog_line ) ) { continue; } if ( substr( $changelog_line, 0, 3 ) === '###' || substr( $changelog_line, 1, 3 ) === '###' ) { if ( isset( $release ) ) { $releases[] = $release; } $release = array( 'title' => substr( $changelog_line, 3 ), 'changes' => array(), ); } else { $release['changes'][] = $changelog_line; } } return $releases; } /** * Render default tab content. * * @param array $tab_content - tab content, title, text, button. */ private function render_default_tab( $tab_content ) { foreach ( $tab_content as $content ) { echo '
    '; echo '

    '; if ( ! empty( $content['icon'] ) ) { echo ''; } echo esc_html( $content['title'] ) . '

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

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

    '; } if ( ! empty( $content['html_content'] ) ) { echo $content['html_content']; } if ( ! empty( $content['button'] ) ) { $this->render_button( $content['button'] ); } echo '
    '; } } /** * Render button. * * @param array $button - args: label, link, new tab. */ private function render_button( $button ) { if ( empty( $button ) ) { return; } if ( $button['link'] === '#recommended_actions' && $this->about_page->get_recommended_actions_left() === 0 ) { echo '' . esc_html__( 'Recommended actions', 'neve' ) . ''; return; } echo ''; echo $button['label']; echo ''; } /** * Render footer messages. */ private function render_footer() { if ( ! array_key_exists( 'footer_messages', $this->tabs ) ) { return; } $footer_data = $this->tabs['footer_messages']['messages']; echo ''; } }