Skip to content

Instantly share code, notes, and snippets.

@flegfleg
Created February 7, 2022 16:04
Show Gist options
  • Save flegfleg/8b4fc52dd3f2eed7fc489b55c8137872 to your computer and use it in GitHub Desktop.
Save flegfleg/8b4fc52dd3f2eed7fc489b55c8137872 to your computer and use it in GitHub Desktop.
Remove profile picture, social notifications and privacy menu entries from userswp profile. Prevent users from accessing others' profiles.
// remove Notifications and privacy menu entries
add_filter('uwp_account_available_tabs', 'uwp_account_available_tabs_cb');
function uwp_account_available_tabs_cb($tabs){
unset($tabs['notifications']);
unset($tabs['privacy']);
return $tabs;
}
// prevent users from accessing other users' profiles
add_action('template_redirect', 'template_redirect_cb', 9);
function template_redirect_cb(){
global $post;
if ( ! is_page() ) {
return false;
}
if ( uwp_is_page_builder() ) {
return false;
}
$current_page_id = isset($post->ID) ? absint($post->ID) : '';
$uwp_page = uwp_get_page_id('profile_page', false);
if ( $uwp_page && ((int) $uwp_page == $current_page_id ) ) {
$user = uwp_get_user_by_author_slug();
if ( !(is_user_logged_in() && $user && $user->ID == get_current_user_id()) ) {
wp_redirect( home_url() );
exit();
}
}
}
// hide profile image
add_action( 'wp_head', function () { ?>
<style>
.uwp_widget_account .card, .uwp_widget_account a.font-weight-bold {
display: none !important;
}
</style>
<?php } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment