由于似乎没有好的php钩子,我最终用CSS隐藏字段,然后用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
}