Skip Navigation

[Resolved] Conditional Display by user Role stopped working after update.

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by Nashaat 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1069323

Hi,
i had this code on my website showing delete user button conditionaly. it shoud pop up only when user role equal administrator or editor.. while this was working fine till the last update stopped.

for example this code now show the delete user button only for editor...

  [wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'editor' )"]
  <div class="p-0 position-absolute pos-t-l">
  	[cred_user_form form='delete-user-button']
  </div>
  [/wpv-conditional]

i checked the access control and the "delete user button" in Toolset user form, is as usual checked for administrator account

#1069559

Hi, can you turn on debugging for this conditional and add some text before the form shortcode? Log in as administrator and check the front-end of the site. Take a screenshot of the page and attach it to your next reply so I can review the debug information.

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'editor' )" debug="true"]
<div class="p-0 position-absolute pos-t-l">
  Delete User button form: [cred_user_form form='delete-user-button']
</div>
[/wpv-conditional]
#1070216
Frontend-debug.png

Here what i get on the frontend:

#################### wpv-conditional attributes #################### Array ( [if] => ( '' = 'administrator' ) OR ( '' = 'editor' ) [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( '' = 'administrator' ) OR ( '' = 'editor' ) -------------------- After replacing 1 general variables and comparing strings: ( '' = 'administrator' ) OR ( '' = 'editor' ) Comparing to administrator After replacing 2 general variables and comparing strings: ( '' = 'administrator' ) OR ( '' = 'editor' ) Comparing to editor
#1070238

Hi Christian,
I think i found something that might be the problem.

I have turned on debugging in the wp-config.php, and i can confirm that i get debugging errors only when the code from the other Ticket is added to my code snippet: https://toolset.com/forums/topic/show-user-role-in-the-loop-of-users-with-views/#post-953233

Notice: Trying to get property of non-object in /home3/tatly/tat.ly/100/wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code on line 7

Warning: array_shift() expects parameter 1 to be array, null given in /home3/tatly/tat.ly/100/wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code on line 8
function get_user_role_func( $atts )
{
  $a = shortcode_atts( array(
      'userid' => ''
  ), $atts );
  $userdata = get_user_by('ID', $a['userid']);
  $user_roles = $userdata->roles;
  $user_role = array_shift($user_roles);
  return $user_role;
}
add_shortcode( 'get_user_role', 'get_user_role_func' );
#1070370

Okay we can fix the warning and notice you found in the logs:

function get_user_role_func( $atts )
{
  $a = shortcode_atts( array(
      'userid' => ''
  ), $atts );
  $userdata = get_user_by('ID', $a['userid']);
  $user_roles = isset($userdata->roles) ? $userdata->roles : array();
  $user_role = array_shift($user_roles);
  return $user_role;
}
add_shortcode( 'get_user_role', 'get_user_role_func' );

The code didn't handle cases where Users have no role, like Guests. The conditional debug information you provided indicates that the current User role was blank, which indicates a Guest User. Try again as a Guest, and try again as an Administrator, to see if the behavior is different.

#1071711
Me-Admin-Good.png
ME Admin-bad.png
Different-Admin-Good.png
Different-Admin-Bad.png

Okay This code is actually working fine and has solved the issue with the error when user is not logged in yes.

I think also the above mentioned condition works also fine but my site behaving weird.

I am Administrator of the page: cant change the role of m account in the Backend.
I have aded another Admin account and the IF condition work for that admin and show the delete user button. Also i have checked for Editor Role and works just fine. So i can confirm now this is not an Issue with the Condition. The Issue with something else.

After Adding a new admin account i noticed that the delete user link show on that account but not on my admin account.
in other word both accounts admins but the link show only on the new admin account.

please see screenshots.. you will see another issue withe Layouts Tabs are not showing in the Toolset menu Bar for the new Admin Account

#1071965

Update:
Tha Layout tabs Issue has been fixed by deactivating all plugins and activate them again.
Other issue with Delete user still there.

#1074301

If the conditional seems to be working correctly but you still cannot see the delete button, there may be a problem in the Form code. Can you copy + paste the code from the Delete User Form here for me to review?

#1084073

I will keep this on the side for nowm Thanks for your support