Skip to content
Open
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
46 changes: 36 additions & 10 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,33 @@ 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];
Comment on lines +566 to +569
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin file detection uses get_plugins() + array_keys()[0] to pick the first plugin file in the folder. This relies on ordering and may activate the wrong file if the folder contains multiple plugin-header files. Since this wizard only installs known slugs, consider mapping slug → expected main plugin file (e.g. optimole-wp/optimole-wp.php, otter-blocks/otter-blocks.php, wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php) and activate that explicitly (or otherwise deterministically choose the correct file).

Suggested change
$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];
$slug_key = sanitize_key( wp_unslash( $slug ) );
$installed_plugins = get_plugins( '/' . $slug_key );
if ( ! empty( $installed_plugins ) ) {
$plugin_main_files = array(
'optimole-wp' = > 'optimole-wp/optimole-wp.php',
'otter-blocks' => 'otter-blocks/otter-blocks.php',
'wp-cloudflare-page-cache' => 'wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php',
);
if ( isset( $plugin_main_files[ $slug_key ] ) ) {
$plugin_file = $plugin_main_files[ $slug_key ];
} else {
$plugin_files = array_keys( $installed_plugins );
sort( $plugin_files );
$plugin_file = $slug_key . '/' . $plugin_files[0];
}

Copilot uses AI. Check for mistakes.
activate_plugin( $plugin_file );
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activate_plugin() can return a WP_Error (e.g., activation failure due to missing requirements). The current code ignores the return value, so the wizard may report success even though the plugin wasn’t activated. Capture the return value and wp_send_json an error status/message when activation fails (and avoid updating wizard_data in that case).

Suggested change
activate_plugin( $plugin_file );
$activation_result = activate_plugin( $plugin_file );
if ( is_wp_error( $activation_result ) ) {
wp_send_json(
array(
'status' => 0,
'message' => $activation_result->get_error_message(),
)
);
}

Copilot uses AI. Check for mistakes.
}
$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;
}
if ( $wizard_data_updated ) {
$this->update_wizard_data( $wizard_data );
}

wp_send_json(
array(
Expand Down
Loading
Loading