| @@ -3,29 +3,69 @@ | ||
| 3 | 3 | * @package Polylang |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * Base class for both admin | |
| 7 | + * Setup features available on all admin pages. | |
| 8 | 8 | * |
| 9 | 9 | * @since 1.8 |
| 10 | 10 | */ |
| 11 | -class PLL_Admin_Base extends PLL_Base { | |
| 12 | - public $filter_lang, $curlang, $pref_lang; | |
| 11 | +abstract class PLL_Admin_Base extends PLL_Base { | |
| 12 | + /** | |
| 13 | + * Current language (used to filter the content). | |
| 14 | + * | |
| 15 | + * @var PLL_Language | |
| 16 | + */ | |
| 17 | + public $curlang; | |
| 13 | 18 | |
| 14 | 19 | /** |
| 15 | - * Loads the polylang text domain | |
| 16 | - * Setups actions needed on all admin pages | |
| 20 | + * Language selected in the admin language filter. | |
| 17 | 21 | * |
| 22 | + * @var PLL_Language | |
| 23 | + */ | |
| 24 | + public $filter_lang; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Preferred language to assign to new contents. | |
| 28 | + * | |
| 29 | + * @var PLL_Language | |
| 30 | + */ | |
| 31 | + public $pref_lang; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * @var PLL_Filters_Links | |
| 35 | + */ | |
| 36 | + public $filters_links; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * @var PLL_Admin_Links | |
| 40 | + */ | |
| 41 | + public $links; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @var PLL_Admin_Notices | |
| 45 | + */ | |
| 46 | + public $notices; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @var PLL_Admin_Static_Pages | |
| 50 | + */ | |
| 51 | + public $static_pages; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @var PLL_Admin_Default_Term | |
| 55 | + */ | |
| 56 | + public $default_term; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Setups actions needed on all admin pages. | |
| 60 | + * | |
| 18 | 61 | * @since 1.8 |
| 19 | 62 | * |
| 20 | - * @param object $links_model | |
| 63 | + * @param PLL_Links_Model $links_model Reference to the links model. | |
| 21 | 64 | */ |
| 22 | 65 | public function __construct( &$links_model ) { |
| 23 | 66 | parent::__construct( $links_model ); |
| 24 | 67 | |
| 25 | - // Plugin i18n, only needed for backend | |
| 26 | - load_plugin_textdomain( 'polylang' ); | |
| 27 | - | |
| 28 | 68 | // Adds the link to the languages panel in the WordPress admin menu |
| 29 | 69 | add_action( 'admin_menu', array( $this, 'add_menus' ) ); |
| 30 | 70 | |
| 31 | 71 | // Setup js scripts and css styles |
| @@ -52,8 +92,10 @@ | ||
| 52 | 92 | |
| 53 | 93 | $this->links = new PLL_Admin_Links( $this ); // FIXME needed here ? |
| 54 | 94 | $this->static_pages = new PLL_Admin_Static_Pages( $this ); // FIXME needed here ? |
| 55 | 95 | $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ? |
| 96 | + $this->default_term = new PLL_Admin_Default_Term( $this ); | |
| 97 | + $this->default_term->add_hooks(); | |
| 56 | 98 | |
| 57 | 99 | // Filter admin language for users |
| 58 | 100 | // We must not call user info before WordPress defines user roles in wp-settings.php |
| 59 | 101 | add_action( 'setup_theme', array( $this, 'init_user' ) ); |
| @@ -66,8 +108,10 @@ | ||
| 66 | 108 | /** |
| 67 | 109 | * Adds the link to the languages panel in the WordPress admin menu |
| 68 | 110 | * |
| 69 | 111 | * @since 0.1 |
| 112 | + * | |
| 113 | + * @return void | |
| 70 | 114 | */ |
| 71 | 115 | public function add_menus() { |
| 72 | 116 | global $admin_page_hooks; |
| 73 | 117 | |
| @@ -95,9 +139,9 @@ | ||
| 95 | 139 | foreach ( $tabs as $tab => $title ) { |
| 96 | 140 | $page = 'lang' === $tab ? 'mlang' : "mlang_$tab"; |
| 97 | 141 | if ( empty( $parent ) ) { |
| 98 | 142 | $parent = $page; |
| 99 | - add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' ); | |
| 143 | + add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, '__return_null', 'dashicons-translation' ); | |
| 100 | 144 | $admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857 |
| 101 | 145 | } |
| 102 | 146 | |
| 103 | 147 | add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) ); |
| @@ -107,8 +151,10 @@ | ||
| 107 | 151 | /** |
| 108 | 152 | * Setup js scripts & css styles ( only on the relevant pages ) |
| 109 | 153 | * |
| 110 | 154 | * @since 0.6 |
| 155 | + * | |
| 156 | + * @return void | |
| 111 | 157 | */ |
| 112 | 158 | public function admin_enqueue_scripts() { |
| 113 | 159 | $screen = get_current_screen(); |
| 114 | 160 | if ( empty( $screen ) ) { |
| @@ -133,14 +179,14 @@ | ||
| 133 | 179 | $scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ); |
| 134 | 180 | |
| 135 | 181 | // Classic editor. |
| 136 | 182 | if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) { |
| 137 | - $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post' ), 0, 1 ); | |
| 183 | + $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-dialog', 'wp-i18n' ), 0, 1 ); | |
| 138 | 184 | } |
| 139 | 185 | |
| 140 | 186 | // Block editor with legacy metabox in WP 5.0+. |
| 141 | 187 | if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() && ! pll_use_block_editor_plugin() ) { |
| 142 | - $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch' ), 0, 1 ); | |
| 188 | + $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch', 'jquery-ui-dialog', 'wp-i18n' ), 0, 1 ); | |
| 143 | 189 | } |
| 144 | 190 | } |
| 145 | 191 | |
| 146 | 192 | if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) { |
| @@ -148,13 +194,17 @@ | ||
| 148 | 194 | } |
| 149 | 195 | |
| 150 | 196 | foreach ( $scripts as $script => $v ) { |
| 151 | 197 | if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) { |
| 152 | - wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] ); | |
| 198 | + wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/build/' . $script . $suffix . '.js', POLYLANG_ROOT_FILE ), $v[1], POLYLANG_VERSION, $v[3] ); | |
| 199 | + if ( 'classic-editor' === $script || 'block-editor' === $script ) { | |
| 200 | + wp_set_script_translations( 'pll_' . $script, 'polylang' ); | |
| 201 | + } | |
| 153 | 202 | } |
| 154 | 203 | } |
| 155 | 204 | |
| 156 | - wp_enqueue_style( 'polylang_admin', plugins_url( '/css/admin' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION ); | |
| 205 | + wp_register_style( 'polylang_admin', plugins_url( '/css/build/admin' . $suffix . '.css', POLYLANG_ROOT_FILE ), array( 'wp-jquery-ui-dialog' ), POLYLANG_VERSION ); | |
| 206 | + wp_enqueue_style( 'polylang_dialog', plugins_url( '/css/build/dialog' . $suffix . '.css', POLYLANG_ROOT_FILE ), array( 'polylang_admin' ), POLYLANG_VERSION ); | |
| 157 | 207 | |
| 158 | 208 | $this->localize_scripts(); |
| 159 | 209 | } |
| 160 | 210 | |
| @@ -161,13 +211,15 @@ | ||
| 161 | 211 | /** |
| 162 | 212 | * Enqueue scripts to the WP Customizer. |
| 163 | 213 | * |
| 164 | 214 | * @since 2.4.0 |
| 215 | + * | |
| 216 | + * @return void | |
| 165 | 217 | */ |
| 166 | 218 | public function customize_controls_enqueue_scripts() { |
| 167 | 219 | if ( $this->model->get_languages_list() ) { |
| 168 | 220 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 169 | - wp_enqueue_script( 'pll_widgets', plugins_url( '/js/widgets' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery' ), POLYLANG_VERSION, true ); | |
| 221 | + wp_enqueue_script( 'pll_widgets', plugins_url( '/js/build/widgets' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION, true ); | |
| 170 | 222 | $this->localize_scripts(); |
| 171 | 223 | } |
| 172 | 224 | } |
| 173 | 225 | |
| @@ -174,8 +226,10 @@ | ||
| 174 | 226 | /** |
| 175 | 227 | * Localize scripts. |
| 176 | 228 | * |
| 177 | 229 | * @since 2.4.0 |
| 230 | + * | |
| 231 | + * @return void | |
| 178 | 232 | */ |
| 179 | 233 | public function localize_scripts() { |
| 180 | 234 | if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) { |
| 181 | 235 | wp_localize_script( |
| @@ -200,8 +254,10 @@ | ||
| 200 | 254 | * when options.data is an empty string (GET request with the method 'load') |
| 201 | 255 | * see: https://wordpress.org/support/topic/invalid-url-during-wordpress-new-dashboard-widget-operation |
| 202 | 256 | * |
| 203 | 257 | * @since 1.4 |
| 258 | + * | |
| 259 | + * @return void | |
| 204 | 260 | */ |
| 205 | 261 | public function admin_print_footer_scripts() { |
| 206 | 262 | global $post_ID, $tag_ID; |
| 207 | 263 | |
| @@ -218,34 +274,57 @@ | ||
| 218 | 274 | $arr = wp_json_encode( $params ); |
| 219 | 275 | ?> |
| 220 | 276 | <script type="text/javascript"> |
| 221 | 277 | if (typeof jQuery != 'undefined') { |
| 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 ?>'; | |
| 278 | + jQuery( | |
| 279 | + function( $ ){ | |
| 280 | + $.ajaxPrefilter( function ( options, originalOptions, jqXHR ) { | |
| 281 | + if ( -1 != options.url.indexOf( ajaxurl ) || -1 != ajaxurl.indexOf( options.url ) ) { | |
| 282 | + | |
| 283 | + function addPolylangParametersAsString() { | |
| 284 | + if ( 'undefined' === typeof options.data || '' === options.data.trim() ) { | |
| 285 | + // Only Polylang data need to be send. So it could be as a simple query string. | |
| 286 | + options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>'; | |
| 231 | 287 | } else { |
| 288 | + /* | |
| 289 | + * In some cases data could be a JSON string like in third party plugins. | |
| 290 | + * So we need not to break their process by adding polylang parameters as valid JSON datas. | |
| 291 | + */ | |
| 232 | 292 | 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); | |
| 293 | + options.data = JSON.stringify( Object.assign( JSON.parse( options.data ), <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?> ) ); | |
| 294 | + } catch( exception ) { | |
| 295 | + // Add Polylang data to the existing query string. | |
| 296 | + options.data = options.data + '&<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>'; | |
| 236 | 297 | } |
| 237 | - catch(e) { | |
| 238 | - options.data = '<?php echo $str; // phpcs:ignore WordPress.Security.EscapeOutput ?>&'+options.data; | |
| 239 | - } | |
| 240 | 298 | } |
| 299 | + } | |
| 300 | + | |
| 301 | + /* | |
| 302 | + * options.processData set to true is the default jQuery process where the data is converted in a query string by using jQuery.param(). | |
| 303 | + * This step is done before applying filters. Thus here the options.data is already a string in this case. | |
| 304 | + * @See https://github.com/jquery/jquery/blob/3.5.1/src/ajax.js#L563-L569 jQuery ajax function. | |
| 305 | + * It is the most case WordPress send ajax request this way however third party plugins or themes could be send JSON string. | |
| 306 | + * Use JSON format is recommended in jQuery.param() documentation to be able to send complex data structures. | |
| 307 | + * @See https://api.jquery.com/jquery.param/ jQuery param function. | |
| 308 | + */ | |
| 309 | + if ( options.processData ) { | |
| 310 | + addPolylangParametersAsString(); | |
| 241 | 311 | } else { |
| 242 | - options.data = $.extend(options.data, <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?>); | |
| 312 | + /* | |
| 313 | + * If options.processData is set to false data could be undefined or pass as a string. | |
| 314 | + * So data as to be processed as if options.processData is set to true. | |
| 315 | + */ | |
| 316 | + if ( 'undefined' === typeof options.data || 'string' === typeof options.data ) { | |
| 317 | + addPolylangParametersAsString(); | |
| 318 | + } else { | |
| 319 | + // Otherwise options.data is probably an object. | |
| 320 | + options.data = Object.assign( options.data || {} , <?php echo $arr; // phpcs:ignore WordPress.Security.EscapeOutput ?> ); | |
| 321 | + } | |
| 243 | 322 | } |
| 244 | 323 | } |
| 245 | - } | |
| 246 | - }); | |
| 247 | - })(jQuery) | |
| 324 | + }); | |
| 325 | + } | |
| 326 | + ); | |
| 248 | 327 | } |
| 249 | 328 | </script> |
| 250 | 329 | <?php |
| 251 | 330 | } |
| @@ -253,8 +332,10 @@ | ||
| 253 | 332 | /** |
| 254 | 333 | * Sets the admin current language, used to filter the content |
| 255 | 334 | * |
| 256 | 335 | * @since 2.0 |
| 336 | + * | |
| 337 | + * @return void | |
| 257 | 338 | */ |
| 258 | 339 | public function set_current_language() { |
| 259 | 340 | $this->curlang = $this->filter_lang; |
| 260 | 341 | |
| @@ -260,9 +341,9 @@ | ||
| 260 | 341 | |
| 261 | 342 | // Edit Post |
| 262 | 343 | if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 263 | 344 | $this->curlang = $lang; |
| 264 | - } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 345 | + } 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 | |
| 265 | 346 | $this->curlang = $lang; |
| 266 | 347 | } 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 |
| 267 | 348 | $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 268 | 349 | } |
| @@ -267,15 +348,14 @@ | ||
| 267 | 348 | $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 268 | 349 | } |
| 269 | 350 | |
| 270 | 351 | // Edit Term |
| 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 | |
| 352 | + elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 273 | 353 | $this->curlang = $lang; |
| 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 | |
| 354 | + } 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 | |
| 355 | + if ( isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 356 | + $this->curlang = $lang; | |
| 357 | + } elseif ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 278 | 358 | $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 279 | 359 | } elseif ( empty( $this->curlang ) ) { |
| 280 | 360 | $this->curlang = $this->pref_lang; |
| 281 | 361 | } |
| @@ -284,8 +364,17 @@ | ||
| 284 | 364 | // Ajax |
| 285 | 365 | if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 286 | 366 | $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 287 | 367 | } |
| 368 | + | |
| 369 | + // Inform that the admin language has been set. | |
| 370 | + if ( $this->curlang ) { | |
| 371 | + /** This action is documented in frontend/choose-lang.php */ | |
| 372 | + do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang ); | |
| 373 | + } else { | |
| 374 | + /** This action is documented in include/class-polylang.php */ | |
| 375 | + do_action( 'pll_no_language_defined' ); // To load overridden textdomains. | |
| 376 | + } | |
| 288 | 377 | } |
| 289 | 378 | |
| 290 | 379 | /** |
| 291 | 380 | * Defines the backend language and the admin language filter based on user preferences |
| @@ -290,8 +379,10 @@ | ||
| 290 | 379 | /** |
| 291 | 380 | * Defines the backend language and the admin language filter based on user preferences |
| 292 | 381 | * |
| 293 | 382 | * @since 1.2.3 |
| 383 | + * | |
| 384 | + * @return void | |
| 294 | 385 | */ |
| 295 | 386 | public function init_user() { |
| 296 | 387 | // Language for admin language filter: may be empty |
| 297 | 388 | // $_GET['lang'] is numeric when editing a language, not when selecting a new language in the filter |
| @@ -305,28 +396,21 @@ | ||
| 305 | 396 | // Set preferred language for use when saving posts and terms: must not be empty |
| 306 | 397 | $this->pref_lang = empty( $this->filter_lang ) ? $this->model->get_language( $this->options['default_lang'] ) : $this->filter_lang; |
| 307 | 398 | |
| 308 | 399 | /** |
| 309 | - * Filter the preferred language on admin side | |
| 310 | - * The preferred language is used for example to determine the language of a new post | |
| 400 | + * Filters the preferred language on admin side. | |
| 401 | + * The preferred language is used for example to determine the language of a new post. | |
| 311 | 402 | * |
| 312 | 403 | * @since 1.2.3 |
| 313 | 404 | * |
| 314 | - * @param object $pref_lang preferred language | |
| 405 | + * @param PLL_Language $pref_lang Preferred language. | |
| 315 | 406 | */ |
| 316 | 407 | $this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang ); |
| 317 | 408 | |
| 318 | 409 | $this->set_current_language(); |
| 319 | 410 | |
| 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 | - } | |
| 411 | + // Plugin i18n, only needed for backend. | |
| 412 | + load_plugin_textdomain( 'polylang' ); | |
| 329 | 413 | } |
| 330 | 414 | |
| 331 | 415 | /** |
| 332 | 416 | * Avoids parsing a tax query when all languages are requested |
| @@ -331,9 +415,9 @@ | ||
| 331 | 415 | /** |
| 332 | 416 | * Avoids parsing a tax query when all languages are requested |
| 333 | 417 | * Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1 |
| 334 | 418 | * |
| 335 | - * @see the suggestion of @boonebgorges, https://core.trac.wordpress.org/ticket/31246 | |
| 419 | + * @see https://core.trac.wordpress.org/ticket/31246 the suggestion of @boonebgorges. | |
| 336 | 420 | * |
| 337 | 421 | * @since 1.6.5 |
| 338 | 422 | * |
| 339 | 423 | * @param array $qvars |
| @@ -347,13 +431,14 @@ | ||
| 347 | 431 | return $qvars; |
| 348 | 432 | } |
| 349 | 433 | |
| 350 | 434 | /** |
| 351 | - * Adds the languages list in admin bar for the admin languages filter | |
| 435 | + * Adds the languages list in admin bar for the admin languages filter. | |
| 352 | 436 | * |
| 353 | 437 | * @since 0.9 |
| 354 | 438 | * |
| 355 | - * @param object $wp_admin_bar | |
| 439 | + * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar global object. | |
| 440 | + * @return void | |
| 356 | 441 | */ |
| 357 | 442 | public function admin_bar_menu( $wp_admin_bar ) { |
| 358 | 443 | $all_item = (object) array( |
| 359 | 444 | 'slug' => 'all', |
| @@ -378,17 +463,23 @@ | ||
| 378 | 463 | * @param array $items The admin languages filter submenu items. |
| 379 | 464 | */ |
| 380 | 465 | $items = apply_filters( 'pll_admin_languages_filter', array_merge( array( $all_item ), $this->model->get_languages_list() ) ); |
| 381 | 466 | |
| 467 | + $menu = array( | |
| 468 | + 'id' => 'languages', | |
| 469 | + 'title' => $selected->flag . $title, | |
| 470 | + 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ), | |
| 471 | + 'meta' => array( | |
| 472 | + 'title' => __( 'Filters content by language', 'polylang' ), | |
| 473 | + ), | |
| 474 | + ); | |
| 475 | + | |
| 476 | + if ( 'all' !== $selected->slug ) { | |
| 477 | + $menu['meta']['class'] = 'pll-filtered-languages'; | |
| 478 | + } | |
| 479 | + | |
| 382 | 480 | if ( ! empty( $items ) ) { |
| 383 | - $wp_admin_bar->add_menu( | |
| 384 | - array( | |
| 385 | - 'id' => 'languages', | |
| 386 | - 'title' => $selected->flag . $title, | |
| 387 | - 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ), | |
| 388 | - 'meta' => array( 'title' => __( 'Filters content by language', 'polylang' ) ), | |
| 389 | - ) | |
| 390 | - ); | |
| 481 | + $wp_admin_bar->add_menu( $menu ); | |
| 391 | 482 | } |
| 392 | 483 | |
| 393 | 484 | foreach ( $items as $lang ) { |
| 394 | 485 | if ( $selected->slug === $lang->slug ) { |