Navigation überspringen

[Gelöst] Conditional display on templates

This support ticket is created vor 3 Jahren. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Dieses Thema enthält 7 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Waqar vor 3 Jahren.

Assistiert von: Waqar.

Author
Artikel
#2239757
image 2.png
image 1.png

I have a challenge with a conditional display on a profile template

I have a subscribers website where people signup as editors. The base is a user setup where users are created for login purposes. The user then creates profiles (CPT) where they load their personal details for their profile.
We have created 4 user rolls, "Superadmin", "Systemadmin" Peg blog admin" "peg-editor".
The capabilities are in order as listed above from most powerful to least powerful. I used Access to setup the permissions and it seems to be working very well.

In the profile, there is a range of fields that are considered private. No "guess" of "Peg editor" does have access to this information. Only the Owner of the information and the "Peg-admins" does have access to this information.

The component that is giving challenge is a content template. This is where the Full profile of a "peg editor" is displayed.

The template is split into 5 of 6 sections to group information with the same type of information. The Template being just a "report" as such does not contain any editable fields. To make editing of the profile easier we created a form for each section that contains the information in that section for the profile holder to edit. we created buttons beneath the Title of each section linking to the form that will update the content of the section from the profile. This button is only available to the editor and the admin listed above.

All of this works 100%. This is where I lost the plot.
The "account" details section of the profile is on the same structure. With only one caveat. The edit button of this section must not be available to the editor but only available to the admins. The information manages various aspects of the user setup and the admin doesn't want the user to be able to change any information in the account section. So the edit button must only show up for admins.

The section "account" and "edit buttons" are hidden from the non logged in users.
The "account" section must only show up for the specific user it belongs to, and peg admin.
The buttons section must only show up for the specific user it belongs to, and peg admin except for the button of the Account section which must only be available to the peg admin.

This is the conditional code for the section "Account details

 NOT ( ( '[wpv-current-user info="role"]' eq 'system_admin' ) OR ( '[wpv-current-user info="role"]' eq 'sa001' ) OR ( '[wpv-current-user info="role"]' eq 'administrator' ) OR  NOT ( ( '[wpv-current-user info="id"]' eq '[wpv-current-user info="id"]' ) )  ) 

This is conditionals for the button

NOT ( ( '[wpv-current-user info="role"]' eq 'system_admin' ) OR ( '[wpv-current-user info="role"]' eq 'sa001' ) OR ( '[wpv-current-user info="role"]' eq 'administrator' ) OR  NOT ( ( '[wpv-current-user info="id"]' eq '[wpv-current-user info="id"]' ) )  ) 

Image one is a full profile page from an peg editor
Image 2 is a zoom of the account and contact details. Contact details are 100% just showing a sample.

So the button and contents in image 2 must not show when logged out (done)
The content of image 2 must show for the owner of the profile. Nobody must have access to that information at any point except if the user views his own profile. The button is only available to the admin for editing purposes. No user must have access to anybody's account information but a user must be able to view any bodies profile.

#2239797

Update, I have manage to sort it all out except for the edit button that must only show for admins
Here is the new conditionals.
his is for the Section "Accounts Details"

 NOT ( ( '[wpv-current-user info="role"]' eq 'system_admin' ) OR ( '[wpv-current-user info="role"]' eq 'sa001' ) OR ( '[wpv-current-user info="role"]' eq 'administrator' ) ) 

This is for the Button

   ( ( '[wpv-current-user info="role"]' eq 'system_admin' ) ) 
#2239899

Hi,

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

Based on what you've shared, the conditional statement for the edit button (in your most recent message), should've worked.

In case it is still not working as expected, can you please share temporary admin login details, along with the link to the profile page. Also, include the access details for a test user that is not an admin.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2240715

Thank you for sharing the admin access.

I noticed that the conditional block to show the account details edit button, is nested inside the other conditional block to show the account details section.
( screenshot: versteckter Link )

But, the conditions used in both these conditional blocks, lead to a contradiction.

Outer block's condition for the account detail section says:
"Do not show this section, if the user belongs to system_admin, sa001, or administrator roles".

This means that this section will only show, if the user doesn't belong to any of these 3 roles.

But, the inner/nested conditional block for the account details edit button, says:
"Show this section, only if the user belongs to system_admin role".

But, because of the outer condition, a user with the system_admin role, would never make it to this block's conditions.

To fix this, you can put these two conditional blocks at the same level instead of nesting them within each other.

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

#2241001

Hi Waqar,

I have moved all conditional to be on the same level. I have added anchor tags for the columns for making it easy to see where each column is.
We took both the "accounts" and the "contact details: deleted all the conditionals and just added on conditional: ie

  ( ( '[wpv-current-user info="id"]' eq '[wpv-current-user info="id"]' ) ) 

