Hide Personal Options in Profile for Author User Role

Hello. Please pardon my simple question, as I must be missing something very basic:

How/where can I implement a display:none; to hide the Personal Options in the Profile of any user with the Author Role?

Thanks,

Clyde

  • Adam Czajczyk

    Hello Clyde,

    I hope you're well today and thank you for your question!

    The CSS for "backend" part of the site has to be added in a slightly different way than a front end CSS. Since you are willing to affect only the users of the "author" role you will also wan't to go a bit beyond the CSS as you need to use WP hook to run PHP code in order to first check the user role of a current user and then output the relevant CSS to the admin area.

    I think I'll be able to help you with that but could you please provide me with a screenshot of the part of the profile page that you wish to hide? I see you mentioned "Personal Options" but I'm not 100% sure if we're thinking of the same part :slight_smile:

    Looking forward to your replay,
    Adam

  • Adam Czajczyk

    Hello Clyde!

    It seems that the screenshot didn't came through but I think your additional explanation is good enough :slight_smile:

    Below is the code that should hide "everything above "Name"" on profile page for all users of "author" role. It will not affect other roles.

    <?php 
    
    function wpmu_hide_personal_profile_settings() {
    
    	$current_user = wp_get_current_user(); // get logged in user data
    	if ( in_array( 'author', (array) $current_user->roles ) ) { // if role = author print CSS
    		?>
    		<style>
    			#profile-page h2:first-of-type {display:none;}
    			#profile-page .form-table:first-of-type {display:none;}
    		</style>
    		<?php
    	}
    }
    add_action('admin_footer','wpmu_hide_personal_profile_settings');

    In order to use it on your site, please create an empty file with a ".php" extension (e.g. "hide-personal-options-for-author.php") and paste this code inside. Then upload the file to the "/wp-content/mu-plugins" folder of your Multisite. If there's no "mu-plugins" folder inside the "/wp-content" folder, please create it.

    I created it using my own test site and it seems to be working fine. Let me know please if it works for you as well.

    Best regards,
    Adam