| @@ -16,31 +16,11 @@ | ||
| 16 | 16 | * |
| 17 | 17 | * @since 1.2 |
| 18 | 18 | */ |
| 19 | 19 | class PLL_Settings extends PLL_Admin_Base { |
| 20 | + protected $active_tab, $modules; | |
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | - * Name of the active module | |
| 23 | - * | |
| 24 | - * @var string $active_tab | |
| 25 | - */ | |
| 26 | - protected $active_tab; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Array of modules classes | |
| 30 | - * | |
| 31 | - * @var array $modules | |
| 32 | - */ | |
| 33 | - protected $modules; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * Reference to PLL_Import_Export | |
| 37 | - * | |
| 38 | - * @var PLL_Import_Export $import_export | |
| 39 | - */ | |
| 40 | - protected $import_export; | |
| 41 | - | |
| 42 | - /** | |
| 43 | 23 | * Constructor |
| 44 | 24 | * |
| 45 | 25 | * @since 1.2 |
| 46 | 26 | * |
| @@ -48,18 +28,14 @@ | ||
| 48 | 28 | */ |
| 49 | 29 | public function __construct( &$links_model ) { |
| 50 | 30 | parent::__construct( $links_model ); |
| 51 | 31 | |
| 52 | - if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 53 | - $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( sanitize_key( $_GET['page'] ), 6 ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 32 | + if ( isset( $_GET['page'] ) ) { | |
| 33 | + $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( $_GET['page'], 6 ); | |
| 54 | 34 | } |
| 55 | 35 | |
| 56 | 36 | PLL_Admin_Strings::init(); |
| 57 | 37 | |
| 58 | - if ( class_exists( 'PLL_Import_Export' ) ) { | |
| 59 | - $this->import_export = new PLL_Import_Export( $this ); | |
| 60 | - } | |
| 61 | - | |
| 62 | 38 | // FIXME put this as late as possible |
| 63 | 39 | add_action( 'admin_init', array( $this, 'register_settings_modules' ) ); |
| 64 | 40 | |
| 65 | 41 | // Adds screen options and the about box in the languages admin panel |
| @@ -76,8 +52,9 @@ | ||
| 76 | 52 | * @since 1.8 |
| 77 | 53 | */ |
| 78 | 54 | public function register_settings_modules() { |
| 79 | 55 | $modules = array( |
| 56 | + 'PLL_Settings_Tools', | |
| 80 | 57 | 'PLL_Settings_Licenses', |
| 81 | 58 | ); |
| 82 | 59 | |
| 83 | 60 | if ( $this->model->get_languages_list() ) { |
| @@ -130,9 +107,9 @@ | ||
| 130 | 107 | add_meta_box( |
| 131 | 108 | 'pll-about-box', |
| 132 | 109 | __( 'About Polylang', 'polylang' ), |
| 133 | 110 | array( $this, 'metabox_about' ), |
| 134 | - 'toplevel_page_mlang', | |
| 111 | + 'settings_page_mlang', // FIXME not shown in screen options | |
| 135 | 112 | 'normal' |
| 136 | 113 | ); |
| 137 | 114 | } |
| 138 | 115 | |
| @@ -189,29 +166,19 @@ | ||
| 189 | 166 | public function handle_actions( $action ) { |
| 190 | 167 | switch ( $action ) { |
| 191 | 168 | case 'add': |
| 192 | 169 | check_admin_referer( 'add-lang', '_wpnonce_add-lang' ); |
| 193 | - $errors = $this->model->add_language( $_POST ); | |
| 194 | 170 | |
| 195 | - if ( is_wp_error( $errors ) ) { | |
| 196 | - foreach ( $errors->get_error_messages() as $message ) { | |
| 197 | - add_settings_error( 'general', 'pll_add_language', $message ); | |
| 171 | + if ( $this->model->add_language( $_POST ) && 'en_US' !== $_POST['locale'] ) { | |
| 172 | + // Attempts to install the language pack | |
| 173 | + require_once ABSPATH . 'wp-admin/includes/translation-install.php'; | |
| 174 | + if ( ! wp_download_language_pack( $_POST['locale'] ) ) { | |
| 175 | + add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) ); | |
| 198 | 176 | } |
| 199 | - } else { | |
| 200 | - add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' ); | |
| 201 | - $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security | |
| 202 | 177 | |
| 203 | - if ( 'en_US' !== $locale ) { | |
| 204 | - // Attempts to install the language pack | |
| 205 | - require_once ABSPATH . 'wp-admin/includes/translation-install.php'; | |
| 206 | - if ( ! wp_download_language_pack( $locale ) ) { | |
| 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' ) ); | |
| 208 | - } | |
| 209 | - | |
| 210 | - // Force checking for themes and plugins translations updates | |
| 211 | - wp_clean_themes_cache(); | |
| 212 | - wp_clean_plugins_cache(); | |
| 213 | - } | |
| 178 | + // Force checking for themes and plugins translations updates | |
| 179 | + wp_clean_themes_cache(); | |
| 180 | + wp_clean_plugins_cache(); | |
| 214 | 181 | } |
| 215 | 182 | self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) |
| 216 | 183 | break; |
| 217 | 184 | |
| @@ -217,10 +184,10 @@ | ||
| 217 | 184 | |
| 218 | 185 | case 'delete': |
| 219 | 186 | check_admin_referer( 'delete-lang' ); |
| 220 | 187 | |
| 221 | - if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) { | |
| 222 | - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' ); | |
| 188 | + if ( ! empty( $_GET['lang'] ) ) { | |
| 189 | + $this->model->delete_language( (int) $_GET['lang'] ); | |
| 223 | 190 | } |
| 224 | 191 | |
| 225 | 192 | self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) |
| 226 | 193 | break; |
| @@ -226,18 +193,9 @@ | ||
| 226 | 193 | break; |
| 227 | 194 | |
| 228 | 195 | case 'update': |
| 229 | 196 | check_admin_referer( 'add-lang', '_wpnonce_add-lang' ); |
| 230 | - $errors = $this->model->update_language( $_POST ); | |
| 231 | - | |
| 232 | - if ( is_wp_error( $errors ) ) { | |
| 233 | - foreach ( $errors->get_error_messages() as $message ) { | |
| 234 | - add_settings_error( 'general', 'pll_update_language', $message ); | |
| 235 | - } | |
| 236 | - } else { | |
| 237 | - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' ); | |
| 238 | - } | |
| 239 | - | |
| 197 | + $error = $this->model->update_language( $_POST ); | |
| 240 | 198 | self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) |
| 241 | 199 | break; |
| 242 | 200 | |
| 243 | 201 | case 'default-lang': |
| @@ -266,25 +224,15 @@ | ||
| 266 | 224 | break; |
| 267 | 225 | |
| 268 | 226 | case 'activate': |
| 269 | 227 | check_admin_referer( 'pll_activate' ); |
| 270 | - if ( isset( $_GET['module'] ) ) { | |
| 271 | - $module = sanitize_key( $_GET['module'] ); | |
| 272 | - if ( isset( $this->modules[ $module ] ) ) { | |
| 273 | - $this->modules[ $module ]->activate(); | |
| 274 | - } | |
| 275 | - } | |
| 228 | + $this->modules[ $_GET['module'] ]->activate(); | |
| 276 | 229 | self::redirect(); |
| 277 | 230 | break; |
| 278 | 231 | |
| 279 | 232 | case 'deactivate': |
| 280 | 233 | check_admin_referer( 'pll_deactivate' ); |
| 281 | - if ( isset( $_GET['module'] ) ) { | |
| 282 | - $module = sanitize_key( $_GET['module'] ); | |
| 283 | - if ( isset( $this->modules[ $module ] ) ) { | |
| 284 | - $this->modules[ $module ]->deactivate(); | |
| 285 | - } | |
| 286 | - } | |
| 234 | + $this->modules[ $_GET['module'] ]->deactivate(); | |
| 287 | 235 | self::redirect(); |
| 288 | 236 | break; |
| 289 | 237 | |
| 290 | 238 | default: |
| @@ -318,11 +266,10 @@ | ||
| 318 | 266 | break; |
| 319 | 267 | } |
| 320 | 268 | |
| 321 | 269 | // Handle user input |
| 322 | - $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification | |
| 323 | - if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 324 | - // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable | |
| 270 | + $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : ''; | |
| 271 | + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { | |
| 325 | 272 | $edit_lang = $this->model->get_language( (int) $_GET['lang'] ); |
| 326 | 273 | } else { |
| 327 | 274 | $this->handle_actions( $action ); |
| 328 | 275 | } |
| @@ -354,9 +301,9 @@ | ||
| 354 | 301 | if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) { |
| 355 | 302 | printf( |
| 356 | 303 | '<div class="error"><p>%s <a href="%s">%s</a></p></div>', |
| 357 | 304 | esc_html__( 'There are posts, pages, categories or tags without language.', 'polylang' ), |
| 358 | - esc_url( wp_nonce_url( '?page=mlang&pll_action=content-default-lang&noheader=true', 'content-default-lang' ) ), | |
| 305 | + wp_nonce_url( '?page=mlang&pll_action=content-default-lang&noheader=true', 'content-default-lang' ), | |
| 359 | 306 | esc_html__( 'You can set them all to the default language.', 'polylang' ) |
| 360 | 307 | ); |
| 361 | 308 | } |
| 362 | 309 | } |
| @@ -383,12 +330,12 @@ | ||
| 383 | 330 | * Get the list of predefined languages |
| 384 | 331 | * |
| 385 | 332 | * @since 2.3 |
| 386 | 333 | */ |
| 387 | - public static function get_predefined_languages() { | |
| 334 | + public function get_predefined_languages() { | |
| 388 | 335 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 336 | + include PLL_SETTINGS_INC . '/languages.php'; | |
| 389 | 337 | |
| 390 | - $languages = include PLL_SETTINGS_INC . '/languages.php'; | |
| 391 | 338 | $translations = wp_get_available_translations(); |
| 392 | 339 | |
| 393 | 340 | // Keep only languages with existing WP language pack |
| 394 | 341 | // Unless the transient has expired and we don't have an internet connection to refresh it |