PluginProbe
Polylang / 2.7.3
Polylang v2.7.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 | admin/admin-base.php +87 -45 2.92.7.3 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
@@ -42,8 +49,16 @@
42 49 parent::init();
43 50
44 51 $this->notices = new PLL_Admin_Notices( $this );
45 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 +
46 61 if ( ! $this->model->get_languages_list() ) {
47 62 return;
48 63 }
49 64
@@ -57,8 +72,14 @@
57 72 add_filter( 'request', array( $this, 'request' ) );
58 73
59 74 // Adds the languages in admin bar
60 75 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 + }
61 82 }
62 83
63 84 /**
64 85 * Adds the link to the languages panel in the WordPress admin menu
@@ -173,8 +194,24 @@
173 194 *
174 195 * @since 2.4.0
175 196 */
176 197 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 +
177 214 if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) {
178 215 wp_localize_script(
179 216 'pll_widgets',
180 217 'pll_widgets',
@@ -215,36 +252,34 @@
215 252 $arr = wp_json_encode( $params );
216 253 ?>
217 254 <script type="text/javascript">
218 255 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 - }
256 + (function($){
257 + $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
258 + if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) {
259 + 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 ?>;
261 + } else {
262 + if ( 'string' === typeof options.data ) {
263 + if ( '' === options.data && 'get' === options.type.toLowerCase() ) {
264 + options.url = options.url+'&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>';
265 + } else {
266 + try {
267 + var o = $.parseJSON(options.data);
268 + o = $.extend(o, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
269 + options.data = JSON.stringify(o);
238 270 }
239 - } else {
240 - options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
271 + catch(e) {
272 + options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data;
273 + }
241 274 }
275 + } else {
276 + options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>);
242 277 }
243 278 }
244 - });
245 - }
246 - );
279 + }
280 + });
281 + })(jQuery)
247 282 }
248 283 </script>
249 284 <?php
250 285 }
@@ -259,9 +294,9 @@
259 294
260 295 // Edit Post
261 296 if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
262 297 $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
298 + } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
264 299 $this->curlang = $lang;
265 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
266 301 $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
267 302 }
@@ -266,14 +301,15 @@
266 301 $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
267 302 }
268 303
269 304 // 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
305 + // 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
271 307 $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
308 + } elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
309 + $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
276 312 $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
277 313 } elseif ( empty( $this->curlang ) ) {
278 314 $this->curlang = $this->pref_lang;
279 315 }
@@ -282,17 +318,8 @@
282 318 // Ajax
283 319 if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
284 320 $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
285 321 }
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 322 }
296 323
297 324 /**
298 325 * Defines the backend language and the admin language filter based on user preferences
@@ -323,10 +350,17 @@
323 350 $this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang );
324 351
325 352 $this->set_current_language();
326 353
327 - // Plugin i18n, only needed for backend.
328 - load_plugin_textdomain( 'polylang' );
354 + // Inform that the admin language has been set
355 + // Only if the admin language is one of the Polylang defined language
356 + if ( $curlang = $this->model->get_language( get_user_locale() ) ) {
357 + /** This action is documented in frontend/choose-lang.php */
358 + do_action( 'pll_language_defined', $curlang->slug, $curlang );
359 + } else {
360 + /** This action is documented in include/class-polylang.php */
361 + do_action( 'pll_no_language_defined' ); // to load overridden textdomains
362 + }
329 363 }
330 364
331 365 /**
332 366 * Avoids parsing a tax query when all languages are requested
@@ -331,9 +365,9 @@
331 365 /**
332 366 * Avoids parsing a tax query when all languages are requested
333 367 * Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1
334 368 *
335 - * @see https://core.trac.wordpress.org/ticket/31246 the suggestion of @boonebgorges.
369 + * @see the suggestion of @boonebgorges, https://core.trac.wordpress.org/ticket/31246
336 370 *
337 371 * @since 1.6.5
338 372 *
339 373 * @param array $qvars
@@ -404,6 +438,14 @@
404 438 'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ),
405 439 )
406 440 );
407 441 }
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 );
408 450 }
409 451 }