Skip Navigation

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

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

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Waqar vor 2 Jahren, 7 Monaten.

Assistiert von: 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

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