-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate_profiles.php
41 lines (34 loc) · 1.15 KB
/
private_profiles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
*
* @since 3.9.1
* @access public
*
* @uses $wpdb to get the current user ID.
* @uses $bp to get the profile user ID.
* @global object $wpdb
* @global object $bp
*/
add_action( 'template_redirect', 'hide_profiles', 1 );
function hide_profiles() {
global $wpdb;
global $bp;
/* Bloqueamos el acceso a la página de miembros para los no admins */
if( bp_current_component('members') && !current_user_can( 'switch_themes' ) ) {
// Redirigir al usuario
bp_core_redirect( get_option( 'home' ));
}
/* Bloqueamos el acceso a la página de un perfil que no sea el propio */
if ( bp_is_user() ){
// Buscamos el ID del perfil del usuario que visitamos, y nuestro ID de usuario
$usuario_visitante = wp_get_current_user()->ID;
$usuario_miembro = $bp->displayed_user->id;
// Comparamos los IDs de usuario. Si no coinciden, el usuario no tiene permiso para ver el perfil y debe salir de la web
if ( $usuario_visitante != $usuario_miembro && !current_user_can( 'switch_themes' ) ) {
// Redirigir al usuario
wp_redirect( home_url() );
exit();
}
}
}