Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

  1. Nickname
  2. Display name publicly as
  3. AIM, Yahoo, Google talk and About yourself fields
  4. 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.

share|improve this question

5 Answers 5

up vote 7 down vote accepted

For the contact methods filter: user_contactmethods.

add_filter( 'user_contactmethods', 'update_contact_methods',10,1);

function update_contact_methods( $contactmethods ) {

unset($contactmethods['aim']);  
unset($contactmethods['jabber']);  
unset($contactmethods['yim']);  


return $contactmethods;
}
share|improve this answer
    
Thanks... got this one! Anything for the 'Show Admin Bar' and 'About yourself' sections? –  Rutwick Gangurde Nov 3 '11 at 11:48
    
Please update this if you find a solution... I'm accepting your answer though. Thanks! –  Rutwick Gangurde Nov 3 '11 at 14:35
    
+1 because as far as I can recall removing fields via PHP also stops WordPress from creating blank entries in the usermeta table. –  Ashfame Apr 9 '12 at 13:12

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.

share|improve this answer
    
Yes, I checked that file already! The JS solution doesn't seem too secure. I'll see what I can do! Thanks! –  Rutwick Gangurde Nov 3 '11 at 14:34
1  
If the only solution you can think of is to hack core, then perhaps you shouldn't answer that particular question. You also don't need to suggest to the question asker to look at the file already mentioned, and you are also not correct in stating that there are no filters at all - surely you must have read the question and earlier answer first? –  helenhousandi Nov 3 '11 at 14:53
    
@helenhousandi xoxo –  EarnestoDev Nov 3 '11 at 14:58

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:

// remove personal options block
if(is_admin()){
  remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  add_action( 'personal_options', 'prefix_hide_personal_options' );
}
function prefix_hide_personal_options() {
?>
<script type="text/javascript">
  jQuery(document).ready(function( $ ){
    $("#your-profile .form-table:first, #your-profile h3:first").remove();
  });
</script>
<?php
}

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.

share|improve this answer
    
+1 Awesome! Awesome! (...but I like to hack the core, I call it 'enhancing'.) –  EarnestoDev Nov 3 '11 at 15:03
    
Thanks! This is a nice solution! What I did was something similar but I used a different action hook so that my script runs only on profile.php. I also needed to do this for a specific custom role defined in my system. Updating my question with the answer. –  Rutwick Gangurde Nov 12 '11 at 11:10
1  
If you add the following to the jQuery it will also hide the Nickname and 'Display Name as' from the question: $("#nickname,#display_name").parent().parent().remove(); –  icc97 Feb 1 '12 at 8:16
    
You can also use edit_user_profile hook. And not use the jQuery( document ).ready method to run the code instantaneously. Like this –  gmaggio May 30 '12 at 7:24

From the wordpress support forum you can do the removal using PHP. This removes the About Yourself section:

if (! function_exists('remove_plain_bio') ){
    function remove_plain_bio($buffer) {
        $titles = array('#<h3>About Yourself</h3>#','#<h3>About the user</h3>#');
        $buffer=preg_replace($titles,'<h3>Password</h3>',$buffer,1);
        $biotable='#<h3>Password</h3>.+?<table.+?/tr>#s';
        $buffer=preg_replace($biotable,'<h3>Password</h3> <table class="form-table">',$buffer,1);
        return $buffer;
    }

    function profile_admin_buffer_start() { ob_start("remove_plain_bio"); }

    function profile_admin_buffer_end() { ob_end_flush(); }
}
add_action('admin_head', 'profile_admin_buffer_start');
add_action('admin_footer', 'profile_admin_buffer_end');

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.

share|improve this answer
    
For future reference, you might wish to use admin_head-profile.php and admin_footer-profile.php instead –  Cor van Noorloos Mar 18 '12 at 14:28

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:

<script type="text/javascript"> jQuery(document).ready(function( $ ){ $("#nickname,#display_name").parent().parent().hide(); }); </script>

2)To hide admin bar, there is a special option in wordpress menu (in Settings). for custom code, like i.e.

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar()
{
  if (!current_user_can('administrator') && !is_admin()) 
  {
    show_admin_bar(false);
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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