Home Forums Plugin Support WP User Frontend Pro User Role Submit Form

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Tareq Hasan 5 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6040

    Alexis Media
    Participant
    Post count: 54

    Is there any way to lock submitting post to one user role?

    #6045

    Tareq Hasan
    Keymaster
    Post count: 2831

    Yes, possible. If you want to access only Author role to the form, you could use this snippet. Change the role name as you need.

    [php]
    if ( !function_exists( ‘get_current_user_role' ) ) {

    /**
    * Returns the translated role of the current user. If that user has
    * no role for the current blog, it returns false.
    *
    * @return string The name of the current role
    * */
    function get_current_user_role() {
    global $wp_roles;

    $current_user = wp_get_current_user();
    $roles = $current_user->roles;
    $role = array_shift( $roles );

    return isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : false;
    }

    }

    function wpuf_block_by_user_role( $form_id ) {

    if ( get_current_user_role() == ‘Author' ) {
    return ‘yes';
    }

    return ‘no';
    }

    add_filter( ‘wpuf_can_post', ‘wpuf_block_by_user_role' );
    [/php]

    #6054

    Alexis Media
    Participant
    Post count: 54

    How do i tell it what form i need to what user? I have a few post forms that will need different user roles.

    #6065

    Tareq Hasan
    Keymaster
    Post count: 2831

    Then you've to change the later function like this, hope that gets you started

    [php]
    function wpuf_block_by_user_role( $form_id ) {
    $user_role = get_current_user_role();

    if ( $form_id == '12' && $user_role == ‘Author' ) {
    return ‘yes';

    } else if ( $form_id == '13' && $user_role == ‘Subsriber' ) {
    return ‘yes';

    } else if ( $form_id == '16' && $user_role == ‘Subsriber' ) {
    return ‘yes';
    }

    return ‘no';
    }
    [/php]

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘User Role Submit Form’ is closed to new replies.