• Resolved savenemo

    (@savenemo)


    Hey there
    thank you for this fantastic plugin.
    My question:
    I try to display a specific form only to a specific role. I used this:
    —————–
    <?php if( current_user_can(‘activate_plugins’) ) { ?>
    [bf form_slug=”publish-test”]
    <?php } ?>
    —————–
    but I am not a pro. The form still shows up regardless of the user role. Can someone help to tweek this ?

    Regards
    Dee

    • This topic was modified 3 years, 4 months ago by savenemo.
    • This topic was modified 3 years, 4 months ago by savenemo.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Romeli

    (@romelirodriguez)

    Hello my friend, how are you?

    With the following code you can check if the user has the administrator role:

    $user = wp_get_current_user();
    if ( in_array( ‘administrator’, (array) $user->roles ) ) {
    echo do_shortcode( ‘[bf form_slug=”publish-test”]’ );
    }

    Regards,
    Romeli

    Thread Starter savenemo

    (@savenemo)

    Hey Romeli,
    Thanks, I am fine.

    I used XYZ PHP Code plugin in inject your snippet:
    ——————-
    <?php
    $user = wp_get_current_user();
    if ( in_array( ‘administrator’, (array) $user->roles ) ) {
    echo do_shortcode( ‘[bf form_slug=”publish-test”]’ ); }
    <?php }
    ——————-
    and I get this error. Can you help again ?

    Parse error: syntax error, unexpected ‘&’ in /is/htdocs/…/insert-php-code-snippet/shortcode-handler.php(97) : eval()’d code on line 3

    Fatal error: Exception thrown without a stack frame in Unknown on line 0

    Romeli

    (@romelirodriguez)

    Hello there, hope you’re doing well.

    I’m sorry for the delay. This seems to be something related with XYZ PHP Code plugin, don’t really know how that plugin works. But you can try adding the code directly directly in your page template.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show Forms only to a role’ is closed to new replies.