User Role Submit Form

This topic contains 3 reply and 2 voices, and was last updated by Tareq Hasan 11 years, 4 months ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
July 17, 2013 at 4:09 am 6040
Tareq Hasan Is there any way to lock submitting post to one user role?
July 17, 2013 at 5:00 am 6045
Tareq Hasan Tareq Hasan

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]

July 17, 2013 at 8:16 am 6054
Alexis Media Alexis Media

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

July 17, 2013 at 4:23 pm 6065
Tareq Hasan Tareq Hasan

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 3 Posts - 1 through 3 (of 3 total)