定制 webdevstudios/cmb2-user-select 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webdevstudios/cmb2-user-select

Composer 安装命令:

composer require webdevstudios/cmb2-user-select

包简介

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

README 文档

README

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

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:

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

This will be serialised if saved directly into the database.

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

/**
 * 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',
) );

统计信息

  • 总下载量: 1.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 26
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2016-02-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固