Make WordPress Core

Ticket #18282: preserve-page-and-taxonomy-hierarchy.php

File preserve-page-and-taxonomy-hierarchy.php, 1.9 KB (added by SergeyBiryukov, 13 years ago)
Line 
1<?php
2/*
3Plugin Name: Preserve Page and Taxonomy Hierarchy on Edit Menus Screen
4Version: 0.1
5Plugin URI: https://core.trac.wordpress.org/ticket/18282
6Description: Disables paging for hierarchical post types and taxonomies on Edit Menus screen to preserve proper hierarchy in meta boxes.
7Author: Sergey Biryukov
8Author URI: http://profiles.wordpress.org/sergeybiryukov/
9*/
10
11class Preserve_Page_and_Taxonomy_Hierarchy {
12
13 function __construct() {
14 add_action( 'load-nav-menus.php', array( $this, 'init' ) );
15 }
16
17 function init() {
18 add_action( 'pre_get_posts', array( $this, 'disable_paging_for_hierarchical_post_types' ) );
19 add_filter( 'get_terms_args', array( $this, 'remove_limit_for_hierarchical_taxonomies' ), 10, 2 );
20 add_filter( 'get_terms_fields', array( $this, 'remove_page_links_for_hierarchical_taxonomies' ), 10, 3 );
21 }
22
23 function disable_paging_for_hierarchical_post_types( $query ) {
24 if ( ! is_admin() || 'nav-menus' !== get_current_screen()->id ) {
25 return;
26 }
27
28 if ( ! is_post_type_hierarchical( $query->get( 'post_type' ) ) ) {
29 return;
30 }
31
32 if ( 50 == $query->get( 'posts_per_page' ) ) {
33 $query->set( 'nopaging', true );
34 }
35 }
36
37 function remove_limit_for_hierarchical_taxonomies( $args, $taxonomies ) {
38 if ( ! is_admin() || 'nav-menus' !== get_current_screen()->id ) {
39 return $args;
40 }
41
42 if ( ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ) {
43 return $args;
44 }
45
46 if ( 50 == $args['number'] ) {
47 $args['number'] = '';
48 }
49
50 return $args;
51 }
52
53 function remove_page_links_for_hierarchical_taxonomies( $selects, $args, $taxonomies ) {
54 if ( ! is_admin() || 'nav-menus' !== get_current_screen()->id ) {
55 return $selects;
56 }
57
58 if ( ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ) {
59 return $selects;
60 }
61
62 if ( 'count' === $args['fields'] ) {
63 $selects = array( '1' );
64 }
65
66 return $selects;
67 }
68
69}
70
71new Preserve_Page_and_Taxonomy_Hierarchy;
72?>