I'd like to remove user fields and I used this code:

add_filter( 'user_contactmethods', 'newfields' );
function newfields( $user_contact ) {

    return $user_contact;

If I use this code in functions.php of my theme, it works, but if I use this code in a plugin, it doesn't work.

Why? How can I resolve it?

  • Did you try playing with the filter priority? – birgire Aug 4 '14 at 13:19
  • I hadn't thought. It is the easiest thing! – Erfo Aug 4 '14 at 13:48

This could be the matter of adjusting the priority of your filter callback, since the plugins files are executed before the functions.php theme file. That could explain why it works in your functions.php file, if the priority is the same.

When you add the code snippet to a plugin, it might be executed before the other plugins that use the same filter.

The default priority is 10, so you should try something higher in your plugin code, for example:

add_filter( 'user_contactmethods', 'newfields', 99 );

or even

add_filter( 'user_contactmethods', 'newfields', PHP_INT_MAX );

if you want to be absolutely sure your filter callback is the last one to be executed - assuming the other plugins are not using PHP_INT_MAX as well.

But better yet, just check the priority the user_contactmethods filter callbacks the other plugins are using.

  • Great, it can be a fun game to play, to find the correct priority of a filter/action ;-) – birgire Aug 4 '14 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.