I have to remove some profile fields from the ‘Profile’ page according to the user roles. For removing the color picker I used remove_action("admin_color_scheme_picker", "admin_color_scheme_picker")
. I want to remove these fields:
- Nickname
- Display name publicly as
- AIM, Yahoo, Google talk and About yourself fields
- The ‘Show Admin Bar’ section along with the 2 checkboxes
I went through the file ‘user-edit.php’ to see if there are any actions/filters that allow me to do so, but it seems there aren’t.
Can anyone tell me how to do this? Any help would be appreciated.
Thanks
EDIT:
Thanks @helenhousandi for the answer. I had already did it this way though.
<?php
add_action('admin_footer-profile.php', 'remove_profile_fields');
function remove_profile_fields()
{
if(current_user_can('custom_role'))
{ ?>
<script type="text/javascript">
jQuery("h3:contains('Personal Options')").next('.form-table').remove();
jQuery("h3:contains('Personal Options')").remove();
jQuery("h3:contains('About Yourself')").next('.form-table').remove();
jQuery("h3:contains('About Yourself')").remove();
</script>
<?php }
}
?>
I know this is a bit longer, but it worked! I think I’ll go with @helenhousandi’s answer.
For the contact methods filter:
user_contactmethods
:Though the
user_contactmethods
filter is the one of the few for the user profile screen, since the other fields are not required in WordPress, you could use jQuery’s.hide()
and.remove()
to effectively get rid of the ones you don’t want without complications in terms of saving the information. Sure, a person without JS on would still see them, but that’s a small minority and I’m guessing that the information changing there won’t actually affect anything.An example of removing the whole personal options piece (show admin bar and color scheme). I know it’s not what you’re looking for exactly, just wanted to give you a quick example I have on hand:
Also, a note about the Show Admin Bar option: in 3.3 the admin bar is becoming the header and thus cannot be turned on or off, so it may not be worth worrying about.
I updated the code example to be more accurate and complete. Had some leftovers in there.
As there seems to be no good php hook for this I ended up hiding the fields with CSS then remove them with JS.
From the wordpress support forum you can do the removal using PHP. This removes the About Yourself section:
The code replaces the ‘About Yourself’ header with ‘Password’ and then strips out anything between that and the next table it finds (which is the password table).
Also the plugin WP Hide Dashboard does similar jQuery replacing if you want to extend that.
BE CAREFUL!!
1) Removing a field may not be good, as on update, if you wont send the essential fields to WORDPRESS update hook, then it might set empty values to those fields! (for example, in submitting form, there should exists i.e.
<input name="username".../>
)I Think, that it’s better to HIDE from users visually only, with jquery
.hide();
and not with.remove();
EXAMPLE code to hide “DISPLAY NAME” and “NICKNAME” fields:
2) To hide admin bar, there is a special option in wordpress menu (in Settings). for custom code, like i.e.
Use
and add
before JavaScript.
There’s no filter to disable them. Look at the source (
/wp-admin/user-edit.php
) when you need to do stuff like this. You could hide them with JS but they can still be made visible and values are updated on POST.Only viable option is to hack the core yourself. Just make sure you handle the update and disregard these fields on POST.