Skip Navigation

[Resolved] 'other role' does not appear

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.

This topic contains 10 replies, has 2 voices.

Last updated by matthiasV-2 6 months ago.

Assigned support staff: Waqar.

Author
Posts
#2217517

Please refer this ticket to Waqar.

We want to create the following condition 'group':

DO NOT show when
Field Status from Current Eigendom is empty
AND
DO (only) show when
Current user role, other role = Koper
OR
Current user role, other role = Bouwprofessional

The issue is that 'other role' does not appear.

Have a look at: hidden link

#2217577

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

user-role-conditional.png

Hi,

Thank you for contacting us and I'd be happy to assist.

For the current user's main role-based conditions, you can add the target role's string on the right-hand side, as a static value.

For example, the attached screenshot, shows a simple condition to see if the current has the "administrator" role (as the main role) or not.

Checking for other or additional roles is tricky, because there is no built-in method available for this. To check for all (i.e. main and additional) roles attached to the current user, you can register a custom shortcode:


add_shortcode('custom_check_user_roles', 'custom_check_user_roles_func');
function custom_check_user_roles_func($atts) {
	$roles = $atts['roles'];
	
	$content = do_shortcode('[toolset_access role="'.$roles.'" operator="allow"]1[/toolset_access]');
	if(!empty($content)) {
		return 'yes';
	}
	else
	{
		return 'no';
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Also add "custom_check_user_roles" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that you'll be able to use this custom shortcode like this:


[custom_check_user_roles roles='Administrator,Editor']

The above shortcode will return 'yes' if the current user has an Administrator or Editor role (no matter as primary or additional roles) and 'no' if not.

And you'll be able to use the same custom shortcode in the conditional block too, by just specifying the role names.
( screenshot: hidden link )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2217667

Waqar,

We followed all your instructions, however that does not seem to work.

As an example:

The 'hebt u vragen?...' section should not appear when the status is empty OR when the user virtify.studio__849@gmail.com with role 'new subscriber' visits a properties page.

ONLY when the user has the role of administrator, koper or bouwprofessional he should be seeing the 'hebt u vragen?...' section.

Check out the video: hidden link

What did we miss here?

#2218349

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

From the video, it seems that the custom code has been registered correctly.

Can you please share the link to the exact property page and the login details for the 'new subscriber' role user, that you used for this testing?

I've set your next reply as private.

#2219293

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing these details.

I'm currently performing some tests with the conditional statements and will update you with my findings, shortly.

#2219319

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting.

During my tests, I was able to set the condition as you want by combining:

1. If the status field is not equal to empty
AND
2. If current user has any of these roles
( screenshot: hidden link )

As a result, the contents of these blocks only show, when both those conditional statements are true.

Note: When I view the property page, as the administrator user that you've provided, I can't see the entire container that contains this conditional block, because it is wrapped inside this shortcode, using two custom HTML blocks.


[MM_Member_Decision membershipId='11|12|13|14|16|17|18']

[/MM_Member_Decision]

I'm not sure what is the purpose of this shortcode, but if it is removed, I can see this container as administrator.

#2220005

Waqar,

That works!

Now, we want to do the same for the following condition 'group':

Show button 'onderzoek eigendom op verkoopintentie' ONLY IF:
Status = static value = 5
AND
User role (primary and additional roles!) = administrator OR koper OR bouwprofessional
AND
Type eigendom = static value = 1 OR 2 OR 11

Have a look at: hidden link

Property page: hidden link
Login details are the same as above.

Can you set this condition as well to return the right value no matter if the administrator, koper or bouwprofessional roles are set as primary or additional?

#2221559

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that it worked.

Have you tried to set conditional block using the example screenshot from my last reply?
( screenshot: hidden link )

The requirement and steps should be similar to the previous conditional block too.

I hope you'll understand that in the support forum we can help users in learning how to use Toolset features and share examples. But, we can't set up all the elements for you.

If you try to set the conditional group the same way as the previous example and it doesn't work, then please let me know and I'll see what needs to be adjusted.

#2221565

This condition is totally different from the previous one.
If it would be similar we would be able to do it ourselves.
Please provide us with the exact condition to return the right value no matter if the administrator, koper or bouwprofessional roles are set as primary or additional.

#2222171

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

This new conditional display requirement can be divided into 3 main parts:

1. Status = static value = 5
( this is similar to how the first part of the condition was set in the previous example and only the value to check is different )
AND
2. User role (primary and additional roles!) = administrator OR koper OR bouwprofessional
( this is exactly the same as how the second part of the condition was set in the previous example )
AND
3. Type eigendom = static value = 1 OR 2 OR 11
This third statement includes 3 substatements, connected through 'OR', so you'll add a nested group and 3 comparison statements, one for each value:

a. Type eigendom = static value = 1
OR
b. Type eigendom = static value = 2
OR
c. Type eigendom = static value = 11

( screenshot: hidden link )

#2222311

My issue is resolved now. Thank you!