array(), 'hero_title' => 'Welcome', 'hero_themes_desc' => '', 'hero_desc' => '', 'hero_image' => '', 'hero_dashboard_link' => '#', 'documentation_link' => '#', 'promo_title' => 'Upgrade to Pro', 'promo_button' => 'Upgrade to Pro', 'promo_link' => '#', 'changelog_version' => '1.0', 'review_link' => '#', 'suggest_idea_link' => '#', 'changelog_link' => '#', 'support_link' => '#', 'support_pro_link' => '#', 'community_link' => '#', ); /** * Constructor. */ public function __construct() { $self = $this; if ( ! function_exists( 'get_plugin_data' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } add_filter( 'woocommerce_enable_setup_wizard', '__return_false' ); add_action( 'init', array( $this, 'set_settings' ) ); add_action( 'init', function () use ( $self ) { add_action( 'admin_menu', array( $self, 'add_menu_page' ) ); } ); add_action( 'admin_notices', array( $this, 'notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 5 ); add_action( 'admin_enqueue_scripts', array( $this, 'notice_enqueue_scripts' ), 5 ); add_action( 'wp_ajax_thd_install_starter_plugin', array( $this, 'install_starter_plugin' ) ); add_action( 'wp_ajax_nopriv_thd_install_starter_plugin', array( $this, 'install_starter_plugin' ) ); add_action( 'wp_ajax_thd_dismissed_handler', array( $this, 'dismissed_handler' ) ); add_action( 'switch_theme', array( $this, 'reset_notices' ) ); add_action( 'after_switch_theme', array( $this, 'reset_notices' ) ); } /** * Add menu page */ public function add_menu_page() { add_submenu_page( 'themes.php', esc_html__( 'Theme Dashboard', 'airi' ), esc_html__( 'Theme Dashboard', 'airi' ), 'manage_options', $this->menu_slug, array( $this, 'html_carcase' ), 1 ); } /** * This function will register scripts and styles for admin dashboard. * * @param string $page Current page. */ public function admin_enqueue_scripts( $page ) { wp_enqueue_script( 'airi', get_template_directory_uri() . '/theme-dashboard/scripts.js', array( 'jquery' ), filemtime( get_template_directory() . '/theme-dashboard/scripts.js' ), true ); wp_localize_script( 'airi', 'thd_localize', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'nonce' ), 'failed_message' => esc_html__( 'Something went wrong, contact support.', 'airi' ), ) ); // Styles. wp_enqueue_style( 'airi', get_template_directory_uri() . '/theme-dashboard/style.css', array(), filemtime( get_template_directory() . '/theme-dashboard/style.css' ) ); // Add RTL support. wp_style_add_data( 'airi', 'rtl', 'replace' ); } /** * Settings * * @param array $settings The settings. */ public function set_settings( $settings ) { $this->settings = apply_filters( 'thd_register_settings', $this->settings ); if ( isset( $this->settings['pro_status'] ) ) { $this->pro_status = $this->settings['pro_status']; } if ( isset( $this->settings['starter_plugin_slug'] ) ) { $this->starter_plugin_slug = $this->settings['starter_plugin_slug']; } if ( isset( $this->settings['starter_plugin_path'] ) ) { $this->starter_plugin_path = $this->settings['starter_plugin_path']; } if ( isset( $this->settings['starter_menu_slug'] ) ) { $this->starter_menu_slug = $this->settings['starter_menu_slug']; } } /** * Is visible * * @param array $data The data. */ public function is_visible( $data ) { $status = isset( $data['visible'] ) ? $data['visible'] : array(); if ( in_array( 'free', $status, true ) && ! $this->pro_status ) { return true; } if ( in_array( 'pro', $status, true ) && $this->pro_status ) { return true; } } /** * Get plugin status. * * @param string $plugin_path Plugin path. */ public function get_plugin_status( $plugin_path ) { if ( ! current_user_can( 'install_plugins' ) ) { return; } if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_path ) ) { return 'not_installed'; } elseif ( in_array( $plugin_path, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin_path ) ) { return 'active'; } else { return 'inactive'; } } /** * Install a plugin. * * @param string $plugin_slug Plugin slug. */ public function install_plugin( $plugin_slug ) { if ( ! current_user_can( 'install_plugins' ) ) { return; } if ( ! function_exists( 'plugins_api' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; } if ( ! class_exists( 'WP_Upgrader' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } if ( false === filter_var( $plugin_slug, FILTER_VALIDATE_URL ) ) { $api = plugins_api( 'plugin_information', array( 'slug' => $plugin_slug, 'fields' => array( 'short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false, ), ) ); $download_link = $api->download_link; } else { $download_link = $plugin_slug; } // Use AJAX upgrader skin instead of plugin installer skin. // ref: function wp_ajax_install_plugin(). $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() ); $install = $upgrader->install( $download_link ); if ( false === $install ) { return false; } else { return true; } } /** * Activate a plugin. * * @param string $plugin_path Plugin path. */ public function activate_plugin( $plugin_path ) { if ( ! current_user_can( 'install_plugins' ) ) { return false; } $activate = activate_plugin( $plugin_path, '', false, true ); if ( is_wp_error( $activate ) ) { return false; } else { return true; } } /** * Install starter plugin. */ public function install_starter_plugin() { check_ajax_referer( 'nonce', 'nonce' ); if ( ! current_user_can( 'install_plugins' ) ) { wp_send_json_error( esc_html__( 'Insufficient permissions to install the plugin.', 'airi' ) ); wp_die(); } if ( 'not_installed' === $this->get_plugin_status( $this->starter_plugin_path ) ) { $this->install_plugin( $this->starter_plugin_slug ); $this->activate_plugin( $this->starter_plugin_path ); } elseif ( 'inactive' === $this->get_plugin_status( $this->starter_plugin_path ) ) { $this->activate_plugin( $this->starter_plugin_path ); } if ( 'active' === $this->get_plugin_status( $this->starter_plugin_path ) ) { wp_send_json_success(); } wp_send_json_error( esc_html__( 'Failed to initialize or activate importer plugin.', 'airi' ) ); wp_die(); } /** * Html Features * * @param array $data The data. */ public function html_features( $data ) { if ( ! $data ) { return; } ?>
pro_status ? $feature_status : 'thd-theme-feature-noactive'; } ?>
pro_status ? $customize_uri : 'javascript:void(0);'; } ?>
display_name ); ?>
settings['hero_title'] ); ?> pro_status ) { ?> pro free
settings['hero_themes_desc'] ) && $this->settings['hero_themes_desc'] ) { ?>
settings['hero_themes_desc'] ); ?>
settings['hero_desc'] ) && $this->settings['hero_desc'] ) { ?>
settings['hero_desc'] ); ?>
get_plugin_status( $this->starter_plugin_path ) ) { $target = 'active'; } ?> base ) { ?>
get_plugin_status( $this->starter_plugin_path ) ) { ?>
settings['hero_image'] ) && $this->settings['hero_image'] ) { ?>

html_hero(); ?>
settings['tabs'] ) { ?>
settings['tabs'] as $tab ) { $counter++; if ( ! $this->is_visible( $tab ) ) { continue; } ?>

settings['tabs'] as $tab ) { $counter++; if ( ! $this->is_visible( $tab ) ) { continue; } ?>
html_features( $tab['data'] ); break; case 'performance': $this->html_performance(); break; case 'html': call_user_func( 'printf', '%s', $tab['data'] ); break; } ?>

pro_status ) { ?>
pro_status ) { ?>
pro_status ) { ?>
settings['promo_title'] ); ?>
settings['promo_desc'] ) && $this->settings['promo_desc'] ) { ?>
settings['promo_desc'] ); ?>

settings['changelog_version'] ) { ?>
settings['changelog_version'] ); ?>
base ) { $transient_name = sprintf( '%s_hero_notice', get_template() ); if ( ! get_transient( $transient_name ) ) { ?>
html_hero( 'themes' ); ?>
', '' ), '', $script ) ); } } new Airi_Theme_Dashboard();