Custom Code for Hiding Profile Fields
-
i m using these code to hide extra field from profile page but these code will apply this setting for All Roles but i need to exclude admin and superadmin from this code.
can someplease please customize this code so that these extra field will hide only for other roles user not for admin
function remove_extra_field_profile() { $current_file_url = preg_replace( "#\?.*#" , "" , basename( $_SERVER['REQUEST_URI'] ) ); if( $current_file_url == "profile.php" ) { add_action( 'wp_loaded', function(){ ob_start("profile_callback"); } ); add_action( 'shutdown', function(){ ob_end_flush(); } ); } } add_action( 'init', 'remove_extra_field_profile' ); function profile_callback( $html ) { $profile_dom = new DOMDocument; $profile_dom->loadHTML( $html ); $all_lines = $profile_dom->getElementsByTagname( 'tr' ); $excludes = array( 'user-rich-editing-wrap', 'user-admin-color-wrap', 'user-comment-shortcuts-wrap', 'show-admin-bar user-admin-bar-front-wrap', 'user-url-wrap', 'user-behance-wrap', 'user-nickname-wrap', 'user-display-name-wrap', 'user-description-wrap' ); $deletes = array(); foreach ( $all_lines as $line ) { $tr_calss = $line->getAttribute("class"); if( in_array( $tr_calss, $excludes ) ) { $deletes[] = $line; } } $deletes[] = $profile_dom->getElementsByTagname( 'h2' )->item(0); foreach ($deletes as $delete) { $delete->parentNode->removeChild( $delete ); } return $profile_dom->saveHTML(); }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom Code for Hiding Profile Fields’ is closed to new replies.