Skip Navigation

[Resolved] Displaying Cred form on page conditionnal on ouser role

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)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years ago.

Assisted by: Waqar.

Author
Posts
#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: English (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.