| @@ -9,46 +9,33 @@ | ||
| 9 | 9 | * @since 2.7 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Wizard { |
| 12 | 12 | /** |
| 13 | - * Reference to the model object | |
| 13 | + * Reference to PLL_Model object | |
| 14 | 14 | * |
| 15 | - * @var PLL_Admin_Model | |
| 15 | + * @var object $model | |
| 16 | 16 | */ |
| 17 | 17 | protected $model; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Reference to the Polylang options array. | |
| 20 | + * Reference to Polylang options array | |
| 21 | 21 | * |
| 22 | - * @var array | |
| 22 | + * @var array $options | |
| 23 | 23 | */ |
| 24 | 24 | protected $options; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * List of steps. | |
| 27 | + * List of steps | |
| 28 | 28 | * |
| 29 | - * @var array $steps { | |
| 30 | - * @type string $name I18n string which names the step. | |
| 31 | - * @type callable $view The callback function use to display the step content. | |
| 32 | - * @type callable $handler The callback function use to process the step after it is submitted. | |
| 33 | - * @type array $scripts List of scripts handle needed by the step. | |
| 34 | - * @type array $styles The list of styles handle needed by the step. | |
| 35 | - * } | |
| 29 | + * @var array $steps | |
| 36 | 30 | */ |
| 37 | 31 | protected $steps = array(); |
| 38 | 32 | |
| 39 | 33 | /** |
| 40 | - * The current step. | |
| 34 | + * List of WordPress CSS file handles | |
| 41 | 35 | * |
| 42 | - * @var string | |
| 36 | + * @var array $styles | |
| 43 | 37 | */ |
| 44 | - protected $step; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * List of WordPress CSS file handles. | |
| 48 | - * | |
| 49 | - * @var string[] | |
| 50 | - */ | |
| 51 | 38 | protected $styles = array(); |
| 52 | 39 | |
| 53 | 40 | /** |
| 54 | 41 | * Constructor |
| @@ -79,12 +66,10 @@ | ||
| 79 | 66 | |
| 80 | 67 | /** |
| 81 | 68 | * Save an activation transient when Polylang is activating to redirect to the wizard |
| 82 | 69 | * |
| 70 | + * @param bool $network_wide if activated for all sites in the network. | |
| 83 | 71 | * @since 2.7 |
| 84 | - * | |
| 85 | - * @param bool $network_wide if activated for all sites in the network. | |
| 86 | - * @return void | |
| 87 | 72 | */ |
| 88 | 73 | public static function start_wizard( $network_wide ) { |
| 89 | 74 | $options = get_option( 'polylang' ); |
| 90 | 75 | |
| @@ -97,10 +82,8 @@ | ||
| 97 | 82 | /** |
| 98 | 83 | * Redirect to the wizard depending on the context |
| 99 | 84 | * |
| 100 | 85 | * @since 2.7 |
| 101 | - * | |
| 102 | - * @return void | |
| 103 | 86 | */ |
| 104 | 87 | public function redirect_to_wizard() { |
| 105 | 88 | if ( get_transient( 'pll_activation_redirect' ) ) { |
| 106 | 89 | $do_redirect = true; |
| @@ -127,25 +110,23 @@ | ||
| 127 | 110 | |
| 128 | 111 | /** |
| 129 | 112 | * Add an admin Polylang submenu to access the wizard |
| 130 | 113 | * |
| 114 | + * @param array $tabs Submenus list. | |
| 115 | + * @return array Submenus list updated. | |
| 131 | 116 | * @since 2.7 |
| 132 | - * | |
| 133 | - * @param string[] $tabs Submenus list. | |
| 134 | - * @return string[] Submenus list updated. | |
| 135 | 117 | */ |
| 136 | 118 | public function settings_tabs( $tabs ) { |
| 137 | - $tabs['wizard'] = esc_html__( 'Setup', 'polylang' ); | |
| 119 | + $tabs['wizard'] = __( 'Setup', 'polylang' ); | |
| 138 | 120 | return $tabs; |
| 139 | 121 | } |
| 140 | 122 | |
| 141 | 123 | /** |
| 142 | - * Returns true if the media step is displayable, false otherwise. | |
| 124 | + * Return if the media step is displayable | |
| 143 | 125 | * |
| 126 | + * @param array $languages List of language objects. | |
| 127 | + * @return bool | |
| 144 | 128 | * @since 2.7 |
| 145 | - * | |
| 146 | - * @param PLL_Language[] $languages List of language objects. | |
| 147 | - * @return bool | |
| 148 | 129 | */ |
| 149 | 130 | public function is_media_step_displayable( $languages ) { |
| 150 | 131 | $media = array(); |
| 151 | 132 | // If there is no language or only one the media step is displayable. |
| @@ -166,11 +147,10 @@ | ||
| 166 | 147 | |
| 167 | 148 | /** |
| 168 | 149 | * Check if the licenses step is displayable |
| 169 | 150 | * |
| 151 | + * @return bool | |
| 170 | 152 | * @since 2.7 |
| 171 | - * | |
| 172 | - * @return bool | |
| 173 | 153 | */ |
| 174 | 154 | public function is_licenses_step_displayable() { |
| 175 | 155 | $licenses = apply_filters( 'pll_settings_licenses', array() ); |
| 176 | 156 | return count( $licenses ) > 0; |
| @@ -179,10 +159,8 @@ | ||
| 179 | 159 | /** |
| 180 | 160 | * Setup the wizard page |
| 181 | 161 | * |
| 182 | 162 | * @since 2.7 |
| 183 | - * | |
| 184 | - * @return void | |
| 185 | 163 | */ |
| 186 | 164 | public function setup_wizard_page() { |
| 187 | 165 | |
| 188 | 166 | PLL_Admin_Notices::add_notice( 'wizard', $this->wizard_notice() ); |
| @@ -228,18 +206,17 @@ | ||
| 228 | 206 | |
| 229 | 207 | /** |
| 230 | 208 | * Adds some admin screens where to display the wizard notice |
| 231 | 209 | * |
| 232 | - * @since 2.7 | |
| 233 | - * | |
| 234 | 210 | * @param bool $can_display_notice Whether the notice can be displayed. |
| 235 | 211 | * @param string $notice The notice name. |
| 236 | 212 | * @return bool |
| 213 | + * @since 2.7 | |
| 237 | 214 | */ |
| 238 | 215 | public function can_display_notice( $can_display_notice, $notice ) { |
| 239 | 216 | if ( ! $can_display_notice && 'wizard' === $notice ) { |
| 240 | 217 | $screen = get_current_screen(); |
| 241 | - $can_display_notice = ! empty( $screen ) && in_array( | |
| 218 | + $can_display_notice = in_array( | |
| 242 | 219 | $screen->base, |
| 243 | 220 | array( |
| 244 | 221 | 'edit', |
| 245 | 222 | 'upload', |
| @@ -253,10 +230,8 @@ | ||
| 253 | 230 | /** |
| 254 | 231 | * Return html code of the wizard notice |
| 255 | 232 | * |
| 256 | 233 | * @since 2.7 |
| 257 | - * | |
| 258 | - * @return string | |
| 259 | 234 | */ |
| 260 | 235 | public function wizard_notice() { |
| 261 | 236 | ob_start(); |
| 262 | 237 | include __DIR__ . '/html-wizard-notice.php'; |
| @@ -266,10 +241,8 @@ | ||
| 266 | 241 | /** |
| 267 | 242 | * Display the wizard page |
| 268 | 243 | * |
| 269 | 244 | * @since 2.7 |
| 270 | - * | |
| 271 | - * @return void | |
| 272 | 245 | */ |
| 273 | 246 | public function display_wizard_page() { |
| 274 | 247 | set_current_screen(); |
| 275 | 248 | include __DIR__ . '/view-wizard-page.php'; |
| @@ -278,14 +251,12 @@ | ||
| 278 | 251 | /** |
| 279 | 252 | * Enqueue scripts and styles for the wizard |
| 280 | 253 | * |
| 281 | 254 | * @since 2.7 |
| 282 | - * | |
| 283 | - * @return void | |
| 284 | 255 | */ |
| 285 | 256 | 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 ); | |
| 257 | + wp_enqueue_style( 'polylang_admin', plugins_url( '/css/admin' . $this->get_suffix() . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION ); | |
| 258 | + wp_enqueue_style( 'pll-wizard', plugins_url( '/modules/wizard/css/wizard' . $this->get_suffix() . '.css', POLYLANG_FILE ), array( 'dashicons', 'install', 'common', 'forms' ), POLYLANG_VERSION ); | |
| 288 | 259 | |
| 289 | 260 | $this->styles = array( 'polylang_admin', 'pll-wizard' ); |
| 290 | 261 | } |
| 291 | 262 | |
| @@ -291,12 +262,11 @@ | ||
| 291 | 262 | |
| 292 | 263 | /** |
| 293 | 264 | * Get the suffix to enqueue non minified files in a Debug context |
| 294 | 265 | * |
| 295 | - * @since 2.7 | |
| 296 | - * | |
| 297 | 266 | * @return string Empty when SCRIPT_DEBUG equal to true |
| 298 | 267 | * otherwise .min |
| 268 | + * @since 2.7 | |
| 299 | 269 | */ |
| 300 | 270 | public function get_suffix() { |
| 301 | 271 | return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 302 | 272 | } |
| @@ -303,13 +273,12 @@ | ||
| 303 | 273 | |
| 304 | 274 | /** |
| 305 | 275 | * Get the URL for the step's screen. |
| 306 | 276 | * |
| 307 | - * @since 2.7 | |
| 308 | - * | |
| 309 | 277 | * @param string $step slug (default: current step). |
| 310 | 278 | * @return string URL for the step if it exists. |
| 311 | 279 | * Empty string on failure. |
| 280 | + * @since 2.7 | |
| 312 | 281 | */ |
| 313 | 282 | public function get_step_link( $step = '' ) { |
| 314 | 283 | if ( ! $step ) { |
| 315 | 284 | $step = $this->step; |
| @@ -327,14 +296,13 @@ | ||
| 327 | 296 | |
| 328 | 297 | /** |
| 329 | 298 | * Get the URL for the next step's screen. |
| 330 | 299 | * |
| 331 | - * @since 2.7 | |
| 332 | - * | |
| 333 | 300 | * @param string $step slug (default: current step). |
| 334 | 301 | * @return string URL for next step if a next step exists. |
| 335 | 302 | * Admin URL if it's the last step. |
| 336 | 303 | * Empty string on failure. |
| 304 | + * @since 2.7 | |
| 337 | 305 | */ |
| 338 | 306 | public function get_next_step_link( $step = '' ) { |
| 339 | 307 | if ( ! $step ) { |
| 340 | 308 | $step = $this->step; |
| @@ -355,25 +323,20 @@ | ||
| 355 | 323 | |
| 356 | 324 | /** |
| 357 | 325 | * Add licenses step to the wizard |
| 358 | 326 | * |
| 359 | - * @since 2.7 | |
| 360 | - * | |
| 361 | 327 | * @param array $steps List of steps. |
| 362 | 328 | * @return array List of steps updated. |
| 329 | + * @since 2.7 | |
| 363 | 330 | */ |
| 364 | 331 | public function add_step_licenses( $steps ) { |
| 365 | 332 | // Add ajax action on deactivate button in licenses step. |
| 366 | 333 | add_action( 'wp_ajax_pll_deactivate_license', array( $this, 'deactivate_license' ) ); |
| 367 | 334 | |
| 368 | - // Be careful pll_admin script is enqueued here without depedency except jquery because only code useful for deactivate license button is needed. | |
| 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 ); | |
| 371 | - wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); | |
| 372 | - | |
| 335 | + wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $this->get_suffix() . '.js', POLYLANG_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 373 | 336 | if ( $this->is_licenses_step_displayable() ) { |
| 374 | 337 | $steps['licenses'] = array( |
| 375 | - 'name' => esc_html__( 'Licenses', 'polylang' ), | |
| 338 | + 'name' => __( 'Licenses', 'polylang' ), | |
| 376 | 339 | 'view' => array( $this, 'display_step_licenses' ), |
| 377 | 340 | 'handler' => array( $this, 'save_step_licenses' ), |
| 378 | 341 | 'scripts' => array( 'pll_admin' ), // Polylang admin script used by deactivate license button. |
| 379 | 342 | 'styles' => array(), |
| @@ -385,10 +348,8 @@ | ||
| 385 | 348 | /** |
| 386 | 349 | * Display the languages step form |
| 387 | 350 | * |
| 388 | 351 | * @since 2.7 |
| 389 | - * | |
| 390 | - * @return void | |
| 391 | 352 | */ |
| 392 | 353 | public function display_step_licenses() { |
| 393 | 354 | include __DIR__ . '/view-wizard-step-licenses.php'; |
| 394 | 355 | } |
| @@ -396,10 +357,8 @@ | ||
| 396 | 357 | /** |
| 397 | 358 | * Execute the languages step |
| 398 | 359 | * |
| 399 | 360 | * @since 2.7 |
| 400 | - * | |
| 401 | - * @return void | |
| 402 | 361 | */ |
| 403 | 362 | public function save_step_licenses() { |
| 404 | 363 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 405 | 364 | |
| @@ -428,10 +387,8 @@ | ||
| 428 | 387 | /** |
| 429 | 388 | * Ajax method to deactivate a license |
| 430 | 389 | * |
| 431 | 390 | * @since 2.7 |
| 432 | - * | |
| 433 | - * @return void | |
| 434 | 391 | */ |
| 435 | 392 | public function deactivate_license() { |
| 436 | 393 | check_ajax_referer( 'pll-wizard', '_pll_nonce' ); |
| 437 | 394 | |
| @@ -458,48 +415,43 @@ | ||
| 458 | 415 | |
| 459 | 416 | /** |
| 460 | 417 | * Add languages step to the wizard |
| 461 | 418 | * |
| 462 | - * @since 2.7 | |
| 463 | - * | |
| 464 | 419 | * @param array $steps List of steps. |
| 465 | 420 | * @return array List of steps updated. |
| 421 | + * @since 2.7 | |
| 466 | 422 | */ |
| 467 | 423 | public function add_step_languages( $steps ) { |
| 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. | |
| 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 ); | |
| 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 ); | |
| 424 | + wp_enqueue_script( 'pll-wizard-language-choice', plugins_url( '/js/admin' . $this->get_suffix() . '.js', POLYLANG_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 425 | + wp_register_script( 'pll-wizard-languages', plugins_url( '/modules/wizard/js/languages-step' . $this->get_suffix() . '.js', POLYLANG_FILE ), array( 'jquery', 'jquery-ui-dialog' ), POLYLANG_VERSION, true ); | |
| 474 | 426 | wp_localize_script( |
| 475 | 427 | 'pll-wizard-languages', |
| 476 | 428 | 'pll_wizard_params', |
| 477 | 429 | array( |
| 478 | - 'i18n_no_language_selected' => esc_html__( 'You need to select a language to be added.', 'polylang' ), | |
| 479 | - 'i18n_language_already_added' => esc_html__( 'You already added this language.', 'polylang' ), | |
| 480 | - 'i18n_no_language_added' => esc_html__( 'You need to add at least one language.', 'polylang' ), | |
| 481 | - 'i18n_add_language_needed' => esc_html__( 'You selected a language, however, to be able to continue, you need to add it.', 'polylang' ), | |
| 482 | - 'i18n_pll_add_language' => esc_html__( 'Impossible to add the language.', 'polylang' ), | |
| 483 | - 'i18n_pll_invalid_locale' => esc_html__( 'Enter a valid WordPress locale', 'polylang' ), | |
| 484 | - 'i18n_pll_invalid_slug' => esc_html__( 'The language code contains invalid characters', 'polylang' ), | |
| 485 | - 'i18n_pll_non_unique_slug' => esc_html__( 'The language code must be unique', 'polylang' ), | |
| 486 | - 'i18n_pll_invalid_name' => esc_html__( 'The language must have a name', 'polylang' ), | |
| 487 | - 'i18n_pll_invalid_flag' => esc_html__( 'The flag does not exist', 'polylang' ), | |
| 488 | - 'i18n_dialog_title' => esc_html__( "A language wasn't added.", 'polylang' ), | |
| 489 | - 'i18n_dialog_yes_button' => esc_html__( 'Yes', 'polylang' ), | |
| 490 | - 'i18n_dialog_no_button' => esc_html__( 'No', 'polylang' ), | |
| 491 | - 'i18n_dialog_ignore_button' => esc_html__( 'Ignore', 'polylang' ), | |
| 492 | - 'i18n_remove_language_icon' => esc_html__( 'Remove this language', 'polylang' ), | |
| 430 | + 'i18n_no_language_selected' => __( 'You need to select a language to be added.', 'polylang' ), | |
| 431 | + 'i18n_language_already_added' => __( 'You already added this language.', 'polylang' ), | |
| 432 | + 'i18n_no_language_added' => __( 'You need to add at least one language.', 'polylang' ), | |
| 433 | + 'i18n_add_language_needed' => __( 'You selected a language, however, to be able to continue, you need to add it.', 'polylang' ), | |
| 434 | + 'i18n_pll_add_language' => __( 'Impossible to add the language.', 'polylang' ), | |
| 435 | + 'i18n_pll_invalid_locale' => __( 'Enter a valid WordPress locale', 'polylang' ), | |
| 436 | + 'i18n_pll_invalid_slug' => __( 'The language code contains invalid characters', 'polylang' ), | |
| 437 | + 'i18n_pll_non_unique_slug' => __( 'The language code must be unique', 'polylang' ), | |
| 438 | + 'i18n_pll_invalid_name' => __( 'The language must have a name', 'polylang' ), | |
| 439 | + 'i18n_pll_invalid_flag' => __( 'The flag does not exist', 'polylang' ), | |
| 440 | + 'i18n_dialog_title' => __( "A language wasn't added.", 'polylang' ), | |
| 441 | + 'i18n_dialog_yes_button' => __( 'Yes', 'polylang' ), | |
| 442 | + 'i18n_dialog_no_button' => __( 'No', 'polylang' ), | |
| 443 | + 'i18n_dialog_ignore_button' => __( 'Ignore', 'polylang' ), | |
| 444 | + 'i18n_remove_language_icon' => __( 'Remove this language', 'polylang' ), | |
| 493 | 445 | ) |
| 494 | 446 | ); |
| 495 | 447 | 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 ); | |
| 448 | + wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/selectmenu' . $this->get_suffix() . '.css', POLYLANG_FILE ), array( 'dashicons', 'install', 'common', 'wp-jquery-ui-dialog' ), POLYLANG_VERSION ); | |
| 497 | 449 | $steps['languages'] = array( |
| 498 | - 'name' => esc_html__( 'Languages', 'polylang' ), | |
| 450 | + 'name' => __( 'Languages', 'polylang' ), | |
| 499 | 451 | 'view' => array( $this, 'display_step_languages' ), |
| 500 | 452 | 'handler' => array( $this, 'save_step_languages' ), |
| 501 | - 'scripts' => array( 'pll-wizard-languages', 'pll_admin' ), | |
| 453 | + 'scripts' => array( 'pll-wizard-languages', 'pll-wizard-language-choice' ), | |
| 502 | 454 | 'styles' => array( 'pll-wizard-selectmenu' ), |
| 503 | 455 | ); |
| 504 | 456 | return $steps; |
| 505 | 457 | } |
| @@ -507,10 +459,8 @@ | ||
| 507 | 459 | /** |
| 508 | 460 | * Display the languages step form |
| 509 | 461 | * |
| 510 | 462 | * @since 2.7 |
| 511 | - * | |
| 512 | - * @return void | |
| 513 | 463 | */ |
| 514 | 464 | public function display_step_languages() { |
| 515 | 465 | include __DIR__ . '/view-wizard-step-languages.php'; |
| 516 | 466 | } |
| @@ -518,10 +468,8 @@ | ||
| 518 | 468 | /** |
| 519 | 469 | * Execute the languages step |
| 520 | 470 | * |
| 521 | 471 | * @since 2.7 |
| 522 | - * | |
| 523 | - * @return void | |
| 524 | 472 | */ |
| 525 | 473 | public function save_step_languages() { |
| 526 | 474 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 527 | 475 | |
| @@ -527,9 +475,9 @@ | ||
| 527 | 475 | |
| 528 | 476 | $existing_languages = $this->model->get_languages_list(); |
| 529 | 477 | |
| 530 | 478 | $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; | |
| 479 | + $languages = isset( $_POST['languages'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['languages'] ) ) : false; | |
| 532 | 480 | $saved_languages = array(); |
| 533 | 481 | |
| 534 | 482 | // If there is no language added or defined. |
| 535 | 483 | if ( empty( $languages ) && empty( $existing_languages ) ) { |
| @@ -582,10 +530,9 @@ | ||
| 582 | 530 | ) |
| 583 | 531 | ); |
| 584 | 532 | exit; |
| 585 | 533 | } |
| 586 | - | |
| 587 | - if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) { | |
| 534 | + if ( 'en_US' !== $locale ) { | |
| 588 | 535 | wp_download_language_pack( $locale ); |
| 589 | 536 | } |
| 590 | 537 | } |
| 591 | 538 | } |
| @@ -593,14 +540,14 @@ | ||
| 593 | 540 | exit; |
| 594 | 541 | } |
| 595 | 542 | |
| 596 | 543 | /** |
| 597 | - * Add the media step to the wizard. | |
| 544 | + * Add media step to the wizard | |
| 545 | + * Add media step to the wizard | |
| 598 | 546 | * |
| 599 | - * @since 2.7 | |
| 600 | - * | |
| 601 | 547 | * @param array $steps List of steps. |
| 602 | 548 | * @return array List of steps updated. |
| 549 | + * @since 2.7 | |
| 603 | 550 | */ |
| 604 | 551 | public function add_step_media( $steps ) { |
| 605 | 552 | $languages = $this->model->get_languages_list(); |
| 606 | 553 | |
| @@ -605,9 +552,9 @@ | ||
| 605 | 552 | $languages = $this->model->get_languages_list(); |
| 606 | 553 | |
| 607 | 554 | if ( $this->is_media_step_displayable( $languages ) ) { |
| 608 | 555 | $steps['media'] = array( |
| 609 | - 'name' => esc_html__( 'Media', 'polylang' ), | |
| 556 | + 'name' => __( 'Media', 'polylang' ), | |
| 610 | 557 | 'view' => array( $this, 'display_step_media' ), |
| 611 | 558 | 'handler' => array( $this, 'save_step_media' ), |
| 612 | 559 | 'scripts' => array(), |
| 613 | 560 | 'styles' => array(), |
| @@ -619,10 +566,8 @@ | ||
| 619 | 566 | /** |
| 620 | 567 | * Display the media step form |
| 621 | 568 | * |
| 622 | 569 | * @since 2.7 |
| 623 | - * | |
| 624 | - * @return void | |
| 625 | 570 | */ |
| 626 | 571 | public function display_step_media() { |
| 627 | 572 | include __DIR__ . '/view-wizard-step-media.php'; |
| 628 | 573 | } |
| @@ -630,10 +575,8 @@ | ||
| 630 | 575 | /** |
| 631 | 576 | * Execute the media step |
| 632 | 577 | * |
| 633 | 578 | * @since 2.7 |
| 634 | - * | |
| 635 | - * @return void | |
| 636 | 579 | */ |
| 637 | 580 | public function save_step_media() { |
| 638 | 581 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 639 | 582 | |
| @@ -649,25 +592,21 @@ | ||
| 649 | 592 | |
| 650 | 593 | /** |
| 651 | 594 | * Add untranslated contents step to the wizard |
| 652 | 595 | * |
| 653 | - * @since 2.7 | |
| 654 | - * | |
| 655 | 596 | * @param array $steps List of steps. |
| 656 | 597 | * @return array List of steps updated. |
| 598 | + * @since 2.7 | |
| 657 | 599 | */ |
| 658 | 600 | public function add_step_untranslated_contents( $steps ) { |
| 659 | 601 | if ( ! $this->model->get_languages_list() || $this->model->get_objects_with_no_lang( 1 ) ) { |
| 660 | - // 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 | - // 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 ); | |
| 663 | - 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 ); | |
| 602 | + wp_enqueue_script( 'pll-wizard-language-choice', plugins_url( '/js/admin' . $this->get_suffix() . '.js', POLYLANG_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 603 | + wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/selectmenu' . $this->get_suffix() . '.css', POLYLANG_FILE ), array( 'dashicons', 'install', 'common' ), POLYLANG_VERSION ); | |
| 665 | 604 | $steps['untranslated-contents'] = array( |
| 666 | - 'name' => esc_html__( 'Content', 'polylang' ), | |
| 605 | + 'name' => __( 'Content', 'polylang' ), | |
| 667 | 606 | 'view' => array( $this, 'display_step_untranslated_contents' ), |
| 668 | 607 | 'handler' => array( $this, 'save_step_untranslated_contents' ), |
| 669 | - 'scripts' => array( 'pll_admin' ), | |
| 608 | + 'scripts' => array( 'pll-wizard-language-choice' ), | |
| 670 | 609 | 'styles' => array( 'pll-wizard-selectmenu' ), |
| 671 | 610 | ); |
| 672 | 611 | } |
| 673 | 612 | return $steps; |
| @@ -676,10 +615,8 @@ | ||
| 676 | 615 | /** |
| 677 | 616 | * Display the untranslated contents step form |
| 678 | 617 | * |
| 679 | 618 | * @since 2.7 |
| 680 | - * | |
| 681 | - * @return void | |
| 682 | 619 | */ |
| 683 | 620 | public function display_step_untranslated_contents() { |
| 684 | 621 | include __DIR__ . '/view-wizard-step-untranslated-contents.php'; |
| 685 | 622 | } |
| @@ -687,10 +624,8 @@ | ||
| 687 | 624 | /** |
| 688 | 625 | * Execute the untranslated contents step |
| 689 | 626 | * |
| 690 | 627 | * @since 2.7 |
| 691 | - * | |
| 692 | - * @return void | |
| 693 | 628 | */ |
| 694 | 629 | public function save_step_untranslated_contents() { |
| 695 | 630 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 696 | 631 | |
| @@ -717,12 +652,11 @@ | ||
| 717 | 652 | |
| 718 | 653 | /** |
| 719 | 654 | * Add home page step to the wizard |
| 720 | 655 | * |
| 721 | - * @since 2.7 | |
| 722 | - * | |
| 723 | 656 | * @param array $steps List of steps. |
| 724 | 657 | * @return array List of steps updated. |
| 658 | + * @since 2.7 | |
| 725 | 659 | */ |
| 726 | 660 | public function add_step_home_page( $steps ) { |
| 727 | 661 | $languages = $this->model->get_languages_list(); |
| 728 | 662 | $home_page_id = get_option( 'page_on_front' ); |
| @@ -730,9 +664,9 @@ | ||
| 730 | 664 | $translations = $this->model->post->get_translations( $home_page_id ); |
| 731 | 665 | |
| 732 | 666 | if ( $home_page_id > 0 && ( ! $languages || count( $languages ) === 1 || count( $translations ) !== count( $languages ) ) ) { |
| 733 | 667 | $steps['home-page'] = array( |
| 734 | - 'name' => esc_html__( 'Homepage', 'polylang' ), | |
| 668 | + 'name' => __( 'Homepage', 'polylang' ), | |
| 735 | 669 | 'view' => array( $this, 'display_step_home_page' ), |
| 736 | 670 | 'handler' => array( $this, 'save_step_home_page' ), |
| 737 | 671 | 'scripts' => array(), |
| 738 | 672 | 'styles' => array(), |
| @@ -744,10 +678,8 @@ | ||
| 744 | 678 | /** |
| 745 | 679 | * Display the home page step form |
| 746 | 680 | * |
| 747 | 681 | * @since 2.7 |
| 748 | - * | |
| 749 | - * @return void | |
| 750 | 682 | */ |
| 751 | 683 | public function display_step_home_page() { |
| 752 | 684 | include __DIR__ . '/view-wizard-step-home-page.php'; |
| 753 | 685 | } |
| @@ -755,10 +687,8 @@ | ||
| 755 | 687 | /** |
| 756 | 688 | * Execute the home page step |
| 757 | 689 | * |
| 758 | 690 | * @since 2.7 |
| 759 | - * | |
| 760 | - * @return void | |
| 761 | 691 | */ |
| 762 | 692 | public function save_step_home_page() { |
| 763 | 693 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 764 | 694 | |
| @@ -790,14 +720,13 @@ | ||
| 790 | 720 | * Create home page translations for each language defined. |
| 791 | 721 | * |
| 792 | 722 | * @since 2.7 |
| 793 | 723 | * |
| 794 | - * @param string $default_language Slug of the default language; null if no default language is defined. | |
| 795 | - * @param int $home_page Post ID of the home page if it's defined, false otherwise. | |
| 796 | - * @param string $home_page_title Home page title if it's defined, 'Homepage' otherwise. | |
| 797 | - * @param string $home_page_language Slug of the home page if it's defined, false otherwise. | |
| 798 | - * @param string[] $untranslated_languages Array of languages which needs to have a home page translated. | |
| 799 | - * @return void | |
| 724 | + * @param string $default_language slug of the default language; null if no default language is defined. | |
| 725 | + * @param int $home_page post_id of the home page if it's defined, false otherwise. | |
| 726 | + * @param string $home_page_title home page title if it's defined, 'Homepage' otherwise. | |
| 727 | + * @param string $home_page_language slug of the home page if it's defined, false otherwise. | |
| 728 | + * @param array $untranslated_languages array of languages which needs to have a home page translated. | |
| 800 | 729 | */ |
| 801 | 730 | public function create_home_page_translations( $default_language, $home_page, $home_page_title, $home_page_language, $untranslated_languages ) { |
| 802 | 731 | $translations = $this->model->post->get_translations( $home_page ); |
| 803 | 732 | |
| @@ -818,16 +747,15 @@ | ||
| 818 | 747 | |
| 819 | 748 | /** |
| 820 | 749 | * Add last step to the wizard |
| 821 | 750 | * |
| 822 | - * @since 2.7 | |
| 823 | - * | |
| 824 | 751 | * @param array $steps List of steps. |
| 825 | 752 | * @return array List of steps updated. |
| 753 | + * @since 2.7 | |
| 826 | 754 | */ |
| 827 | 755 | public function add_step_last( $steps ) { |
| 828 | 756 | $steps['last'] = array( |
| 829 | - 'name' => esc_html__( 'Ready!', 'polylang' ), | |
| 757 | + 'name' => __( 'Ready!', 'polylang' ), | |
| 830 | 758 | 'view' => array( $this, 'display_step_last' ), |
| 831 | 759 | 'handler' => array( $this, 'save_step_last' ), |
| 832 | 760 | 'scripts' => array(), |
| 833 | 761 | 'styles' => array(), |
| @@ -838,10 +766,8 @@ | ||
| 838 | 766 | /** |
| 839 | 767 | * Display the last step form |
| 840 | 768 | * |
| 841 | 769 | * @since 2.7 |
| 842 | - * | |
| 843 | - * @return void | |
| 844 | 770 | */ |
| 845 | 771 | public function display_step_last() { |
| 846 | 772 | // We ran the wizard once. So we can dismiss its notice. |
| 847 | 773 | PLL_Admin_Notices::dismiss( 'wizard' ); |
| @@ -851,10 +777,8 @@ | ||
| 851 | 777 | /** |
| 852 | 778 | * Execute the last step |
| 853 | 779 | * |
| 854 | 780 | * @since 2.7 |
| 855 | - * | |
| 856 | - * @return void | |
| 857 | 781 | */ |
| 858 | 782 | public function save_step_last() { |
| 859 | 783 | check_admin_referer( 'pll-wizard', '_pll_nonce' ); |
| 860 | 784 | |