本文整理汇总了PHP中RWMB_Select_Field类的典型用法代码示例。如果您正苦于以下问题:PHP RWMB_Select_Field类的具体用法?PHP RWMB_Select_Field怎么用?PHP RWMB_Select_Field使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RWMB_Select_Field类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: normalize_field
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field($field)
{
$field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
/**
* Set default placeholder
* - If multiple post types: show 'Select a post'
* - If single post type: show 'Select a %post_type_name%'
*/
if (empty($field['placeholder'])) {
$label = __('Select a post', 'meta-box');
if (is_string($field['post_type']) && post_type_exists($field['post_type'])) {
$post_type_object = get_post_type_object($field['post_type']);
$label = sprintf(__('Select a %s', 'meta-box'), $post_type_object->labels->singular_name);
}
$field['placeholder'] = $label;
}
if ($field['parent']) {
$field['multiple'] = false;
$field['field_name'] = 'parent_id';
}
$field['query_args'] = wp_parse_args($field['query_args'], array('post_type' => $field['post_type'], 'post_status' => 'publish', 'posts_per_page' => -1));
switch ($field['field_type']) {
case 'select':
return RWMB_Select_Field::normalize_field($field);
break;
case 'select_advanced':
default:
return RWMB_Select_Advanced_Field::normalize_field($field);
}
}
示例2: admin_enqueue_scripts
/**
* Enqueue scripts and styles
*/
public static function admin_enqueue_scripts()
{
RWMB_Input_List_Field::admin_enqueue_scripts();
RWMB_Select_Field::admin_enqueue_scripts();
RWMB_Select_Tree_Field::admin_enqueue_scripts();
RWMB_Select_Advanced_Field::admin_enqueue_scripts();
}
示例3: normalize_field
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field($field)
{
$field = wp_parse_args($field, array('field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
$field['std'] = empty($field['std']) ? __('Select an user', 'meta-box') : $field['std'];
$field['query_args'] = wp_parse_args($field['query_args'], array('orderby' => 'display_name', 'order' => 'asc', 'role' => '', 'fields' => 'all'));
switch ($field['field_type']) {
case 'select':
return RWMB_Select_Field::normalize_field($field);
break;
case 'select_advanced':
default:
return RWMB_Select_Advanced_Field::normalize_field($field);
}
}
示例4: walk_select_tree
/**
* Walker for displaying select in tree format
*
* @param $meta
* @param $field
* @param $elements
* @param int $parent
* @param bool $active
*
* @return string
*/
static function walk_select_tree($meta, $field, $elements, $parent = 0, $active = false)
{
if (!isset($elements[$parent])) {
return;
}
$terms = $elements[$parent];
$field['options'] = self::get_options($terms);
$classes = array('rw-taxonomy-tree');
$classes[] = $active ? 'active' : 'disabled';
$classes[] = "rwmb-taxonomy-{$parent}";
$html = '<div class="' . implode(' ', $classes) . '">';
$html .= RWMB_Select_Field::html($meta, $field);
foreach ($terms as $term) {
$html .= self::walk_select_tree($meta, $field, $elements, $term->term_id, $active && in_array($term->term_id, $meta));
}
$html .= '</div>';
return $html;
}
示例5: save
/**
* Save meta value
* If field is cloneable, value is saved as a single entry in DB
* Otherwise value is saved as multiple entries (for backward compatibility)
*
* TODO: A good way to ALWAYS save values in single entry in DB, while maintaining backward compatibility
*
* @param $new
* @param $old
* @param $post_id
* @param $field
*/
static function save($new, $old, $post_id, $field)
{
return RWMB_Select_Field::save($new, $old, $post_id, $field);
}
示例6: admin_enqueue_scripts
/**
* Enqueue scripts and styles
*
* @return void
*/
static function admin_enqueue_scripts()
{
wp_enqueue_style('rwmb-object-choice', RWMB_CSS_URL . 'object-choice.css', array(), RWMB_VER);
wp_enqueue_script('rwmb-object-choice', RWMB_JS_URL . 'object-choice.js', array(), RWMB_VER, true);
RWMB_Select_Field::admin_enqueue_scripts();
RWMB_Select_Advanced_Field::admin_enqueue_scripts();
}
示例7: the_value
/**
* Output the field value
* Display unordered list of option labels, not option values
*
* @param array $field Field parameters
* @param array $args Additional arguments. Not used for these fields.
* @param int|null $post_id Post ID. null for current post. Optional.
*
* @return string Link(s) to post
*/
static function the_value($field, $args = array(), $post_id = null)
{
return RWMB_Select_Field::the_value($field, $args, $post_id);
}
示例8: walk_select_tree
/**
* Walker for displaying select in treeformat
*
* @param $meta
* @param $field
* @param $elements
* @param int $parent
* @param string $parent_slug
* @param bool $active
*
* @return string
*/
static function walk_select_tree($meta, $field, $elements, $parent = 0, $parent_slug = '', $active = false)
{
if (!isset($elements[$parent])) {
return;
}
$terms = $elements[$parent];
$field['options'] = self::get_options($terms);
$hidden = $active ? 'active' : 'disabled';
$disabled = disabled($active, false, false);
$id = empty($parent_slug) ? '' : " id='rwmb-taxonomy-{$parent_slug}'";
$html = "<div{$id} class='rw-taxonomy-tree {$hidden}'>";
$html .= RWMB_Select_Field::html($html, $meta, $field);
foreach ($terms as $term) {
$html .= self::walk_select_tree($meta, $field, $elements, $term->term_id, $term->slug, in_array($term->slug, $meta) && $active) . '</li>';
}
$html .= '</div>';
return $html;
}
示例9: html
/**
* Get field HTML
*
* @param mixed $meta
* @param array $field
*
* @return string
*/
static function html($meta, $field)
{
$field['options'] = self::get_options($field);
return RWMB_Select_Field::html($meta, $field);
}
示例10: array
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field($field)
{
$field = parent::normalize_field($field);
$field = wp_parse_args($field, array('js_options' => array()));
$field['js_options'] = wp_parse_args($field['js_options'], array('allowClear' => true, 'width' => 'resolve', 'placeholder' => $field['placeholder']));
return $field;
}
示例11: get_attributes
/**
* Get the attributes for a field
*
* @param array $field
* @param mixed $value
*
* @return array
*/
public static function get_attributes($field, $value = null)
{
$attributes = parent::get_attributes($field, $value);
$attributes['multiple'] = false;
$attributes['id'] = false;
return $attributes;
}
示例12: array
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field($field)
{
$field = parent::normalize_field($field);
$field = wp_parse_args($field, array('js_options' => array()));
$field['js_options'] = wp_parse_args($field['js_options'], array('allowClear' => true, 'width' => 'resolve', 'placeholder' => empty($field['std']) ? __('Select a value', 'rwmb') : $field['std']));
$field['std'] = '';
return $field;
}
示例13: array
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field($field)
{
$field = wp_parse_args($field, array('js_options' => array()));
$field['js_options'] = wp_parse_args($field['js_options'], array('allowClear' => true, 'width' => 'resolve', 'placeholder' => __('Select a value', 'rwmb')));
$field['default'] = isset($field['default']) ? $field['default'] : $field['js_options']['placeholder'];
$field = parent::normalize_field($field);
return $field;
}
示例14: array
/**
* Get the attributes for a field
*
* @param array $field
* @param mixed value
*
* @return array
*/
static function get_attributes($field, $value = null)
{
$attributes = parent::get_attributes($field, $value);
$attributes = wp_parse_args($attributes, array('data-options' => wp_json_encode($field['js_options'])));
return $attributes;
}