WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#14562 closed defect (bug) (fixed)

manage_users_custom_column is both an action and a filter

Reported by: mikelittle Owned by: westi
Milestone: 3.1 Priority: normal
Severity: major Version: 3.0.1
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

In wp-admin/includes/template.php function user_row(), filter 'manage_users_custom_column' is called with 3 parameters and is expected to return the contents for the custom column.

However, in wp-admin/ms-users.php, action 'manage_users_custom_column' is called with two parameters and is expected to echo the contents for the custom column.

They both have the same name which is initially confusing, but worse it breaks WordPress.

I tried using two functions
add_filter( 'manage_users_custom_column', 'function1', 10, 3);
and
add_action( 'manage_users_custom_column', 'function2', 10, 2);

But *BOTH* functions are called during the filter processing and *BOTH* functions are called during action processing.

That is, during filter processing, function1 is called with the correct three parameters, then function2 is called with the output of function1 as the first parameter and what should be the first parameter as it's second parameter.

During action processing, function1 is called with the two action parameters (and a warning for the missing third), then function2 is called correctly.

There seem to be two issues here:
1) the action and the filter should not really have the same name. Ideally custom user column functionality in the two places should be brought into line.

2) a registered action should not be called during filter processing and vice versa, but maybe that's a side effect of the names being the same and the behaviour in those circumstances is not defined.

Code to reproduce:

add_filter('manage_users_columns', 'add_users_column');
add_filter('wpmu_users_columns', 'add_users_column');
function add_users_column($column_headers) {
	$column_headers['myextra'] = 'My Extra';
	return $column_headers;
}

add_filter('manage_users_custom_column', 'function1', 10, 3);
function function1($default, $column_name, $user_id) {
	error_log( "function1 called with (default=$default, column_name=$column_name, user_id=$user_id)" );
	if ('myextra' == $column_name) {
		return "function1 called with ($default, $column_name, $user_id)";
	}
	return $default;
}

add_action('manage_users_custom_column', 'function2', 10, 2);
function function2($column_name, $user_id) {
	error_log( "function2 called with (column_name=$column_name, user_id=$user_id)" );
	if ('myextra' == $column_name) {
		echo "(function2 called with $column_name, $user_id)";
	}
}

Attachments (2)

trac-14562-ms-users-patch.diff (473 bytes) - added by mikelittle 4 years ago.
Patch against 3.0 branch to rename action
14562.diff (565 bytes) - added by scribu 3 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 mikelittle4 years ago

  • Version set to 3.0.1

comment:2 scribu4 years ago

I think we should make ms-users.php use user_row() or at least pass the same parameters in the hook.

comment:3 westi4 years ago

  • Keywords needs-patch added
  • Owner set to westi
  • Status changed from new to accepted

I need to look into this more but I guess for 3.0.x branch we should at least rename the filter so it doesn't clash with the old action.

Moving to the use of user_row() is also a good idea.

mikelittle4 years ago

Patch against 3.0 branch to rename action

comment:4 mikelittle4 years ago

  • Keywords has-patch added; needs-patch removed

comment:5 nacin3 years ago

  • Cc scribu@… added
  • Milestone changed from Awaiting Review to 3.1

Is this handled by #14579?

comment:6 scribu3 years ago

No, this is still a problem.

The right thing to do would be to transform the filter into an action, since that's the standard o nthe rest of the list tables.

The name could stay the same, since plugin authors can now check is_network_admin().

comment:7 scribu3 years ago

14562.diff contains my proposed fix.

scribu3 years ago

comment:8 voyagerfan57613 years ago

  • Cc WordPress@… added

comment:9 scribu3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [16354]) Make manage_users_custom_column hook consistent between WP_(MS)?_Users_List_Table. Fixes #14562

comment:10 scribu3 years ago

I favored the WP_Users_List_Table approach, since I figured there are a lot more plugins targeting that than the network users screen.

Note: See TracTickets for help on using tickets.