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 +39 -101 2.72.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 }
@@ -141,9 +117,10 @@
141 117 // 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
142 118 // 3 => 1 if loaded in footer
143 119 // FIXME: check if I can load more scripts in footer
144 120 $scripts = array(
145 - 'post' => array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ),
121 + 'post' => array( array( 'edit' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ),
122 + 'media' => array( array( 'upload' ), array( 'jquery' ), 0, 1 ),
146 123 'term' => array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ),
147 124 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
148 125 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
149 126 );
@@ -148,16 +125,13 @@
148 125 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
149 126 );
150 127
151 128 if ( ! empty( $screen->post_type ) && $this->model->is_translated_post_type( $screen->post_type ) ) {
152 - // Classic editor.
153 - if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) {
154 - $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post' ), 0, 1 );
155 - }
129 + $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-autocomplete' ), 0, 1 );
156 130
157 - // Block editor with legacy metabox in WP 5.0+.
158 - if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() && ! pll_use_block_editor_plugin() ) {
159 - $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch' ), 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 );
160 134 }
161 135 }
162 136
163 137 foreach ( $scripts as $script => $v ) {
@@ -189,24 +163,8 @@
189 163 *
190 164 * @since 2.4.0
191 165 */
192 166 public function localize_scripts() {
193 - if ( wp_script_is( 'pll_classic-editor', 'enqueued' ) ) {
194 - wp_localize_script(
195 - 'pll_classic-editor',
196 - 'confirm_text',
197 - __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' )
198 - );
199 - }
200 -
201 - if ( wp_script_is( 'pll_block-editor', 'enqueued' ) ) {
202 - wp_localize_script(
203 - 'pll_block-editor',
204 - 'confirm_text',
205 - __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' )
206 - );
207 - }
208 -
209 167 if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) {
210 168 wp_localize_script(
211 169 'pll_widgets',
212 170 'pll_widgets',
@@ -243,9 +201,9 @@
243 201 $params = array_merge( $params, array( 'pll_term_id' => (int) $tag_ID ) );
244 202 }
245 203
246 204 $str = http_build_query( $params );
247 - $arr = wp_json_encode( $params );
205 + $arr = json_encode( $params );
248 206 ?>
249 207 <script type="text/javascript">
250 208 if (typeof jQuery != 'undefined') {
251 209 (function($){
@@ -251,25 +209,25 @@
251 209 (function($){
252 210 $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
253 211 if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
254 212 if ( 'undefined' === typeof options.data ) {
255 - 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; ?>;
256 214 } else {
257 215 if ( 'string' === typeof options.data ) {
258 216 if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
259 - options.url = options.url+'&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
217 + options.url = options.url+'&<?php echo $str; ?>';
260 218 } else {
261 219 try {
262 220 var o = $.parseJSON(options.data);
263 - o = $.extend(o, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
221 + o = $.extend(o, <?php echo $arr; ?>);
264 222 options.data = JSON.stringify(o);
265 223 }
266 224 catch(e) {
267 - options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data;
225 + options.data = '<?php echo $str; ?>&'+options.data;
268 226 }
269 227 }
270 228 } else {
271 - options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
229 + options.data = $.extend(options.data, <?php echo $arr; ?>);
272 230 }
273 231 }
274 232 }
275 233 });
@@ -287,25 +245,25 @@
287 245 public function set_current_language() {
288 246 $this->curlang = $this->filter_lang;
289 247
290 248 // Edit Post
291 - 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'] ) ) {
292 250 $this->curlang = $lang;
293 - } 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'] ) ) {
294 252 $this->curlang = $lang;
295 - } 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
296 - $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'] );
297 255 }
298 256
299 257 // Edit Term
300 258 // FIXME 'edit-tags.php' for backward compatibility with WP < 4.5
301 - 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'] ) ) {
302 260 $this->curlang = $lang;
303 - } 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'] ) ) {
304 262 $this->curlang = $lang;
305 - } elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
306 - if ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
307 - $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'] );
308 266 } elseif ( empty( $this->curlang ) ) {
309 267 $this->curlang = $this->pref_lang;
310 268 }
311 269 }
@@ -310,10 +268,10 @@
310 268 }
311 269 }
312 270
313 271 // Ajax
314 - if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
315 - $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'] );
316 274 }
317 275 }
318 276
319 277 /**
@@ -323,11 +281,10 @@
323 281 */
324 282 public function init_user() {
325 283 // Language for admin language filter: may be empty
326 284 // $_GET['lang'] is numeric when editing a language, not when selecting a new language in the filter
327 - // We intentionally don't use a nonce to update the language filter
328 - 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
329 - 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 : '' );
330 287 }
331 288
332 289 $this->filter_lang = $this->model->get_language( get_user_meta( get_current_user_id(), 'pll_filter_content', true ) );
333 290
@@ -398,29 +355,18 @@
398 355 __( 'Filters content by language', 'polylang' ),
399 356 esc_html( $selected->name )
400 357 );
401 358
402 - /**
403 - * Filters the admin languages filter submenu items
404 - *
405 - * @since 2.6
406 - *
407 - * @param array $items The admin languages filter submenu items.
408 - */
409 - $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 + );
410 367
411 - if ( ! empty( $items ) ) {
412 - $wp_admin_bar->add_menu(
413 - array(
414 - 'id' => 'languages',
415 - 'title' => $selected->flag . $title,
416 - 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ),
417 - 'meta' => array( 'title' => __( 'Filters content by language', 'polylang' ) ),
418 - )
419 - );
420 - }
421 -
422 - foreach ( $items as $lang ) {
368 + foreach ( array_merge( array( $all_item ), $this->model->get_languages_list() ) as $lang ) {
423 369 if ( $selected->slug === $lang->slug ) {
424 370 continue;
425 371 }
426 372
@@ -433,14 +379,6 @@
433 379 'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ),
434 380 )
435 381 );
436 382 }
437 - }
438 - /**
439 - * Instantiate PLL_Wizard_Pro class.
440 - *
441 - * @since 2.7
442 - */
443 - public function instantiate_wizard_pro() {
444 - $this->wizard_pro = new PLL_Wizard_Pro( $this );
445 383 }
446 384 }