| @@ -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 |
| @@ -151,8 +152,14 @@ | ||
| 151 | 152 | * @param bool $redirect_to_dashboard Redirect to dashboard. |
| 152 | 153 | * @return bool|void |
| 153 | 154 | */ |
| 154 | 155 | 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 | + } | |
| 155 | 162 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 156 | 163 | $status = isset( $_REQUEST['status'] ) ? (int) $_REQUEST['status'] : 0; |
| 157 | 164 | update_option( 'visualizer_fresh_install', $status ); |
| 158 | 165 | delete_option( 'visualizer_wizard_data' ); |
| @@ -167,9 +174,12 @@ | ||
| 167 | 174 | * Setup wizard process. |
| 168 | 175 | */ |
| 169 | 176 | public function visualizer_wizard_step_process() { |
| 170 | 177 | check_ajax_referer( VISUALIZER_ABSPATH, 'security' ); |
| 171 | - $step = ! empty( $_POST['step'] ) ? filter_input( INPUT_POST, 'step', FILTER_SANITIZE_STRING ) : 1; | |
| 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; | |
| 172 | 182 | switch ( $step ) { |
| 173 | 183 | case 'step_2': |
| 174 | 184 | $this->setup_wizard_import_chart(); |
| 175 | 185 | break; |
| @@ -192,9 +202,9 @@ | ||
| 192 | 202 | * Step: 2 import chart. |
| 193 | 203 | */ |
| 194 | 204 | private function setup_wizard_import_chart() { |
| 195 | 205 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 196 | - $chart_type = ! empty( $_POST['chart_type'] ) ? filter_input( INPUT_POST, 'chart_type', FILTER_SANITIZE_STRING ) : ''; | |
| 206 | + $chart_type = ! empty( $_POST['chart_type'] ) ? sanitize_text_field( wp_unslash( $_POST['chart_type'] ) ) : ''; | |
| 197 | 207 | $chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type ); |
| 198 | 208 | if ( ! $chart_status ) { |
| 199 | 209 | wp_send_json( |
| 200 | 210 | array( |
| @@ -211,14 +221,15 @@ | ||
| 211 | 221 | 'success' => 2, |
| 212 | 222 | 'message' => __( 'Something went wrong while importing the chart', 'visualizer' ), |
| 213 | 223 | ); |
| 214 | 224 | |
| 225 | + $data = $source->getData(); | |
| 215 | 226 | $args = array( |
| 216 | 227 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 217 | 228 | 'post_title' => 'Visualization', |
| 218 | 229 | 'post_author' => get_current_user_id(), |
| 219 | 230 | 'post_status' => 'publish', |
| 220 | - 'post_content' => $source->getData(), | |
| 231 | + 'post_content' => $data, | |
| 221 | 232 | ); |
| 222 | 233 | $chart_id = wp_insert_post( $args ); |
| 223 | 234 | |
| 224 | 235 | if ( $chart_id && ! is_wp_error( $chart_id ) ) { |
| @@ -231,10 +242,12 @@ | ||
| 231 | 242 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 232 | 243 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $series ); |
| 233 | 244 | update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' ); |
| 234 | 245 | |
| 246 | + $data = Visualizer_Module::decode_content( $data ); | |
| 235 | 247 | $setting_series = array(); |
| 236 | - foreach ( $series as $s ) { | |
| 248 | + $setting_slices = array(); | |
| 249 | + foreach ( $data as $s ) { | |
| 237 | 250 | $setting_series[] = array( |
| 238 | 251 | 'visibleInLegend' => '', |
| 239 | 252 | 'lineWidth' => '', |
| 240 | 253 | 'pointSize' => '', |
| @@ -242,8 +255,12 @@ | ||
| 242 | 255 | 'curveType' => '', |
| 243 | 256 | 'color' => '', |
| 244 | 257 | 'role' => '', |
| 245 | 258 | ); |
| 259 | + $setting_slices[] = array( | |
| 260 | + 'offset' => 0, | |
| 261 | + 'color' => '', | |
| 262 | + ); | |
| 246 | 263 | } |
| 247 | 264 | update_post_meta( |
| 248 | 265 | $chart_id, |
| 249 | 266 | Visualizer_Plugin::CF_SETTINGS, |
| @@ -288,9 +305,9 @@ | ||
| 288 | 305 | 'height' => '', |
| 289 | 306 | ), |
| 290 | 307 | 'focusTarget' => 'datum', |
| 291 | 308 | 'series' => $setting_series, |
| 292 | - 'slices' => array(), | |
| 309 | + 'slices' => $setting_slices, | |
| 293 | 310 | 'vAxis' => array( |
| 294 | 311 | 'title' => '', |
| 295 | 312 | 'textPosition' => '', |
| 296 | 313 | 'direction' => 1, |
| @@ -333,8 +350,45 @@ | ||
| 333 | 350 | 'max' => '', |
| 334 | 351 | 'min' => '', |
| 335 | 352 | ), |
| 336 | 353 | ), |
| 354 | + 'customcss' => array( | |
| 355 | + 'headerRow' => array( | |
| 356 | + 'background-color' => '', | |
| 357 | + 'color' => '', | |
| 358 | + 'transform' => '', | |
| 359 | + ), | |
| 360 | + 'tableRow' => array( | |
| 361 | + 'background-color' => '', | |
| 362 | + 'color' => '', | |
| 363 | + 'transform' => '', | |
| 364 | + ), | |
| 365 | + 'oddTableRow' => array( | |
| 366 | + 'background-color' => '', | |
| 367 | + 'color' => '', | |
| 368 | + 'transform' => '', | |
| 369 | + ), | |
| 370 | + 'selectedTableRow' => array( | |
| 371 | + 'background-color' => '', | |
| 372 | + 'color' => '', | |
| 373 | + 'transform' => '', | |
| 374 | + ), | |
| 375 | + 'hoverTableRow' => array( | |
| 376 | + 'background-color' => '', | |
| 377 | + 'color' => '', | |
| 378 | + 'transform' => '', | |
| 379 | + ), | |
| 380 | + 'headerCell' => array( | |
| 381 | + 'background-color' => '', | |
| 382 | + 'color' => '', | |
| 383 | + 'transform' => '', | |
| 384 | + ), | |
| 385 | + 'tableCell' => array( | |
| 386 | + 'background-color' => '', | |
| 387 | + 'color' => '', | |
| 388 | + 'transform' => '', | |
| 389 | + ), | |
| 390 | + ), | |
| 337 | 391 | ) |
| 338 | 392 | ); |
| 339 | 393 | $wizard_data = array( |
| 340 | 394 | 'chart_type' => $chart_type, |
| @@ -341,9 +395,10 @@ | ||
| 341 | 395 | 'chart_id' => $chart_id, |
| 342 | 396 | ); |
| 343 | 397 | $this->update_wizard_data( $wizard_data, false ); |
| 344 | 398 | $response = array( |
| 345 | - 'success' => 1, | |
| 399 | + 'success' => 1, | |
| 400 | + 'chart_id' => $chart_id, | |
| 346 | 401 | ); |
| 347 | 402 | } |
| 348 | 403 | wp_send_json( $response ); |
| 349 | 404 | exit; |
| @@ -371,9 +426,9 @@ | ||
| 371 | 426 | */ |
| 372 | 427 | private function setup_wizard_create_draft_page( $return_page_id = false ) { |
| 373 | 428 | $add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 374 | 429 | $add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false; |
| 375 | - $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? filter_input( INPUT_POST, 'basic_shortcode', FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 430 | + $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 376 | 431 | |
| 377 | 432 | if ( ! $add_basic_shortcode ) { |
| 378 | 433 | wp_send_json( |
| 379 | 434 | array( |
| @@ -431,9 +486,9 @@ | ||
| 431 | 486 | * Step: 3 Install plugin. |
| 432 | 487 | */ |
| 433 | 488 | private function setup_wizard_install_plugin() { |
| 434 | 489 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 435 | - $slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : ''; | |
| 490 | + $slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | |
| 436 | 491 | if ( empty( $slug ) ) { |
| 437 | 492 | wp_send_json( |
| 438 | 493 | array( |
| 439 | 494 | 'status' => 0, |
| @@ -451,10 +506,12 @@ | ||
| 451 | 506 | ); |
| 452 | 507 | } |
| 453 | 508 | |
| 454 | 509 | if ( ! empty( $slug ) ) { |
| 510 | + $wizard_data = get_option( self::OPTION_NAME, array() ); | |
| 455 | 511 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 456 | 512 | include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 513 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 457 | 514 | |
| 458 | 515 | $api = plugins_api( |
| 459 | 516 | 'plugin_information', |
| 460 | 517 | array( |
| @@ -514,13 +571,38 @@ | ||
| 514 | 571 | |
| 515 | 572 | wp_send_json( $status ); |
| 516 | 573 | } |
| 517 | 574 | |
| 518 | - activate_plugin( 'optimole-wp/optimole-wp.php' ); | |
| 519 | - delete_transient( 'optml_fresh_install' ); | |
| 520 | - // Update wizard data. | |
| 521 | - $wizard_data['enable_perfomance'] = true; | |
| 522 | - $this->update_wizard_data( $wizard_data ); | |
| 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 | + } | |
| 523 | 605 | |
| 524 | 606 | wp_send_json( |
| 525 | 607 | array( |
| 526 | 608 | 'status' => 1, |
| @@ -569,18 +651,19 @@ | ||
| 569 | 651 | ); |
| 570 | 652 | } |
| 571 | 653 | |
| 572 | 654 | if ( $with_subscribe && is_email( $email ) ) { |
| 573 | - $request_res = wp_remote_post( | |
| 655 | + wp_remote_post( | |
| 574 | 656 | VISUALIZER_SUBSCRIBE_API, |
| 575 | 657 | array( |
| 576 | - 'timeout' => 100, | |
| 577 | - 'headers' => array( | |
| 658 | + 'timeout' => 5, | |
| 659 | + 'blocking' => false, | |
| 660 | + 'headers' => array( | |
| 578 | 661 | 'Content-Type' => 'application/json', |
| 579 | 662 | 'Cache-Control' => 'no-cache', |
| 580 | 663 | 'Accept' => 'application/json, */*;q=0.1', |
| 581 | 664 | ), |
| 582 | - 'body' => wp_json_encode( | |
| 665 | + 'body' => wp_json_encode( | |
| 583 | 666 | array( |
| 584 | 667 | 'slug' => 'visualizer', |
| 585 | 668 | 'site' => home_url(), |
| 586 | 669 | 'email' => $email, |
| @@ -590,26 +673,12 @@ | ||
| 590 | 673 | ) |
| 591 | 674 | ), |
| 592 | 675 | ) |
| 593 | 676 | ); |
| 594 | - if ( ! is_wp_error( $request_res ) ) { | |
| 595 | - $body = json_decode( wp_remote_retrieve_body( $request_res ) ); | |
| 596 | - if ( 'success' === $body->code ) { | |
| 597 | - $this->dismissWizard( false ); | |
| 598 | - wp_send_json( $response ); | |
| 599 | - } | |
| 600 | - } | |
| 601 | - wp_send_json( | |
| 602 | - array( | |
| 603 | - 'status' => 0, | |
| 604 | - 'redirect_to' => '', | |
| 605 | - 'message' => '', | |
| 606 | - ) | |
| 607 | - ); | |
| 608 | - } else { | |
| 609 | - $this->dismissWizard( false ); | |
| 610 | - wp_send_json( $response ); | |
| 611 | 677 | } |
| 678 | + | |
| 679 | + $this->dismissWizard( false ); | |
| 680 | + wp_send_json( $response ); | |
| 612 | 681 | } |
| 613 | 682 | |
| 614 | 683 | /** |
| 615 | 684 | * Filter chart setting. |