Skip to content

Instantly share code, notes, and snippets.

@ZachWatkins
Last active September 1, 2021 16:46
Show Gist options
  • Save ZachWatkins/076d8eeaf7e7ce66ccc5b17511f65fab to your computer and use it in GitHub Desktop.
Save ZachWatkins/076d8eeaf7e7ce66ccc5b17511f65fab to your computer and use it in GitHub Desktop.
WordPress - Remove User Profile fields
if ( ! function_exists( 'remove_unneeded_account_options' ) ) {
/**
* Removes user settings sections by their heading element pattern.
*/
function remove_unneeded_account_options( $subject ) {
$subject = preg_replace( '#<h2>Personal Options</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>About Yourself</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>Author Archive Settings</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>Author Archive SEO Settings</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>Layout Settings</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>User Permissions</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>Account Management</h2>.+?/table>#s', '', $subject, 1 );
return $subject;
}
function profile_subject_start() {
ob_start( 'remove_unneeded_account_options' );
}
function profile_subject_end() {
ob_end_flush();
}
}
add_action( 'admin_head-profile.php', 'profile_subject_start' );
add_action( 'admin_footer-profile.php', 'profile_subject_end' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment