PluginProbe
Polylang / 2.8
Polylang v2.8
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 | admin/admin-base.php +58 -120 3.02.8 View file →
@@ -3,64 +3,29 @@
3 3 * @package Polylang
4 4 */
5 5
6 6 /**
7 - * Setup features available on all admin pages.
7 + * Base class for both admin
8 8 *
9 9 * @since 1.8
10 10 */
11 -abstract class PLL_Admin_Base extends PLL_Base {
12 - /**
13 - * Current language (used to filter the content).
14 - *
15 - * @var PLL_Language
16 - */
17 - public $curlang;
11 +class PLL_Admin_Base extends PLL_Base {
12 + public $filter_lang, $curlang, $pref_lang;
18 13
19 14 /**
20 - * Language selected in the admin language filter.
15 + * Loads the polylang text domain
16 + * Setups actions needed on all admin pages
21 17 *
22 - * @var PLL_Language
23 - */
24 - public $filter_lang;
25 -
26 - /**
27 - * Preferred language to assign to new contents.
28 - *
29 - * @var PLL_Language
30 - */
31 - public $pref_lang;
32 -
33 - /**
34 - * @var PLL_Filters_Links
35 - */
36 - public $filters_links;
37 -
38 - /**
39 - * @var PLL_Admin_Links
40 - */
41 - public $links;
42 -
43 - /**
44 - * @var PLL_Admin_Notices
45 - */
46 - public $notices;
47 -
48 - /**
49 - * @var PLL_Admin_Static_Pages
50 - */
51 - public $static_pages;
52 -
53 - /**
54 - * Setups actions needed on all admin pages.
55 - *
56 18 * @since 1.8
57 19 *
58 - * @param PLL_Links_Model $links_model Reference to the links model.
20 + * @param object $links_model
59 21 */
60 22 public function __construct( &$links_model ) {
61 23 parent::__construct( $links_model );
62 24
25 + // Plugin i18n, only needed for backend
26 + load_plugin_textdomain( 'polylang' );
27 +
63 28 // Adds the link to the languages panel in the WordPress admin menu
64 29 add_action( 'admin_menu', array( $this, 'add_menus' ) );
65 30
66 31 // Setup js scripts and css styles
@@ -101,10 +66,8 @@
101 66 /**
102 67 * Adds the link to the languages panel in the WordPress admin menu
103 68 *
104 69 * @since 0.1
105 - *
106 - * @return void
107 70 */
108 71 public function add_menus() {
109 72 global $admin_page_hooks;
110 73
@@ -132,9 +95,9 @@
132 95 foreach ( $tabs as $tab => $title ) {
133 96 $page = 'lang' === $tab ? 'mlang' : "mlang_$tab";
134 97 if ( empty( $parent ) ) {
135 98 $parent = $page;
136 - add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, '__return_null', 'dashicons-translation' );
99 + add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' );
137 100 $admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857
138 101 }
139 102
140 103 add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) );
@@ -144,10 +107,8 @@
144 107 /**
145 108 * Setup js scripts & css styles ( only on the relevant pages )
146 109 *
147 110 * @since 0.6
148 - *
149 - * @return void
150 111 */
151 112 public function admin_enqueue_scripts() {
152 113 $screen = get_current_screen();
153 114 if ( empty( $screen ) ) {
@@ -172,14 +133,14 @@
172 133 $scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 );
173 134
174 135 // Classic editor.
175 136 if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) {
176 - $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-dialog' ), 0, 1 );
137 + $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post' ), 0, 1 );
177 138 }
178 139
179 140 // Block editor with legacy metabox in WP 5.0+.
180 141 if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() && ! pll_use_block_editor_plugin() ) {
181 - $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch', 'jquery-ui-dialog' ), 0, 1 );
142 + $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch' ), 0, 1 );
182 143 }
183 144 }
184 145
185 146 if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) {
@@ -187,14 +148,13 @@
187 148 }
188 149
189 150 foreach ( $scripts as $script => $v ) {
190 151 if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) {
191 - wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/build/' . $script . $suffix . '.js', POLYLANG_BASENAME ), $v[1], POLYLANG_VERSION, $v[3] );
152 + wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] );
192 153 }
193 154 }
194 155
195 - wp_register_style( 'polylang_admin', plugins_url( '/css/build/admin' . $suffix . '.css', POLYLANG_BASENAME ), array( 'wp-jquery-ui-dialog' ), POLYLANG_VERSION );
196 - wp_enqueue_style( 'polylang_dialog', plugins_url( '/css/build/dialog' . $suffix . '.css', POLYLANG_BASENAME ), array( 'polylang_admin' ), POLYLANG_VERSION );
156 + wp_enqueue_style( 'polylang_admin', plugins_url( '/css/admin' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
197 157
198 158 $this->localize_scripts();
199 159 }
200 160
@@ -201,15 +161,13 @@
201 161 /**
202 162 * Enqueue scripts to the WP Customizer.
203 163 *
204 164 * @since 2.4.0
205 - *
206 - * @return void
207 165 */
208 166 public function customize_controls_enqueue_scripts() {
209 167 if ( $this->model->get_languages_list() ) {
210 168 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
211 - wp_enqueue_script( 'pll_widgets', plugins_url( '/js/build/widgets' . $suffix . '.js', POLYLANG_BASENAME ), array( 'jquery' ), POLYLANG_VERSION, true );
169 + wp_enqueue_script( 'pll_widgets', plugins_url( '/js/widgets' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery' ), POLYLANG_VERSION, true );
212 170 $this->localize_scripts();
213 171 }
214 172 }
215 173
@@ -216,10 +174,8 @@
216 174 /**
217 175 * Localize scripts.
218 176 *
219 177 * @since 2.4.0
220 - *
221 - * @return void
222 178 */
223 179 public function localize_scripts() {
224 180 if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) {
225 181 wp_localize_script(
@@ -244,10 +200,8 @@
244 200 * when options.data is an empty string (GET request with the method 'load')
245 201 * see: https://wordpress.org/support/topic/invalid-url-during-wordpress-new-dashboard-widget-operation
246 202 *
247 203 * @since 1.4
248 - *
249 - * @return void
250 204 */
251 205 public function admin_print_footer_scripts() {
252 206 global $post_ID, $tag_ID;
253 207
@@ -264,44 +218,34 @@
264 218 $arr = wp_json_encode( $params );
265 219 ?>
266 220 <script type="text/javascript">
267 221 if (typeof jQuery != 'undefined') {
268 - jQuery(
269 - function( $ ){
270 - $.ajaxPrefilter( function ( options, originalOptions, jqXHR ) {
271 - if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
272 -
273 - function addStringParameters() {
274 - if ( 'undefined' === typeof options.data || '' === options.data ) {
275 - options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
222 + (function($){
223 + $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
224 + if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
225 + if ( 'undefined' === typeof options.data ) {
226 + options.data = ( 'get' === options.type.toLowerCase() ) ? '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>' : <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>;
227 + } else {
228 + if ( 'string' === typeof options.data ) {
229 + if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
230 + options.url = options.url+'&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
276 231 } else {
277 - options.data = options.data + '&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
232 + try {
233 + var o = $.parseJSON(options.data);
234 + o = $.extend(o, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
235 + options.data = JSON.stringify(o);
236 + }
237 + catch(e) {
238 + options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data;
239 + }
278 240 }
279 - }
280 -
281 - /*
282 - * options.processData set to true is the default jQuery process where the data is converted in a query string by using jQuery.param().
283 - * This step is done before applying filters. Thus here the options.data is already a string in this case.
284 - * @See https://github.com/jquery/jquery/blob/3.5.1/src/ajax.js#L563-L569 jQuery ajax function.
285 - */
286 - if ( options.processData ) {
287 - addStringParameters();
288 241 } else {
289 - /*
290 - * If options.processData is set to false data could be undefined or pass as a string.
291 - * So data as to be processed as if options.processData is set to true.
292 - */
293 - if ( 'undefined' === typeof options.data || 'string' === typeof options.data ) {
294 - addStringParameters();
295 - } else {
296 - // Otherwise options.data is probably an object.
297 - options.data = Object.assign( options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?> );
298 - }
242 + options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
299 243 }
300 244 }
301 - });
302 - }
303 - );
245 + }
246 + });
247 + })(jQuery)
304 248 }
305 249 </script>
306 250 <?php
307 251 }
@@ -309,10 +253,8 @@
309 253 /**
310 254 * Sets the admin current language, used to filter the content
311 255 *
312 256 * @since 2.0
313 - *
314 - * @return void
315 257 */
316 258 public function set_current_language() {
317 259 $this->curlang = $this->filter_lang;
318 260
@@ -318,9 +260,9 @@
318 260
319 261 // Edit Post
320 262 if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
321 263 $this->curlang = $lang;
322 - } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $this->model->is_translated_post_type( get_post_type( (int) $_GET['post'] ) ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
264 + } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
323 265 $this->curlang = $lang;
324 266 } elseif ( 'post-new.php' === $GLOBALS['pagenow'] && ( empty( $_GET['post_type'] ) || $this->model->is_translated_post_type( sanitize_key( $_GET['post_type'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
325 267 $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
326 268 }
@@ -325,14 +267,15 @@
325 267 $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
326 268 }
327 269
328 270 // Edit Term
329 - elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
271 + // FIXME 'edit-tags.php' for backward compatibility with WP < 4.5
272 + elseif ( in_array( $GLOBALS['pagenow'], array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
330 273 $this->curlang = $lang;
331 - } elseif ( in_array( $GLOBALS['pagenow'], array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
332 - if ( isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
333 - $this->curlang = $lang;
334 - } elseif ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
274 + } elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
275 + $this->curlang = $lang;
276 + } elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
277 + if ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
335 278 $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
336 279 } elseif ( empty( $this->curlang ) ) {
337 280 $this->curlang = $this->pref_lang;
338 281 }
@@ -341,17 +284,8 @@
341 284 // Ajax
342 285 if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
343 286 $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
344 287 }
345 -
346 - // Inform that the admin language has been set.
347 - if ( $this->curlang ) {
348 - /** This action is documented in frontend/choose-lang.php */
349 - do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang );
350 - } else {
351 - /** This action is documented in include/class-polylang.php */
352 - do_action( 'pll_no_language_defined' ); // To load overridden textdomains.
353 - }
354 288 }
355 289
356 290 /**
357 291 * Defines the backend language and the admin language filter based on user preferences
@@ -356,10 +290,8 @@
356 290 /**
357 291 * Defines the backend language and the admin language filter based on user preferences
358 292 *
359 293 * @since 1.2.3
360 - *
361 - * @return void
362 294 */
363 295 public function init_user() {
364 296 // Language for admin language filter: may be empty
365 297 // $_GET['lang'] is numeric when editing a language, not when selecting a new language in the filter
@@ -373,21 +305,28 @@
373 305 // Set preferred language for use when saving posts and terms: must not be empty
374 306 $this->pref_lang = empty( $this->filter_lang ) ? $this->model->get_language( $this->options['default_lang'] ) : $this->filter_lang;
375 307
376 308 /**
377 - * Filters the preferred language on admin side.
378 - * The preferred language is used for example to determine the language of a new post.
309 + * Filter the preferred language on admin side
310 + * The preferred language is used for example to determine the language of a new post
379 311 *
380 312 * @since 1.2.3
381 313 *
382 - * @param PLL_Language $pref_lang Preferred language.
314 + * @param object $pref_lang preferred language
383 315 */
384 316 $this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang );
385 317
386 318 $this->set_current_language();
387 319
388 - // Plugin i18n, only needed for backend.
389 - load_plugin_textdomain( 'polylang' );
320 + // Inform that the admin language has been set
321 + // Only if the admin language is one of the Polylang defined language
322 + if ( $curlang = $this->model->get_language( get_user_locale() ) ) {
323 + /** This action is documented in frontend/choose-lang.php */
324 + do_action( 'pll_language_defined', $curlang->slug, $curlang );
325 + } else {
326 + /** This action is documented in include/class-polylang.php */
327 + do_action( 'pll_no_language_defined' ); // to load overridden textdomains
328 + }
390 329 }
391 330
392 331 /**
393 332 * Avoids parsing a tax query when all languages are requested
@@ -392,9 +331,9 @@
392 331 /**
393 332 * Avoids parsing a tax query when all languages are requested
394 333 * Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1
395 334 *
396 - * @see https://core.trac.wordpress.org/ticket/31246 the suggestion of @boonebgorges.
335 + * @see the suggestion of @boonebgorges, https://core.trac.wordpress.org/ticket/31246
397 336 *
398 337 * @since 1.6.5
399 338 *
400 339 * @param array $qvars
@@ -408,14 +347,13 @@
408 347 return $qvars;
409 348 }
410 349
411 350 /**
412 - * Adds the languages list in admin bar for the admin languages filter.
351 + * Adds the languages list in admin bar for the admin languages filter
413 352 *
414 353 * @since 0.9
415 354 *
416 - * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar global object.
417 - * @return void
355 + * @param object $wp_admin_bar
418 356 */
419 357 public function admin_bar_menu( $wp_admin_bar ) {
420 358 $all_item = (object) array(
421 359 'slug' => 'all',