Esempio n. 1
0
 /**
  * Render the field and setup the field for the JS autocomplete.
  * @since  0.1.0
  */
 public function render_term_select_field($field, $escaped_value, $object_id, $object_type, $field_type)
 {
     $taxonomy = $field->args('taxonomy');
     if (!$taxonomy) {
         wp_die('no taxonomy specified for the `term_select` field!');
     }
     $value = wp_parse_args($escaped_value, array('taxonomy' => $taxonomy, 'name' => '', 'id' => ''));
     echo $field_type->input(array('id' => $field_type->_id('_name'), 'name' => $field_type->_name('[name]'), 'value' => $value['name'], 'autocomplete' => 'off'));
     // Reset field type as we don't want our hidden inputs inheriting the field settings.
     $field->args['attributes'] = array();
     $field_type = new CMB2_Types($field);
     echo $field_type->input(array('id' => $field_type->_id('_id'), 'name' => $field_type->_name('[id]'), 'value' => $value['id'], 'type' => 'hidden', 'desc' => '', 'class' => false));
     echo $field_type->input(array('id' => $field_type->_id('_taxonomy'), 'name' => $field_type->_name('[taxonomy]'), 'value' => $value['taxonomy'], 'type' => 'hidden', 'desc' => '', 'class' => false));
     self::$script_data[] = array('id' => $field->args('id'), 'taxonomy' => $taxonomy);
     if (!self::$script_added) {
         wp_enqueue_script('jquery-ui-autocomplete');
         add_action(is_admin() ? 'admin_footer' : 'wp_footer', array(__CLASS__, 'footer_js'));
         self::$script_added = true;
     }
 }
Esempio n. 2
0
 /**
  * Default field render callback
  * @since 2.1.1
  */
 public function render_field_callback()
 {
     // If field is requesting to not be shown on the front-end
     if (!is_admin() && !$this->args('on_front')) {
         return;
     }
     // If field is requesting to be conditionally shown
     if (!$this->should_show()) {
         return;
     }
     $this->peform_param_callback('before_row');
     printf("<div class=\"cmb-row %s\">\n", $this->row_classes());
     if (!$this->args('show_names')) {
         echo "\n\t<div class=\"cmb-td\">\n";
         $this->peform_param_callback('label_cb');
     } else {
         if ($this->get_param_callback_result('label_cb', false)) {
             echo '<div class="cmb-th">', $this->peform_param_callback('label_cb'), '</div>';
         }
         echo "\n\t<div class=\"cmb-td\">\n";
     }
     $this->peform_param_callback('before');
     $field_type = new CMB2_Types($this);
     $field_type->render();
     $this->peform_param_callback('after');
     echo "\n\t</div>\n</div>";
     $this->peform_param_callback('after_row');
     // For chaining
     return $this;
 }
Esempio n. 3
0
 /**
  * Render a field row
  * @since 1.0.0
  */
 public function render_field()
 {
     // If field is requesting to not be shown on the front-end
     if (!is_admin() && !$this->args('on_front')) {
         return;
     }
     // If field is requesting to be conditionally shown
     if (is_callable($this->args('show_on_cb')) && !call_user_func($this->args('show_on_cb'), $this)) {
         return;
     }
     $classes = 'cmb-type-' . sanitize_html_class($this->type());
     $classes .= ' cmb2_id_' . sanitize_html_class($this->id());
     $classes .= $this->args('repeatable') ? ' cmb-repeat' : '';
     $classes .= $this->group ? ' cmb-repeat-group-field' : '';
     // 'inline' flag, or _inline in the field type, set to true
     $classes .= $this->args('inline') ? ' cmb-inline' : '';
     printf("<li class=\"cmb-row %s\">\n", $classes);
     if ('title' == $this->type() || !$this->args('show_names')) {
         echo "\t<div class=\"cmb-td\">\n";
         if (!$this->args('show_names')) {
             $style = 'title' == $this->type() ? ' style="display:none;"' : '';
             printf("\n<label%s for=\"%s\">%s</label>\n", $style, $this->id(), $this->args('name'));
         }
     } else {
         printf('<div class="cmb-th"><label for="%1$s">%2$s</label></div>', $this->id(), $this->args('name'));
         echo "\n\t<div class=\"cmb-td\">\n";
     }
     echo $this->args('before');
     $this_type = new CMB2_Types($this);
     $this_type->render();
     echo $this->args('after');
     echo "\n\t</div>\n</li>";
 }
Esempio n. 4
0
 /**
  * Render a field row
  * @since 1.0.0
  */
 public function render_field()
 {
     // If field is requesting to not be shown on the front-end
     if (!is_admin() && !$this->args('on_front')) {
         return;
     }
     // If field is requesting to be conditionally shown
     if (is_callable($this->args('show_on_cb')) && !call_user_func($this->args('show_on_cb'), $this)) {
         return;
     }
     $this->peform_param_callback('before_row');
     printf("<div class=\"cmb-row %s\">\n", $this->row_classes());
     if ('title' == $this->type() || !$this->args('show_names')) {
         echo "\t<div class=\"cmb-td\">\n";
         if (!$this->args('show_names')) {
             $style = 'title' == $this->type() ? '' : ' style="display:none;"';
             printf("\n<label%s for=\"%s\">%s</label>\n", $style, $this->id(), $this->args('name'));
         }
     } else {
         if ($this->args('name')) {
             printf('<div class="cmb-th"><label for="%1$s">%2$s</label></div>', $this->id(), $this->args('name'));
         }
         echo "\n\t<div class=\"cmb-td\">\n";
     }
     $this->peform_param_callback('before');
     $this_type = new CMB2_Types($this);
     $this_type->render();
     $this->peform_param_callback('after');
     echo "\n\t</div>\n</div>";
     $this->peform_param_callback('after_row');
 }
 public function render_status_select($field, $escaped_value = '', $object_id = '', $object_type = '')
 {
     // Get CMB2 types object for extending.
     $CMB2_Types = new CMB2_Types($field);
     // Output base dropdown.
     echo $CMB2_Types->select();
     // Output color code.
     printf('<span class="mkp-status-indicator %s"></span>', $escaped_value);
 }