| @@ -72,9 +72,8 @@ | ||
| 72 | 72 | add_action( "load-$hook", array( $this, 'visualizer_load_setup_wizard_page' ) ); |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - | |
| 77 | 76 | /** |
| 78 | 77 | * Method to register the setup wizard page. |
| 79 | 78 | * |
| 80 | 79 | * @access public |
| @@ -168,9 +167,9 @@ | ||
| 168 | 167 | * Setup wizard process. |
| 169 | 168 | */ |
| 170 | 169 | public function visualizer_wizard_step_process() { |
| 171 | 170 | check_ajax_referer( VISUALIZER_ABSPATH, 'security' ); |
| 172 | - $step = ! empty( $_POST['step'] ) ? sanitize_text_field( wp_unslash( $_POST['step'] ) ) : 1; | |
| 171 | + $step = ! empty( $_POST['step'] ) ? filter_input( INPUT_POST, 'step', FILTER_SANITIZE_STRING ) : 1; | |
| 173 | 172 | switch ( $step ) { |
| 174 | 173 | case 'step_2': |
| 175 | 174 | $this->setup_wizard_import_chart(); |
| 176 | 175 | break; |
| @@ -193,9 +192,9 @@ | ||
| 193 | 192 | * Step: 2 import chart. |
| 194 | 193 | */ |
| 195 | 194 | private function setup_wizard_import_chart() { |
| 196 | 195 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 197 | - $chart_type = ! empty( $_POST['chart_type'] ) ? sanitize_text_field( wp_unslash( $_POST['chart_type'] ) ) : ''; | |
| 196 | + $chart_type = ! empty( $_POST['chart_type'] ) ? filter_input( INPUT_POST, 'chart_type', FILTER_SANITIZE_STRING ) : ''; | |
| 198 | 197 | $chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type ); |
| 199 | 198 | if ( ! $chart_status ) { |
| 200 | 199 | wp_send_json( |
| 201 | 200 | array( |
| @@ -233,9 +232,9 @@ | ||
| 233 | 232 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 234 | 233 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $series ); |
| 235 | 234 | update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' ); |
| 236 | 235 | |
| 237 | - $data = Visualizer_Module::decode_content( $data ); | |
| 236 | + $data = maybe_unserialize( $data ); | |
| 238 | 237 | $setting_series = array(); |
| 239 | 238 | $setting_slices = array(); |
| 240 | 239 | foreach ( $data as $s ) { |
| 241 | 240 | $setting_series[] = array( |
| @@ -386,10 +385,9 @@ | ||
| 386 | 385 | 'chart_id' => $chart_id, |
| 387 | 386 | ); |
| 388 | 387 | $this->update_wizard_data( $wizard_data, false ); |
| 389 | 388 | $response = array( |
| 390 | - 'success' => 1, | |
| 391 | - 'chart_id' => $chart_id, | |
| 389 | + 'success' => 1, | |
| 392 | 390 | ); |
| 393 | 391 | } |
| 394 | 392 | wp_send_json( $response ); |
| 395 | 393 | exit; |
| @@ -417,9 +415,9 @@ | ||
| 417 | 415 | */ |
| 418 | 416 | private function setup_wizard_create_draft_page( $return_page_id = false ) { |
| 419 | 417 | $add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 420 | 418 | $add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false; |
| 421 | - $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 419 | + $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? filter_input( INPUT_POST, 'basic_shortcode', FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 422 | 420 | |
| 423 | 421 | if ( ! $add_basic_shortcode ) { |
| 424 | 422 | wp_send_json( |
| 425 | 423 | array( |
| @@ -477,9 +475,9 @@ | ||
| 477 | 475 | * Step: 3 Install plugin. |
| 478 | 476 | */ |
| 479 | 477 | private function setup_wizard_install_plugin() { |
| 480 | 478 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 481 | - $slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 479 | + $slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : ''; | |
| 482 | 480 | if ( empty( $slug ) ) { |
| 483 | 481 | wp_send_json( |
| 484 | 482 | array( |
| 485 | 483 | 'status' => 0, |
| @@ -497,12 +495,10 @@ | ||
| 497 | 495 | ); |
| 498 | 496 | } |
| 499 | 497 | |
| 500 | 498 | if ( ! empty( $slug ) ) { |
| 501 | - $wizard_data = get_option( self::OPTION_NAME, array() ); | |
| 502 | 499 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 503 | 500 | include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 504 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 505 | 501 | |
| 506 | 502 | $api = plugins_api( |
| 507 | 503 | 'plugin_information', |
| 508 | 504 | array( |
| @@ -562,38 +558,13 @@ | ||
| 562 | 558 | |
| 563 | 559 | wp_send_json( $status ); |
| 564 | 560 | } |
| 565 | 561 | |
| 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 | - } | |
| 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 ); | |
| 596 | 567 | |
| 597 | 568 | wp_send_json( |
| 598 | 569 | array( |
| 599 | 570 | 'status' => 1, |
| @@ -642,19 +613,18 @@ | ||
| 642 | 613 | ); |
| 643 | 614 | } |
| 644 | 615 | |
| 645 | 616 | if ( $with_subscribe && is_email( $email ) ) { |
| 646 | - wp_remote_post( | |
| 617 | + $request_res = wp_remote_post( | |
| 647 | 618 | VISUALIZER_SUBSCRIBE_API, |
| 648 | 619 | array( |
| 649 | - 'timeout' => 5, | |
| 650 | - 'blocking' => false, | |
| 651 | - 'headers' => array( | |
| 620 | + 'timeout' => 100, | |
| 621 | + 'headers' => array( | |
| 652 | 622 | 'Content-Type' => 'application/json', |
| 653 | 623 | 'Cache-Control' => 'no-cache', |
| 654 | 624 | 'Accept' => 'application/json, */*;q=0.1', |
| 655 | 625 | ), |
| 656 | - 'body' => wp_json_encode( | |
| 626 | + 'body' => wp_json_encode( | |
| 657 | 627 | array( |
| 658 | 628 | 'slug' => 'visualizer', |
| 659 | 629 | 'site' => home_url(), |
| 660 | 630 | 'email' => $email, |
| @@ -664,12 +634,26 @@ | ||
| 664 | 634 | ) |
| 665 | 635 | ), |
| 666 | 636 | ) |
| 667 | 637 | ); |
| 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 ); | |
| 668 | 655 | } |
| 669 | - | |
| 670 | - $this->dismissWizard( false ); | |
| 671 | - wp_send_json( $response ); | |
| 672 | 656 | } |
| 673 | 657 | |
| 674 | 658 | /** |
| 675 | 659 | * Filter chart setting. |