| @@ -17,9 +17,9 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Name of the active module. |
| 20 | 20 | * |
| 21 | - * @var string | |
| 21 | + * @var string|null | |
| 22 | 22 | */ |
| 23 | 23 | protected $active_tab; |
| 24 | 24 | |
| 25 | 25 | /** |
| @@ -24,9 +24,9 @@ | ||
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Array of modules classes. |
| 27 | 27 | * |
| 28 | - * @var PLL_Settings_Module[] | |
| 28 | + * @var PLL_Settings_Module[]|null | |
| 29 | 29 | */ |
| 30 | 30 | protected $modules; |
| 31 | 31 | |
| 32 | 32 | /** |
| @@ -46,14 +46,15 @@ | ||
| 46 | 46 | PLL_Admin_Strings::init(); |
| 47 | 47 | |
| 48 | 48 | add_action( 'admin_init', array( $this, 'register_settings_modules' ) ); |
| 49 | 49 | |
| 50 | - // Adds screen options and the about box in the languages admin panel | |
| 50 | + // Adds screen options and the about box in the languages admin panel. | |
| 51 | 51 | add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) ); |
| 52 | 52 | add_action( 'load-languages_page_mlang_strings', array( $this, 'load_page_strings' ) ); |
| 53 | 53 | |
| 54 | - // Saves per-page value in screen option | |
| 55 | - add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 ); | |
| 54 | + // Saves the per-page value in screen options. | |
| 55 | + add_filter( 'set_screen_option_pll_lang_per_page', array( $this, 'set_screen_option' ), 10, 3 ); | |
| 56 | + add_filter( 'set_screen_option_pll_strings_per_page', array( $this, 'set_screen_option' ), 10, 3 ); | |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | /** |
| 59 | 60 | * Initializes the modules |
| @@ -64,9 +65,9 @@ | ||
| 64 | 65 | */ |
| 65 | 66 | public function register_settings_modules() { |
| 66 | 67 | $modules = array(); |
| 67 | 68 | |
| 68 | - if ( $this->model->get_languages_list() ) { | |
| 69 | + if ( $this->model->has_languages() ) { | |
| 69 | 70 | $modules = array( |
| 70 | 71 | 'PLL_Settings_Url', |
| 71 | 72 | 'PLL_Settings_Browser', |
| 72 | 73 | 'PLL_Settings_Media', |
| @@ -150,28 +151,27 @@ | ||
| 150 | 151 | ); |
| 151 | 152 | } |
| 152 | 153 | |
| 153 | 154 | /** |
| 154 | - * Save the "Views/Uploads per page" option set by this user | |
| 155 | + * Saves the number of rows in the languages or strings table set by this user. | |
| 155 | 156 | * |
| 156 | 157 | * @since 0.9.5 |
| 157 | 158 | * |
| 158 | - * @param mixed $status false or value returned by previous filter | |
| 159 | - * @param string $option Name of the option being changed | |
| 160 | - * @param string $value Value of the option | |
| 161 | - * | |
| 162 | - * @return string New value if this is our option, otherwise nothing | |
| 159 | + * @param mixed $screen_option False or value returned by a previous filter, not used. | |
| 160 | + * @param string $option The name of the option, not used. | |
| 161 | + * @param int $value The new value of the option to save. | |
| 162 | + * @return int The new value of the option. | |
| 163 | 163 | */ |
| 164 | - public function set_screen_option( $status, $option, $value ) { | |
| 165 | - return 'pll_lang_per_page' === $option || 'pll_strings_per_page' === $option ? $value : $status; | |
| 164 | + public function set_screen_option( $screen_option, $option, $value ) { | |
| 165 | + return (int) $value; | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * Manages the user input for the languages pages | |
| 169 | + * Manages the user input for the languages pages. | |
| 170 | 170 | * |
| 171 | 171 | * @since 1.9 |
| 172 | 172 | * |
| 173 | - * @param string $action | |
| 173 | + * @param string $action The action name. | |
| 174 | 174 | * @return void |
| 175 | 175 | */ |
| 176 | 176 | public function handle_actions( $action ) { |
| 177 | 177 | switch ( $action ) { |
| @@ -179,20 +179,18 @@ | ||
| 179 | 179 | check_admin_referer( 'add-lang', '_wpnonce_add-lang' ); |
| 180 | 180 | $errors = $this->model->add_language( $_POST ); |
| 181 | 181 | |
| 182 | 182 | if ( is_wp_error( $errors ) ) { |
| 183 | - foreach ( $errors->get_error_messages() as $message ) { | |
| 184 | - add_settings_error( 'general', 'pll_add_language', $message ); | |
| 185 | - } | |
| 183 | + pll_add_notice( $errors ); | |
| 186 | 184 | } else { |
| 187 | - add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' ); | |
| 188 | - $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security | |
| 185 | + pll_add_notice( new WP_Error( 'pll_languages_created', __( 'Language added.', 'polylang' ), 'success' ) ); | |
| 186 | + $locale = sanitize_locale_name( $_POST['locale'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 189 | 187 | |
| 190 | 188 | if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) { |
| 191 | 189 | // Attempts to install the language pack |
| 192 | 190 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 193 | 191 | if ( ! wp_download_language_pack( $locale ) ) { |
| 194 | - add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) ); | |
| 192 | + pll_add_notice( new WP_Error( 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ), 'warning' ) ); | |
| 195 | 193 | } |
| 196 | 194 | |
| 197 | 195 | // Force checking for themes and plugins translations updates |
| 198 | 196 | wp_clean_themes_cache(); |
| @@ -205,9 +203,9 @@ | ||
| 205 | 203 | case 'delete': |
| 206 | 204 | check_admin_referer( 'delete-lang' ); |
| 207 | 205 | |
| 208 | 206 | if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) { |
| 209 | - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' ); | |
| 207 | + pll_add_notice( new WP_Error( 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'success' ) ); | |
| 210 | 208 | } |
| 211 | 209 | |
| 212 | 210 | self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) |
| 213 | 211 | break; |
| @@ -216,13 +214,11 @@ | ||
| 216 | 214 | check_admin_referer( 'add-lang', '_wpnonce_add-lang' ); |
| 217 | 215 | $errors = $this->model->update_language( $_POST ); |
| 218 | 216 | |
| 219 | 217 | if ( is_wp_error( $errors ) ) { |
| 220 | - foreach ( $errors->get_error_messages() as $message ) { | |
| 221 | - add_settings_error( 'general', 'pll_update_language', $message ); | |
| 222 | - } | |
| 218 | + pll_add_notice( $errors ); | |
| 223 | 219 | } else { |
| 224 | - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' ); | |
| 220 | + pll_add_notice( new WP_Error( 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'success' ) ); | |
| 225 | 221 | } |
| 226 | 222 | |
| 227 | 223 | self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) |
| 228 | 224 | break; |
| @@ -239,16 +235,9 @@ | ||
| 239 | 235 | |
| 240 | 236 | case 'content-default-lang': |
| 241 | 237 | check_admin_referer( 'content-default-lang' ); |
| 242 | 238 | |
| 243 | - if ( $nolang = $this->model->get_objects_with_no_lang() ) { | |
| 244 | - if ( ! empty( $nolang['posts'] ) ) { | |
| 245 | - $this->model->set_language_in_mass( 'post', $nolang['posts'], $this->options['default_lang'] ); | |
| 246 | - } | |
| 247 | - if ( ! empty( $nolang['terms'] ) ) { | |
| 248 | - $this->model->set_language_in_mass( 'term', $nolang['terms'], $this->options['default_lang'] ); | |
| 249 | - } | |
| 250 | - } | |
| 239 | + $this->model->set_language_in_mass(); | |
| 251 | 240 | |
| 252 | 241 | self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) |
| 253 | 242 | break; |
| 254 | 243 | |
| @@ -329,12 +318,12 @@ | ||
| 329 | 318 | parent::admin_enqueue_scripts(); |
| 330 | 319 | |
| 331 | 320 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 332 | 321 | |
| 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 ); | |
| 322 | + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu', 'wp-hooks' ), POLYLANG_VERSION, true ); | |
| 334 | 323 | wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); |
| 335 | 324 | |
| 336 | - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_BASENAME ), array(), POLYLANG_VERSION ); | |
| 325 | + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_ROOT_FILE ), array(), POLYLANG_VERSION ); | |
| 337 | 326 | } |
| 338 | 327 | |
| 339 | 328 | /** |
| 340 | 329 | * Displays a notice when there are objects with no language assigned |
| @@ -363,9 +352,10 @@ | ||
| 363 | 352 | * @param array $args query arguments to add to the url |
| 364 | 353 | * @return void |
| 365 | 354 | */ |
| 366 | 355 | public static function redirect( $args = array() ) { |
| 367 | - if ( $errors = get_settings_errors() ) { | |
| 356 | + $errors = get_settings_errors( 'polylang' ); | |
| 357 | + if ( ! empty( $errors ) ) { | |
| 368 | 358 | set_transient( 'settings_errors', $errors, 30 ); |
| 369 | 359 | $args['settings-updated'] = 1; |
| 370 | 360 | } |
| 371 | 361 | // Remove possible 'pll_action' and 'lang' query args from the referer before redirecting |
| @@ -411,9 +401,9 @@ | ||
| 411 | 401 | * @param array $languages |
| 412 | 402 | */ |
| 413 | 403 | $languages = apply_filters( 'pll_predefined_languages', $languages ); |
| 414 | 404 | |
| 415 | - // Keep only languages with all necessary informations | |
| 405 | + // Keep only languages with all necessary information | |
| 416 | 406 | foreach ( $languages as $k => $lang ) { |
| 417 | 407 | if ( ! isset( $lang['code'], $lang['locale'], $lang['name'], $lang['dir'], $lang['flag'] ) ) { |
| 418 | 408 | unset( $languages[ $k ] ); |
| 419 | 409 | } |