Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Last active August 2, 2023 22:03
Show Gist options
  • Save nikitasinelnikov/445b43e35a67383d578af64cc9641a62 to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/445b43e35a67383d578af64cc9641a62 to your computer and use it in GitHub Desktop.
Adds profile permissions to view/edit.
function um_custom_can_view_profile( $can_view, $user_id ) {
if ( ! is_user_logged_in() ) {
if ( user_can( $user_id, 'um_volunteer' ) ) {
$can_view = false;
}
} else {
if ( current_user_can( 'um_volunteer' ) && user_can( $user_id, 'um_volunteer' ) ) {
$can_view = false;
}
}
return $can_view;
}
add_filter( 'um_can_view_profile', 'um_custom_can_view_profile', 10, 2 );
function um_custom_pre_profile_shortcode() {
add_filter( 'um_redirect_home_custom_url', 'um_custom_redirect_home_custom_url', 10, 3 );
}
add_action( 'um_pre_profile_shortcode', 'um_custom_pre_profile_shortcode', 9 );
function um_custom_redirect_home_custom_url( $url, $requested_user_id, $is_my_profile ) {
if ( ! $is_my_profile ) {
if ( ! is_user_logged_in() ) {
if ( user_can( $requested_user_id, 'um_volunteer' ) ) {
$url = 'redirect_url_with_notice;
}
} else {
if ( current_user_can( 'um_volunteer' ) && user_can( $requested_user_id, 'um_volunteer' ) ) {
$url = 'redirect_url_with_notice;
}
}
}
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment