PluginProbe
Polylang / 2.5
Polylang v2.5
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 +48 -115 2.7.32.5 View file →
@@ -30,13 +30,11 @@
30 30 add_action( 'admin_print_footer_scripts', array( $this, 'admin_print_footer_scripts' ), 0 ); // High priority in case an ajax request is sent by an immediately invoked function
31 31
32 32 add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts' ) );
33 33
34 - if ( defined( 'POLYLANG_PRO' ) ) {
35 - new PLL_Pro();
36 - } elseif ( ! defined( 'PLL_LINGOTEK_AD' ) || PLL_LINGOTEK_AD ) {
37 - require_once POLYLANG_DIR . '/lingotek/lingotek.php'; // Lingotek
38 - add_action( 'wp_loaded', array( new PLL_Lingotek(), 'init' ) );
34 + // Lingotek
35 + if ( ! defined( 'POLYLANG_PRO' ) && ( ! defined( 'PLL_LINGOTEK_AD' ) || PLL_LINGOTEK_AD ) ) {
36 + require_once POLYLANG_DIR . '/lingotek/lingotek.php';
39 37 }
40 38 }
41 39
42 40 /**
@@ -45,24 +43,13 @@
45 43 *
46 44 * @since 1.2
47 45 */
48 46 public function init() {
49 - parent::init();
50 -
51 - $this->notices = new PLL_Admin_Notices( $this );
52 -
53 - if ( Polylang::is_wizard() && class_exists( 'PLL_Wizard_Pro' ) ) {
54 - // Instantiate PLL_Wizard_Pro class after all PLL_Admin object is all initialized.
55 - // After PLL_Admin::maybe_load_sync_post which is hooked on admin_init with priority 20.
56 - add_action( 'admin_init', array( $this, 'instantiate_wizard_pro' ), 30 );
57 - }
58 -
59 - $this->wizard = new PLL_Wizard( $this );
60 -
61 47 if ( ! $this->model->get_languages_list() ) {
62 48 return;
63 49 }
64 50
51 + $this->notices = new PLL_Admin_Notices( $this );
65 52 $this->links = new PLL_Admin_Links( $this ); // FIXME needed here ?
66 53 $this->static_pages = new PLL_Admin_Static_Pages( $this ); // FIXME needed here ?
67 54 $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ?
68 55
@@ -67,19 +54,13 @@
67 54 $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ?
68 55
69 56 // Filter admin language for users
70 57 // We must not call user info before WordPress defines user roles in wp-settings.php
71 - add_action( 'setup_theme', array( $this, 'init_user' ) );
58 + add_filter( 'setup_theme', array( $this, 'init_user' ) );
72 59 add_filter( 'request', array( $this, 'request' ) );
73 60
74 61 // Adds the languages in admin bar
75 62 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100 ); // 100 determines the position
76 -
77 - // Translate slugs, only for pretty permalinks
78 - if ( get_option( 'permalink_structure' ) && class_exists( 'PLL_Translate_Slugs' ) ) {
79 - $slugs_model = new PLL_Translate_Slugs_Model( $this );
80 - $this->translate_slugs = new PLL_Translate_Slugs( $slugs_model, $this->curlang );
81 - }
82 63 }
83 64
84 65 /**
85 66 * Adds the link to the languages panel in the WordPress admin menu
@@ -86,10 +67,8 @@
86 67 *
87 68 * @since 0.1
88 69 */
89 70 public function add_menus() {
90 - global $admin_page_hooks;
91 -
92 71 // Prepare the list of tabs
93 72 $tabs = array( 'lang' => __( 'Languages', 'polylang' ) );
94 73
95 74 // Only if at least one language has been created
@@ -107,16 +86,13 @@
107 86 * @param array $tabs list of tab names
108 87 */
109 88 $tabs = apply_filters( 'pll_settings_tabs', $tabs );
110 89
111 - $parent = '';
112 -
113 90 foreach ( $tabs as $tab => $title ) {
114 91 $page = 'lang' === $tab ? 'mlang' : "mlang_$tab";
115 92 if ( empty( $parent ) ) {
116 93 $parent = $page;
117 94 add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' );
118 - $admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857
119 95 }
120 96
121 97 add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) );
122 98 }
@@ -134,38 +110,31 @@
134 110 }
135 111
136 112 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
137 113
138 - /*
139 - * For each script:
140 - * 0 => the pages on which to load the script
141 - * 1 => the scripts it needs to work
142 - * 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
143 - * 3 => 1 if loaded in footer
144 - */
114 + // For each script:
115 + // 0 => the pages on which to load the script
116 + // 1 => the scripts it needs to work
117 + // 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
118 + // 3 => 1 if loaded in footer
119 + // FIXME: check if I can load more scripts in footer
145 120 $scripts = array(
146 - 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
147 - 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
121 + 'post' => array( array( 'edit' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ),
122 + 'media' => array( array( 'upload' ), array( 'jquery' ), 0, 1 ),
123 + 'term' => array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ),
124 + 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
125 + 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
148 126 );
149 127
150 128 if ( ! empty( $screen->post_type ) && $this->model->is_translated_post_type( $screen->post_type ) ) {
151 - $scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 );
129 + $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-autocomplete' ), 0, 1 );
152 130
153 - // Classic editor.
154 - if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) {
155 - $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post' ), 0, 1 );
131 + // Block editor in WP 5.0+
132 + if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) {
133 + $scripts['block-editor'] = array( array( 'post' ), array( 'wp-api-fetch' ), 0, 1 );
156 134 }
157 -
158 - // Block editor with legacy metabox in WP 5.0+.
159 - if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() && ! pll_use_block_editor_plugin() ) {
160 - $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch' ), 0, 1 );
161 - }
162 135 }
163 136
164 - if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) {
165 - $scripts['term'] = array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 );
166 - }
167 -
168 137 foreach ( $scripts as $script => $v ) {
169 138 if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) {
170 139 wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] );
171 140 }
@@ -194,24 +163,8 @@
194 163 *
195 164 * @since 2.4.0
196 165 */
197 166 public function localize_scripts() {
198 - if ( wp_script_is( 'pll_classic-editor', 'enqueued' ) ) {
199 - wp_localize_script(
200 - 'pll_classic-editor',
201 - 'confirm_text',
202 - __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' )
203 - );
204 - }
205 -
206 - if ( wp_script_is( 'pll_block-editor', 'enqueued' ) ) {
207 - wp_localize_script(
208 - 'pll_block-editor',
209 - 'confirm_text',
210 - __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' )
211 - );
212 - }
213 -
214 167 if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) {
215 168 wp_localize_script(
216 169 'pll_widgets',
217 170 'pll_widgets',
@@ -248,9 +201,9 @@
248 201 $params = array_merge( $params, array( 'pll_term_id' => (int) $tag_ID ) );
249 202 }
250 203
251 204 $str = http_build_query( $params );
252 - $arr = wp_json_encode( $params );
205 + $arr = json_encode( $params );
253 206 ?>
254 207 <script type="text/javascript">
255 208 if (typeof jQuery != 'undefined') {
256 209 (function($){
@@ -256,25 +209,25 @@
256 209 (function($){
257 210 $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
258 211 if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
259 212 if ( 'undefined' === typeof options.data ) {
260 - options.data = ( 'get' === options.type.toLowerCase() ) ? '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>' : <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>;
213 + options.data = ( 'get' === options.type.toLowerCase() ) ? '<?php echo $str; ?>' : <?php echo $arr; ?>;
261 214 } else {
262 215 if ( 'string' === typeof options.data ) {
263 216 if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
264 - options.url = options.url+'&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
217 + options.url = options.url+'&<?php echo $str; ?>';
265 218 } else {
266 219 try {
267 220 var o = $.parseJSON(options.data);
268 - o = $.extend(o, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
221 + o = $.extend(o, <?php echo $arr; ?>);
269 222 options.data = JSON.stringify(o);
270 223 }
271 224 catch(e) {
272 - options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data;
225 + options.data = '<?php echo $str; ?>&'+options.data;
273 226 }
274 227 }
275 228 } else {
276 - options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
229 + options.data = $.extend(options.data, <?php echo $arr; ?>);
277 230 }
278 231 }
279 232 }
280 233 });
@@ -292,25 +245,25 @@
292 245 public function set_current_language() {
293 246 $this->curlang = $this->filter_lang;
294 247
295 248 // Edit Post
296 - if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
249 + if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) {
297 250 $this->curlang = $lang;
298 - } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
251 + } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && is_numeric( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) {
299 252 $this->curlang = $lang;
300 - } 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
301 - $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
253 + } elseif ( 'post-new.php' === $GLOBALS['pagenow'] && ( empty( $_GET['post_type'] ) || $this->model->is_translated_post_type( $_GET['post_type'] ) ) ) {
254 + $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( $_GET['new_lang'] );
302 255 }
303 256
304 257 // Edit Term
305 258 // FIXME 'edit-tags.php' for backward compatibility with WP < 4.5
306 - 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
259 + 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'] ) ) {
307 260 $this->curlang = $lang;
308 - } elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
261 + } elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) {
309 262 $this->curlang = $lang;
310 - } elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
311 - if ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
312 - $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
263 + } elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( $_GET['taxonomy'] ) ) {
264 + if ( ! empty( $_GET['new_lang'] ) ) {
265 + $this->curlang = $this->model->get_language( $_GET['new_lang'] );
313 266 } elseif ( empty( $this->curlang ) ) {
314 267 $this->curlang = $this->pref_lang;
315 268 }
316 269 }
@@ -315,10 +268,10 @@
315 268 }
316 269 }
317 270
318 271 // Ajax
319 - if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
320 - $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
272 + if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) {
273 + $this->curlang = $this->model->get_language( $_REQUEST['lang'] );
321 274 }
322 275 }
323 276
324 277 /**
@@ -328,11 +281,10 @@
328 281 */
329 282 public function init_user() {
330 283 // Language for admin language filter: may be empty
331 284 // $_GET['lang'] is numeric when editing a language, not when selecting a new language in the filter
332 - // We intentionally don't use a nonce to update the language filter
333 - if ( ! wp_doing_ajax() && ! empty( $_GET['lang'] ) && ! is_numeric( sanitize_key( $_GET['lang'] ) ) && current_user_can( 'edit_user', $user_id = get_current_user_id() ) ) { // phpcs:ignore WordPress.Security.NonceVerification
334 - update_user_meta( $user_id, 'pll_filter_content', ( $lang = $this->model->get_language( sanitize_key( $_GET['lang'] ) ) ) ? $lang->slug : '' ); // phpcs:ignore WordPress.Security.NonceVerification
285 + if ( ! wp_doing_ajax() && ! empty( $_GET['lang'] ) && ! is_numeric( $_GET['lang'] ) && current_user_can( 'edit_user', $user_id = get_current_user_id() ) ) {
286 + update_user_meta( $user_id, 'pll_filter_content', ( $lang = $this->model->get_language( $_GET['lang'] ) ) ? $lang->slug : '' );
335 287 }
336 288
337 289 $this->filter_lang = $this->model->get_language( get_user_meta( get_current_user_id(), 'pll_filter_content', true ) );
338 290
@@ -403,29 +355,18 @@
403 355 __( 'Filters content by language', 'polylang' ),
404 356 esc_html( $selected->name )
405 357 );
406 358
407 - /**
408 - * Filters the admin languages filter submenu items
409 - *
410 - * @since 2.6
411 - *
412 - * @param array $items The admin languages filter submenu items.
413 - */
414 - $items = apply_filters( 'pll_admin_languages_filter', array_merge( array( $all_item ), $this->model->get_languages_list() ) );
359 + $wp_admin_bar->add_menu(
360 + array(
361 + 'id' => 'languages',
362 + 'title' => $selected->flag . $title,
363 + 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ),
364 + 'meta' => array( 'title' => __( 'Filters content by language', 'polylang' ) ),
365 + )
366 + );
415 367
416 - if ( ! empty( $items ) ) {
417 - $wp_admin_bar->add_menu(
418 - array(
419 - 'id' => 'languages',
420 - 'title' => $selected->flag . $title,
421 - 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ),
422 - 'meta' => array( 'title' => __( 'Filters content by language', 'polylang' ) ),
423 - )
424 - );
425 - }
426 -
427 - foreach ( $items as $lang ) {
368 + foreach ( array_merge( array( $all_item ), $this->model->get_languages_list() ) as $lang ) {
428 369 if ( $selected->slug === $lang->slug ) {
429 370 continue;
430 371 }
431 372
@@ -438,14 +379,6 @@
438 379 'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ),
439 380 )
440 381 );
441 382 }
442 - }
443 - /**
444 - * Instantiate PLL_Wizard_Pro class.
445 - *
446 - * @since 2.7
447 - */
448 - public function instantiate_wizard_pro() {
449 - $this->wizard_pro = new PLL_Wizard_Pro( $this );
450 383 }
451 384 }