| @@ -21,8 +21,11 @@ | ||
| 21 | 21 | */ |
| 22 | 22 | public function __construct( &$links_model ) { |
| 23 | 23 | parent::__construct( $links_model ); |
| 24 | 24 | |
| 25 | + // Plugin i18n, only needed for backend | |
| 26 | + load_plugin_textdomain( 'polylang' ); | |
| 27 | + | |
| 25 | 28 | // Adds the link to the languages panel in the WordPress admin menu |
| 26 | 29 | add_action( 'admin_menu', array( $this, 'add_menus' ) ); |
| 27 | 30 | |
| 28 | 31 | // Setup js scripts and css styles |
| @@ -215,36 +218,34 @@ | ||
| 215 | 218 | $arr = wp_json_encode( $params ); |
| 216 | 219 | ?> |
| 217 | 220 | <script type="text/javascript"> |
| 218 | 221 | 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 | - } | |
| 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 ?>'; | |
| 231 | + } else { | |
| 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); | |
| 238 | 236 | } |
| 239 | - } else { | |
| 240 | - options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>); | |
| 237 | + catch(e) { | |
| 238 | + options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data; | |
| 239 | + } | |
| 241 | 240 | } |
| 241 | + } else { | |
| 242 | + options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>); | |
| 242 | 243 | } |
| 243 | 244 | } |
| 244 | - }); | |
| 245 | - } | |
| 246 | - ); | |
| 245 | + } | |
| 246 | + }); | |
| 247 | + })(jQuery) | |
| 247 | 248 | } |
| 248 | 249 | </script> |
| 249 | 250 | <?php |
| 250 | 251 | } |
| @@ -259,9 +260,9 @@ | ||
| 259 | 260 | |
| 260 | 261 | // Edit Post |
| 261 | 262 | if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 262 | 263 | $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 | |
| 264 | + } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 264 | 265 | $this->curlang = $lang; |
| 265 | 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 |
| 266 | 267 | $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 267 | 268 | } |
| @@ -266,14 +267,15 @@ | ||
| 266 | 267 | $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 267 | 268 | } |
| 268 | 269 | |
| 269 | 270 | // 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 | |
| 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 | |
| 271 | 273 | $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 | |
| 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 | |
| 276 | 278 | $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 277 | 279 | } elseif ( empty( $this->curlang ) ) { |
| 278 | 280 | $this->curlang = $this->pref_lang; |
| 279 | 281 | } |
| @@ -282,17 +284,8 @@ | ||
| 282 | 284 | // Ajax |
| 283 | 285 | if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 284 | 286 | $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 285 | 287 | } |
| 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 | 288 | } |
| 296 | 289 | |
| 297 | 290 | /** |
| 298 | 291 | * Defines the backend language and the admin language filter based on user preferences |
| @@ -323,10 +316,17 @@ | ||
| 323 | 316 | $this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang ); |
| 324 | 317 | |
| 325 | 318 | $this->set_current_language(); |
| 326 | 319 | |
| 327 | - // Plugin i18n, only needed for backend. | |
| 328 | - 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 | + } | |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
| 332 | 332 | * Avoids parsing a tax query when all languages are requested |
| @@ -331,9 +331,9 @@ | ||
| 331 | 331 | /** |
| 332 | 332 | * Avoids parsing a tax query when all languages are requested |
| 333 | 333 | * Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1 |
| 334 | 334 | * |
| 335 | - * @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 | |
| 336 | 336 | * |
| 337 | 337 | * @since 1.6.5 |
| 338 | 338 | * |
| 339 | 339 | * @param array $qvars |