PluginProbe
Polylang / trunk
Polylang vtrunk
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 | src/admin/admin-filters-post.php +115 -6 3.8.4 → trunk View file →
@@ -9,10 +9,15 @@
9 9 * Manages filters and actions related to posts on admin side
10 10 *
11 11 * @since 1.2
12 12 */
13 -class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base {
13 +class PLL_Admin_Filters_Post {
14 14 /**
15 + * @var PLL_Model
16 + */
17 + public $model;
18 +
19 + /**
15 20 * Current language (used to filter the content).
16 21 *
17 22 * @var PLL_Language|null
18 23 */
@@ -25,9 +30,9 @@
25 30 *
26 31 * @param object $polylang The Polylang object.
27 32 */
28 33 public function __construct( &$polylang ) {
29 - parent::__construct( $polylang );
34 + $this->model = &$polylang->model;
30 35 $this->curlang = &$polylang->curlang;
31 36
32 37 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
33 38
@@ -40,8 +45,16 @@
40 45 add_action( 'wp_ajax_inline-save', array( $this, 'inline_edit_post' ), 0 ); // Before WordPress
41 46
42 47 // Sets the language in Tiny MCE
43 48 add_filter( 'tiny_mce_before_init', array( $this, 'tiny_mce_before_init' ) );
49 +
50 + // Filter untranslated items in the posts list table.
51 + add_action( 'restrict_manage_posts', array( $this, 'untranslated_dropdown' ) );
52 +
53 + // Languages views in post list tables.
54 + foreach ( $this->model->get_translated_post_types() as $post_type ) {
55 + add_filter( "views_edit-{$post_type}", array( $this, 'add_per_language_edit_views' ) );
56 + }
44 57 }
45 58
46 59 /**
47 60 * Outputs a javascript list of terms ordered by language and hierarchical taxonomies
@@ -89,13 +102,22 @@
89 102 }
90 103 }
91 104
92 105 // Hierarchical post types
93 - if ( 'edit' == $screen->base && is_post_type_hierarchical( $screen->post_type ) ) {
94 - $pages = get_pages( array( 'sort_column' => 'menu_order, post_title' ) ); // Same arguments as the parent pages dropdown to avoid an extra query.
106 + if ( 'edit' == $screen->base && is_post_type_hierarchical( $screen->post_type ) && post_type_supports( $screen->post_type, 'page-attributes' ) ) {
107 + $pages = get_pages(
108 + array(
109 + 'sort_column' => 'menu_order, post_title',
110 + 'post_type' => $screen->post_type,
111 + )
112 + ); // Same arguments as the parent pages dropdown to avoid an extra query.
95 113
96 - update_post_caches( $pages, $screen->post_type, true, false );
114 + if ( ! is_array( $pages ) ) {
115 + return;
116 + }
97 117
118 + update_object_term_cache( wp_list_pluck( $pages, 'ID' ), $screen->post_type );
119 +
98 120 $page_languages = array();
99 121
100 122 foreach ( $pages as $page ) {
101 123 if ( $lang = $this->model->post->get_language( $page->ID ) ) {
@@ -168,9 +190,9 @@
168 190 if ( ! isset( $_POST['post_tr_lang'] ) ) {
169 191 return;
170 192 }
171 193
172 - $this->save_translations( $post_id, array_map( 'absint', $_POST['post_tr_lang'] ) );
194 + $this->model->post->save_translations( $post_id, array_map( 'absint', $_POST['post_tr_lang'] ) );
173 195 }
174 196
175 197 /**
176 198 * Save language when bulk editing posts.
@@ -256,6 +278,93 @@
256 278 $mce_init['wp_lang_attr'] = $this->curlang->get_locale( 'display' );
257 279 $mce_init['directionality'] = $this->curlang->is_rtl ? 'rtl' : 'ltr';
258 280 }
259 281 return $mce_init;
282 + }
283 +
284 + /**
285 + * Displays a dropdown for filtering unstranslated items in the posts list table.
286 + *
287 + * @since 3.9
288 + *
289 + * @param string $post_type The post type.
290 + * @return void
291 + */
292 + public function untranslated_dropdown( $post_type ) {
293 + if ( ! $this->model->is_translated_post_type( $post_type ) ) {
294 + return;
295 + }
296 +
297 + $languages = $this->model->get_languages_list();
298 +
299 + foreach ( $languages as $k => $language ) {
300 + $languages[ $k ] = $language->to_std_class(); // Important not to modify the language name everywhere.
301 + /* translators: %s is a native language name */
302 + $languages[ $k ]->name = sprintf( __( 'Untranslated in %s', 'polylang' ), $language->name );
303 + }
304 +
305 + $dropdown = new PLL_Walker_Dropdown();
306 +
307 + $dropdown_html = $dropdown->walk(
308 + array_merge(
309 + array( (object) array( 'slug' => 0, 'name' => __( 'All translation statuses', 'polylang' ) ) ),
310 + $languages
311 + ),
312 + -1,
313 + array(
314 + 'id' => 'pll_untranslated_in',
315 + 'name' => 'untranslated_in',
316 + 'class' => 'postform',
317 + 'selected' => isset( $_GET['untranslated_in'] ) ? sanitize_key( $_GET['untranslated_in'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
318 + )
319 + );
320 +
321 + printf(
322 + '<label class="screen-reader-text" for="pll_untranslated_in">%s</label>',
323 + esc_html__( 'Filter untranslated items', 'polylang' )
324 + );
325 +
326 + echo $dropdown_html; // phpcs:ignore WordPress.Security.EscapeOutput
327 + }
328 +
329 + /**
330 + * Add languages filter views to the list of views available for the post list table.
331 + *
332 + * @since 3.9
333 + *
334 + * @param string[] $views Array of available list table views.
335 + * @return string[]
336 + */
337 + public function add_per_language_edit_views( $views ) {
338 + global $typenow;
339 +
340 + if ( empty( $typenow ) ) {
341 + return $views;
342 + }
343 +
344 + $q = array(
345 + 'post_type' => $typenow,
346 + 'post_status' => 'any',
347 + );
348 +
349 + foreach ( $this->model->languages->get_list() as $language ) {
350 + $views[ $language->slug ] = sprintf(
351 + '<a href="%s" %s>%s <span class="count">(%s)</span></a>',
352 + esc_url( add_query_arg( 'lang', $language->slug, remove_query_arg( 'paged' ) ) ),
353 + ! empty( $this->curlang ) && $this->curlang->slug === $language->slug ? 'class="current" aria-current="page"' : '',
354 + esc_html( $language->name ),
355 + number_format_i18n( (int) $this->model->count_posts( $language, $q ) )
356 + );
357 + }
358 +
359 + if ( isset( $views['all'] ) ) { // In case a filter removes this key.
360 + $replacement = 'lang=all&';
361 +
362 + if ( ! str_contains( $views['all'], 'all_posts=1' ) ) {
363 + $replacement .= 'all_posts=1&';
364 + }
365 + $views['all'] = str_replace( 'edit.php?', 'edit.php?' . $replacement, $views['all'] );
366 + }
367 +
368 + return $views;
260 369 }
261 370 }