Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#14562 closed defect (bug) (fixed)

manage_users_custom_column is both an action and a filter

Reported by: mikelittle's profile mikelittle Owned by: westi's profile 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 15 years ago.
Patch against 3.0 branch to rename action
14562.diff (565 bytes) - added by scribu 14 years ago.

Download all attachments as: .zip

Change History (12)

#1 @mikelittle
15 years ago

  • Version set to 3.0.1

#2 @scribu
15 years ago

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

#3 @westi
15 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.

@mikelittle
15 years ago

Patch against 3.0 branch to rename action

#4 @mikelittle
15 years ago

  • Keywords has-patch added; needs-patch removed

#5 @nacin
14 years ago

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

Is this handled by #14579?

#6 @scribu
14 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().

#7 @scribu
14 years ago

14562.diff contains my proposed fix.

@scribu
14 years ago

#8 @voyagerfan5761
14 years ago

  • Cc WordPress@… added

#9 @scribu
14 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

#10 @scribu
14 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.