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 get started 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' ) );
add_action( 'wp_loaded', array( $this, 'hide_notice' ) );
/* activation notice */
add_action( 'admin_notices', array( $this, 'activation_admin_notice' ) );
/* enqueue script and style for about page */
add_action( 'admin_enqueue_scripts', array( $this, 'style_and_scripts' ) );
}
/**
* Register the menu page under Appearance menu.
*/
function register() {
if ( ! empty( $this->menu_name ) && ! empty( $this->page_name ) ) {
add_theme_page( $this->menu_name, $this->page_name, 'activate_plugins', 'blog-writer-welcome', array(
$this,
'page_render',
) );
}
}
/**
* Adds an admin notice upon successful activation.
*/
public function activation_admin_notice() {
global $pagenow;
add_action( 'admin_notices', array( $this, 'welcome_admin_notice' ), 99 );
}
/**
* Display an admin notice linking to the about page
*/
public function welcome_admin_notice() {
global $pagenow;
if ( ! empty( $this->notification ) ) {
// display notice if not previously dismissed
if ( current_user_can( 'edit_theme_options' ) && !get_option( 'blog_writer_notice_welcome' ) && 'themes.php' == $pagenow ) {
echo '';
}
}
}
/**
* Render the main content page.
*/
public function 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 ) . '
';
}
/* Add upgrade box*/
$upgrade = $this->config['upgrade'];
echo '';
/* Display tabs */
if ( ! empty( $this->tabs ) ) {
//$active_tab = isset( $_GET['tab'] ) ? wp_unslash( $_GET['tab'] ) : 'getting_started';
$active_tab = isset( $_GET['tab'] ) ? sanitize_title(wp_unslash( $_GET['tab'] )) : 'getting_started';
echo '
';
/* Display content for current tab */
if ( method_exists( $this, $active_tab ) ) {
$this->$active_tab();
}
}
echo '
';
}
}
/**
* Review tab
*/
public function theme_review() {
echo '';
if ( ! empty( $this->config['theme_review'] ) ) {
$support_steps = $this->config['theme_review'];
if ( ! empty( $support_steps ) ) {
foreach ( $support_steps as $support_step ) {
echo '
';
if ( ! empty( $support_step['title'] ) ) {
echo '
';
if ( ! empty( $support_step['icon'] ) ) {
echo '';
}
echo esc_html($support_step['title'] );
echo '
';
}
if ( ! empty( $support_step['text'] ) ) {
echo '
' . esc_html($support_step['text'] ) . '
';
}
if ( ! empty( $support_step['button_link'] ) && ! empty( $support_step['button_label'] ) ) {
echo '
';
$button_class = '';
if ( $support_step['is_button'] ) {
$button_class = 'button button-primary';
}
$button_new_tab = '_self';
if ( isset( $support_step['is_new_tab'] ) ) {
if ( $support_step['is_new_tab'] ) {
$button_new_tab = '_blank';
}
}
echo '' . esc_html($support_step['button_label'] ) . '';
echo '
';
}
echo '
';
}
}
}
echo '
';
}
/**
* Changelog tab
*/
public function changelog() {
$changelog = $this->parse_changelog();
if ( ! empty( $changelog ) ) {
echo '';
foreach ( $changelog as $release ) {
if ( ! empty($release['title'] ) ) {
echo '
' . esc_html( $release['title'] ) . '
';
}
if ( ! empty( $release['changes'] ) ) {
if ( is_array($release['changes'] ) ) {
$release['changes'] = implode( '
', $release['changes'] );
}
echo wp_kses_post( $release['changes'] );
}
}
echo '';
}
}
/**
* Return the releases changes array.
* @return array The releases array.
*/
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 ) === '###' ) {
if ( isset( $release ) ) {
$releases[] = $release;
}
$release = array(
'title' => substr( $changelog_line, 3 ),
'changes' => array(),
);
} else {
$release['changes'][] = $changelog_line;
}
}
return $releases;
}
/**
* 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 '
' . 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';
}
$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 '
';
}
echo '
';
}
}
}
/**
* Support tab
*/
public function support_content() {
echo '';
if ( ! empty( $this->config['support_content'] ) ) {
$support_steps = $this->config['support_content'];
if ( ! empty( $support_steps ) ) {
foreach ( $support_steps as $support_step ) {
echo '
';
if ( ! empty( $support_step['title'] ) ) {
echo '
';
if ( ! empty( $support_step['icon'] ) ) {
echo '';
}
echo esc_html( $support_step['title'] );
echo '
';
}
if ( ! empty( $support_step['text'] ) ) {
echo '
' . esc_html( $support_step['text'] ) . '
';
}
if ( ! empty( $support_step['button_link'] ) && ! empty( $support_step['button_label'] ) ) {
echo '
';
$button_class = '';
if ( $support_step['is_button'] ) {
$button_class = 'button button-primary';
}
$button_new_tab = '_self';
if ( isset( $support_step['is_new_tab'] ) ) {
if ( $support_step['is_new_tab'] ) {
$button_new_tab = '_blank';
}
}
echo '' . esc_html( $support_step['button_label'] ) . '';
echo '
';
}
echo '
';
}
}
}
echo '
';
}
/**
* Free vs PRO tab
*/
public function free_pro() {
$free_pro = isset( $this->config['free_pro'] ) ? $this->config['free_pro'] : array();
if ( ! empty( $free_pro ) ) {
if ( ! empty( $free_pro['free_theme_name'] ) && ! empty( $free_pro['pro_theme_name'] ) && ! empty( $free_pro['features'] ) && is_array( $free_pro['features'] ) ) {
echo '';
echo '
';
echo '
';
echo '';
echo '';
echo ' | ';
echo '' . esc_html( $free_pro['free_theme_name'] ) . ' | ';
echo '' . esc_html( $free_pro['pro_theme_name'] ) . ' | ';
echo '
';
echo '';
echo '';
foreach ( $free_pro['features'] as $feature ) {
/* Hide feature is needed */
if ( $feature['hidden'] == 'true' ) {
$feature['hidden'] = ' class="hidden"';
}
echo '';
if ( ! empty( $feature['title'] ) || ! empty( $feature['description'] ) ) {
echo '';
if ( ! empty( $feature['title'] ) ) {
echo '' . wp_kses_post( $feature['title'] ) . '';
}
if ( ! empty( $feature['description'] ) ) {
echo '' . wp_kses_post( $feature['description'] ) . ' ';
}
echo ' | ';
}
/* Add in for lite version */
if ( ! empty( $feature['is_in_lite'] ) && ( $feature['is_in_lite'] == 'true' ) && empty( $feature['is_in_lite_text'] ) ) {
echo ' | ';
} else if ( ! empty( $feature['is_in_lite_text'] ) ) {
echo '' . esc_html($feature['is_in_lite_text'] ) . ' | ';
} else {
echo ' | ';
}
/* Add in for pro version */
if ( ! empty( $feature['is_in_pro'] ) && ( $feature['is_in_pro'] == 'true' ) && empty( $feature['is_in_pro_text'] ) ) {
echo ' | ';
} else if ( ! empty( $feature['is_in_pro_text'] ) ) {
echo '' . esc_html($feature['is_in_pro_text'] ) . ' | ';
} else {
echo ' | ';
}
echo '
';
}
if ( ! empty( $free_pro['pro_theme_link'] ) && ! empty( $free_pro['get_pro_theme_label'] ) ) {
echo '';
echo ' | ';
echo '' . wp_kses_post( $free_pro['get_pro_theme_label'] ) . ' | ';
echo '
';
}
echo '';
echo '
';
echo '
';
echo '
';
}
}
}
/**
* Load css and scripts for the about page
*/
public function style_and_scripts( $hook_suffix ) {
global $pagenow;
// enqueue css files
if ( 'themes.php' === $pagenow || 'appearance_page_blog-writer-welcome' == $hook_suffix ) {
wp_enqueue_style( 'blog-writer-about-page-css', get_template_directory_uri() . '/inc/theme-info/css/blog-writer-info-backend.css' );
}
// enqueue js files
if ( 'appearance_page_blog-writer-welcome' == $hook_suffix ) {
wp_enqueue_script( 'blog-writer-about-page-js', ( get_template_directory_uri() . '/inc/theme-info/js/blog-writer-info-backend.js' ), array( 'jquery' ), '', 'true' );
}
}
/**
* Hide welcome notice when dismissed.
*/
public function hide_notice() {
if (isset($_GET['blog-writer-hide-notice']) && isset($_GET['_blog_writer_notice_nonce'])) {
if (!wp_verify_nonce($_GET['_blog_writer_notice_nonce'], 'blog_writer_hide_notices_nonce')) {
wp_die(esc_html__('Action failed. Please refresh the page and retry.', 'blog-writer'));
}
if (!current_user_can('edit_theme_options')) {
wp_die(esc_html__('You do not have the necessary permission to perform this action.', 'blog-writer'));
}
$hide_notice = sanitize_text_field( wp_unslash($_GET['blog-writer-hide-notice']));
update_option('blog_writer_notice_' . $hide_notice, 1);
}
}
}
}