PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | settings/settings.php +121 -197 2.72.0.3 View file →
@@ -3,9 +3,9 @@
3 3 /**
4 4 * A class for the Polylang settings pages
5 5 * accessible in $polylang global object
6 6 *
7 - * Properties:
7 + * properties:
8 8 * options => inherited, reference to Polylang options array
9 9 * model => inherited, reference to PLL_Model object
10 10 * links_model => inherited, reference to PLL_Links_Model object
11 11 * links => inherited, reference to PLL_Admin_Links object
@@ -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,26 +28,19 @@
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
54 - }
32 + $this->active_tab = ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'lang';
55 33
56 34 PLL_Admin_Strings::init();
57 35
58 - if ( class_exists( 'PLL_Import_Export' ) ) {
59 - $this->import_export = new PLL_Import_Export( $this );
60 - }
61 -
62 36 // FIXME put this as late as possible
63 37 add_action( 'admin_init', array( $this, 'register_settings_modules' ) );
64 38
65 - // Adds screen options and the about box in the languages admin panel
66 - add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
67 - add_action( 'load-languages_page_mlang_strings', array( $this, 'load_page_strings' ) );
39 + // adds screen options and the about box in the languages admin panel
40 + add_action( 'load-settings_page_mlang', array( $this, 'load_page' ) );
68 41
69 - // Saves per-page value in screen option
42 + // saves per-page value in screen option
70 43 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
71 44 }
72 45
73 46 /**
@@ -76,25 +49,23 @@
76 49 * @since 1.8
77 50 */
78 51 public function register_settings_modules() {
79 52 $modules = array(
53 + 'PLL_Settings_Tools',
80 54 'PLL_Settings_Licenses',
81 55 );
82 56
83 57 if ( $this->model->get_languages_list() ) {
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
96 - );
58 + $modules = array_merge( array(
59 + 'PLL_Settings_Url',
60 + 'PLL_Settings_Browser',
61 + 'PLL_Settings_Media',
62 + 'PLL_Settings_CPT',
63 + 'PLL_Settings_Sync',
64 + 'PLL_Settings_WPML',
65 + 'PLL_Settings_Share_Slug',
66 + 'PLL_Settings_Translate_Slugs',
67 + ), $modules );
97 68 }
98 69
99 70 /**
100 71 * Filter the list of setting modules
@@ -111,14 +82,23 @@
111 82 }
112 83 }
113 84
114 85 /**
86 + * Adds the link to the languages panel in the WordPress admin menu
87 + *
88 + * @since 0.1
89 + */
90 + public function add_menus() {
91 + add_submenu_page( 'options-general.php', $title = __( 'Languages', 'polylang' ), $title, 'manage_options', 'mlang', array( $this, 'languages_page' ) );
92 + }
93 +
94 + /**
115 95 * Loads the about metabox
116 96 *
117 97 * @since 0.8
118 98 */
119 99 public function metabox_about() {
120 - include PLL_SETTINGS_INC . '/view-about.php';
100 + include( PLL_SETTINGS_INC.'/view-about.php' );
121 101 }
122 102
123 103 /**
124 104 * Adds screen options and the about box in the languages admin panel
@@ -125,44 +105,38 @@
125 105 *
126 106 * @since 0.9.5
127 107 */
128 108 public function load_page() {
129 - if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) {
130 - add_meta_box(
131 - 'pll-about-box',
132 - __( 'About Polylang', 'polylang' ),
133 - array( $this, 'metabox_about' ),
134 - 'toplevel_page_mlang',
135 - 'normal'
136 - );
137 - }
109 + // test of $this->active_tab avoids displaying the automatically generated screen options on other tabs
110 + switch ( $this->active_tab ) {
111 + case 'lang':
112 + if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) {
113 + add_meta_box(
114 + 'pll-about-box',
115 + __( 'About Polylang', 'polylang' ),
116 + array( $this, 'metabox_about' ),
117 + 'settings_page_mlang',
118 + 'normal'
119 + );
120 + }
138 121
139 - add_screen_option(
140 - 'per_page',
141 - array(
142 - 'label' => __( 'Languages', 'polylang' ),
143 - 'default' => 10,
144 - 'option' => 'pll_lang_per_page',
145 - )
146 - );
122 + add_screen_option( 'per_page', array(
123 + 'label' => __( 'Languages', 'polylang' ),
124 + 'default' => 10,
125 + 'option' => 'pll_lang_per_page',
126 + ) );
147 127
148 - add_action( 'admin_notices', array( $this, 'notice_objects_with_no_lang' ) );
149 - }
128 + add_action( 'admin_notices', array( $this, 'notice_objects_with_no_lang' ) );
129 + break;
150 130
151 - /**
152 - * Adds screen options in the strings translations admin panel
153 - *
154 - * @since 2.1
155 - */
156 - public function load_page_strings() {
157 - add_screen_option(
158 - 'per_page',
159 - array(
160 - 'label' => __( 'Strings translations', 'polylang' ),
161 - 'default' => 10,
162 - 'option' => 'pll_strings_per_page',
163 - )
164 - );
131 + case 'strings':
132 + add_screen_option( 'per_page', array(
133 + 'label' => __( 'Strings translations', 'polylang' ),
134 + 'default' => 10,
135 + 'option' => 'pll_strings_per_page',
136 + ) );
137 + break;
138 + }
165 139 }
166 140
167 141 /**
168 142 * Save the "Views/Uploads per page" option set by this user
@@ -168,11 +142,11 @@
168 142 * Save the "Views/Uploads per page" option set by this user
169 143 *
170 144 * @since 0.9.5
171 145 *
172 - * @param mixed $status false or value returned by previous filter
173 - * @param string $option Name of the option being changed
174 - * @param string $value Value of the option
146 + * @param mixed $status false or value returned by previous filter
147 + * @param string $option Name of the option being changed
148 + * @param string $value Value of the option
175 149 *
176 150 * @return string New value if this is our option, otherwise nothing
177 151 */
178 152 public function set_screen_option( $status, $option, $value ) {
@@ -189,58 +163,39 @@
189 163 public function handle_actions( $action ) {
190 164 switch ( $action ) {
191 165 case 'add':
192 166 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
193 - $errors = $this->model->add_language( $_POST );
194 167
195 - if ( is_wp_error( $errors ) ) {
196 - foreach ( $errors->get_error_messages() as $message ) {
197 - add_settings_error( 'general', 'pll_add_language', $message );
168 + if ( $this->model->add_language( $_POST ) && 'en_US' !== $_POST['locale'] ) {
169 + // attempts to install the language pack
170 + require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
171 + if ( ! wp_download_language_pack( $_POST['locale'] ) ) {
172 + 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 173 }
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 174
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 - }
175 + // force checking for themes and plugins translations updates
176 + wp_clean_themes_cache();
177 + wp_clean_plugins_cache();
214 178 }
215 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
216 - break;
179 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
180 + break;
217 181
218 182 case 'delete':
219 183 check_admin_referer( 'delete-lang' );
220 184
221 - if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
222 - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
185 + if ( ! empty( $_GET['lang'] ) ) {
186 + $this->model->delete_language( (int) $_GET['lang'] );
223 187 }
224 188
225 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
226 - break;
189 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
190 + break;
227 191
228 192 case 'update':
229 193 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
230 - $errors = $this->model->update_language( $_POST );
194 + $error = $this->model->update_language( $_POST );
195 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
196 + break;
231 197
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 -
240 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
241 - break;
242 -
243 198 case 'default-lang':
244 199 check_admin_referer( 'default-lang' );
245 200
246 201 if ( $lang = $this->model->get_language( (int) $_GET['lang'] ) ) {
@@ -246,10 +201,10 @@
246 201 if ( $lang = $this->model->get_language( (int) $_GET['lang'] ) ) {
247 202 $this->model->update_default_lang( $lang->slug );
248 203 }
249 204
250 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
251 - break;
205 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
206 + break;
252 207
253 208 case 'content-default-lang':
254 209 check_admin_referer( 'content-default-lang' );
255 210
@@ -261,32 +216,22 @@
261 216 $this->model->set_language_in_mass( 'term', $nolang['terms'], $this->options['default_lang'] );
262 217 }
263 218 }
264 219
265 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
266 - break;
220 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
221 + break;
267 222
268 223 case 'activate':
269 224 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 - }
225 + $this->modules[ $_GET['module'] ]->activate();
276 226 self::redirect();
277 - break;
227 + break;
278 228
279 229 case 'deactivate':
280 230 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 - }
231 + $this->modules[ $_GET['module'] ]->deactivate();
287 232 self::redirect();
288 - break;
233 + break;
289 234
290 235 default:
291 236 /**
292 237 * Fires when a non default action has been sent to Polylang settings
@@ -293,43 +238,61 @@
293 238 *
294 239 * @since 1.8
295 240 */
296 241 do_action( "mlang_action_$action" );
297 - break;
242 + break;
298 243 }
299 244 }
300 245
301 246 /**
302 247 * Displays the 3 tabs pages: languages, strings translations, settings
303 - * Also manages user input for these pages
248 + * also manages user input for these pages
304 249 *
305 250 * @since 0.1
306 251 */
307 252 public function languages_page() {
253 + // prepare the list of tabs
254 + $tabs = array( 'lang' => __( 'Languages','polylang' ) );
255 +
256 + // only if at least one language has been created
257 + if ( $listlanguages = $this->model->get_languages_list() ) {
258 + $tabs['strings'] = __( 'Strings translations', 'polylang' );
259 + }
260 +
261 + $tabs['settings'] = __( 'Settings', 'polylang' );
262 +
263 + /**
264 + * Filter the list of tabs in Polylang settings
265 + *
266 + * @since 1.5.1
267 + *
268 + * @param array $tabs list of tab names
269 + */
270 + $tabs = apply_filters( 'pll_settings_tabs', $tabs );
271 +
308 272 switch ( $this->active_tab ) {
309 273 case 'lang':
310 - // Prepare the list table of languages
274 + // prepare the list table of languages
311 275 $list_table = new PLL_Table_Languages();
312 - $list_table->prepare_items( $this->model->get_languages_list() );
313 - break;
276 + $list_table->prepare_items( $listlanguages );
277 + break;
314 278
315 279 case 'strings':
316 - $string_table = new PLL_Table_String( $this->model->get_languages_list() );
280 + $string_table = new PLL_Table_String( $listlanguages );
317 281 $string_table->prepare_items();
318 - break;
282 + break;
319 283 }
320 284
321 - // 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
285 + // handle user input
286 + $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : '';
287 + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) {
325 288 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
326 289 } else {
327 290 $this->handle_actions( $action );
328 291 }
329 292
330 - // Displays the page
331 - include PLL_SETTINGS_INC . '/view-languages.php';
293 + // displays the page
294 + include( PLL_SETTINGS_INC.'/view-languages.php' );
332 295 }
333 296
334 297 /**
335 298 * Enqueues scripts and styles
@@ -338,12 +301,12 @@
338 301 parent::admin_enqueue_scripts();
339 302
340 303 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
341 304
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 ) );
305 + wp_enqueue_script( 'pll_admin', POLYLANG_URL .'/js/admin'.$suffix.'.js', array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION );
306 + wp_localize_script( 'pll_admin', 'pll_flag_base_url', POLYLANG_URL . '/flags/' );
344 307
345 - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
308 + wp_enqueue_style( 'pll_selectmenu', POLYLANG_URL .'/css/selectmenu'.$suffix.'.css', array(), POLYLANG_VERSION );
346 309 }
347 310
348 311 /**
349 312 * Displays a notice when there are objects with no language assigned
@@ -350,13 +313,13 @@
350 313 *
351 314 * @since 1.8
352 315 */
353 316 public function notice_objects_with_no_lang() {
354 - if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
317 + if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang() ) {
355 318 printf(
356 319 '<div class="error"><p>%s <a href="%s">%s</a></p></div>',
357 320 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' ) ),
321 + wp_nonce_url( '?page=mlang&amp;pll_action=content-default-lang&amp;noheader=true', 'content-default-lang' ),
359 322 esc_html__( 'You can set them all to the default language.', 'polylang' )
360 323 );
361 324 }
362 325 }
@@ -368,53 +331,14 @@
368 331 * @since 1.5
369 332 *
370 333 * @param array $args query arguments to add to the url
371 334 */
372 - public static function redirect( $args = array() ) {
335 + static public function redirect( $args = array() ) {
373 336 if ( $errors = get_settings_errors() ) {
374 337 set_transient( 'settings_errors', $errors, 30 );
375 338 $args['settings-updated'] = 1;
376 339 }
377 - // Remove possible 'pll_action' and 'lang' query args from the referer before redirecting
378 - wp_safe_redirect( add_query_arg( $args, remove_query_arg( array( 'pll_action', 'lang' ), wp_get_referer() ) ) );
340 + // remove possible 'pll_action' and 'lang' query args from the referer before redirecting
341 + wp_safe_redirect( add_query_arg( $args, remove_query_arg( array( 'pll_action', 'lang' ), wp_get_referer() ) ) );
379 342 exit;
380 - }
381 -
382 - /**
383 - * Get the list of predefined languages
384 - *
385 - * @since 2.3
386 - */
387 - public static function get_predefined_languages() {
388 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
389 -
390 - $languages = include PLL_SETTINGS_INC . '/languages.php';
391 - $translations = wp_get_available_translations();
392 -
393 - // Keep only languages with existing WP language pack
394 - // Unless the transient has expired and we don't have an internet connection to refresh it
395 - if ( ! empty( $translations ) ) {
396 - $translations['en_US'] = ''; // Languages packs don't include en_US
397 - $languages = array_intersect_key( $languages, $translations );
398 - }
399 -
400 - /**
401 - * Filter the list of predefined languages
402 - *
403 - * @since 1.7.10
404 - * @since 2.3 The languages arrays use associative keys instead of numerical keys
405 - * @see settings/languages.php
406 - *
407 - * @param array $languages
408 - */
409 - $languages = apply_filters( 'pll_predefined_languages', $languages );
410 -
411 - // Keep only languages with all necessary informations
412 - foreach ( $languages as $k => $lang ) {
413 - if ( ! isset( $lang['code'], $lang['locale'], $lang['name'], $lang['dir'], $lang['flag'] ) ) {
414 - unset( $languages[ $k ] );
415 - }
416 - }
417 -
418 - return $languages;
419 343 }
420 344 }