Removing user contact methods works from functions.php but not from a plugin

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.

Leave a Comment