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, '', '' ) . '
';
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( sanitize_text_field( $_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 '';
$actions = array();
foreach ( $recommended_actions['content'] as $action ) {
$actions[] = $action;
}
if ( ! empty( $actions ) && is_array( $actions ) ) {
$about_recommended_actions = get_option( $this->action_key );
foreach ( $actions as $action_key => $action_value ) {
$hidden = false;
if ( isset( $action_value['id'] ) && isset( $about_recommended_actions[ $action_value['id'] ] ) && ( false === $about_recommended_actions[ $action_value['id'] ] ) ) {
$hidden = true;
}
$complete = false;
if ( isset( $action_value['check'] ) && $action_value['check'] ) {
$complete = true;
}
$complete_class = ( true === $complete ) ? 'complete': '';
echo '
';
if ( isset( $action_value['id'] ) ) {
$nonce = 'action-' . $action_value['id'];
if ( ! $hidden ) {
$nonce .= '-dismiss';
echo '
';
} else {
$nonce .= '-add';
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['help'] ) ) {
echo '
' . wp_kses_post( $action_value['help'] ) . '
';
}
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';
$label = esc_html__( 'Install', 'fire-blog' );
break;
case 'activate':
$class = 'activate-now button button-primary';
$label = esc_html__( 'Activate', 'fire-blog' );
break;
case 'deactivate':
$class = 'deactivate-now button';
$label = esc_html__( 'Deactivate', 'fire-blog' );
break;
}
?>
';
} // End foreach().
} // End if().
echo '
';
} // End if().
}
/**
* Render upgrade tab.
*
* @since 1.0.0
*/
public function upgrade_to_pro() {
$upgrade_to_pro = ( isset( $this->config['upgrade_to_pro'] ) ) ? $this->config['upgrade_to_pro'] : array();
echo '
';
if ( isset( $upgrade_to_pro['description'] ) && ! empty( $upgrade_to_pro['description'] ) ) {
echo '
' . wp_kses_post( $upgrade_to_pro['description'] ) . '
';
}
if ( isset( $upgrade_to_pro['button_link'] ) && ! empty( $upgrade_to_pro['button_link'] ) ) {
$button_text = esc_html__( 'Upgrade to Pro', 'fire-blog' );
if ( isset( $upgrade_to_pro['button_label'] ) && ! empty( $upgrade_to_pro['button_label'] ) ) {
$button_text = $upgrade_to_pro['button_label'];
}
$target = '_self';
if ( isset( $upgrade_to_pro['is_new_tab'] ) && true === $upgrade_to_pro['is_new_tab'] ) {
$target = '_blank';
}
echo '
' . esc_html( $button_text ) . '';
}
echo '
';
}
/**
* Render support tab.
*
* @since 1.0.0
*/
public function support() {
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 '
' . wp_kses_post( $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 '
';
} // End foreach().
} // End if().
} // End if().
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 ) ) {
/*defaults values for child theme array */
$defaults = array(
'title'=> '',
'desc' => '',
'free' => '',
'pro' => '',
);
if ( ! empty( $free_pro ) && is_array( $free_pro ) ) {
echo '
';
echo '
';
echo '
';
echo '';
echo '';
echo ' | ';
echo '' . esc_html__( 'Fire Blog','fire-blog' ) . ' | ';
echo '' . esc_html__( 'Fire Blog PRO','fire-blog' ) . ' | ';
echo '
';
echo '';
echo '';
foreach ( $free_pro as $feature ) {
$instance = wp_parse_args( (array) $feature, $defaults );
/*allowed 7 value in array */
$title = $instance[ 'title' ];
$desc = $instance[ 'desc'];
$free = $instance[ 'free'];
$pro = $instance[ 'pro'];
echo '';
if ( ! empty( $title ) || ! empty( $desc ) ) {
echo '';
if ( ! empty( $title ) ) {
echo '' . wp_kses_post( $title ) . '';
}
if ( ! empty( $desc ) ) {
echo '' . wp_kses_post( $desc ) . ' ';
}
echo ' | ';
}
if ( ! empty( $free )) {
if( 'yes' === $free ){
echo ' | ';
}
elseif ( 'no' === $free ){
echo ' | ';
}
else{
echo ''.esc_html($free ).' | ';
}
}
if ( ! empty( $pro )) {
if( 'yes' === $pro ){
echo ' | ';
}
elseif ( 'no' === $pro ){
echo ' | ';
}
else{
echo ''.esc_html($pro ).' | ';
}
}
echo '
';
}
echo '';
echo ' | ';
echo 'Fire Blog PRO | ';
echo '
';
echo '';
echo '
';
echo '
';
echo '
';
}
}
}
/**
* Check if plugin is active.
*
* @since 1.0.0
*
* @param string $slug Plugin slug.
* @return array Status detail.
*/
public function check_if_plugin_active( $slug ) {
$output = array(
'status' => null,
'needs' => null,
);
$is_installed = $this->is_plugin_installed( $slug );
if ( true === $is_installed ) {
// Installed.
$status = $this->is_plugin_active( $slug );
if ( false === $status ) {
// Plugin is inactive.
$output = array(
'status' => $status,
'needs' => 'activate',
);
} else {
// Plugin is active.
$output = array(
'status' => $status,
'needs' => 'deactivate',
);
}
} else {
// Not installed.
$output = array(
'status' => false,
'needs' => 'install',
);
}
return $output;
}
/**
* Create action link.
*
* @since 1.0.0
*
* @param string $state State.
* @param string $slug Plugin slug.
* @return string Plugin detail.
*/
public function create_action_link( $state, $slug ) {
$file_path = $this->get_plugin_basename_from_slug( $slug );
switch ( $state ) {
case 'install':
$action_url = wp_nonce_url(
add_query_arg(
array(
'action' => 'install-plugin',
'plugin' => $slug,
),
network_admin_url( 'update.php' )
),
'install-plugin_' . $slug
);
break;
case 'deactivate':
$action_url = add_query_arg(
array(
'action' => 'deactivate',
'plugin' => rawurlencode( $file_path ),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $file_path ),
), network_admin_url( 'plugins.php' )
);
break;
case 'activate':
$action_url = add_query_arg(
array(
'action' => 'activate',
'plugin' => rawurlencode( $file_path ),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_path ),
), network_admin_url( 'plugins.php' )
);
break;
} // End switch().
return esc_url_raw( $action_url );
}
/**
* Callback for AJAX dismiss recommended action.
*
* @since 1.0.0
*/
public function dismiss_recommended_action_callback() {
$todo = ( isset( $_GET['todo'] ) ) ? esc_attr( wp_unslash( sanitize_text_field( $_GET['todo'] ) ) ) : '';
$action_id = ( isset( $_GET['id'] ) ) ? esc_attr( wp_unslash( sanitize_text_field( $_GET['id'] ) ) ) : '';
$wpnonce = ( isset( $_GET['_wpnonce'] ) ) ? esc_attr( wp_unslash( sanitize_text_field( $_GET['_wpnonce'] ) ) ) : '';
$nonce = 'action-' . $action_id . '-' . $todo;
if ( false === wp_verify_nonce( $wpnonce, $nonce ) ) {
wp_die();
}
$action_detail = array();
$recommended_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array();
if ( ! empty( $recommended_actions ) ) {
foreach ( $recommended_actions['content'] as $action ) {
$action_detail[ $action['id'] ] = true;
}
}
$options = get_option( $this->action_key );
if ( $options ) {
$action_detail = array_merge( $action_detail, $options );
}
switch ( $todo ) {
case 'add':
$action_detail[ $action_id ] = true;
break;
case 'dismiss':
$action_detail[ $action_id ] = false;
break;
default:
break;
}
update_option( $this->action_key, $action_detail );
wp_die();
}
/**
* Helper function to extract the file path of the plugin file from the
* plugin slug, if the plugin is installed.
*
* @since 1.0.0
*
* @param string $slug Plugin slug (typically folder name).
* @return string Either file path for plugin if installed, or just the plugin slug.
*/
private function get_plugin_basename_from_slug( $slug ) {
$keys = array_keys( $this->get_plugins() );
foreach ( $keys as $key ) {
if ( preg_match( '|^' . $slug . '/|', $key ) ) {
return $key;
}
}
return $slug;
}
/**
* Wrapper around the core WP get_plugins function, making sure it's actually available.
*
* @since 1.0.0
*
* @param string $plugin_folder Optional. Relative path to single plugin folder.
* @return array Array of installed plugins with plugin information.
*/
public function get_plugins( $plugin_folder = '' ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return get_plugins( $plugin_folder );
}
/**
* Check if a plugin is installed.
*
* @since 1.0.0
*
* @param string $slug Plugin slug.
* @return bool True if installed, false otherwise.
*/
private function is_plugin_installed( $slug ) {
$installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached).
$file_path = $this->get_plugin_basename_from_slug( $slug );
return ( ! empty( $installed_plugins[ $file_path ] ) );
}
/**
* Check if a plugin is active.
*
* @since 1.0.0
*
* @param string $slug Plugin slug.
* @return bool True if active, false otherwise.
*/
private function is_plugin_active( $slug ) {
$file_path = $this->get_plugin_basename_from_slug( $slug );
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return is_plugin_active( $file_path );
}
}
} // End if().