PluginProbe
Polylang / 2.6.2
Polylang v2.6.2
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 +83 -68 2.9.12.6.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Base class for both admin
8 5 *
@@ -21,8 +18,11 @@
21 18 */
22 19 public function __construct( &$links_model ) {
23 20 parent::__construct( $links_model );
24 21
22 + // Plugin i18n, only needed for backend
23 + load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' );
24 +
25 25 // Adds the link to the languages panel in the WordPress admin menu
26 26 add_action( 'admin_menu', array( $this, 'add_menus' ) );
27 27
28 28 // Setup js scripts and css styles
@@ -29,8 +29,15 @@
29 29 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
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 +
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' ) );
39 + }
33 40 }
34 41
35 42 /**
36 43 * Setups filters and action needed on all admin pages and on plugins page
@@ -40,14 +47,13 @@
40 47 */
41 48 public function init() {
42 49 parent::init();
43 50
44 - $this->notices = new PLL_Admin_Notices( $this );
45 -
46 51 if ( ! $this->model->get_languages_list() ) {
47 52 return;
48 53 }
49 54
55 + $this->notices = new PLL_Admin_Notices( $this );
50 56 $this->links = new PLL_Admin_Links( $this ); // FIXME needed here ?
51 57 $this->static_pages = new PLL_Admin_Static_Pages( $this ); // FIXME needed here ?
52 58 $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ?
53 59
@@ -52,13 +58,19 @@
52 58 $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ?
53 59
54 60 // Filter admin language for users
55 61 // We must not call user info before WordPress defines user roles in wp-settings.php
56 - add_action( 'setup_theme', array( $this, 'init_user' ) );
62 + add_filter( 'setup_theme', array( $this, 'init_user' ) );
57 63 add_filter( 'request', array( $this, 'request' ) );
58 64
59 65 // Adds the languages in admin bar
60 66 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100 ); // 100 determines the position
67 +
68 + // Translate slugs, only for pretty permalinks
69 + if ( get_option( 'permalink_structure' ) && class_exists( 'PLL_Translate_Slugs' ) ) {
70 + $slugs_model = new PLL_Translate_Slugs_Model( $this );
71 + $this->translate_slugs = new PLL_Translate_Slugs( $slugs_model, $this->curlang );
72 + }
61 73 }
62 74
63 75 /**
64 76 * Adds the link to the languages panel in the WordPress admin menu
@@ -65,10 +77,8 @@
65 77 *
66 78 * @since 0.1
67 79 */
68 80 public function add_menus() {
69 - global $admin_page_hooks;
70 -
71 81 // Prepare the list of tabs
72 82 $tabs = array( 'lang' => __( 'Languages', 'polylang' ) );
73 83
74 84 // Only if at least one language has been created
@@ -86,16 +96,13 @@
86 96 * @param array $tabs list of tab names
87 97 */
88 98 $tabs = apply_filters( 'pll_settings_tabs', $tabs );
89 99
90 - $parent = '';
91 -
92 100 foreach ( $tabs as $tab => $title ) {
93 101 $page = 'lang' === $tab ? 'mlang' : "mlang_$tab";
94 102 if ( empty( $parent ) ) {
95 103 $parent = $page;
96 104 add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' );
97 - $admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857
98 105 }
99 106
100 107 add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) );
101 108 }
@@ -113,23 +120,22 @@
113 120 }
114 121
115 122 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
116 123
117 - /*
118 - * For each script:
119 - * 0 => the pages on which to load the script
120 - * 1 => the scripts it needs to work
121 - * 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
122 - * 3 => 1 if loaded in footer
123 - */
124 + // For each script:
125 + // 0 => the pages on which to load the script
126 + // 1 => the scripts it needs to work
127 + // 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise
128 + // 3 => 1 if loaded in footer
129 + // FIXME: check if I can load more scripts in footer
124 130 $scripts = array(
125 - 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
126 - 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
131 + 'post' => array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ),
132 + 'term' => array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ),
133 + 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ),
134 + 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ),
127 135 );
128 136
129 137 if ( ! empty( $screen->post_type ) && $this->model->is_translated_post_type( $screen->post_type ) ) {
130 - $scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 );
131 -
132 138 // Classic editor.
133 139 if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) {
134 140 $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post' ), 0, 1 );
135 141 }
@@ -139,12 +145,8 @@
139 145 $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch' ), 0, 1 );
140 146 }
141 147 }
142 148
143 - if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) {
144 - $scripts['term'] = array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 );
145 - }
146 -
147 149 foreach ( $scripts as $script => $v ) {
148 150 if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) {
149 151 wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] );
150 152 }
@@ -173,8 +175,24 @@
173 175 *
174 176 * @since 2.4.0
175 177 */
176 178 public function localize_scripts() {
179 + if ( wp_script_is( 'pll_classic-editor', 'enqueued' ) ) {
180 + wp_localize_script(
181 + 'pll_classic-editor',
182 + 'confirm_text',
183 + __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' )
184 + );
185 + }
186 +
187 + if ( wp_script_is( 'pll_block-editor', 'enqueued' ) ) {
188 + wp_localize_script(
189 + 'pll_block-editor',
190 + 'confirm_text',
191 + __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' )
192 + );
193 + }
194 +
177 195 if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) {
178 196 wp_localize_script(
179 197 'pll_widgets',
180 198 'pll_widgets',
@@ -215,36 +233,34 @@
215 233 $arr = wp_json_encode( $params );
216 234 ?>
217 235 <script type="text/javascript">
218 236 if (typeof jQuery != 'undefined') {
219 - jQuery(
220 - function($){
221 - $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
222 - if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
223 - if ( 'undefined' === typeof options.data ) {
224 - options.data = ( 'get' === options.type.toLowerCase() ) ? '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>' : <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>;
225 - } else {
226 - if ( 'string' === typeof options.data ) {
227 - if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
228 - options.url = options.url+'&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
229 - } else {
230 - try {
231 - var o = JSON.parse(options.data);
232 - o = $.extend(o, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
233 - options.data = JSON.stringify(o);
234 - }
235 - catch(e) {
236 - options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data;
237 - }
237 + (function($){
238 + $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
239 + if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
240 + if ( 'undefined' === typeof options.data ) {
241 + options.data = ( 'get' === options.type.toLowerCase() ) ? '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>' : <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>;
242 + } else {
243 + if ( 'string' === typeof options.data ) {
244 + if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
245 + options.url = options.url+'&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
246 + } else {
247 + try {
248 + var o = $.parseJSON(options.data);
249 + o = $.extend(o, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
250 + options.data = JSON.stringify(o);
238 251 }
239 - } else {
240 - options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
252 + catch(e) {
253 + options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data;
254 + }
241 255 }
256 + } else {
257 + options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
242 258 }
243 259 }
244 - });
245 - }
246 - );
260 + }
261 + });
262 + })(jQuery)
247 263 }
248 264 </script>
249 265 <?php
250 266 }
@@ -259,9 +275,9 @@
259 275
260 276 // Edit Post
261 277 if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
262 278 $this->curlang = $lang;
263 - } 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
279 + } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
264 280 $this->curlang = $lang;
265 281 } 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
266 282 $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
267 283 }
@@ -266,14 +282,15 @@
266 282 $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
267 283 }
268 284
269 285 // Edit Term
270 - elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
286 + // FIXME 'edit-tags.php' for backward compatibility with WP < 4.5
287 + 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
271 288 $this->curlang = $lang;
272 - } 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
273 - if ( isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
274 - $this->curlang = $lang;
275 - } elseif ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
289 + } elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
290 + $this->curlang = $lang;
291 + } elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
292 + if ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
276 293 $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
277 294 } elseif ( empty( $this->curlang ) ) {
278 295 $this->curlang = $this->pref_lang;
279 296 }
@@ -282,17 +299,8 @@
282 299 // Ajax
283 300 if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
284 301 $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
285 302 }
286 -
287 - // Inform that the admin language has been set.
288 - if ( $this->curlang ) {
289 - /** This action is documented in frontend/choose-lang.php */
290 - do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang );
291 - } else {
292 - /** This action is documented in include/class-polylang.php */
293 - do_action( 'pll_no_language_defined' ); // To load overridden textdomains.
294 - }
295 303 }
296 304
297 305 /**
298 306 * Defines the backend language and the admin language filter based on user preferences
@@ -323,10 +331,17 @@
323 331 $this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang );
324 332
325 333 $this->set_current_language();
326 334
327 - // Plugin i18n, only needed for backend.
328 - load_plugin_textdomain( 'polylang' );
335 + // Inform that the admin language has been set
336 + // Only if the admin language is one of the Polylang defined language
337 + if ( $curlang = $this->model->get_language( get_user_locale() ) ) {
338 + /** This action is documented in frontend/choose-lang.php */
339 + do_action( 'pll_language_defined', $curlang->slug, $curlang );
340 + } else {
341 + /** This action is documented in include/class-polylang.php */
342 + do_action( 'pll_no_language_defined' ); // to load overridden textdomains
343 + }
329 344 }
330 345
331 346 /**
332 347 * Avoids parsing a tax query when all languages are requested
@@ -331,9 +346,9 @@
331 346 /**
332 347 * Avoids parsing a tax query when all languages are requested
333 348 * Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1
334 349 *
335 - * @see https://core.trac.wordpress.org/ticket/31246 the suggestion of @boonebgorges.
350 + * @see the suggestion of @boonebgorges, https://core.trac.wordpress.org/ticket/31246
336 351 *
337 352 * @since 1.6.5
338 353 *
339 354 * @param array $qvars