Support

Account

Home Forums General Issues User role selector

Solving

User role selector

  • Dear developers,

    I need the function “User Role Selector” but the only plugin was updated 3 years ago!
    (https://wordpress.org/plugins/acf-role-selector-field/)

    Anybody tested that plugin or have another solution?

    Please let me know and thank you very much

  • Hi,

    This post is a bit old but it mights be useful for others.

    This plugin is working for me (ACF 5.8.5 / WordPress 4.x or 5.x)
    It uses the same functions describe in the documentation: https://www.advancedcustomfields.com/resources/creating-a-new-field-type/

    As far as i know it’s update for all versions of ACF 5.
    (There is a callback file for ACF4, i don’t know if it’s working).

    BUT

    You could only use the ID return value, the object return doesn’t work (i don’t know why).

    Basically it uses the global variable $wp_roles and the method $wp_roles->roles to get all roles.

    It uses also a get_role() function to display the name in back-end.

    If you want a role object using this plugin, you could retrieve it with the ID’s returned.
    It’s not the best way but it’s working.

    Finally it could be really usefull to integrate this field in a future version 😉

  • Use this :

    if( function_exists(‘acf_add_local_field_group’) ):

    acf_add_local_field_group(array(
    ‘key’ => ‘group_5f33968e2461e’,
    ‘title’ => ‘Champs Articles’,
    ‘fields’ => array(
    array(
    ‘key’ => ‘field_5f33969714b2f’,
    ‘label’ => ‘Gestion des droits’,
    ‘name’ => ‘manage-role’,
    ‘type’ => ‘checkbox’,
    ‘instructions’ => ”,
    ‘required’ => 0,
    ‘conditional_logic’ => 0,
    ‘wrapper’ => array(
    ‘width’ => ”,
    ‘class’ => ”,
    ‘id’ => ”,
    ),
    ‘choices’ => get_roles(),
    ‘allow_custom’ => 0,
    ‘default_value’ => false,
    ‘layout’ => ‘vertical’,
    ‘toggle’ => 0,
    ‘return_format’ => ‘value’,
    ‘save_custom’ => 0,
    ),
    ),
    ‘location’ => array(
    array(
    array(
    ‘param’ => ‘post_type’,
    ‘operator’ => ‘==’,
    ‘value’ => ‘post’,
    ),
    ),
    ),
    ‘menu_order’ => 0,
    ‘position’ => ‘side’,
    ‘style’ => ‘default’,
    ‘label_placement’ => ‘left’,
    ‘instruction_placement’ => ‘label’,
    ‘hide_on_screen’ => ”,
    ‘active’ => true,
    ‘description’ => ”,
    ));

    endif;

    function get_roles() {

    $wp_roles = new WP_Roles();
    $roles = $wp_roles->get_names();

    return $roles;
    }

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

The topic ‘User role selector’ is closed to new replies.