{"id":19238029,"url":"https://github.com/cmb2/cmb2-user-select","last_synced_at":"2025-04-21T06:31:40.726Z","repository":{"id":62547589,"uuid":"46070447","full_name":"CMB2/CMB2-User-Select","owner":"CMB2","description":"Select a user to associate with your object","archived":false,"fork":false,"pushed_at":"2019-01-30T15:57:25.000Z","size":12,"stargazers_count":21,"open_issues_count":2,"forks_count":10,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-12T23:26:48.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CMB2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-12T17:56:56.000Z","updated_at":"2023-10-01T00:50:44.000Z","dependencies_parsed_at":"2022-11-02T22:16:12.400Z","dependency_job_id":null,"html_url":"https://github.com/CMB2/CMB2-User-Select","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMB2%2FCMB2-User-Select","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMB2%2FCMB2-User-Select/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMB2%2FCMB2-User-Select/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMB2%2FCMB2-User-Select/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CMB2","download_url":"https://codeload.github.com/CMB2/CMB2-User-Select/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250008206,"owners_count":21359948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T16:29:05.636Z","updated_at":"2025-04-21T06:31:40.707Z","avatar_url":"https://github.com/CMB2.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CMB2-User-Select\n\nSpecial CMB2 Field that allows users to define an autocomplete text field for users\n\n### Example\n```php\n$cmb2-\u003eadd_field( array(\n\t'name'  =\u003e 'Author',,\n\t'id'    =\u003e 'author',\n\t'desc'  =\u003e 'Type the name of the author and select from the options',\n\t'type'  =\u003e 'user_select_text'\n\t'options' =\u003e array(\n\t\t'user_roles' =\u003e array( 'role1', 'role2' ), // Specify which roles to query for.\n\t),\n) );\n```\n\nThe value returned is an array with the users `id` and `name`, eg:\n\n```php\narray(\n\t'id'   =\u003e 1\n\t'name' =\u003e 'Joe Blogs'\n)\n```\n\nThis will be serialised if saved directly into the database.\n\nIf you wish to store the users ID only, you can use `escape_cb` and `sanitization_cb` to transform\nthe data.\n\n```php\n/**\n * Takes the id from the database and returns an array for user_select_text\n * @param int $value\n * @return array('name' =\u003e string, 'id' =\u003e int)\n */\nfunction id_to_user_select_text($value) {\n\t$user = get_user_by('id', (int)$value);\n\treturn array(\n\t\t'name' =\u003e $user-\u003edisplay_name,\n\t\t'id'   =\u003e $user-\u003eID,\n\t);\n}\n\n/**\n * Takes the array from user_select_text and returns the id for the database\n * @param array('name' =\u003e string, 'id' =\u003e int) $value\n * @return int\n */\nfunction user_select_text_to_id($value) {\n\treturn $value['id'];\n}\n\n$cmb2-\u003eadd_field( array(\n\t// ...snip...\n\t'escape_cb'       =\u003e 'user_select_text_to_id',\n\t'sanitization_cb' =\u003e 'id_to_user_select_text',\n) );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmb2%2Fcmb2-user-select","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmb2%2Fcmb2-user-select","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmb2%2Fcmb2-user-select/lists"}