Skip Navigation

[Gelöst] Displaying Cred form on page conditionnal on ouser role

This support ticket is created vor 2 Jahre. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

This topic contains 1 Antwort, has 2 Stimmen.

Last updated by Waqar vor 2 Jahre.

Assisted by: Waqar.

Author
Artikel
#2349379

Hi just wondering if its possible to use [wpv-conditional] on a page like this

`[wpv-conditional if="(current_user_can('edit_posts') eq 1)"]
can edit [cred_form form="workers-add-new-retirement-housing-to-the-database"]
[/wpv-conditional]

[wpv-conditional if="(current_user_can('edit_posts') ne 1)"]
cannot edit [cred_form form="new_entry"]
[/wpv-conditional]`

- attempting to show a different form based on whether user has edit permission or not.
am I doing this wrong?

#2349525

Waqar
Supporter

Languages: Englisch (English )

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

Hi,

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

To check for the user's specific capability, you can register a custom shortcode:


add_shortcode('check_current_user_can', 'check_current_user_can_func');
function check_current_user_can_func($atts) {
	$user_cap = $atts['cap'];
	return current_user_can( $user_cap );
}

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

After that, this custom shortcode can be used to check for a specific capability for example "edit_posts" like this:


[check_current_user_can cap="edit_posts"]

Note: The shortcode will return '1' when true and nothing when false.

And the same shortcode can be used in a conditional statement, like this:


[wpv-conditional if="( '[check_current_user_can  cap="edit_posts"]' eq '1' )"]
can edit [cred_form form="workers-add-new-retirement-housing-to-the-database"]
[/wpv-conditional]

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

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.