Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions classes/Visualizer/Module/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,21 @@ public function adminInit() {
// fire any upgrades necessary.
Visualizer_Module_Upgrade::upgrade();

if ( get_option( 'visualizer-activated' ) ) {
$activated_flag = get_option( 'visualizer-activated' );
$fresh_install = get_option( 'visualizer_fresh_install', false );
$is_pro = Visualizer_Module::is_pro();
if ( $activated_flag ) {
if ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) {
// Defer redirect until a normal admin request.
return;
}
if ( wp_doing_cron() ) {
// Defer redirect during cron requests.
return;
}
delete_option( 'visualizer-activated' );
if ( ! headers_sent() ) {
if ( ! Visualizer_Module::is_pro() && ! empty( get_option( 'visualizer_fresh_install', false ) ) ) {
if ( ! $is_pro && ! empty( $fresh_install ) ) {
$redirect_url = array(
'page' => 'visualizer-setup-wizard',
'tab' => '#step-1',
Expand Down
76 changes: 45 additions & 31 deletions classes/Visualizer/Module/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function registerAdminMenu() {
}
}


/**
* Method to register the setup wizard page.
*
Expand Down Expand Up @@ -168,7 +169,7 @@ public function dismissWizard( $redirect_to_dashboard = true ) {
*/
public function visualizer_wizard_step_process() {
check_ajax_referer( VISUALIZER_ABSPATH, 'security' );
$step = ! empty( $_POST['step'] ) ? filter_input( INPUT_POST, 'step', FILTER_SANITIZE_STRING ) : 1;
$step = ! empty( $_POST['step'] ) ? sanitize_text_field( wp_unslash( $_POST['step'] ) ) : 1;
switch ( $step ) {
case 'step_2':
$this->setup_wizard_import_chart();
Expand All @@ -193,7 +194,7 @@ public function visualizer_wizard_step_process() {
*/
private function setup_wizard_import_chart() {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$chart_type = ! empty( $_POST['chart_type'] ) ? filter_input( INPUT_POST, 'chart_type', FILTER_SANITIZE_STRING ) : '';
$chart_type = ! empty( $_POST['chart_type'] ) ? sanitize_text_field( wp_unslash( $_POST['chart_type'] ) ) : '';
$chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type );
if ( ! $chart_status ) {
wp_send_json(
Expand Down Expand Up @@ -386,7 +387,8 @@ private function setup_wizard_import_chart() {
);
$this->update_wizard_data( $wizard_data, false );
$response = array(
'success' => 1,
'success' => 1,
'chart_id' => $chart_id,
);
}
wp_send_json( $response );
Expand Down Expand Up @@ -416,7 +418,7 @@ private function update_wizard_data( $data = array(), $merge_option = true ) {
private function setup_wizard_create_draft_page( $return_page_id = false ) {
$add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false;
$basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? filter_input( INPUT_POST, 'basic_shortcode', FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing

if ( ! $add_basic_shortcode ) {
wp_send_json(
Expand Down Expand Up @@ -476,7 +478,7 @@ private function setup_wizard_create_draft_page( $return_page_id = false ) {
*/
private function setup_wizard_install_plugin() {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : '';
$slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
if ( empty( $slug ) ) {
wp_send_json(
array(
Expand All @@ -496,8 +498,10 @@ private function setup_wizard_install_plugin() {
}

if ( ! empty( $slug ) ) {
$wizard_data = get_option( self::OPTION_NAME, array() );
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';

$api = plugins_api(
'plugin_information',
Expand Down Expand Up @@ -559,11 +563,34 @@ private function setup_wizard_install_plugin() {
wp_send_json( $status );
}

activate_plugin( 'optimole-wp/optimole-wp.php' );
delete_transient( 'optml_fresh_install' );
// Update wizard data.
$wizard_data['enable_perfomance'] = true;
$this->update_wizard_data( $wizard_data );
$installed_plugins = get_plugins( '/' . sanitize_key( wp_unslash( $slug ) ) );
if ( ! empty( $installed_plugins ) ) {
$plugin_files = array_keys( $installed_plugins );
$plugin_file = sanitize_key( wp_unslash( $slug ) ) . '/' . $plugin_files[0];
activate_plugin( $plugin_file );
}
$wizard_data_updated = false;
if ( 'optimole-wp' === $slug ) {
delete_transient( 'optml_fresh_install' );
// Update wizard data.
$wizard_data['enable_perfomance'] = true;
$wizard_data_updated = true;
}
if ( 'otter-blocks' === $slug ) {
// Update wizard data.
$wizard_data['enable_otter_blocks'] = true;
$wizard_data_updated = true;
update_option( 'themeisle_blocks_settings_onboarding', false );
}
if ( 'wp-cloudflare-page-cache' === $slug ) {
// Update wizard data.
$wizard_data['enable_page_cache'] = true;
$wizard_data_updated = true;
update_option( 'swcfpc_dashboard_redirect', false );
}
if ( $wizard_data_updated ) {
$this->update_wizard_data( $wizard_data );
}

wp_send_json(
array(
Expand Down Expand Up @@ -614,16 +641,17 @@ private function setup_wizard_subscribe_process() {
}

if ( $with_subscribe && is_email( $email ) ) {
$request_res = wp_remote_post(
wp_remote_post(
VISUALIZER_SUBSCRIBE_API,
array(
'timeout' => 100,
'headers' => array(
'timeout' => 5,
'blocking' => false,
'headers' => array(
'Content-Type' => 'application/json',
'Cache-Control' => 'no-cache',
'Accept' => 'application/json, */*;q=0.1',
),
'body' => wp_json_encode(
'body' => wp_json_encode(
array(
'slug' => 'visualizer',
'site' => home_url(),
Expand All @@ -635,24 +663,10 @@ private function setup_wizard_subscribe_process() {
),
)
);
if ( ! is_wp_error( $request_res ) ) {
$body = json_decode( wp_remote_retrieve_body( $request_res ) );
if ( 'success' === $body->code ) {
$this->dismissWizard( false );
wp_send_json( $response );
}
}
wp_send_json(
array(
'status' => 0,
'redirect_to' => '',
'message' => '',
)
);
} else {
$this->dismissWizard( false );
wp_send_json( $response );
}

$this->dismissWizard( false );
wp_send_json( $response );
}

/**
Expand Down
Loading
Loading