@@ -73,6 +73,7 @@ public function registerAdminMenu() {
7373 }
7474 }
7575
76+
7677 /**
7778 * Method to register the setup wizard page.
7879 *
@@ -168,7 +169,7 @@ public function dismissWizard( $redirect_to_dashboard = true ) {
168169 */
169170 public function visualizer_wizard_step_process () {
170171 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 ;
172173 switch ( $ step ) {
173174 case 'step_2 ' :
174175 $ this ->setup_wizard_import_chart ();
@@ -193,7 +194,7 @@ public function visualizer_wizard_step_process() {
193194 */
194195 private function setup_wizard_import_chart () {
195196 // 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 ' ] ) ) : '' ;
197198 $ chart_status = Visualizer_Module_Admin::checkChartStatus ( $ chart_type );
198199 if ( ! $ chart_status ) {
199200 wp_send_json (
@@ -386,7 +387,8 @@ private function setup_wizard_import_chart() {
386387 );
387388 $ this ->update_wizard_data ( $ wizard_data , false );
388389 $ response = array (
389- 'success ' => 1 ,
390+ 'success ' => 1 ,
391+ 'chart_id ' => $ chart_id ,
390392 );
391393 }
392394 wp_send_json ( $ response );
@@ -416,7 +418,7 @@ private function update_wizard_data( $data = array(), $merge_option = true ) {
416418 private function setup_wizard_create_draft_page ( $ return_page_id = false ) {
417419 $ add_basic_shortcode = ! empty ( $ _POST ['add_basic_shortcode ' ] ) ? sanitize_text_field ( wp_unslash ( $ _POST ['add_basic_shortcode ' ] ) ) : '' ; // phpcs:ignore WordPress.Security.NonceVerification.Missing
418420 $ 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
420422
421423 if ( ! $ add_basic_shortcode ) {
422424 wp_send_json (
@@ -476,7 +478,7 @@ private function setup_wizard_create_draft_page( $return_page_id = false ) {
476478 */
477479 private function setup_wizard_install_plugin () {
478480 // 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 ' ] ) ) : '' ;
480482 if ( empty ( $ slug ) ) {
481483 wp_send_json (
482484 array (
@@ -496,8 +498,10 @@ private function setup_wizard_install_plugin() {
496498 }
497499
498500 if ( ! empty ( $ slug ) ) {
501+ $ wizard_data = get_option ( self ::OPTION_NAME , array () );
499502 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php ' ;
500503 include_once ABSPATH . 'wp-admin/includes/plugin-install.php ' ;
504+ require_once ABSPATH . 'wp-admin/includes/plugin.php ' ;
501505
502506 $ api = plugins_api (
503507 'plugin_information ' ,
@@ -559,11 +563,34 @@ private function setup_wizard_install_plugin() {
559563 wp_send_json ( $ status );
560564 }
561565
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+ update_option ( 'themeisle_blocks_settings_onboarding ' , false );
584+ }
585+ if ( 'wp-cloudflare-page-cache ' === $ slug ) {
586+ // Update wizard data.
587+ $ wizard_data ['enable_page_cache ' ] = true ;
588+ $ wizard_data_updated = true ;
589+ update_option ( 'swcfpc_dashboard_redirect ' , false );
590+ }
591+ if ( $ wizard_data_updated ) {
592+ $ this ->update_wizard_data ( $ wizard_data );
593+ }
567594
568595 wp_send_json (
569596 array (
@@ -614,16 +641,17 @@ private function setup_wizard_subscribe_process() {
614641 }
615642
616643 if ( $ with_subscribe && is_email ( $ email ) ) {
617- $ request_res = wp_remote_post (
644+ wp_remote_post (
618645 VISUALIZER_SUBSCRIBE_API ,
619646 array (
620- 'timeout ' => 100 ,
621- 'headers ' => array (
647+ 'timeout ' => 5 ,
648+ 'blocking ' => false ,
649+ 'headers ' => array (
622650 'Content-Type ' => 'application/json ' ,
623651 'Cache-Control ' => 'no-cache ' ,
624652 'Accept ' => 'application/json, */*;q=0.1 ' ,
625653 ),
626- 'body ' => wp_json_encode (
654+ 'body ' => wp_json_encode (
627655 array (
628656 'slug ' => 'visualizer ' ,
629657 'site ' => home_url (),
@@ -635,24 +663,10 @@ private function setup_wizard_subscribe_process() {
635663 ),
636664 )
637665 );
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 );
655666 }
667+
668+ $ this ->dismissWizard ( false );
669+ wp_send_json ( $ response );
656670 }
657671
658672 /**
0 commit comments