Created
February 5, 2014 23:54
-
-
Save joshuadavidnelson/8835823 to your computer and use it in GitHub Desktop.
Remove Biographical Box from User Profile (or other element) for specific users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set which users to hide box | |
add_action( 'admin_init', 'jdn_remove_bio_box' ); | |
function jdn_remove_bio_box() { | |
if( !current_user_can( 'edit_published_posts' ) ) { | |
add_action( 'personal_options', array ( 'JDN_Hide_Profile_Bio_Box', 'start' ) ); | |
} | |
} | |
/** | |
* Captures the part with the biobox in an output buffer and removes it. | |
* | |
* @author Thomas Scholz, <[email protected]> | |
* | |
*/ | |
class JDN_Hide_Profile_Bio_Box | |
{ | |
/** | |
* Called on 'personal_options'. | |
* | |
* @return void | |
*/ | |
public static function start() | |
{ | |
$action = ( IS_PROFILE_PAGE ? 'show' : 'edit' ) . '_user_profile'; | |
add_action( $action, array ( __CLASS__, 'stop' ) ); | |
ob_start(); | |
} | |
/** | |
* Strips the bio box from the buffered content. | |
* | |
* @return void | |
*/ | |
public static function stop() | |
{ | |
$html = ob_get_contents(); | |
ob_end_clean(); | |
// replace the headline for passwords | |
$headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' ); | |
$html = str_replace( '<h3>' . $headline . '</h3>', '<h3>Password</h3>', $html ); | |
// remove the table row | |
$html = preg_replace( '~<tr>\s*<th><label for="description".*</tr>~imsUu', '', $html ); | |
print $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment