@@ -268,6 +268,8 @@ function wp_nav_menu_post_type_meta_boxes() {
268268 *
269269 * If a falsey value is returned instead of an object, the menu items
270270 * meta box for the current meta box object will not be added.
271+ * This filter is also applied to taxonomy objects when registering
272+ * taxonomy menu item meta boxes.
271273 *
272274 * @since 3.0.0
273275 *
@@ -864,11 +866,12 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
864866 $ taxonomy_name = $ box ['args ' ]->name ;
865867 $ taxonomy = get_taxonomy ( $ taxonomy_name );
866868 $ tab_name = $ taxonomy_name . '-tab ' ;
869+ $ default_query = isset ( $ box ['args ' ]->_default_query ) ? (array ) $ box ['args ' ]->_default_query : array ();
867870
868871 // Paginate browsing for large numbers of objects.
869- $ per_page = 50 ;
872+ $ per_page = isset ( $ default_query [ ' number ' ] ) ? ( int ) $ default_query [ ' number ' ] : 50 ;
870873 $ pagenum = isset ( $ _REQUEST [ $ tab_name ] ) && isset ( $ _REQUEST ['paged ' ] ) ? absint ( $ _REQUEST ['paged ' ] ) : 1 ;
871- $ offset = 0 < $ pagenum ? $ per_page * ( $ pagenum - 1 ) : 0 ;
874+ $ offset = 0 < $ per_page && 0 < $ pagenum ? $ per_page * ( $ pagenum - 1 ) : 0 ;
872875
873876 $ args = array (
874877 'taxonomy ' => $ taxonomy_name ,
@@ -883,6 +886,12 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
883886 'orderby ' => 'name ' ,
884887 'pad_counts ' => false ,
885888 );
889+ $ args = array_merge ( $ args , $ default_query );
890+
891+ // WP_Term_Query uses 0 to return all terms, unlike WP_Query's -1.
892+ if ( 0 > $ per_page ) {
893+ $ args ['number ' ] = 0 ;
894+ }
886895
887896 $ terms = get_terms ( $ args );
888897
@@ -891,17 +900,20 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
891900 return ;
892901 }
893902
894- $ num_pages = (int ) ceil (
895- (int ) wp_count_terms (
896- array_merge (
897- $ args ,
898- array (
899- 'number ' => '' ,
900- 'offset ' => '' ,
903+ $ num_pages = 1 ;
904+ if ( 0 < $ per_page ) {
905+ $ num_pages = (int ) ceil (
906+ (int ) wp_count_terms (
907+ array_merge (
908+ $ args ,
909+ array (
910+ 'number ' => '' ,
911+ 'offset ' => '' ,
912+ )
901913 )
902- )
903- ) / $ per_page
904- );
914+ ) / $ per_page
915+ );
916+ }
905917
906918 $ page_links = paginate_links (
907919 array (
@@ -1218,32 +1230,38 @@ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
12181230 */
12191231function _wp_nav_menu_meta_box_object ( $ data_object = null ) {
12201232 if ( isset ( $ data_object ->name ) ) {
1233+ $ default_query = array ();
12211234
12221235 if ( 'page ' === $ data_object ->name ) {
1223- $ data_object -> _default_query = array (
1236+ $ default_query = array (
12241237 'orderby ' => 'menu_order title ' ,
12251238 'post_status ' => 'publish ' ,
12261239 );
12271240
12281241 // Posts should show only published items.
12291242 } elseif ( 'post ' === $ data_object ->name ) {
1230- $ data_object -> _default_query = array (
1243+ $ default_query = array (
12311244 'post_status ' => 'publish ' ,
12321245 );
12331246
12341247 // Categories should be in reverse chronological order.
12351248 } elseif ( 'category ' === $ data_object ->name ) {
1236- $ data_object -> _default_query = array (
1249+ $ default_query = array (
12371250 'orderby ' => 'id ' ,
12381251 'order ' => 'DESC ' ,
12391252 );
12401253
12411254 // Custom post types should show only published items.
12421255 } else {
1243- $ data_object -> _default_query = array (
1256+ $ default_query = array (
12441257 'post_status ' => 'publish ' ,
12451258 );
12461259 }
1260+
1261+ $ data_object ->_default_query = array_merge (
1262+ $ default_query ,
1263+ (array ) ( $ data_object ->_default_query ?? array () )
1264+ );
12471265 }
12481266
12491267 return $ data_object ;
0 commit comments