Example #1
0
 /**
  * Handles outputting an 'input' element
  * @since  1.1.0
  * @param  array  $args Override arguments
  * @return string       Form input element
  */
 public function render($args = array())
 {
     $args = empty($args) ? $this->args : $args;
     $a = $this->parse_args($this->type, array('type' => 'text', 'class' => 'regular-text', 'name' => $this->_name(), 'id' => $this->_id(), 'value' => $this->field->escaped_value(), 'desc' => $this->_desc(true), 'js_dependencies' => array()), $args);
     if (!empty($a['js_dependencies'])) {
         CMB2_JS::add_dependencies($a['js_dependencies']);
     }
     return $this->rendered(sprintf('<input%s/>%s', $this->concat_attrs($a, array('desc', 'js_dependencies')), $a['desc']));
 }
Example #2
0
 public function file()
 {
     $meta_value = $this->field->escaped_value();
     $options = (array) $this->field->options();
     $img_size = $this->field->args('preview_size');
     $query_args = $this->field->args('query_args');
     // if options array and 'url' => false, then hide the url field
     $input_type = array_key_exists('url', $options) && false === $options['url'] ? 'hidden' : 'text';
     echo $this->input(array('type' => $input_type, 'class' => 'cmb2-upload-file regular-text', 'size' => 45, 'desc' => '', 'data-previewsize' => is_array($img_size) ? '[' . implode(',', $img_size) . ']' : 350, 'data-queryargs' => !empty($query_args) ? json_encode($query_args) : ''));
     printf('<input class="cmb2-upload-button button" type="button" value="%s" />', esc_attr($this->_text('add_upload_file_text', __('Add or Upload File', 'cmb2'))));
     $this->_desc(true, true);
     // If we're looking at a file in a group, we need to get the non-prefixed id
     $cached_id = $this->field->group ? $this->field->args('_id') : $this->_id();
     // Reset field args for attachment ID
     $args = $this->field->args();
     $args['id'] = $cached_id . '_id';
     unset($args['_id'], $args['_name']);
     // And get new field object
     $this->field = new CMB2_Field(array('field_args' => $args, 'group_field' => $this->field->group, 'object_type' => $this->field->object_type, 'object_id' => $this->field->object_id));
     // Get ID value
     $_id_value = $this->field->escaped_value('absint');
     // If there is no ID saved yet, try to get it from the url
     if ($meta_value && !$_id_value) {
         $_id_value = cmb2_utils()->image_id_from_url(esc_url_raw($meta_value));
     }
     echo $this->input(array('type' => 'hidden', 'class' => 'cmb2-upload-file-id', 'value' => $_id_value, 'desc' => '')), '<div id="', $this->_id('-status'), '" class="cmb2-media-status">';
     if (!empty($meta_value)) {
         if ($this->is_valid_img_ext($meta_value)) {
             if ($_id_value) {
                 $image = wp_get_attachment_image($_id_value, $img_size, null, array('class' => 'cmb-file-field-image'));
             } else {
                 $size = is_array($img_size) ? $img_size[0] : 350;
                 $image = '<img style="max-width: ' . absint($size) . 'px; width: 100%; height: auto;" src="' . $meta_value . '" alt="" />';
             }
             $this->img_status_output(array('image' => $image, 'tag' => 'div', 'cached_id' => $cached_id));
         } else {
             $this->file_status_output(array('value' => $meta_value, 'tag' => 'div', 'cached_id' => $cached_id));
         }
     }
     echo '</div>';
     CMB2_JS::add_dependencies('media-editor');
 }
        function cmb2_render_te_date_time_stamp_custom($field, $meta, $object_id, $object_type, $field_type_object)
        {
            // get date picker depencies
            CMB2_JS::add_dependencies(array('jquery-ui-core', 'jquery-ui-datepicker'));
            ?>
					<style>
						#ui-datepicker-div { z-index: 99999 !important; }
						#wpbody-content { overflow: hidden !important; }
						.cmb_id_announcement_image td .cmb_upload_button { height: 32px !important; }
					</style>
					<?php 
            if ($meta && isset($meta)) {
                echo '<input class="cmb2-text-small cmb2-datepicker" type="text" name="', $field->args['id'], '" id="', $field->args['id'], '" value="', '' !== $meta ? date('m/d/Y', $meta) : $field->args['default'], '" />';
                echo '<p class="cmb_metabox_description">' . $field->args['desc'] . '</p>';
            } else {
                echo '<input class="cmb2-text-small cmb2-datepicker" type="text" name="', $field->args['id'], '" id="', $field->args['id'], '" value="' . date('m/d/Y') . '" />';
                echo '<p class="cmb_metabox_description">' . $field->args['desc'] . '</p>';
            }
        }