WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#35307 closed enhancement (fixed)

Pass $which variable to to restrict_manage_users action hook

Reported by: mcbenton Owned by: ocean90
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.4
Component: Users Keywords: has-patch
Focuses: Cc:

Description

The restrict_manage_users hook is placed so as to allow additional controls to be added above and below the admin Users table. It gets called twice: once ABOVE and once BELOW the Users table. While the containing function has awareness of the above/below context via the $which variable, extensions which use this hook must jump through extra hoops to determine the context. The recommendation is to change the above line to:

do_action( 'restrict_manage_users', $which );

This will allow writers of extensions using the restrict_manage_users hook not to have to resort to the workarounds described in the StackExchange thread above.

FYI, the corresponding function in class-wp-posts-list-table.php has TWO action hooks: restrict_manage_posts (which does not receive the $which context variable), and manage_posts_extra_tablenav (which does). Therefore an alternative solution would be to add an additional action hook to this function corresponding to manage_posts_extra_tablenav called manage_users_extra_tablenav that looks like:

do_action( 'manage_users_extra_tablenav', $which );

The benefit of this second solution is that it creates parity between User and Post administration hooks, and it also avoids the possibility of corrupting any extensions based on the current restrict_manage_users hook.

Attachments (1)

patch-for-bug-35307-for-wp-4.4.2.patch (1.5 KB) - added by martin.krcho 3 years ago.
Patch for this ticket.

Download all attachments as: .zip

Change History (6)

#1 @DrewAPicture
3 years ago

  • Keywords needs-patch added

Hi @mcbenton, this seems like a sensible proposal. Would you like to contribute a patch for consideration? We'd need a changelog entry added to the hook doc for the new parameter.

@martin.krcho
3 years ago

Patch for this ticket.

#2 @martin.krcho
3 years ago

I've uploaded a patch for this bug. Could you include it in the next release, please?

#3 @ocean90
3 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 4.6

Related: #BB2906

#4 @ocean90
3 years ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 37422:

List Tables: Pass the $which parameter to restrict_manage_posts and restrict_manage_users.

$which contains the location of the extra table nav markup: 'top' or 'bottom'.

Props martin.krcho.
Fixes #35307.

#5 @ocean90
3 years ago

#37485 was marked as a duplicate.

Note: See TracTickets for help on using tickets.