| @@ -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 |
| @@ -152,14 +151,8 @@ | ||
| 152 | 151 | * @param bool $redirect_to_dashboard Redirect to dashboard. |
| 153 | 152 | * @return bool|void |
| 154 | 153 | */ |
| 155 | 154 | public function dismissWizard( $redirect_to_dashboard = true ) { |
| 156 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 157 | - wp_die( esc_html__( 'You do not have permission to perform this action.', 'visualizer' ), '', array( 'response' => 403 ) ); | |
| 158 | - } | |
| 159 | - if ( false !== $redirect_to_dashboard ) { | |
| 160 | - check_admin_referer( 'visualizer_dismiss_wizard' ); | |
| 161 | - } | |
| 162 | 155 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 163 | 156 | $status = isset( $_REQUEST['status'] ) ? (int) $_REQUEST['status'] : 0; |
| 164 | 157 | update_option( 'visualizer_fresh_install', $status ); |
| 165 | 158 | delete_option( 'visualizer_wizard_data' ); |
| @@ -174,12 +167,9 @@ | ||
| 174 | 167 | * Setup wizard process. |
| 175 | 168 | */ |
| 176 | 169 | public function visualizer_wizard_step_process() { |
| 177 | 170 | check_ajax_referer( VISUALIZER_ABSPATH, 'security' ); |
| 178 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 179 | - wp_send_json( array( 'status' => 0 ), 403 ); | |
| 180 | - } | |
| 181 | - $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; | |
| 182 | 172 | switch ( $step ) { |
| 183 | 173 | case 'step_2': |
| 184 | 174 | $this->setup_wizard_import_chart(); |
| 185 | 175 | break; |
| @@ -202,9 +192,9 @@ | ||
| 202 | 192 | * Step: 2 import chart. |
| 203 | 193 | */ |
| 204 | 194 | private function setup_wizard_import_chart() { |
| 205 | 195 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 206 | - $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 ) : ''; | |
| 207 | 197 | $chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type ); |
| 208 | 198 | if ( ! $chart_status ) { |
| 209 | 199 | wp_send_json( |
| 210 | 200 | array( |
| @@ -242,9 +232,9 @@ | ||
| 242 | 232 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 243 | 233 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $series ); |
| 244 | 234 | update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' ); |
| 245 | 235 | |
| 246 | - $data = Visualizer_Module::decode_content( $data ); | |
| 236 | + $data = maybe_unserialize( $data ); | |
| 247 | 237 | $setting_series = array(); |
| 248 | 238 | $setting_slices = array(); |
| 249 | 239 | foreach ( $data as $s ) { |
| 250 | 240 | $setting_series[] = array( |
| @@ -395,10 +385,9 @@ | ||
| 395 | 385 | 'chart_id' => $chart_id, |
| 396 | 386 | ); |
| 397 | 387 | $this->update_wizard_data( $wizard_data, false ); |
| 398 | 388 | $response = array( |
| 399 | - 'success' => 1, | |
| 400 | - 'chart_id' => $chart_id, | |
| 389 | + 'success' => 1, | |
| 401 | 390 | ); |
| 402 | 391 | } |
| 403 | 392 | wp_send_json( $response ); |
| 404 | 393 | exit; |
| @@ -426,9 +415,9 @@ | ||
| 426 | 415 | */ |
| 427 | 416 | private function setup_wizard_create_draft_page( $return_page_id = false ) { |
| 428 | 417 | $add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 429 | 418 | $add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false; |
| 430 | - $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 | |
| 431 | 420 | |
| 432 | 421 | if ( ! $add_basic_shortcode ) { |
| 433 | 422 | wp_send_json( |
| 434 | 423 | array( |
| @@ -486,9 +475,9 @@ | ||
| 486 | 475 | * Step: 3 Install plugin. |
| 487 | 476 | */ |
| 488 | 477 | private function setup_wizard_install_plugin() { |
| 489 | 478 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 490 | - $slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 479 | + $slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : ''; | |
| 491 | 480 | if ( empty( $slug ) ) { |
| 492 | 481 | wp_send_json( |
| 493 | 482 | array( |
| 494 | 483 | 'status' => 0, |
| @@ -506,12 +495,10 @@ | ||
| 506 | 495 | ); |
| 507 | 496 | } |
| 508 | 497 | |
| 509 | 498 | if ( ! empty( $slug ) ) { |
| 510 | - $wizard_data = get_option( self::OPTION_NAME, array() ); | |
| 511 | 499 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 512 | 500 | include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 513 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 514 | 501 | |
| 515 | 502 | $api = plugins_api( |
| 516 | 503 | 'plugin_information', |
| 517 | 504 | array( |
| @@ -571,38 +558,13 @@ | ||
| 571 | 558 | |
| 572 | 559 | wp_send_json( $status ); |
| 573 | 560 | } |
| 574 | 561 | |
| 575 | - $installed_plugins = get_plugins( '/' . sanitize_key( wp_unslash( $slug ) ) ); | |
| 576 | - if ( ! empty( $installed_plugins ) ) { | |
| 577 | - $plugin_files = array_keys( $installed_plugins ); | |
| 578 | - $plugin_file = sanitize_key( wp_unslash( $slug ) ) . '/' . $plugin_files[0]; | |
| 579 | - activate_plugin( $plugin_file ); | |
| 580 | - } | |
| 581 | - $wizard_data_updated = false; | |
| 582 | - if ( 'optimole-wp' === $slug ) { | |
| 583 | - delete_transient( 'optml_fresh_install' ); | |
| 584 | - // Update wizard data. | |
| 585 | - $wizard_data['enable_perfomance'] = true; | |
| 586 | - $wizard_data_updated = true; | |
| 587 | - } | |
| 588 | - if ( 'otter-blocks' === $slug ) { | |
| 589 | - // Update wizard data. | |
| 590 | - $wizard_data['enable_otter_blocks'] = true; | |
| 591 | - $wizard_data_updated = true; | |
| 592 | - // Suppress Otter's post-activation redirects so the user stays in Visualizer. | |
| 593 | - update_option( 'themeisle_blocks_settings_redirect', '0' ); | |
| 594 | - update_option( 'themeisle_blocks_settings_onboarding', '0' ); | |
| 595 | - } | |
| 596 | - if ( 'wp-cloudflare-page-cache' === $slug ) { | |
| 597 | - // Update wizard data. | |
| 598 | - $wizard_data['enable_page_cache'] = true; | |
| 599 | - $wizard_data_updated = true; | |
| 600 | - update_option( 'swcfpc_dashboard_redirect', false ); | |
| 601 | - } | |
| 602 | - if ( $wizard_data_updated ) { | |
| 603 | - $this->update_wizard_data( $wizard_data ); | |
| 604 | - } | |
| 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 ); | |
| 605 | 567 | |
| 606 | 568 | wp_send_json( |
| 607 | 569 | array( |
| 608 | 570 | 'status' => 1, |
| @@ -651,19 +613,18 @@ | ||
| 651 | 613 | ); |
| 652 | 614 | } |
| 653 | 615 | |
| 654 | 616 | if ( $with_subscribe && is_email( $email ) ) { |
| 655 | - wp_remote_post( | |
| 617 | + $request_res = wp_remote_post( | |
| 656 | 618 | VISUALIZER_SUBSCRIBE_API, |
| 657 | 619 | array( |
| 658 | - 'timeout' => 5, | |
| 659 | - 'blocking' => false, | |
| 660 | - 'headers' => array( | |
| 620 | + 'timeout' => 100, | |
| 621 | + 'headers' => array( | |
| 661 | 622 | 'Content-Type' => 'application/json', |
| 662 | 623 | 'Cache-Control' => 'no-cache', |
| 663 | 624 | 'Accept' => 'application/json, */*;q=0.1', |
| 664 | 625 | ), |
| 665 | - 'body' => wp_json_encode( | |
| 626 | + 'body' => wp_json_encode( | |
| 666 | 627 | array( |
| 667 | 628 | 'slug' => 'visualizer', |
| 668 | 629 | 'site' => home_url(), |
| 669 | 630 | 'email' => $email, |
| @@ -673,12 +634,26 @@ | ||
| 673 | 634 | ) |
| 674 | 635 | ), |
| 675 | 636 | ) |
| 676 | 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 ); | |
| 677 | 655 | } |
| 678 | - | |
| 679 | - $this->dismissWizard( false ); | |
| 680 | - wp_send_json( $response ); | |
| 681 | 656 | } |
| 682 | 657 | |
| 683 | 658 | /** |
| 684 | 659 | * Filter chart setting. |