| @@ -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 |
| @@ -177,9 +190,9 @@ | ||
| 177 | 190 | if ( ! isset( $_POST['post_tr_lang'] ) ) { |
| 178 | 191 | return; |
| 179 | 192 | } |
| 180 | 193 | |
| 181 | - $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'] ) ); | |
| 182 | 195 | } |
| 183 | 196 | |
| 184 | 197 | /** |
| 185 | 198 | * Save language when bulk editing posts. |
| @@ -265,6 +278,93 @@ | ||
| 265 | 278 | $mce_init['wp_lang_attr'] = $this->curlang->get_locale( 'display' ); |
| 266 | 279 | $mce_init['directionality'] = $this->curlang->is_rtl ? 'rtl' : 'ltr'; |
| 267 | 280 | } |
| 268 | 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; | |
| 269 | 369 | } |
| 270 | 370 | } |