| @@ -1,34 +1,44 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | - * A class for the Polylang settings pages, accessible from @see PLL(). | |
| 4 | + * A class for the Polylang settings pages | |
| 5 | + * accessible in $polylang global object | |
| 8 | 6 | * |
| 7 | + * Properties: | |
| 8 | + * options => inherited, reference to Polylang options array | |
| 9 | + * model => inherited, reference to PLL_Model object | |
| 10 | + * links_model => inherited, reference to PLL_Links_Model object | |
| 11 | + * links => inherited, reference to PLL_Admin_Links object | |
| 12 | + * static_pages => inherited, reference to PLL_Admin_Static_Pages object | |
| 13 | + * filters_links => inherited, reference to PLL_Filters_Links object | |
| 14 | + * curlang => inherited, optional, current language used to filter admin content | |
| 15 | + * pref_lang => inherited, preferred language used as default when saving posts or terms | |
| 16 | + * | |
| 9 | 17 | * @since 1.2 |
| 10 | 18 | */ |
| 11 | 19 | class PLL_Settings extends PLL_Admin_Base { |
| 12 | 20 | |
| 13 | 21 | /** |
| 14 | - * @var PLL_Admin_Model | |
| 22 | + * Name of the active module | |
| 23 | + * | |
| 24 | + * @var string $active_tab | |
| 15 | 25 | */ |
| 16 | - public $model; | |
| 26 | + protected $active_tab; | |
| 17 | 27 | |
| 18 | 28 | /** |
| 19 | - * Name of the active module. | |
| 29 | + * Array of modules classes | |
| 20 | 30 | * |
| 21 | - * @var string | |
| 31 | + * @var array $modules | |
| 22 | 32 | */ |
| 23 | - protected $active_tab; | |
| 33 | + protected $modules; | |
| 24 | 34 | |
| 25 | 35 | /** |
| 26 | - * Array of modules classes. | |
| 36 | + * Reference to PLL_Import_Export | |
| 27 | 37 | * |
| 28 | - * @var PLL_Settings_Module[] | |
| 38 | + * @var PLL_Import_Export $import_export | |
| 29 | 39 | */ |
| 30 | - protected $modules; | |
| 40 | + protected $import_export; | |
| 31 | 41 | |
| 32 | 42 | /** |
| 33 | 43 | * Constructor |
| 34 | 44 | * |
| @@ -33,9 +43,9 @@ | ||
| 33 | 43 | * Constructor |
| 34 | 44 | * |
| 35 | 45 | * @since 1.2 |
| 36 | 46 | * |
| 37 | - * @param PLL_Links_Model $links_model Reference to the links model. | |
| 47 | + * @param object $links_model | |
| 38 | 48 | */ |
| 39 | 49 | public function __construct( &$links_model ) { |
| 40 | 50 | parent::__construct( $links_model ); |
| 41 | 51 | |
| @@ -44,8 +54,13 @@ | ||
| 44 | 54 | } |
| 45 | 55 | |
| 46 | 56 | PLL_Admin_Strings::init(); |
| 47 | 57 | |
| 58 | + if ( class_exists( 'PLL_Import_Export' ) ) { | |
| 59 | + $this->import_export = new PLL_Import_Export( $this ); | |
| 60 | + } | |
| 61 | + | |
| 62 | + // FIXME put this as late as possible | |
| 48 | 63 | add_action( 'admin_init', array( $this, 'register_settings_modules' ) ); |
| 49 | 64 | |
| 50 | 65 | // Adds screen options and the about box in the languages admin panel |
| 51 | 66 | add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) ); |
| @@ -58,25 +73,30 @@ | ||
| 58 | 73 | /** |
| 59 | 74 | * Initializes the modules |
| 60 | 75 | * |
| 61 | 76 | * @since 1.8 |
| 62 | - * | |
| 63 | - * @return void | |
| 64 | 77 | */ |
| 65 | 78 | public function register_settings_modules() { |
| 66 | - $modules = array(); | |
| 79 | + $modules = array( | |
| 80 | + 'PLL_Settings_Licenses', | |
| 81 | + ); | |
| 67 | 82 | |
| 68 | 83 | if ( $this->model->get_languages_list() ) { |
| 69 | - $modules = array( | |
| 70 | - 'PLL_Settings_Url', | |
| 71 | - 'PLL_Settings_Browser', | |
| 72 | - 'PLL_Settings_Media', | |
| 73 | - 'PLL_Settings_CPT', | |
| 84 | + $modules = array_merge( | |
| 85 | + array( | |
| 86 | + 'PLL_Settings_Url', | |
| 87 | + 'PLL_Settings_Browser', | |
| 88 | + 'PLL_Settings_Media', | |
| 89 | + 'PLL_Settings_CPT', | |
| 90 | + 'PLL_Settings_Sync', | |
| 91 | + 'PLL_Settings_WPML', | |
| 92 | + 'PLL_Settings_Share_Slug', | |
| 93 | + 'PLL_Settings_Translate_Slugs', | |
| 94 | + ), | |
| 95 | + $modules | |
| 74 | 96 | ); |
| 75 | 97 | } |
| 76 | 98 | |
| 77 | - $modules[] = 'PLL_Settings_Licenses'; | |
| 78 | - | |
| 79 | 99 | /** |
| 80 | 100 | * Filter the list of setting modules |
| 81 | 101 | * |
| 82 | 102 | * @since 1.8 |
| @@ -94,13 +114,11 @@ | ||
| 94 | 114 | /** |
| 95 | 115 | * Loads the about metabox |
| 96 | 116 | * |
| 97 | 117 | * @since 0.8 |
| 98 | - * | |
| 99 | - * @return void | |
| 100 | 118 | */ |
| 101 | 119 | public function metabox_about() { |
| 102 | - include __DIR__ . '/view-about.php'; | |
| 120 | + include PLL_SETTINGS_INC . '/view-about.php'; | |
| 103 | 121 | } |
| 104 | 122 | |
| 105 | 123 | /** |
| 106 | 124 | * Adds screen options and the about box in the languages admin panel |
| @@ -105,10 +123,8 @@ | ||
| 105 | 123 | /** |
| 106 | 124 | * Adds screen options and the about box in the languages admin panel |
| 107 | 125 | * |
| 108 | 126 | * @since 0.9.5 |
| 109 | - * | |
| 110 | - * @return void | |
| 111 | 127 | */ |
| 112 | 128 | public function load_page() { |
| 113 | 129 | if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) { |
| 114 | 130 | add_meta_box( |
| @@ -135,10 +151,8 @@ | ||
| 135 | 151 | /** |
| 136 | 152 | * Adds screen options in the strings translations admin panel |
| 137 | 153 | * |
| 138 | 154 | * @since 2.1 |
| 139 | - * | |
| 140 | - * @return void | |
| 141 | 155 | */ |
| 142 | 156 | public function load_page_strings() { |
| 143 | 157 | add_screen_option( |
| 144 | 158 | 'per_page', |
| @@ -170,9 +184,8 @@ | ||
| 170 | 184 | * |
| 171 | 185 | * @since 1.9 |
| 172 | 186 | * |
| 173 | 187 | * @param string $action |
| 174 | - * @return void | |
| 175 | 188 | */ |
| 176 | 189 | public function handle_actions( $action ) { |
| 177 | 190 | switch ( $action ) { |
| 178 | 191 | case 'add': |
| @@ -186,9 +199,9 @@ | ||
| 186 | 199 | } else { |
| 187 | 200 | add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' ); |
| 188 | 201 | $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security |
| 189 | 202 | |
| 190 | - if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) { | |
| 203 | + if ( 'en_US' !== $locale ) { | |
| 191 | 204 | // Attempts to install the language pack |
| 192 | 205 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 193 | 206 | if ( ! wp_download_language_pack( $locale ) ) { |
| 194 | 207 | add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) ); |
| @@ -289,10 +302,8 @@ | ||
| 289 | 302 | * Displays the 3 tabs pages: languages, strings translations, settings |
| 290 | 303 | * Also manages user input for these pages |
| 291 | 304 | * |
| 292 | 305 | * @since 0.1 |
| 293 | - * | |
| 294 | - * @return void | |
| 295 | 306 | */ |
| 296 | 307 | public function languages_page() { |
| 297 | 308 | switch ( $this->active_tab ) { |
| 298 | 309 | case 'lang': |
| @@ -309,9 +320,9 @@ | ||
| 309 | 320 | |
| 310 | 321 | // Handle user input |
| 311 | 322 | $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
| 312 | 323 | if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 313 | - // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 324 | + // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable | |
| 314 | 325 | $edit_lang = $this->model->get_language( (int) $_GET['lang'] ); |
| 315 | 326 | } else { |
| 316 | 327 | $this->handle_actions( $action ); |
| 317 | 328 | } |
| @@ -316,15 +327,13 @@ | ||
| 316 | 327 | $this->handle_actions( $action ); |
| 317 | 328 | } |
| 318 | 329 | |
| 319 | 330 | // Displays the page |
| 320 | - include __DIR__ . '/view-languages.php'; | |
| 331 | + include PLL_SETTINGS_INC . '/view-languages.php'; | |
| 321 | 332 | } |
| 322 | 333 | |
| 323 | 334 | /** |
| 324 | 335 | * Enqueues scripts and styles |
| 325 | - * | |
| 326 | - * @return void | |
| 327 | 336 | */ |
| 328 | 337 | public function admin_enqueue_scripts() { |
| 329 | 338 | parent::admin_enqueue_scripts(); |
| 330 | 339 | |
| @@ -329,12 +338,12 @@ | ||
| 329 | 338 | parent::admin_enqueue_scripts(); |
| 330 | 339 | |
| 331 | 340 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 332 | 341 | |
| 333 | - wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $suffix . '.js', POLYLANG_BASENAME ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); | |
| 334 | - wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); | |
| 342 | + wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION ); | |
| 343 | + wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) ); | |
| 335 | 344 | |
| 336 | - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_BASENAME ), array(), POLYLANG_VERSION ); | |
| 345 | + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION ); | |
| 337 | 346 | } |
| 338 | 347 | |
| 339 | 348 | /** |
| 340 | 349 | * Displays a notice when there are objects with no language assigned |
| @@ -339,10 +348,8 @@ | ||
| 339 | 348 | /** |
| 340 | 349 | * Displays a notice when there are objects with no language assigned |
| 341 | 350 | * |
| 342 | 351 | * @since 1.8 |
| 343 | - * | |
| 344 | - * @return void | |
| 345 | 352 | */ |
| 346 | 353 | public function notice_objects_with_no_lang() { |
| 347 | 354 | if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) { |
| 348 | 355 | printf( |
| @@ -360,9 +367,8 @@ | ||
| 360 | 367 | * |
| 361 | 368 | * @since 1.5 |
| 362 | 369 | * |
| 363 | 370 | * @param array $args query arguments to add to the url |
| 364 | - * @return void | |
| 365 | 371 | */ |
| 366 | 372 | public static function redirect( $args = array() ) { |
| 367 | 373 | if ( $errors = get_settings_errors() ) { |
| 368 | 374 | set_transient( 'settings_errors', $errors, 30 ); |
| @@ -376,23 +382,13 @@ | ||
| 376 | 382 | /** |
| 377 | 383 | * Get the list of predefined languages |
| 378 | 384 | * |
| 379 | 385 | * @since 2.3 |
| 380 | - * | |
| 381 | - * @return string[] { | |
| 382 | - * @type string $code ISO 639-1 language code. | |
| 383 | - * @type string $locale WordPress locale. | |
| 384 | - * @type string $name Native language name. | |
| 385 | - * @type string $dir Text direction: 'ltr' or 'rtl'. | |
| 386 | - * @type string $flag Flag code, generally the country code. | |
| 387 | - * @type string $w3c W3C locale. | |
| 388 | - * @type string $facebook Facebook locale. | |
| 389 | - * } | |
| 390 | 386 | */ |
| 391 | 387 | public static function get_predefined_languages() { |
| 392 | 388 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 393 | 389 | |
| 394 | - $languages = include __DIR__ . '/languages.php'; | |
| 390 | + $languages = include PLL_SETTINGS_INC . '/languages.php'; | |
| 395 | 391 | $translations = wp_get_available_translations(); |
| 396 | 392 | |
| 397 | 393 | // Keep only languages with existing WP language pack |
| 398 | 394 | // Unless the transient has expired and we don't have an internet connection to refresh it |
| @@ -405,9 +401,9 @@ | ||
| 405 | 401 | * Filter the list of predefined languages |
| 406 | 402 | * |
| 407 | 403 | * @since 1.7.10 |
| 408 | 404 | * @since 2.3 The languages arrays use associative keys instead of numerical keys |
| 409 | - * @see https://github.com/polylang/polylang/blob/2.8.2/settings/languages.php the list of predefined languages | |
| 405 | + * @see settings/languages.php | |
| 410 | 406 | * |
| 411 | 407 | * @param array $languages |
| 412 | 408 | */ |
| 413 | 409 | $languages = apply_filters( 'pll_predefined_languages', $languages ); |