Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Last active December 24, 2021 15:16
Show Gist options
  • Save nikitasinelnikov/2ccbd61e537c0e78e4abe3f53b4ee4af to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/2ccbd61e537c0e78e4abe3f53b4ee4af to your computer and use it in GitHub Desktop.
Customize homepage redirect when one user doesn't have access to the another one user
$GLOBALS['um_custom_redirect'] = false;
function um_custom_pre_profile_shortcode( $args ) {
global $um_custom_redirect;
/**
* @var $mode
*/
extract( $args );
if ( $mode == 'profile' ) {
if ( UM()->fields()->editing ) {
if ( um_get_requested_user() ) {
if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) {
$um_custom_redirect = true;
}
}
} else {
if ( um_get_requested_user() ) {
if ( ! um_can_view_profile( um_get_requested_user() ) && ! um_is_myprofile() ) {
$um_custom_redirect = true;
}
} else {
if ( ! is_user_logged_in() ) {
$um_custom_redirect = true;
}
}
}
}
}
add_action( 'um_pre_profile_shortcode', 'um_custom_pre_profile_shortcode', 9, 1);
function um_customize_restrict_redirect( $url ) {
global $um_custom_redirect;
if ( ! empty( $um_custom_redirect ) ) {
$url = '{your_custom_url_here}';
}
return $url;
}
add_filter( 'um_redirect_home_custom_url', 'um_customize_restrict_redirect', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment