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 fully take advantage of the best our theme can offer please make sure you visit our %2$swelcome page%3$s.', $this->theme_name, '', '' ) . '
';
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 ) . '
';
}
echo '
';
$this->render_quick_links();
/* Display tabs */
if ( ! empty( $this->tabs ) ) {
$active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'getting_started';
echo '
';
/* Display content for current tab */
if ( method_exists( $this, $active_tab ) ) {
$this->$active_tab();
}
}
echo '
';
}
}
/*
* Call plugin api
*/
public function call_plugin_api( $slug ) {
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); // phpcs:ignore
if ( false === ( $call_api = get_transient( 'ti_about_page_plugin_information_transient_' . $slug ) ) ) {
$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
)
)
);
set_transient( 'ti_about_page_plugin_information_transient_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
}
return $call_api;
}
public function check_if_plugin_active( $slug ) {
if( ( $slug == 'intergeo-maps' ) || ( $slug == 'visualizer' ) ) {
$plugin_root_file = 'index';
} elseif ( $slug == 'adblock-notify-by-bweb' ) {
$plugin_root_file = 'adblock-notify';
} else {
$plugin_root_file = $slug;
}
$path = WPMU_PLUGIN_DIR . '/' . $slug . '/' . $plugin_root_file . '.php';
if ( ! file_exists( $path ) ) {
$path = WP_PLUGIN_DIR . '/' . $slug . '/' . $plugin_root_file . '.php';
if ( ! file_exists( $path ) ) {
$path = false;
}
}
if ( file_exists( $path ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // phpcs:ignore
$needs = is_plugin_active( $slug . '/' . $plugin_root_file . '.php' ) ? 'deactivate' : 'activate';
return array( 'status' => is_plugin_active( $slug . '/' . $plugin_root_file . '.php' ), 'needs' => $needs );
}
return array( 'status' => false, 'needs' => 'install' );
}
/**
* Get icon of wordpress.org plugin
* @param $arr
*
* @return mixed
*/
public function get_plugin_icon( $arr ) {
if ( ! empty( $arr['svg'] ) ) {
$plugin_icon_url = $arr['svg'];
} elseif ( ! empty( $arr['2x'] ) ) {
$plugin_icon_url = $arr['2x'];
} elseif ( ! empty( $arr['1x'] ) ) {
$plugin_icon_url = $arr['1x'];
} else {
$plugin_icon_url = get_template_directory_uri() . '/inc/about/images/logo.png';
}
return $plugin_icon_url;
}
public function create_action_link( $state, $slug ) {
if( ( $slug == 'intergeo-maps' ) || ( $slug == 'visualizer' ) ) {
$plugin_root_file = 'index';
} elseif ( $slug == 'adblock-notify-by-bweb' ) {
$plugin_root_file = 'adblock-notify';
} else {
$plugin_root_file = $slug;
}
switch ( $state ) {
case 'install':
return wp_nonce_url(
add_query_arg(
array(
'action' => 'install-plugin',
'plugin' => $slug
),
network_admin_url( 'update.php' )
),
'install-plugin_' . $slug
);
break;
case 'deactivate':
return add_query_arg(
array(
'action' => 'deactivate',
'plugin' => rawurlencode( $slug . '/' . $plugin_root_file . '.php' ),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce( 'deactivate-plugin_' . $slug . '/' . $plugin_root_file . '.php' ),
), network_admin_url( 'plugins.php' )
);
break;
case 'activate':
return add_query_arg(
array(
'action' => 'activate',
'plugin' => rawurlencode( $slug . '/' . $plugin_root_file . '.php' ),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $slug . '/' . $plugin_root_file . '.php' ),
), network_admin_url( 'plugins.php' )
);
break;
}
}
/**
* Render quick links.
*
* @since 1.0.0
*/
public function render_quick_links() {
$quick_links = ( isset( $this->config['quick_links'] ) ) ? $this->config['quick_links'] : array();
if ( ! empty( $quick_links ) ) {
echo '';
foreach ( $quick_links as $link ) {
$button_type = '';
if ( isset( $link['button'] ) ) {
$button_type = 'button-' . esc_attr( $link['button'] );
}
echo '' . esc_html( $link['text'] ) . '';
}
echo '
';
}
}
/**
* Render getting started.
*
* @since 1.0.0
*/
public function getting_started() {
$content = ( isset( $this->config['getting_started'] ) ) ? $this->config['getting_started'] : array();
if ( empty( $content ) ) {
return;
}
?>
';
$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;
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 useful_plugins() {
$useful_plugins = $this->config['useful_plugins'];
if ( ! empty( $useful_plugins ) ) {
if ( ! empty( $useful_plugins['content'] ) && is_array( $useful_plugins['content'] ) ) {
echo '
';
foreach ( $useful_plugins['content'] as $useful_plugins_item ) {
if ( ! empty( $useful_plugins_item['slug'] ) ) {
$info = $this->call_plugin_api( $useful_plugins_item['slug'] );
if ( ! empty( $info->icons ) ) {
$icon = $this->get_plugin_icon( $info->icons );
}
$active = $this->check_if_plugin_active( $useful_plugins_item['slug'] );
if ( ! empty( $active['needs'] ) ) {
$url = $this->create_action_link( $active['needs'], $useful_plugins_item['slug'] );
}
echo '
';
if ( ! empty( $icon ) ) {
echo '
';
}
if ( ! empty( $info->version ) ) {
echo '
'. ( ! empty( $this->config['useful_plugins']['version_label'] ) ? esc_html( $this->config['useful_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['useful_plugins']['install_label'] ) ) {
$label = $this->config['useful_plugins']['install_label'];
}
break;
case 'activate':
$class = 'activate-now button button-primary';
if ( ! empty( $this->config['useful_plugins']['activate_label'] ) ) {
$label = $this->config['useful_plugins']['activate_label'];
}
break;
case 'deactivate':
$class = 'deactivate-now button';
if ( ! empty( $this->config['useful_plugins']['deactivate_label'] ) ) {
$label = $this->config['useful_plugins']['deactivate_label'];
}
break;
}
echo '
';
echo '' . esc_html( $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 '
' . wp_kses_post( $release['title'] ) . '
';
}
if ( ! empty( $release['changes'] ) ) {
echo wp_kses_post( 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 '
';
}
echo ' | | ';
echo esc_html ('gute Pro Live Preview', 'gute');
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( 'about-page-css', get_template_directory_uri() . '/inc/about/css/about.min.css',array(),'1.3.0','all' );
wp_enqueue_script( 'gute-notice-js', get_template_directory_uri() . '/inc/about/js/notice.js', array('jquery'), '1.7.0', true );
if ( 'appearance_page_' . $this->theme_slug . '-welcome' == $hook_suffix ) {
wp_enqueue_script( 'about-page-js', get_template_directory_uri() . '/inc/about/js/about.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(
'about-page-js', 'tiAboutPageObject', array(
'nr_actions_required' => count( $required_actions ),
'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
'template_directory' => get_template_directory_uri(),
'activating_string' => __( 'Activating', 'gute' )
)
);
}
}
/**
* 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'] ) ) ? sanitize_text_field( wp_unslash( $_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' );
$todo = ( isset( $_GET['todo'] ) ) ? sanitize_text_field( wp_unslash( $_GET['todo'] ) ) : '';
switch ( $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 );
}
}
}
}
}
}