PHP unset / hide field based on WordPress user role
-
Hi, I am trying to hide a specific field for user role: subscriber but it does not hide the field.
Any idea/suggestion is highly apreciated 🙂add_filter (‘bps_before_search_form_filter’ , ‘hide_field_19_wrap’, 10, 1);
$array1 = array(field_19_wrap, field_28_match_any_wrap, field_34_distance_wrap);
function hide_field_19_wrap ($field_ids){global $current_user;
$user_roles = $current_user->roles;
if (!current_user_can(‘subscriber’)) {
unset($array1[field_19_wrap]);}
return $field_ids;
}
-
Try:
function hide_field_19_wrap ( $field_ids ) { global $current_user; if ( user_can( $current_user, "subscriber" ) ) { unset( $field_ids[19] ); } return $field_ids; } add_filter ('bps_before_search_form_filter' , 'hide_field_19_wrap', 10, 1);
Thank you for your resonse shane but it does not work.
I might use the wrong words for the function…I use it in the code snippet plugin but no luck.
Its definitely the get user role part as this part I have seen on many forum pages…Is the word:”unset” the right one? Not “hide” or “remove”?
Change this:
global $current_user;
to :global $current_user; var_dump( $field_ids );
And then post the dump here.
Sorry Shane, what do you mean “post the dump here”?
I just looked up this var_dum expression, looks like many functions include some more variables in brackets….for example:
“var_dump(var_dump(2, 2.1, TRUE, array(1, 2, 3, 4)));” So, dont I need to include some more things in brackets too?Anyway, I just tried to send you screenshots via email as here there is no option to attach images (although I assume the email wont be send).
Learn how to use var_dump – it shows the output on the screen.
You are using the BP Profile Search plugin, correct?
If so, ask the creators of that plugin.
If not, then you are using BuddyBoss and you should ask them.
- You must be logged in to reply to this topic.