so that just the logged in user can only see the the edit button on his own profile. Then the button shows on all the profiles.
When we add the NO in then it shows no buttons.

We used the following two profiles to test it:
versteckter Link
versteckter Link

There seems to be some issue with the conditionals.

For each of the sections on the user profile with the exception of the "account", the edit button must show under the following 4 conditions.
If user roll is:
superadmin
Systems admin
administrator

and if the logged-in user is the same as the profile.

On the "Account" section:
If user roll is:
superadmin
Systems admin
administrator

The User must not be able to see the edit button on this section at all. Only the admin must be able to edit the account section.
We would greatly appreciate it if this can be addressed before 11 AM tomorrow morning your time as we are supposed to do the final sign over to our client at that time.

#2241327

Thanks for writing back.

If you'll check the conditional block around the link "Edit account details", you'll see this condition:


( ( '[wpv-current-user info="role"]' eq 'sa001' ) OR ( '[wpv-current-user info="role"]' eq 'system_admin' ) OR ( '[wpv-current-user info="role"]' eq 'administrator' ) ) 

This is working correctly and I can see this button when I'm logged in as administrator, but not if I'm logged in using the test user account (peg editor).

But for the other edit links like "Edit contact details and profile image", the condition needs to be different:
( I've added the statement with spaces and indentations here only to make its structure more clear )


( 
	( 
		( '[wpv-current-user info="role"]' eq 'administrator' ) 
		OR 
		( '[wpv-current-user info="role"]' eq 'sa001' ) 
		OR 
		( '[wpv-current-user info="role"]' eq 'system_admin' ) 
	)  
	OR 
	( '[wpv-post-author format="meta" meta="ID" ]' eq '[wpv-current-user info="id"]' ) 
) 

The first part includes conditions for the admin roles and the second part check if the current post author is the same as the currently logged-in user.

This condition is working correctly in my tests for the link "Edit contact details and profile image":

- When logged in as administrator, I can see this link on all editor profiles.
- When logged in using the test user (peg editor), I can see the link on his own profile, but not if I visit the profile for the other user like Alexis Grewan.

You can update the conditional statement around the other edit sections, the same way.

#2241375

Hi Waqar

This worked! We appreciate this very much.
Just two minor questions, please.

First Question, I don't know if this is intended or a bug,
When I do a visual condition like my admin rights on the visual editor side I use the following:
Current user roll - equal other roll value selected "administrator"
Then sometimes when I come back to it would have been automatically changed
the current user rolls equal static value "se001" This has happened more than once at random. (or should this be a new ticket?)

The second question has two parts:
part one - can the above conditional be made with the Visual Builder of would this type of query always be an advanced editing function. If it could be done with the visual builder how would you achieve the extra "level" indented entry?
Part two, what is the logic behind your code. why the Extra level and why did you use

 
Author ID from Current Editor Profile is equal to Current user.

vs current user id = current User id.
Author ID from Current Editor Profile is equal to Current user.

Once again thank you for your invaluable help.

#2241623
screenshot-2.png
screenshot-1.png

Thanks for the update and glad I could help.

1. In my random tests, I couldn't reproduce this on my test website. If you continue to see this behaviour, you're welcome to start a new ticket, with the specific steps to reproduce the issue and we'll have it investigated, accordingly.

2. a. Yes, it is possible to add the same conditional statements using the visual mode too, as shown in the attached "screenshot-1.png".

When adding a new statement in the visual mode through the plus sign, you'll see the options to whether add an if statement at the same level or start a new group for a combination of statements.
( example screenshot "screenshot-2.png" attached )

2. b. Comparing "current user id = current User id" will achieve nothing, because the two values will always be the same. For example, if I'm logged in using a user with ID '12345', then the same value '12345' will be on both sides of the equation (12345 = 12345) and this condition will always be true.

You wanted the edit button to show in two main scenarios:

In the first part, the button should show for users with any of these roles: administrator, sa001, system_admin


( 
        ( '[wpv-current-user info="role"]' eq 'administrator' ) 
        OR 
        ( '[wpv-current-user info="role"]' eq 'sa001' ) 
        OR 
        ( '[wpv-current-user info="role"]' eq 'system_admin' ) 
)

In the second part, the button should also show, if the currently logged-in user is viewing his/her own profile:


( '[wpv-post-author format="meta" meta="ID" ]' eq '[wpv-current-user info="id"]' )

This part tells that if the current profile post's author ID is the same as the currently logged-in user, then this condition will be true and the edit button should show.

And combining the two parts, you get the conditional statement that I shared in my last reply and what is shown in the "screenshot-1.png" from the visual mode.

Note: You can read the details about the shortcodes used in these conditional statements in this shortcode reference:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/