#14562 closed defect (bug) (fixed)
manage_users_custom_column is both an action and a filter
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (12)
#3
@
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.
#5
@
14 years ago
- Cc scribu@… added
- Milestone changed from Awaiting Review to 3.1
Is this handled by #14579?
#6
@
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().
I think we should make ms-users.php use user_row() or at least pass the same parameters in the hook.