WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 8 weeks ago

#47555 reviewing enhancement

Add per_page filter to nav-menu.php

Reported by: Martin Snajdr Owned by: audrasjb
Milestone: Future Release Priority: low
Severity: normal Version:
Component: Menus Keywords: has-patch needs-dev-note
Focuses: Cc:
PR Number:

Description

Right now there is a hardcoded number of posts / terms (50) displayed per page in wp-admin/includes/nav-menu.php, which might be ok for posts, but it's a nightmare when having a lot of terms (hierarchical). For example in WooCommerce, I have like 200 categories and some of those are having the same name (but different parent). When I go through the list of those categories, it's quite hard to find exactly the one I'm looking for if the parent is on previous page.

Having pagination as default is ok, but there should be a simple filter that will allow plugins / themes to change the per_page variable value (at least in wp_nav_menu_item_taxonomy_meta_box), so you could list more than 50 terms per page.

Attachments (2)

47555.patch (677 bytes) - added by manishamakhija 5 months ago.
Added filter for category list per page in nav menu metabox
47555.1.diff (874 bytes) - added by audrasjb 4 months ago.
Add nav_menu_metabox_per_page_number filter to allow developers to filter $per_page variable

Download all attachments as: .zip

Change History (12)

@manishamakhija
5 months ago

Added filter for category list per page in nav menu metabox

#1 @manishamakhija
5 months ago

  • Component changed from Administration to Menus
  • Keywords has-patch added

#2 @audrasjb
4 months ago

  • Focuses administration removed
  • Milestone changed from Awaiting Review to 5.3
  • Owner set to audrasjb
  • Priority changed from normal to low
  • Status changed from new to reviewing
  • Version 5.2.1 deleted

Hi, thanks for the the ticket and thaks @manishamakhija for the patch. Looks good on my side.
Moving this one for 5.3 consideration.

#3 @audrasjb
4 months ago

  • Keywords needs-refresh added

Hi and thanks for the patch,

There is a coding standard issue in the current patch. Refreshing.

@audrasjb
4 months ago

Add nav_menu_metabox_per_page_number filter to allow developers to filter $per_page variable

#4 @audrasjb
4 months ago

  • Keywords 2nd-opinion added; needs-refresh removed

In 47555.1.diff:

  • Add inline documentation for nav_menu_metabox_per_page_number filter.
  • Use absint() function to ensure to get a proper integer.

Adding 2nd-opinion keyword to get a second opinion on that.
Adding needs-dev-note keyword: if this patch is released, the new filter would maybe deserve a dev-note (but not sure if we need it since this is a very small enhancement).

#5 @audrasjb
4 months ago

Implementation example:

function worg_per_page_number( $per_page ) {
    return 10;
}
add_filter( 'nav_menu_metabox_per_page_number', 'worg_per_page_number', 10, 3 );

#6 @audrasjb
4 months ago

  • Keywords needs-dev-note added

#7 @SergeyBiryukov
4 months ago

Right now there is a hardcoded number of posts / terms (50) displayed per page in wp-admin/includes/nav-menu.php

FWIW, this value is already filterable via get_terms_args, see an example in #18282:
https://core.trac.wordpress.org/attachment/ticket/18282/preserve-page-and-taxonomy-hierarchy.php

A dedicated filter might still be helpful though.

#8 @davidbaumwald
8 weeks ago

  • Keywords commit added

#9 @davidbaumwald
8 weeks ago

  • Keywords 2nd-opinion removed

I think a dedicated filter is fine here.

#10 @davidbaumwald
8 weeks ago

  • Keywords commit removed
  • Milestone changed from 5.3 to Future Release

With version 5.3 Beta 1 landing shortly, this is being moved to Future Release.

Note: See TracTickets for help on using tickets.