Last active
September 16, 2017 23:09
-
-
Save duurland/e83dc34f2d1745cafa1c0e40f7bff50e to your computer and use it in GitHub Desktop.
Hide default WordPress users profile fields
This file contains hidden or 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 | |
// As there seems to be no good php hook to remove default wordpress profile fields, | |
// I ended up hiding the fields with CSS then remove them with JS. | |
add_action( 'admin_head', 'remove_default_profile_fields' ); | |
function remove_default_profile_fields() { | |
global $pagenow; | |
if( 'profile.php' != $pagenow) return; | |
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' ); | |
// <tr> selectors, each containing a field | |
$tr = array( | |
"tr.user-rich-editing-wrap", | |
"tr.user-comment-shortcuts-wrap", | |
"tr.user-first-name-wrap", | |
"tr.user-last-name-wrap", | |
"tr.user-admin-bar-front-wrap", | |
"tr.user-profile-picture", | |
"tr.user-user-login-wrap", | |
"tr.user-display-name-wrap", | |
"h2" // Personally I decided to remove all H2 tags too. | |
); | |
$selectors = implode(", ", $tr); | |
// Hide the fields with css, so even if javascript is disabled they wont show up. | |
echo "<style>{$selectors}{display:none;}</style>"; ?> | |
<script type="text/javascript"> | |
jQuery( document ).ready(function( $ ){ | |
// Remove selected <tr>'s | |
$( '<?= $selectors; ?>' ).remove(); | |
// Remove any empty table that may have been left over | |
$(".form-table:not(:has(tr))").remove(); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment