2017 © Pedro Peláez
 

wordpress-plugin cmb2-user-select

Special CMB2 Field that allows users to define an autocomplete text field for users

image

webdevstudios/cmb2-user-select

Special CMB2 Field that allows users to define an autocomplete text field for users

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users, (*1)

Example

$cmb2->add_field( array(
    'name'  => 'Author',,
    'id'    => 'author',
    'desc'  => 'Type the name of the author and select from the options',
    'type'  => 'user_select_text'
    'options' => array(
        'user_roles' => array( 'role1', 'role2' ), // Specify which roles to query for.
    ),
) );

The value returned is an array with the users id and name, eg:, (*2)

array(
    'id'   => 1
    'name' => 'Joe Blogs'
)

This will be serialised if saved directly into the database., (*3)

If you wish to store the users ID only, you can use escape_cb and sanitization_cb to transform the data., (*4)

/**
 * Takes the id from the database and returns an array for user_select_text
 * @param int $value
 * @return array('name' => string, 'id' => int)
 */
function id_to_user_select_text($value) {
    $user = get_user_by('id', (int)$value);
    return array(
        'name' => $user->display_name,
        'id'   => $user->ID,
    );
}

/**
 * Takes the array from user_select_text and returns the id for the database
 * @param array('name' => string, 'id' => int) $value
 * @return int
 */
function user_select_text_to_id($value) {
    return $value['id'];
}

$cmb2->add_field( array(
    // ...snip...
    'escape_cb'       => 'user_select_text_to_id',
    'sanitization_cb' => 'id_to_user_select_text',
) );

The Versions

07/06 2017

dev-master

9999999-dev https://github.com/WebDevStudios/CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

wordpress meta cmb2

07/06 2017

v0.2.3

0.2.3.0 https://github.com/WebDevStudios/CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

wordpress meta cmb2

03/10 2016

v0.2.2

0.2.2.0 https://github.com/WebDevStudios/CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

wordpress meta cmb2

28/03 2016

v0.2.1

0.2.1.0 https://github.com/WebDevStudios/CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

wordpress meta cmb2

21/03 2016

v0.2.0

0.2.0.0 https://github.com/WebDevStudios/CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

wordpress meta cmb2

28/02 2016

v0.1.0

0.1.0.0 https://github.com/WebDevStudios/CMB2-User-Select

Special CMB2 Field that allows users to define an autocomplete text field for users

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

wordpress meta cmb2