$theme->get( 'Name' ),
'theme-slug' => $theme->get( 'TextDomain' ),
'author-logo' => get_template_directory_uri() . '/includes/libraries/welcome-screen/img/logo-cpothemes.png',
'actions' => array(),
'plugins' => array(),
'notice' => '',
'sections' => array(),
'edd' => false,
'download_id' => '',
);
$config = wp_parse_args( $config, $defaults );
/**
* Configure our welcome screen
*/
$this->theme_name = $config['theme-name'];
$this->theme_slug = $config['theme-slug'];
$this->author_logo = $config['author-logo'];
$this->actions = $config['actions'];
$this->actions_count = $this->count_actions();
$this->plugins = $config['plugins'];
$this->notice = $config['notice'];
$this->sections = $config['sections'];
$this->edd = $config['edd'];
$this->download_id = $config['download_id'];
if ( $this->edd ) {
$this->strings = EDD_Theme_Helper::get_strings();
}
if ( empty( $config['sections'] ) ) {
$this->sections = $this->set_default_sections( $config );
}
/**
* Create the dashboard page
*/
add_action( 'admin_menu', array( $this, 'welcome_screen_menu' ) );
/**
* Load the welcome screen styles and scripts
*/
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
/**
* Add the notice in the admin backend
*/
$this->add_admin_notice();
/**
* Ajax callbacks
*/
add_action(
'wp_ajax_welcome_screen_ajax_callback', array(
$this,
'welcome_screen_ajax_callback',
)
);
add_action(
'wp_ajax_nopriv_welcome_screen_ajax_callback', array(
$this,
'welcome_screen_ajax_callback',
)
);
if ( $this->edd ) {
/**
* Initiate EDD Stuff
*/
add_action( 'admin_init', array( 'EDD_Theme_Helper', 'init' ) );
add_filter( 'http_request_args', array( 'EDD_Theme_Helper', 'disable_wporg_request' ), 5, 2 );
add_action(
'update_option_' . $this->theme_slug . '_license_key',
array(
'EDD_Theme_Helper',
'license_activator_deactivator',
),
10,
2
);
}
}
/**
* AJAX Handler
*/
public function welcome_screen_ajax_callback() {
if ( isset( $_POST['args'], $_POST['args']['nonce'] ) && ! wp_verify_nonce( sanitize_key( $_POST['args']['nonce'] ), 'welcome_nonce' ) ) {
wp_die(
wp_json_encode(
array(
'status' => false,
'error' => esc_html__( 'Not allowed', 'epsilon-framework' ),
)
)
);
}
$args_action = array_map( 'sanitize_text_field', wp_unslash( $_POST['args']['action'] ) );
if ( count( $args_action ) !== 2 ) {
wp_die(
wp_json_encode(
array(
'status' => false,
'error' => esc_html__( 'Not allowed', 'epsilon-framework' ),
)
)
);
}
if ( ! class_exists( $args_action[0] ) ) {
wp_die(
wp_json_encode(
array(
'status' => false,
'error' => esc_html__( 'Class does not exist', 'epsilon-framework' ),
)
)
);
}
$class = $args_action[0];
$method = $args_action[1];
$args = array();
// if ( is_array( $_POST['args']['args'] ) ) {
// $args = Epsilon_Sanitizers::array_map_recursive( 'sanitize_text_field', wp_unslash( $_POST['args']['args'] ) );
// }
$args = $_POST['args']['args'];
$response = $class::$method( $args );
if ( is_array( $response ) ) {
wp_die( wp_json_encode( $response ) );
}
if ( 'ok' === $response ) {
wp_die(
wp_json_encode(
array(
'status' => true,
'message' => 'ok',
)
)
);
}
wp_die(
wp_json_encode(
array(
'status' => false,
'message' => 'nok',
)
)
);
}
/**
* Instance constructor
*
* @param array $config Configuration array.
*
* @returns object
*/
public static function get_instance( $config = array() ) {
static $inst;
if ( ! $inst ) {
$inst = new Epsilon_Welcome_Screen( $config );
}
return $inst;
}
/**
* Load welcome screen css and javascript
*/
public function enqueue() {
if ( is_admin() ) {
wp_enqueue_style(
'welcome-screen',
get_template_directory_uri() . '/includes/libraries/welcome-screen/css/welcome.css'
);
wp_enqueue_script(
'welcome-screen',
get_template_directory_uri() . '/includes/libraries/welcome-screen/js/welcome.js',
array(
'jquery-ui-slider',
),
'12123'
);
wp_localize_script(
'welcome-screen',
'welcomeScreen',
array(
'nr_actions_required' => absint( $this->count_actions() ),
'template_directory' => esc_url( get_template_directory_uri() ),
'no_required_actions_text' => esc_html__( 'Hooray! There are no required actions for you right now.', 'epsilon-framework' ),
'ajax_nonce' => wp_create_nonce( 'welcome_nonce' ),
'activating_string' => esc_html__( 'Activating', 'epsilon-framework' ),
'body_class' => 'appearance_page_' . $this->theme_slug . '-welcome',
'no_actions' => esc_html__( 'Hooray! There are no required actions for you right now.', 'epsilon-framework' ),
)
);
}
}
/**
* Return the actions left
*
* @return array|mixed
*/
private function get_actions_left() {
if ( ! empty( $this->actions ) ) {
$actions_left = get_option( $this->theme_slug . '_actions_left', array() );
return $actions_left;
}
return array();
}
/**
* Returns the plugins left to be installed
*
* @return array|mixed
*/
private function get_plugins_left() {
if ( ! empty( $this->plugins ) ) {
$plugins_left = get_option( $this->theme_slug . '_plugins_left', array() );
if ( empty( $plugins_left ) ) {
foreach ( $this->plugins as $plugin => $prop ) {
$plugins_left[ $plugin ] = true;
}
return $plugins_left;
}
return $plugins_left;
}
return array();
}
/**
* Adds an admin notice in the backend
*
* If the Epsilon Notification class does not exist, we stop
*/
private function add_admin_notice() {
if ( ! class_exists( 'Epsilon_Notifications' ) ) {
return;
}
if ( CPOTheme_Notify_System::check_content_import() ) {
return;
}
if ( empty( $this->notice ) ) {
if ( ! empty( $this->author_logo ) ) {
$this->notice .= '';
}
/* Translators: Notice Title */
$this->notice .= '
'; $this->notice .= sprintf( /* Translators: Notice */ esc_html__( 'Welcome! Thank you for choosing %3$s! To fully take advantage of the best our theme can offer please make sure you visit our %1$swelcome page%2$s.', 'epsilon-framework' ), '', '', $this->theme_name ); $this->notice .= '
'; /* Translators: Notice URL */ $this->notice .= '' . sprintf( esc_html__( 'Get started with %1$s', 'epsilon-framework' ), $this->theme_name ) . '
'; } $notifications = Epsilon_Notifications::get_instance(); $notifications->add_notice( array( 'id' => 'affluent_welcome_notification', 'type' => 'notice epsilon-big', 'message' => $this->notice, ) ); } /** * Registers the welcome screen menu */ public function welcome_screen_menu() { /* Translators: Menu Title */ $title = sprintf( esc_html__( 'About %1$s', 'epsilon-framework' ), esc_html( $this->theme_name ) ); if ( 0 < $this->actions_count ) { $title .= '' . esc_html( $this->actions_count ) . ''; } add_theme_page( $this->theme_name, $title, 'edit_theme_options', $this->theme_slug . '-welcome', array( $this, 'render_welcome_screen', ) ); } /** * Render the welcome screen */ public function render_welcome_screen() { require_once( ABSPATH . 'wp-load.php' ); require_once( ABSPATH . 'wp-admin/admin.php' ); require_once( ABSPATH . 'wp-admin/admin-header.php' ); $theme = wp_get_theme(); $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'getting-started'; ?>