CMB2 Documentation
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hooks
  • Download Docs
  • Github

Packages

  • CMB2
  • Demo
    • CMB2
  • None
  • Tests
    • CMB2

Classes

  • CMB2
  • CMB2_Ajax
  • CMB2_Base
  • CMB2_Bootstrap_2101
  • CMB2_Boxes
  • CMB2_Display_Checkbox
  • CMB2_Display_Colorpicker
  • CMB2_Display_File
  • CMB2_Display_File_List
  • CMB2_Display_Multicheck
  • CMB2_Display_oEmbed
  • CMB2_Display_Select
  • CMB2_Display_Taxonomy_Multicheck
  • CMB2_Display_Taxonomy_Radio
  • CMB2_Display_Text_Date
  • CMB2_Display_Text_Date_Timezone
  • CMB2_Display_Text_Money
  • CMB2_Display_Text_Time
  • CMB2_Display_Text_Url
  • CMB2_Display_Textarea
  • CMB2_Display_Textarea_Code
  • CMB2_Field
  • CMB2_Field_Display
  • CMB2_Hookup
  • CMB2_Hookup_Base
  • CMB2_Integration_Box
  • CMB2_JS
  • CMB2_Option
  • CMB2_Options
  • CMB2_Options_Hookup
  • CMB2_REST
  • CMB2_REST_Controller
  • CMB2_REST_Controller_Boxes
  • CMB2_REST_Controller_Fields
  • CMB2_Sanitize
  • CMB2_Show_Filters
  • CMB2_Type_Base
  • CMB2_Type_Checkbox
  • CMB2_Type_Colorpicker
  • CMB2_Type_Counter_Base
  • CMB2_Type_File
  • CMB2_Type_File_Base
  • CMB2_Type_File_List
  • CMB2_Type_Multi_Base
  • CMB2_Type_Multicheck
  • CMB2_Type_Oembed
  • CMB2_Type_Picker_Base
  • CMB2_Type_Radio
  • CMB2_Type_Select
  • CMB2_Type_Select_Timezone
  • CMB2_Type_Taxonomy_Base
  • CMB2_Type_Taxonomy_Multicheck
  • CMB2_Type_Taxonomy_Multicheck_Hierarchical
  • CMB2_Type_Taxonomy_Radio
  • CMB2_Type_Taxonomy_Radio_Hierarchical
  • CMB2_Type_Taxonomy_Select
  • CMB2_Type_Taxonomy_Select_Hierarchical
  • CMB2_Type_Text
  • CMB2_Type_Text_Date
  • CMB2_Type_Text_Datetime_Timestamp
  • CMB2_Type_Text_Datetime_Timestamp_Timezone
  • CMB2_Type_Text_Time
  • CMB2_Type_Textarea
  • CMB2_Type_Textarea_Code
  • CMB2_Type_Title
  • CMB2_Type_Wysiwyg
  • CMB2_Types
  • CMB2_Utils

Hooks

  • Hook Reference
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 
<?php
/**
 * CMB Multi base field type
 *
 * @since  2.2.2
 *
 * @category  WordPress_Plugin
 * @package   CMB2
 * @author    CMB2 team
 * @license   GPL-2.0+
 * @link      https://cmb2.io
 */
abstract class CMB2_Type_Multi_Base extends CMB2_Type_Base {

    /**
     * Generates html for an option element
     *
     * @since  1.1.0
     * @param  array $args Arguments array containing value, label, and checked boolean
     * @return string       Generated option element html
     */
    public function select_option( $args = array() ) {
        return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n";
    }

    /**
     * Generates html for list item with input
     *
     * @since  1.1.0
     * @param  array $args Override arguments
     * @param  int   $i    Iterator value
     * @return string       Gnerated list item html
     */
    public function list_input( $args = array(), $i = '' ) {
        $a = $this->parse_args( 'list_input', array(
            'type'  => 'radio',
            'class' => 'cmb2-option',
            'name'  => $this->_name(),
            'id'    => $this->_id( $i ),
            'value' => $this->field->escaped_value(),
            'label' => '',
        ), $args );

        return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] );
    }

    /**
     * Generates html for list item with checkbox input
     *
     * @since  1.1.0
     * @param  array $args Override arguments
     * @param  int   $i    Iterator value
     * @return string       Gnerated list item html
     */
    public function list_input_checkbox( $args, $i ) {
        $saved_value = $this->field->escaped_value();
        if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) {
            $args['checked'] = 'checked';
        }
        $args['type'] = 'checkbox';
        return $this->list_input( $args, $i );
    }

    /**
     * Generates html for concatenated items
     *
     * @since  1.1.0
     * @param  array $args Optional arguments
     * @return string        Concatenated html items
     */
    public function concat_items( $args = array() ) {
        $field = $this->field;

        $method = isset( $args['method'] ) ? $args['method'] : 'select_option';
        unset( $args['method'] );

        $value = null !== $field->escaped_value()
            ? $field->escaped_value()
            : $field->get_default();

        $value = CMB2_Utils::normalize_if_numeric( $value );

        $concatenated_items = '';
        $i = 1;

        $options = array();
        if ( $option_none = $field->args( 'show_option_none' ) ) {
            $options[''] = $option_none;
        }
        $options = $options + (array) $field->options();
        foreach ( $options as $opt_value => $opt_label ) {

            // Clone args & modify for just this item
            $a = $args;

            $a['value'] = $opt_value;
            $a['label'] = $opt_label;

            // Check if this option is the value of the input
            if ( $value === CMB2_Utils::normalize_if_numeric( $opt_value ) ) {
                $a['checked'] = 'checked';
            }

            $concatenated_items .= $this->$method( $a, $i++ );
        }

        return $concatenated_items;
    }

}
CMB2 Documentation API documentation generated by ApiGen