includes();
add_action( 'admin_menu', array( $this, 'add_ocean_wizard_menu' ) );
add_action( 'admin_init', array( $this, 'ocean_wizard_setup' ), 99 );
add_action( 'wp_loaded', array( $this, 'remove_notice' ) );
add_action( 'admin_print_styles', array( $this, 'add_notice' ) );
add_action( 'add_second_notice', array( $this, 'install' ) );
}
/**
* Install.
*
* @return void
*/
public static function install() {
if ( ! get_option( 'owp_wizard' ) ) {
update_option( 'owp_wizard', 'un-setup' );
( wp_safe_redirect( admin_url( 'admin.php?page=owp_setup' ) ) );
} else {
// first run for automatic message after first 24 hour.
if ( ! get_option( 'automatic_2nd_notice' ) ) {
update_option( 'automatic_2nd_notice', 'second-time' );
} else {
// clear cronjob after second 24 hour.
wp_clear_scheduled_hook( 'add_second_notice' );
delete_option( 'automatic_2nd_notice' );
delete_option( '2nd_notice' );
delete_option( 'owp_wizard' );
wp_safe_redirect( admin_url() );
exit;
}
}
}
/**
* Clear cronjob when deactivate plugin.
*
* @return void
*/
public static function uninstall() {
wp_clear_scheduled_hook( 'add_second_notice' );
delete_option( 'automatic_2nd_notice' );
delete_option( '2nd_notice' );
delete_option( 'owp_wizard' );
}
public function remove_notice() {
if ( isset( $_GET['owp_wizard_hide_notice'] ) && $_GET['owp_wizard_hide_notice'] == 'install' ) { // WPCS: input var ok, CSRF ok.
// when install is finished.
delete_option( 'owp_wizard' );
// clear cronjob when install is finished.
wp_clear_scheduled_hook( 'add_second_notice' );
delete_option( '2nd_notice' );
if ( isset( $_GET['show'] ) ) {
wp_safe_redirect( home_url() );
exit;
}
} elseif ( isset( $_GET['owp_wizard_hide_notice'] ) && $_GET['owp_wizard_hide_notice'] == '2nd_notice' ) { // WPCS: input var ok, CSRF ok.
// when install is skipped.
delete_option( 'owp_wizard' );
if ( ! get_option( '2nd_notice' ) ) {
update_option( '2nd_notice', 'second-time' );
$timezone_string = get_option( 'timezone_string' );
if ( ! $timezone_string ) {
return false;
}
date_default_timezone_set( $timezone_string );
// set time for next day.
$new_time_format = time() + ( 24 * 60 * 60 );
// add "add_second_notice" cronjob.
if ( ! wp_next_scheduled( 'add_second_notice' ) ) {
wp_schedule_event( $new_time_format, 'daily', 'add_second_notice' );
}
} else {
// clear cronjob when wizard is skipped for the second time.
wp_clear_scheduled_hook( 'add_second_notice' );
}
if ( isset( $_GET['show'] ) ) {
wp_safe_redirect( home_url() );
exit;
} else {
wp_safe_redirect( admin_url() );
exit;
}
}
}
/**
* Add notice.
*
* @return void
*/
public function add_notice() {
if ( current_user_can( 'administrator' ) ) {
if ( ( get_option( 'owp_wizard' ) == 'un-setup' ) && ( empty( $_GET['page'] ) || 'owp_setup' !== $_GET['page'] ) ) {
if ( ! get_option( '2nd_notice' ) && ! get_option( 'automatic_2nd_notice' ) ) {?>
array(
'name' => __( 'Welcome', 'ocean-extra' ),
'view' => array( $this, 'ocean_welcome' ),
),
'demo' => array(
'name' => __( 'Choosing Demo', 'ocean-extra' ),
'view' => array( $this, 'ocean_demo_setup' ),
),
'customize' => array(
'name' => __( 'Customize', 'ocean-extra' ),
'view' => array( $this, 'ocean_customize_setup' ),
),
'ready' => array(
'name' => __( 'Ready', 'ocean-extra' ),
'view' => array( $this, 'ocean_ready_setup' ),
),
);
$this->steps = apply_filters( 'owp_setup_wizard_steps', $default_steps );
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); // WPCS: CSRF ok, input var ok.
// CSS.
wp_enqueue_style( 'owp-wizard-style', plugins_url( '/assets/css/style.min.css', __FILE__ ) );
// RTL.
if ( is_RTL() ) {
wp_enqueue_style( 'owp-wizard-rtl', plugins_url( '/assets/css/rtl.min.css', __FILE__ ) );
}
// JS.
wp_enqueue_script( 'owp-wizard-js', plugins_url( '/assets/js/wizard.min.js', __FILE__ ), array( 'jquery', 'wp-util', 'updates' ) );
wp_localize_script(
'owp-wizard-js',
'owpDemos',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'demo_data_nonce' => wp_create_nonce( 'get-demo-data' ),
'owp_import_data_nonce' => wp_create_nonce( 'owp_import_data_nonce' ),
'content_importing_error' => esc_html__( 'There was a problem during the importing process resulting in the following error from your server:', 'ocean-extra' ),
'button_activating' => esc_html__( 'Activating', 'ocean-extra' ) . '…',
'button_active' => esc_html__( 'Active', 'ocean-extra' ),
)
);
global $current_screen, $hook_suffix, $wp_locale;
if ( empty( $current_screen ) ) {
set_current_screen();
}
$admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix );
ob_start();
?>
>
step == 'demo' || $this->step == 'welcome' || $this->step == 'customize' ) {
wp_print_styles( 'themes' );
wp_print_styles( 'buttons' );
wp_print_styles( 'dashboard' );
wp_print_styles( 'common' );
}
if ( $this->step == 'customize' ) {
wp_print_styles( 'media' );
wp_enqueue_media();
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
}
// add admin styles.
do_action( 'admin_print_styles' );
do_action( 'admin_head' );
?>
OceanWP' ); ?>
setup_wizard_steps();
$this->setup_wizard_content();
_wp_footer_scripts();
do_action( 'admin_footer' );
?>
steps;
?>
$step ) {
$is_completed = array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true );
if ( $step_key === $this->step ) {
?>
-
';
if ( ! empty( $this->steps[ $this->step ]['view'] ) ) {
call_user_func( $this->steps[ $this->step ]['view'], $this );
}
echo '';
}
/**
* Get Next Step
*
* @param type $step
* @return string
*/
public function get_next_step_link( $step = '' ) {
if ( ! $step ) {
$step = $this->step;
}
$keys = array_keys( $this->steps );
if ( end( $keys ) === $step ) {
return admin_url();
}
$step_index = array_search( $step, $keys, true );
if ( false === $step_index ) {
return '';
}
return add_query_arg( 'step', $keys[ $step_index + 1 ], remove_query_arg( 'activate_error' ) );
}
/**
* Get Previous Step
*
* @param type $step
* @return string
*/
public function get_previous_step_link( $step = '' ) {
if ( ! $step ) {
$step = $this->step;
}
$keys = array_keys( $this->steps );
$step_index = array_search( $step, $keys, true );
if ( false === $step_index ) {
return '';
}
$url = false;
if ( isset( $keys[ $step_index - 1 ] ) ) {
$url = add_query_arg( 'step', $keys[ $step_index - 1 ], remove_query_arg( 'activate_error' ) );
}
return $url;
}
/**
* Helper method to retrieve the current user's email address.
*
* @return string Email address
*/
protected function get_current_user_email() {
$current_user = wp_get_current_user();
$user_email = $current_user->user_email;
return $user_email;
}
/**
* Step 1 Welcome.
*/
public function ocean_welcome() {
// Image.
$img = plugins_url( '/assets/img/jack.png', __FILE__ );
// Button icon.
if ( is_RTL() ) {
$icon = 'left';
} else {
$icon = 'right';
}
?>
',
''
);
?>
$key ) {
// Vars.
$item_categories = OceanWP_Demos::get_demo_item_categories( $key );
?>
$key ) {
// Vars.
$item_categories = OceanWP_Demos::get_demo_item_categories( $key );
?>
save_ocean_customize();
}
// Button icon.
if ( is_RTL() ) {
$icon = 'left';
} else {
$icon = 'right';
}
?>
removeElementorUpdateOptionAction( 'blogname' );
update_option( 'blogname', esc_html( $site_title ) );
if ( isset( $_POST['ocean-tagline'] ) ) {
$site_tagline = wp_filter_nohtml_kses( $_POST['ocean-tagline'] );
}
$this->removeElementorUpdateOptionAction( 'blogdescription' );
update_option( 'blogdescription', esc_html( $site_tagline ) );
if ( isset( $_POST['ocean-favicon'] ) ) {
update_option( 'site_icon', $_POST['ocean-favicon'] );
}
if ( isset( $_POST['ocean-primary-color'] ) ) {
$primary_color = sanitize_hex_color( $_POST['ocean-primary-color'] );
}
set_theme_mod( 'ocean_primary_color', esc_html( $primary_color ) );
if ( isset( $_POST['ocean-hover-primary-color'] ) ) {
$primary_color_hover = sanitize_hex_color( $_POST['ocean-hover-primary-color'] );
}
set_theme_mod( 'ocean_hover_primary_color', esc_html( $primary_color_hover ) );
if ( isset( $_POST['ocean-main-border-color'] ) ) {
$main_border_color = sanitize_hex_color( $_POST['ocean-main-border-color'] );
}
set_theme_mod( 'ocean_main_border_color', esc_html( $main_border_color ) );
if ( isset( $_POST['ocean-links-color'] ) ) {
$links_color = sanitize_hex_color( $_POST['ocean-links-color'] );
}
set_theme_mod( 'ocean_links_color', esc_html( $links_color ) );
if ( isset( $_POST['ocean-links-hover-color'] ) ) {
$links_color_hover = sanitize_hex_color( $_POST['ocean-links-hover-color'] );
}
set_theme_mod( 'ocean_links_color_hover', esc_html( $links_color_hover ) );
wp_safe_redirect( $this->get_next_step_link() );
exit;
} else {
print 'Your are not authorized to submit this form';
exit;
}
}
/**
* Step 4 ready step
*/
public function ocean_ready_setup() {
$user_email = $this->get_current_user_email();
?>
callbacks as $priority => $callbacks ) {
foreach ( $callbacks as $callback_key => $callback_data ) {
unset( $wp_filter[ $action_name ]->callbacks[ $priority ][ $callback_key ] );
}
}
}
}
}
new Ocean_Extra_Theme_Wizard();
register_activation_hook( OE_FILE_PATH, 'Ocean_Extra_Theme_Wizard::install' );
// when deactivate plugin.
register_deactivation_hook( OE_FILE_PATH, 'Ocean_Extra_Theme_Wizard::uninstall' );
// when activate plugin for automatic second notice.
register_activation_hook( OE_FILE_PATH, array( 'Ocean_Extra_Theme_Wizard', 'cronjob_activation' ) );
register_deactivation_hook( OE_FILE_PATH, array( 'Ocean_Extra_Theme_Wizard', 'cronjob_deactivation' ) );
endif;