config = $config;
self::$instance->setup_config();
self::$instance->setup_actions();
}
}
}
/**
* Notice for Neve theme
*
* @return string
*/
public function neve_notice() {
global $current_user;
$user_id = $current_user->ID;
$ignored_notice = get_user_meta( $user_id, 'zerif_ignore_neve_notice' );
if ( ! empty( $ignored_notice ) ) {
return;
}
$theme_args = wp_get_theme();
$name = $theme_args->__get( 'Name' );
$notice_template = '
';
echo $dismiss_button;
echo $this->neve_notice();
echo '
';
}
/**
* Render the main content page.
*/
public function ti_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 '';
$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 ) ) {
$ti_about_page_show_required_actions = get_option( $this->theme_slug . '_required_actions' );
$hooray = true;
foreach ( $actions as $action_key => $action_value ) {
$hidden = false;
if ( $ti_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;
}
?>
';
}
}
echo '
';
}
}
/**
* 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 '
';
foreach ( $recommended_plugins['content'] as $recommended_plugins_item ) {
if ( ! empty( $recommended_plugins_item['slug'] ) ) {
$info = $this->call_plugin_api( $recommended_plugins_item['slug'] );
if ( ! empty( $info->icons ) ) {
$icon = $this->get_plugin_icon( $info->icons );
}
$active = $this->check_if_plugin_active( $recommended_plugins_item['slug'] );
if ( ! empty( $active['needs'] ) ) {
$url = $this->create_action_link( $active['needs'], $recommended_plugins_item['slug'] );
}
echo '
';
if ( ! empty( $icon ) ) {
echo '
 . ')
';
}
if ( ! empty( $info->version ) ) {
echo '
' . ( ! empty( $this->config['recommended_plugins']['version_label'] ) ? esc_html( $this->config['recommended_plugins']['version_label'] ) : '' ) . esc_html( $info->version ) . '';
}
if ( ! empty( $info->author ) ) {
echo '
| ' . wp_kses_post( $info->author );
}
if ( ! empty( $info->name ) && ! empty( $active ) ) {
echo '
';
echo '' . ( ( $active['needs'] !== 'install' && $active['status'] ) ? 'Active: ' : '' ) . esc_html( $info->name ) . '';
echo '
';
$label = '';
switch ( $active['needs'] ) {
case 'install':
$class = 'install-now button';
if ( ! empty( $this->config['recommended_plugins']['install_label'] ) ) {
$label = $this->config['recommended_plugins']['install_label'];
}
break;
case 'activate':
$class = 'activate-now button button-primary';
if ( ! empty( $this->config['recommended_plugins']['activate_label'] ) ) {
$label = $this->config['recommended_plugins']['activate_label'];
}
break;
case 'deactivate':
$class = 'deactivate-now button';
if ( ! empty( $this->config['recommended_plugins']['deactivate_label'] ) ) {
$label = $this->config['recommended_plugins']['deactivate_label'];
}
break;
}
echo '
';
echo '' . esc_html( $label ) . '';
echo '';
}
echo '
';
}
}
echo '
';
}
}
}
/**
* Child themes
*/
public function child_themes() {
echo '
';
$child_themes = isset( $this->config['child_themes'] ) ? $this->config['child_themes'] : array();
if ( ! empty( $child_themes ) ) {
if ( ! empty( $child_themes['content'] ) && is_array( $child_themes['content'] ) ) {
echo '
';
for ( $i = 0; $i < count( $child_themes['content'] ); $i ++ ) {
if ( ( $i !== 0 ) && ( $i / 3 === 0 ) ) {
echo '
';
echo '
';
}
$child = $child_themes['content'][ $i ];
if ( ! empty( $child['image'] ) ) {
echo '
';
echo '
';
echo '
![' . ( ! empty( $child['image_alt'] ) ? esc_html( $child['image_alt'] ) : '' ) . '](' . esc_url( $child['image'] ) . ')
';
if ( ! empty( $child['title'] ) ) {
echo '
';
if ( $child['title'] != $this->theme_name ) {
echo '
';
}
echo '
';
}
echo '
';
echo '
';
}// End if().
}// End for().
echo '
';
}// End if().
}// End if().
echo '
';
}
/**
* Support tab
*/
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 $support_step['title'];
echo '
';
}
if ( ! empty( $support_step['text'] ) ) {
echo '
' . $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 '' . $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 '
' . $release['title'] . '
';
}
if ( ! empty( $release['changes'] ) ) {
echo implode( '
', $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;
}
/**
* 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 ) {
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 ' | ';
}
if ( ! empty( $feature['is_in_lite'] ) && ( $feature['is_in_lite'] == 'true' ) ) {
echo ' | ';
} else {
echo ' | ';
}
if ( ! empty( $feature['is_in_pro'] ) && ( $feature['is_in_pro'] == 'true' ) ) {
echo ' | ';
} 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 ) {
// this is needed on all admin pages, not just the about page, for the badge action count in the WordPress main sidebar
wp_enqueue_style( 'ti-about-page-css', get_template_directory_uri() . '/ti-about-page/css/ti_about_page_css.css' );
if ( 'appearance_page_' . $this->theme_slug . '-welcome' == $hook_suffix ) {
wp_enqueue_script( 'ti-about-page-js', get_template_directory_uri() . '/ti-about-page/js/ti_about_page_scripts.js', array( 'jquery' ) );
wp_enqueue_style( 'plugin-install' );
wp_enqueue_script( 'plugin-install' );
wp_enqueue_script( 'updates' );
$recommended_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array();
$required_actions = $this->get_required_actions();
wp_localize_script(
'ti-about-page-js',
'tiAboutPageObject',
array(
'nr_actions_required' => count( $required_actions ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'template_directory' => get_template_directory_uri(),
'activating_string' => __( 'Activating', 'zerif-lite' ),
)
);
}
}
/**
* Return the valid array of required actions.
*
* @return array The valid array of required actions.
*/
private function get_required_actions() {
$saved_actions = get_option( $this->theme_slug . '_required_actions' );
if ( ! is_array( $saved_actions ) ) {
$saved_actions = array();
}
$req_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array();
$valid = array();
foreach ( $req_actions['content'] as $req_action ) {
if ( ( ! isset( $req_action['check'] ) || ( isset( $req_action['check'] ) && ( $req_action['check'] == false ) ) ) && ( ! isset( $saved_actions[ $req_action['id'] ] ) ) ) {
$valid[] = $req_action;
}
}
return $valid;
}
/**
* Dismiss required actions
*/
public function dismiss_required_action_callback() {
$recommended_actions = array();
$req_actions = isset( $this->config['recommended_actions'] ) ? $this->config['recommended_actions'] : array();
foreach ( $req_actions['content'] as $req_action ) {
$recommended_actions[] = $req_action;
}
$action_id = ( isset( $_GET['id'] ) ) ? $_GET['id'] : 0;
echo esc_html( wp_unslash( $action_id ) ); /* this is needed and it's the id of the dismissable required action */
if ( ! empty( $action_id ) ) {
/* if the option exists, update the record for the specified id */
if ( get_option( $this->theme_slug . '_required_actions' ) ) {
$ti_about_page_show_required_actions = get_option( $this->theme_slug . '_required_actions' );
switch ( esc_html( $_GET['todo'] ) ) {
case 'add':
$ti_about_page_show_required_actions[ absint( $action_id ) ] = true;
break;
case 'dismiss':
$ti_about_page_show_required_actions[ absint( $action_id ) ] = false;
break;
}
update_option( $this->theme_slug . '_required_actions', $ti_about_page_show_required_actions );
/* create the new option,with false for the specified id */
} else {
$ti_about_page_show_required_actions_new = array();
if ( ! empty( $recommended_actions ) ) {
foreach ( $recommended_actions as $ti_about_page_required_action ) {
if ( $ti_about_page_required_action['id'] == $action_id ) {
$ti_about_page_show_required_actions_new[ $ti_about_page_required_action['id'] ] = false;
} else {
$ti_about_page_show_required_actions_new[ $ti_about_page_required_action['id'] ] = true;
}
}
update_option( $this->theme_slug . '_required_actions', $ti_about_page_show_required_actions_new );
}
}
}
}
}
}