calle81
Forum Replies Created
-
???♂?
@sarmina5 Now I tried the link and it loads perfectly https://ibb.co/ZJpsbPt or https://ibb.co/vQhDkRt
Can anyone help me? Do you have support or not?
Thanks.
@missveronicatv You’re right, I hadn’t thought of that.
Thanks.
I got what I wanted by changing the code like this:
// Add custom privacy option
add_filter( 'um_field_privacy_options', 'um_field_privacy_options_custom', 10, 1 );
function um_field_privacy_options_custom( $privacy_options ) {
$privacy_options['-4'] = 'Edit visibile solo da admin';
return $privacy_options;
}
// Control field visibility for non-admins (view mode)
add_filter( 'um_can_view_field_custom', 'um_can_view_field_custom_4', 10, 2 );
function um_can_view_field_custom_4( $can_view, $data ) {
if ( $data['public'] == '-4' ) {
// Allow non-admin users to view their own profile fields unless it's the profile edit page
if ( um_profile_id() == get_current_user_id() && !isset($_GET['um_action']) ) {
$can_view = true;
} elseif ( isset($_GET['um_action']) && $_GET['um_action'] === 'edit' && !current_user_can('administrator') ) {
// Non-admins can't view the field on the profile edit page
$can_view = false;
}
// Always allow admins to view the field
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
$can_view = true;
}
}
return $can_view;
}
// Control field editability for non-admins (edit mode)
add_filter( 'um_can_edit_field', 'um_can_edit_field_custom_4', 10, 2 );
function um_can_edit_field_custom_4( $can_edit, $data ) {
if ( $data['public'] == '-4' ) {
// Prevent non-admin users from editing fields in their profile
if ( um_profile_id() == get_current_user_id() && !current_user_can( 'administrator' ) ) {
$can_edit = false;
}
// Allow only admins to edit these fields
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
$can_edit = true;
}
}
return $can_edit;
}Thanks.
@missveronicatv I changed line 10 to if ( is_user_logged_in() && current_user_can( ‘administrator’ ) ) and I almost got what I wanted. I’ll give you a summary below the code.
add_filter( 'um_field_privacy_options', 'um_field_privacy_options_custom', 10, 1 );
function um_field_privacy_options_custom( $privacy_options ) {
$privacy_options['-4'] = 'Edit visibile solo da admin';
return $privacy_options;
}
add_filter( 'um_can_view_field_custom', 'um_can_view_field_custom_4', 10, 2 );
function um_can_view_field_custom_4( $can_view, $data ) {
if ( $data['public'] == '-4' ) {
$can_view = false;
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
$can_view = true;
}
}
return $can_view;
}
add_filter( 'um_can_edit_field', 'um_can_edit_field_custom_4', 10, 2 );
function um_can_edit_field_custom_4( $can_edit, $data ) {
if ( $data['public'] == '-4' ) {
$can_edit = false;
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
$can_edit = true;
}
}
return $can_edit;
}- Now the admin sees these fields both on his profile edit page and on other profiles’ page and also sees them on his profile view page and on other profiles’ page (this is perfect).
The problem is the other users:
- They don’t see the fields in edit of their profile (this is perfect)
- Now they don’t see the fields in view of their profile and in view of other users (this is not good).
I would like these users who are not admins to be able to see these fields in view of their profile, but not in edit of their profile.
I hope I explained myself ??
Thanks.
I changed it to “View Everywhere” but it still doesn’t work. Now if I go to edit profile the fields are seen by the user who owns the profile (which shouldn’t be) and by the administrator. I would like them to be seen only by the admin and not also by the owner of the profile.
Thanks.
@missveronicatv Thanks for the reply. I tried to insert the snippet but it doesn’t work ??.The privacy of the field is set to “my custom option” while the visibility is set to “only view mode”.if I go to the profile I see the fields both as a normal user and as an admin, but if I go to edit profile I don’t see those fields as a normal user (this is fine) and not as an admin as I would like.
Thanks.
I tried to write the code below to get what I want, but it doesn’t work. Any suggestions?
add_filter('um_profile_field_filter_hook', 'custom_um_only_view_fields_visibility', 10, 2);
function custom_um_only_view_fields_visibility($output, $args) {
// Controlla se il campo è impostato su "Only View"
if ( isset($args['only_view']) && $args['only_view'] == 1 ) {
// Se siamo in modalità di modifica
if ( is_profile_edit() ) {
// Se l'utente è un amministratore
if ( current_user_can('administrator') ) {
// Mostra il campo in modalità di modifica per l'amministratore
return $output; // Ritorna il campo senza modifiche
} else {
// Nascondi il campo per gli utenti non amministratori in modalità di modifica
return ''; // Nascondi il campo
}
}
// Se siamo in modalità di visualizzazione, mostra il campo a tutti
return $output; // Mostra il campo a tutti in modalità di visualizzazione
}
// Ritorna il campo normalmente per tutti gli altri campi che non sono "Only View"
return $output;
}
// Permetti agli amministratori di modificare i campi "Only View"
add_filter('um_can_edit_field', 'custom_um_allow_admin_edit_only_view_fields', 10, 2);
function custom_um_allow_admin_edit_only_view_fields($can_edit, $meta_key) {
// Se l'utente è un amministratore
if ( current_user_can('administrator') ) {
// Controlla se il campo è impostato su "Only View"
$field = um_get_profile_field($meta_key);
if ( isset($field['only_view']) && $field['only_view'] == 1 ) {
return true; // L'amministratore può modificare il campo
}
}
// Mantieni il comportamento predefinito per tutti gli altri utenti
return $can_edit;
}Thanks
@juaancmendez thanks.
@mdibrahimk48 Ok, sorry. I didn’t think it was a premium version since in the first versions of the plugin it was free. I will look for another plugin.Thanks.
@missveronicatv perfect !! Thanks.
This is my current setting https://ibb.co/Jc0y6n1. What should I change? Thanks.
I tried, but I can’t find Profile Photo Thumbnail Sizes (px) ??
@missveronicatv thanks for the reply.
- This reply was modified 10 months, 1 week ago by calle81.