| @@ -38,9 +38,9 @@ | ||
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * The current step. |
| 41 | 41 | * |
| 42 | - * @var string | |
| 42 | + * @var string|null | |
| 43 | 43 | */ |
| 44 | 44 | protected $step; |
| 45 | 45 | |
| 46 | 46 | /** |
| @@ -60,9 +60,9 @@ | ||
| 60 | 60 | $this->options = &$polylang->options; |
| 61 | 61 | $this->model = &$polylang->model; |
| 62 | 62 | |
| 63 | 63 | // Display Wizard page before any other action to ensure displaying it outside the WordPress admin context. |
| 64 | - // Hooked on admin_init with priority 40 to ensure PLL_Wizard_Pro is corretly initialized. | |
| 64 | + // Hooked on admin_init with priority 40 to ensure PLL_Wizard_Pro is correctly initialized. | |
| 65 | 65 | add_action( 'admin_init', array( $this, 'setup_wizard_page' ), 40 ); |
| 66 | 66 | // Add Wizard submenu. |
| 67 | 67 | add_filter( 'pll_settings_tabs', array( $this, 'settings_tabs' ), 10, 1 ); |
| 68 | 68 | // Add filter to select screens where to display the notice. |
| @@ -202,16 +202,16 @@ | ||
| 202 | 202 | $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification |
| 203 | 203 | |
| 204 | 204 | $this->step = $step && array_key_exists( $step, $this->steps ) ? $step : current( array_keys( $this->steps ) ); |
| 205 | 205 | |
| 206 | - $languages = $this->model->get_languages_list(); | |
| 206 | + $has_languages = $this->model->has_languages(); | |
| 207 | 207 | |
| 208 | - if ( count( $languages ) === 0 && ! in_array( $this->step, array( 'licenses', 'languages' ) ) ) { | |
| 208 | + if ( ! $has_languages && ! in_array( $this->step, array( 'licenses', 'languages' ) ) ) { | |
| 209 | 209 | wp_safe_redirect( esc_url_raw( $this->get_step_link( 'languages' ) ) ); |
| 210 | 210 | exit; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( count( $languages ) > 0 && $this->model->get_objects_with_no_lang( 1 ) && ! in_array( $this->step, array( 'licenses', 'languages', 'media', 'untranslated-contents' ) ) ) { | |
| 213 | + if ( $has_languages && $this->model->get_objects_with_no_lang( 1 ) && ! in_array( $this->step, array( 'licenses', 'languages', 'media', 'untranslated-contents' ) ) ) { | |
| 214 | 214 | wp_safe_redirect( esc_url_raw( $this->get_step_link( 'untranslated-contents' ) ) ); |
| 215 | 215 | exit; |
| 216 | 216 | } |
| 217 | 217 | |
| @@ -270,9 +270,9 @@ | ||
| 270 | 270 | * |
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | 273 | public function display_wizard_page() { |
| 274 | - set_current_screen(); | |
| 274 | + set_current_screen( 'pll-wizard' ); | |
| 275 | 275 | include __DIR__ . '/view-wizard-page.php'; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
| @@ -282,10 +282,10 @@ | ||
| 282 | 282 | * |
| 283 | 283 | * @return void |
| 284 | 284 | */ |
| 285 | 285 | public function enqueue_scripts() { |
| 286 | - wp_enqueue_style( 'polylang_admin', plugins_url( '/css/build/admin' . $this->get_suffix() . '.css', POLYLANG_BASENAME ), array(), POLYLANG_VERSION ); | |
| 287 | - wp_enqueue_style( 'pll-wizard', plugins_url( '/css/build/wizard' . $this->get_suffix() . '.css', POLYLANG_BASENAME ), array( 'dashicons', 'install', 'common', 'forms' ), POLYLANG_VERSION ); | |
| 286 | + wp_enqueue_style( 'polylang_admin', plugins_url( '/css/build/admin' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array(), POLYLANG_VERSION ); | |
| 287 | + wp_enqueue_style( 'pll-wizard', plugins_url( '/css/build/wizard' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array( 'dashicons', 'install', 'common', 'forms' ), POLYLANG_VERSION ); | |
| 288 | 288 | |
| 289 | 289 | $this->styles = array( 'polylang_admin', 'pll-wizard' ); |
| 290 | 290 | } |
| 291 | 291 | |
| @@ -364,11 +364,11 @@ | ||
| 364 | 364 | public function add_step_licenses( $steps ) { |
| 365 | 365 | // Add ajax action on deactivate button in licenses step. |
| 366 | 366 | add_action( 'wp_ajax_pll_deactivate_license', array( $this, 'deactivate_license' ) ); |
| 367 | 367 | |
| 368 | - // Be careful pll_admin script is enqueued here without depedency except jquery because only code useful for deactivate license button is needed. | |
| 368 | + // Be careful pll_admin script is enqueued here without dependency except jquery because only code useful for deactivate license button is needed. | |
| 369 | 369 | // To be really loaded the script need to be passed to the $steps['licenses']['scripts'] array below with the same handle than in wp_enqueue_script(). |
| 370 | - wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_BASENAME ), array( 'jquery' ), POLYLANG_VERSION, true ); | |
| 370 | + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION, true ); | |
| 371 | 371 | wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); |
| 372 | 372 | |
| 373 | 373 | if ( $this->is_licenses_step_displayable() ) { |
| 374 | 374 | $steps['licenses'] = array( |
| @@ -465,13 +465,13 @@ | ||
| 465 | 465 | * @return array List of steps updated. |
| 466 | 466 | */ |
| 467 | 467 | public function add_step_languages( $steps ) { |
| 468 | 468 | wp_deregister_script( 'pll_admin' ); // Deregister after the licenses step enqueue to update jquery-ui-selectmenu dependency. |
| 469 | - // The wp-ajax-response and postbox dependencies is useless in wizard steps espacially postbox which triggers a javascript error otherwise. | |
| 469 | + // The wp-ajax-response and postbox dependencies is useless in wizard steps especially postbox which triggers a javascript error otherwise. | |
| 470 | 470 | // To be really loaded the script need to be passed to the $steps['languages']['scripts'] array below with the same handle than in wp_enqueue_script(). |
| 471 | - wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_BASENAME ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 471 | + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 472 | 472 | wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); |
| 473 | - wp_register_script( 'pll-wizard-languages', plugins_url( '/js/build/languages-step' . $this->get_suffix() . '.js', POLYLANG_BASENAME ), array( 'jquery', 'jquery-ui-dialog' ), POLYLANG_VERSION, true ); | |
| 473 | + wp_register_script( 'pll-wizard-languages', plugins_url( '/js/build/languages-step' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'jquery-ui-dialog' ), POLYLANG_VERSION, true ); | |
| 474 | 474 | wp_localize_script( |
| 475 | 475 | 'pll-wizard-languages', |
| 476 | 476 | 'pll_wizard_params', |
| 477 | 477 | array( |
| @@ -492,9 +492,9 @@ | ||
| 492 | 492 | 'i18n_remove_language_icon' => esc_html__( 'Remove this language', 'polylang' ), |
| 493 | 493 | ) |
| 494 | 494 | ); |
| 495 | 495 | wp_enqueue_script( 'pll-wizard-languages' ); |
| 496 | - wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/build/selectmenu' . $this->get_suffix() . '.css', POLYLANG_BASENAME ), array( 'dashicons', 'install', 'common', 'wp-jquery-ui-dialog' ), POLYLANG_VERSION ); | |
| 496 | + wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/build/selectmenu' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array( 'dashicons', 'install', 'common', 'wp-jquery-ui-dialog' ), POLYLANG_VERSION ); | |
| 497 | 497 | $steps['languages'] = array( |
| 498 | 498 | 'name' => esc_html__( 'Languages', 'polylang' ), |
| 499 | 499 | 'view' => array( $this, 'display_step_languages' ), |
| 500 | 500 | 'handler' => array( $this, 'save_step_languages' ), |
| @@ -524,16 +524,14 @@ | ||
| 524 | 524 | */ |
| 525 | 525 | public function save_step_languages() { |
| 526 | 526 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 527 | 527 | |
| 528 | - $existing_languages = $this->model->get_languages_list(); | |
| 529 | - | |
| 530 | - $all_languages = include POLYLANG_DIR . '/settings/languages.php'; | |
| 531 | - $languages = isset( $_POST['languages'] ) && is_array( $_POST['languages'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['languages'] ) ) : false; | |
| 528 | + $all_languages = include POLYLANG_DIR . '/settings/languages.php'; | |
| 529 | + $languages = isset( $_POST['languages'] ) && is_array( $_POST['languages'] ) ? array_map( 'sanitize_locale_name', $_POST['languages'] ) : false; | |
| 532 | 530 | $saved_languages = array(); |
| 533 | 531 | |
| 534 | 532 | // If there is no language added or defined. |
| 535 | - if ( empty( $languages ) && empty( $existing_languages ) ) { | |
| 533 | + if ( empty( $languages ) && ! $this->model->has_languages() ) { | |
| 536 | 534 | // Stay on this step with an error. |
| 537 | 535 | wp_safe_redirect( |
| 538 | 536 | esc_url_raw( |
| 539 | 537 | add_query_arg( |
| @@ -655,14 +653,14 @@ | ||
| 655 | 653 | * @param array $steps List of steps. |
| 656 | 654 | * @return array List of steps updated. |
| 657 | 655 | */ |
| 658 | 656 | public function add_step_untranslated_contents( $steps ) { |
| 659 | - if ( ! $this->model->get_languages_list() || $this->model->get_objects_with_no_lang( 1 ) ) { | |
| 657 | + if ( ! $this->model->has_languages() || $this->model->get_objects_with_no_lang( 1 ) ) { | |
| 660 | 658 | // Even if pll_admin is already enqueued with the same dependencies by the languages step, it is interesting to keep that it's also useful for the untranslated-contents step. |
| 661 | 659 | // To be really loaded the script need to be passed to the $steps['untranslated-contents']['scripts'] array below with the same handle than in wp_enqueue_script(). |
| 662 | - wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_BASENAME ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 660 | + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 663 | 661 | wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); |
| 664 | - wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/build/selectmenu' . $this->get_suffix() . '.css', POLYLANG_BASENAME ), array( 'dashicons', 'install', 'common' ), POLYLANG_VERSION ); | |
| 662 | + wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/build/selectmenu' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array( 'dashicons', 'install', 'common' ), POLYLANG_VERSION ); | |
| 665 | 663 | $steps['untranslated-contents'] = array( |
| 666 | 664 | 'name' => esc_html__( 'Content', 'polylang' ), |
| 667 | 665 | 'view' => array( $this, 'display_step_untranslated_contents' ), |
| 668 | 666 | 'handler' => array( $this, 'save_step_untranslated_contents' ), |
| @@ -693,9 +691,9 @@ | ||
| 693 | 691 | */ |
| 694 | 692 | public function save_step_untranslated_contents() { |
| 695 | 693 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 696 | 694 | |
| 697 | - $lang = isset( $_POST['language'] ) ? sanitize_text_field( wp_unslash( $_POST['language'] ) ) : false; | |
| 695 | + $lang = ! empty( $_POST['language'] ) && is_string( $_POST['language'] ) ? sanitize_locale_name( $_POST['language'] ) : false; | |
| 698 | 696 | |
| 699 | 697 | if ( empty( $lang ) ) { |
| 700 | 698 | $lang = $this->options['default_lang']; |
| 701 | 699 | } |
| @@ -701,15 +699,10 @@ | ||
| 701 | 699 | } |
| 702 | 700 | |
| 703 | 701 | $language = $this->model->get_language( $lang ); |
| 704 | 702 | |
| 705 | - while ( $nolang = $this->model->get_objects_with_no_lang( 1000 ) ) { | |
| 706 | - if ( ! empty( $nolang['posts'] ) ) { | |
| 707 | - $this->model->set_language_in_mass( 'post', $nolang['posts'], $language->slug ); | |
| 708 | - } | |
| 709 | - if ( ! empty( $nolang['terms'] ) ) { | |
| 710 | - $this->model->set_language_in_mass( 'term', $nolang['terms'], $language->slug ); | |
| 711 | - } | |
| 703 | + if ( $language instanceof PLL_Language ) { | |
| 704 | + $this->model->set_language_in_mass( $language ); | |
| 712 | 705 | } |
| 713 | 706 | |
| 714 | 707 | wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 715 | 708 | exit; |
| @@ -761,11 +754,9 @@ | ||
| 761 | 754 | */ |
| 762 | 755 | public function save_step_home_page() { |
| 763 | 756 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 764 | 757 | |
| 765 | - $languages = $this->model->get_languages_list(); | |
| 766 | - | |
| 767 | - $default_language = count( $languages ) > 0 ? $this->options['default_lang'] : null; | |
| 758 | + $default_language = $this->model->has_languages() ? $this->options['default_lang'] : null; | |
| 768 | 759 | $home_page = isset( $_POST['home_page'] ) ? sanitize_key( $_POST['home_page'] ) : false; |
| 769 | 760 | $home_page_title = isset( $_POST['home_page_title'] ) ? sanitize_text_field( wp_unslash( $_POST['home_page_title'] ) ) : esc_html__( 'Homepage', 'polylang' ); |
| 770 | 761 | $home_page_language = isset( $_POST['home_page_language'] ) ? sanitize_key( $_POST['home_page_language'] ) : false; |
| 771 | 762 | |