| @@ -72,8 +72,9 @@ | ||
| 72 | 72 | add_action( "load-$hook", array( $this, 'visualizer_load_setup_wizard_page' ) ); |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | + | |
| 76 | 77 | /** |
| 77 | 78 | * Method to register the setup wizard page. |
| 78 | 79 | * |
| 79 | 80 | * @access public |
| @@ -167,9 +168,9 @@ | ||
| 167 | 168 | * Setup wizard process. |
| 168 | 169 | */ |
| 169 | 170 | public function visualizer_wizard_step_process() { |
| 170 | 171 | check_ajax_referer( VISUALIZER_ABSPATH, 'security' ); |
| 171 | - $step = ! empty( $_POST['step'] ) ? filter_input( INPUT_POST, 'step', FILTER_SANITIZE_STRING ) : 1; | |
| 172 | + $step = ! empty( $_POST['step'] ) ? sanitize_text_field( wp_unslash( $_POST['step'] ) ) : 1; | |
| 172 | 173 | switch ( $step ) { |
| 173 | 174 | case 'step_2': |
| 174 | 175 | $this->setup_wizard_import_chart(); |
| 175 | 176 | break; |
| @@ -192,9 +193,9 @@ | ||
| 192 | 193 | * Step: 2 import chart. |
| 193 | 194 | */ |
| 194 | 195 | private function setup_wizard_import_chart() { |
| 195 | 196 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 196 | - $chart_type = ! empty( $_POST['chart_type'] ) ? filter_input( INPUT_POST, 'chart_type', FILTER_SANITIZE_STRING ) : ''; | |
| 197 | + $chart_type = ! empty( $_POST['chart_type'] ) ? sanitize_text_field( wp_unslash( $_POST['chart_type'] ) ) : ''; | |
| 197 | 198 | $chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type ); |
| 198 | 199 | if ( ! $chart_status ) { |
| 199 | 200 | wp_send_json( |
| 200 | 201 | array( |
| @@ -385,9 +386,10 @@ | ||
| 385 | 386 | 'chart_id' => $chart_id, |
| 386 | 387 | ); |
| 387 | 388 | $this->update_wizard_data( $wizard_data, false ); |
| 388 | 389 | $response = array( |
| 389 | - 'success' => 1, | |
| 390 | + 'success' => 1, | |
| 391 | + 'chart_id' => $chart_id, | |
| 390 | 392 | ); |
| 391 | 393 | } |
| 392 | 394 | wp_send_json( $response ); |
| 393 | 395 | exit; |
| @@ -415,9 +417,9 @@ | ||
| 415 | 417 | */ |
| 416 | 418 | private function setup_wizard_create_draft_page( $return_page_id = false ) { |
| 417 | 419 | $add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 418 | 420 | $add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false; |
| 419 | - $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? filter_input( INPUT_POST, 'basic_shortcode', FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 421 | + $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 420 | 422 | |
| 421 | 423 | if ( ! $add_basic_shortcode ) { |
| 422 | 424 | wp_send_json( |
| 423 | 425 | array( |
| @@ -475,9 +477,9 @@ | ||
| 475 | 477 | * Step: 3 Install plugin. |
| 476 | 478 | */ |
| 477 | 479 | private function setup_wizard_install_plugin() { |
| 478 | 480 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 479 | - $slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : ''; | |
| 481 | + $slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 480 | 482 | if ( empty( $slug ) ) { |
| 481 | 483 | wp_send_json( |
| 482 | 484 | array( |
| 483 | 485 | 'status' => 0, |
| @@ -495,10 +497,12 @@ | ||
| 495 | 497 | ); |
| 496 | 498 | } |
| 497 | 499 | |
| 498 | 500 | if ( ! empty( $slug ) ) { |
| 501 | + $wizard_data = get_option( self::OPTION_NAME, array() ); | |
| 499 | 502 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 500 | 503 | include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 504 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 501 | 505 | |
| 502 | 506 | $api = plugins_api( |
| 503 | 507 | 'plugin_information', |
| 504 | 508 | array( |
| @@ -558,13 +562,38 @@ | ||
| 558 | 562 | |
| 559 | 563 | wp_send_json( $status ); |
| 560 | 564 | } |
| 561 | 565 | |
| 562 | - activate_plugin( 'optimole-wp/optimole-wp.php' ); | |
| 563 | - delete_transient( 'optml_fresh_install' ); | |
| 564 | - // Update wizard data. | |
| 565 | - $wizard_data['enable_perfomance'] = true; | |
| 566 | - $this->update_wizard_data( $wizard_data ); | |
| 566 | + $installed_plugins = get_plugins( '/' . sanitize_key( wp_unslash( $slug ) ) ); | |
| 567 | + if ( ! empty( $installed_plugins ) ) { | |
| 568 | + $plugin_files = array_keys( $installed_plugins ); | |
| 569 | + $plugin_file = sanitize_key( wp_unslash( $slug ) ) . '/' . $plugin_files[0]; | |
| 570 | + activate_plugin( $plugin_file ); | |
| 571 | + } | |
| 572 | + $wizard_data_updated = false; | |
| 573 | + if ( 'optimole-wp' === $slug ) { | |
| 574 | + delete_transient( 'optml_fresh_install' ); | |
| 575 | + // Update wizard data. | |
| 576 | + $wizard_data['enable_perfomance'] = true; | |
| 577 | + $wizard_data_updated = true; | |
| 578 | + } | |
| 579 | + if ( 'otter-blocks' === $slug ) { | |
| 580 | + // Update wizard data. | |
| 581 | + $wizard_data['enable_otter_blocks'] = true; | |
| 582 | + $wizard_data_updated = true; | |
| 583 | + // Suppress Otter's post-activation redirects so the user stays in Visualizer. | |
| 584 | + update_option( 'themeisle_blocks_settings_redirect', '0' ); | |
| 585 | + update_option( 'themeisle_blocks_settings_onboarding', '0' ); | |
| 586 | + } | |
| 587 | + if ( 'wp-cloudflare-page-cache' === $slug ) { | |
| 588 | + // Update wizard data. | |
| 589 | + $wizard_data['enable_page_cache'] = true; | |
| 590 | + $wizard_data_updated = true; | |
| 591 | + update_option( 'swcfpc_dashboard_redirect', false ); | |
| 592 | + } | |
| 593 | + if ( $wizard_data_updated ) { | |
| 594 | + $this->update_wizard_data( $wizard_data ); | |
| 595 | + } | |
| 567 | 596 | |
| 568 | 597 | wp_send_json( |
| 569 | 598 | array( |
| 570 | 599 | 'status' => 1, |
| @@ -613,18 +642,19 @@ | ||
| 613 | 642 | ); |
| 614 | 643 | } |
| 615 | 644 | |
| 616 | 645 | if ( $with_subscribe && is_email( $email ) ) { |
| 617 | - $request_res = wp_remote_post( | |
| 646 | + wp_remote_post( | |
| 618 | 647 | VISUALIZER_SUBSCRIBE_API, |
| 619 | 648 | array( |
| 620 | - 'timeout' => 100, | |
| 621 | - 'headers' => array( | |
| 649 | + 'timeout' => 5, | |
| 650 | + 'blocking' => false, | |
| 651 | + 'headers' => array( | |
| 622 | 652 | 'Content-Type' => 'application/json', |
| 623 | 653 | 'Cache-Control' => 'no-cache', |
| 624 | 654 | 'Accept' => 'application/json, */*;q=0.1', |
| 625 | 655 | ), |
| 626 | - 'body' => wp_json_encode( | |
| 656 | + 'body' => wp_json_encode( | |
| 627 | 657 | array( |
| 628 | 658 | 'slug' => 'visualizer', |
| 629 | 659 | 'site' => home_url(), |
| 630 | 660 | 'email' => $email, |
| @@ -634,26 +664,12 @@ | ||
| 634 | 664 | ) |
| 635 | 665 | ), |
| 636 | 666 | ) |
| 637 | 667 | ); |
| 638 | - if ( ! is_wp_error( $request_res ) ) { | |
| 639 | - $body = json_decode( wp_remote_retrieve_body( $request_res ) ); | |
| 640 | - if ( 'success' === $body->code ) { | |
| 641 | - $this->dismissWizard( false ); | |
| 642 | - wp_send_json( $response ); | |
| 643 | - } | |
| 644 | - } | |
| 645 | - wp_send_json( | |
| 646 | - array( | |
| 647 | - 'status' => 0, | |
| 648 | - 'redirect_to' => '', | |
| 649 | - 'message' => '', | |
| 650 | - ) | |
| 651 | - ); | |
| 652 | - } else { | |
| 653 | - $this->dismissWizard( false ); | |
| 654 | - wp_send_json( $response ); | |
| 655 | 668 | } |
| 669 | + | |
| 670 | + $this->dismissWizard( false ); | |
| 671 | + wp_send_json( $response ); | |
| 656 | 672 | } |
| 657 | 673 | |
| 658 | 674 | /** |
| 659 | 675 | * Filter chart setting. |