当前位置: 首页>>代码示例>>PHP>>正文


PHP cmb2_utils函数代码示例

本文整理汇总了PHP中cmb2_utils函数的典型用法代码示例。如果您正苦于以下问题:PHP cmb2_utils函数的具体用法?PHP cmb2_utils怎么用?PHP cmb2_utils使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cmb2_utils函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_image_id_from_url

 public function test_image_id_from_url()
 {
     global $wp_version;
     $_id_value = cmb2_utils()->image_id_from_url(esc_url_raw(get_permalink($this->attachment_id)));
     if ($wp_version > 3.9) {
         $this->assertEquals($_id_value, $this->attachment_id);
     } else {
         $this->assertGreaterThan(0, $this->attachment_id);
     }
 }
开发者ID:Groonya,项目名称:black-and-white-portfolio,代码行数:10,代码来源:test-cmb-utils.php

示例2: render

 public function render()
 {
     $field = $this->field;
     $meta_value = $field->escaped_value();
     $options = (array) $field->options();
     $img_size = $field->args('preview_size');
     $query_args = $field->args('query_args');
     $output = '';
     // if options array and 'url' => false, then hide the url field
     $input_type = array_key_exists('url', $options) && false === $options['url'] ? 'hidden' : 'text';
     $output .= parent::render(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) : '', 'js_dependencies' => 'media-editor'));
     $output .= sprintf('<input class="cmb2-upload-button button" type="button" value="%s" />', esc_attr($this->_text('add_upload_file_text', __('Add or Upload File', 'cmb2'))));
     $output .= $this->_desc(true);
     $cached_id = $this->_id();
     // Reset field args for attachment ID
     $args = array('id' => ($field->group ? $field->args('_id') : $cached_id) . '_id');
     // And get new field object
     // (Need to set it to the types field property)
     $this->types->field = $field = $field->get_field_clone($args);
     // Get ID value
     $_id_value = $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));
     }
     $output .= parent::render(array('type' => 'hidden', 'class' => 'cmb2-upload-file-id', 'value' => $_id_value, 'desc' => ''));
     $output .= '<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="" />';
             }
             $output .= $this->img_status_output(array('image' => $image, 'tag' => 'div', 'cached_id' => $cached_id));
         } else {
             $output .= $this->file_status_output(array('value' => $meta_value, 'tag' => 'div', 'cached_id' => $cached_id));
         }
     }
     $output .= '</div>';
     return $this->rendered($output);
 }
开发者ID:jrfnl,项目名称:CMB2,代码行数:43,代码来源:CMB2_Type_File.php

示例3: parse_picker_options

 /**
  * Parse the picker attributes.
  * @since  2.2.0
  * @param  string  $arg  'date' or 'time'
  * @param  array   $args Optional arguments to modify (else use $this->field->args['attributes'])
  * @return array         Array of field attributes
  */
 public function parse_picker_options($arg = 'date', $args = array())
 {
     $att = 'data-' . $arg . 'picker';
     $update = empty($args);
     $atts = array();
     $format = $this->field->args($arg . '_format');
     if ($js_format = cmb2_utils()->php_to_js_dateformat($format)) {
         if ($update) {
             $atts = $this->field->args('attributes');
         } else {
             $atts = isset($args['attributes']) ? $args['attributes'] : $atts;
         }
         // Don't override user-provided datepicker values
         $data = isset($atts[$att]) ? json_decode($atts[$att], true) : array();
         $data[$arg . 'Format'] = $js_format;
         $atts[$att] = function_exists('wp_json_encode') ? wp_json_encode($data) : json_encode($data);
     }
     if ($update) {
         $this->field->args['attributes'] = $atts;
     }
     return array_merge($args, $atts);
 }
开发者ID:jrfnl,项目名称:CMB2,代码行数:29,代码来源:CMB2_Type_Picker_Base.php

示例4: enqueue

 /**
  * Enqueue the CMB2 JS
  * @since  2.0.7
  */
 public static function enqueue()
 {
     // Filter required script dependencies
     $dependencies = apply_filters('cmb2_script_dependencies', self::$dependencies);
     // if colorpicker
     if (!is_admin() && isset($dependencies['wp-color-picker'])) {
         self::colorpicker_frontend();
     }
     // if file/file_list
     if (isset($dependencies['media-editor'])) {
         wp_enqueue_media();
     }
     // if timepicker
     if (isset($dependencies['jquery-ui-datetimepicker'])) {
         wp_register_script('jquery-ui-datetimepicker', cmb2_utils()->url('js/jquery-ui-timepicker-addon.min.js'), array('jquery-ui-slider'), CMB2_VERSION);
     }
     // Only use minified files if SCRIPT_DEBUG is off
     $debug = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG;
     $min = $debug ? '' : '.min';
     // Register cmb JS
     wp_enqueue_script(self::$handle, cmb2_utils()->url("js/cmb2{$min}.js"), $dependencies, CMB2_VERSION, true);
     self::localize($debug);
 }
开发者ID:emaxees,项目名称:elpandecadadia,代码行数:27,代码来源:CMB2_JS.php

示例5: field_timezone_offset

 /**
  * Offset a time value based on timezone
  * @since  1.0.0
  * @return string Offset time string
  */
 public function field_timezone_offset()
 {
     return cmb2_utils()->timezone_offset($this->field_timezone());
 }
开发者ID:gurustump,项目名称:cyclegarden,代码行数:9,代码来源:CMB2_Field.php

示例6: render

 public function render()
 {
     $this->field->args['default'] = $this->field->get_default() ? $this->field->get_default() : cmb2_utils()->timezone_string();
     $this->args = wp_parse_args($this->args, array('class' => 'cmb2_select cmb2-select-timezone', 'options' => wp_timezone_choice($this->field->escaped_value()), 'desc' => $this->_desc()));
     return parent::render();
 }
开发者ID:jrfnl,项目名称:CMB2,代码行数:6,代码来源:CMB2_Type_Select_Timezone.php

示例7: file

 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');
 }
开发者ID:somratexel,项目名称:somrat_dot_me,代码行数:42,代码来源:CMB2_Types.php

示例8: test_class_getters

 public function test_class_getters()
 {
     $this->assertInstanceOf('CMB2_Ajax', cmb2_ajax());
     $this->assertInstanceOf('CMB2_Utils', cmb2_utils());
     $this->assertInstanceOf('CMB2_Option', cmb2_options('test'));
 }
开发者ID:Makenrro,项目名称:repos,代码行数:6,代码来源:test-cmb-core.php

示例9: file

 public function file()
 {
     $meta_value = $this->field->escaped_value();
     $options = (array) $this->field->args('options');
     $img_size = $this->field->args('preview_size');
     // 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', 'size' => 45, 'desc' => '', 'data-previewsize' => is_array($img_size) ? '[' . implode(',', $img_size) . ']' : 350)), '<input class="cmb2-upload-button button" type="button" value="' . esc_attr($this->_text('add_upload_file_text', __('Add or Upload File', 'cmb2'))) . '" />', $this->_desc(true);
     $cached_id = $this->_id();
     // Reset field args for attachment ID
     $args = $this->field->args();
     $args['id'] = $args['_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)) {
             echo '<div class="img-status">';
             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="" />';
             }
             echo $image;
             echo '<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button" rel="', $cached_id, '">' . esc_html($this->_text('remove_image_text', __('Remove Image', 'cmb2'))) . '</a></p>';
             echo '</div>';
         } else {
             // $file_ext = $this->get_file_ext( $meta_value );
             $parts = explode('/', $meta_value);
             for ($i = 0; $i < count($parts); ++$i) {
                 $title = $parts[$i];
             }
             echo esc_html($this->_text('file_text', __('File:', 'cmb2'))), ' <strong>', $title, '</strong>&nbsp;&nbsp;&nbsp; (<a href="', $meta_value, '" target="_blank" rel="external">', esc_html($this->_text('file-download-text', __('Download', 'cmb2'))), '</a> / <a href="#" class="cmb2-remove-file-button" rel="', $cached_id, '">', esc_html($this->_text('remove_text', __('Remove', 'cmb2'))), '</a>)';
         }
     }
     echo '</div>';
 }
开发者ID:Brandonsmith23,项目名称:prodgyr,代码行数:45,代码来源:CMB2_Types.php

示例10: file_output

 protected function file_output($url_value, $id, CMB2_Type_File_Base $field_type)
 {
     // If there is no ID saved yet, try to get it from the url
     if ($url_value && !$id) {
         $id = cmb2_utils()->image_id_from_url(esc_url_raw($url_value));
     }
     if ($field_type->is_valid_img_ext($url_value)) {
         $img_size = $this->field->args('preview_size');
         if ($id) {
             $image = wp_get_attachment_image($id, $img_size, null, array('class' => 'cmb-image-display'));
         } else {
             $size = is_array($img_size) ? $img_size[0] : 200;
             $image = '<img class="cmb-image-display" style="max-width: ' . absint($size) . 'px; width: 100%; height: auto;" src="' . $url_value . '" alt="" />';
         }
         echo $image;
     } else {
         printf('<div class="file-status"><span>%1$s <strong><a href="%2$s">%3$s</a></strong></span></div>', esc_html($field_type->_text('file_text', __('File:', 'cmb2'))), $url_value, cmb2_utils()->get_file_name_from_path($url_value));
     }
 }
开发者ID:jrfnl,项目名称:CMB2,代码行数:19,代码来源:CMB2_Field_Display.php

示例11: _add_field_to_array

 /**
  * Add a field array to a fields array in desired position
  * @since 2.0.2
  * @param array   $field    Metabox field config array
  * @param array   &$fields  Array (passed by reference) to append the field (array) to
  * @param integer $position Optionally specify a position in the array to be inserted
  */
 protected function _add_field_to_array($field, &$fields, $position = 0)
 {
     if ($position) {
         cmb2_utils()->array_insert($fields, array($field['id'] => $field), $position);
     } else {
         $fields[$field['id']] = $field;
     }
 }
开发者ID:kps3,项目名称:wordpress-base,代码行数:15,代码来源:CMB2.php

示例12: file_status_output

 /**
  * file/file_list file wrap
  * @since  2.0.2
  * @param  array  $args Array of arguments for output
  * @return string       File wrap output
  */
 public function file_status_output($args)
 {
     return sprintf('<%1$s class="file-status"><span>%2$s <strong>%3$s</strong></span>&nbsp;&nbsp; (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>', $args['tag'], esc_html($this->_text('file_text', __('File:', 'cmb2'))), cmb2_utils()->get_file_name_from_path($args['value']), $args['value'], esc_html($this->_text('file_download_text', __('Download', 'cmb2'))), isset($args['cached_id']) ? ' rel="' . $args['cached_id'] . '"' : '', esc_html($this->_text('remove_text', __('Remove', 'cmb2'))), isset($args['id_input']) ? $args['id_input'] : '');
 }
开发者ID:jrfnl,项目名称:CMB2,代码行数:10,代码来源:CMB2_Type_File_Base.php

示例13: get_timestamp_from_value

 /**
  * Get timestamp from text date
  * @since  2.2.0
  * @param  string $value Date value
  * @return mixed         Unix timestamp representing the date.
  */
 public function get_timestamp_from_value($value)
 {
     return cmb2_utils()->get_timestamp_from_value($value, $this->args('date_format'));
 }
开发者ID:markbiek,项目名称:Silencio,代码行数:10,代码来源:CMB2_Field.php

示例14: get_terms

 /**
  * Wrapper for `get_terms` to account for changes in WP 4.6 where taxonomy is expected
  * as part of the arguments.
  * @since  2.2.2
  * @return mixed Array of terms on success
  */
 public function get_terms()
 {
     return cmb2_utils()->wp_at_least('4.5.0') ? get_terms(array('taxonomy' => $this->field->args('taxonomy'), 'hide_empty' => false)) : get_terms($this->field->args('taxonomy'), 'hide_empty=0');
 }
开发者ID:jrfnl,项目名称:CMB2,代码行数:10,代码来源:CMB2_Type_Taxonomy_Base.php

示例15: _save_file_id_value

 /**
  * Peforms saving of `file` attachement's ID
  * @since  1.1.0
  */
 public function _save_file_id_value($file_id_key)
 {
     $id_field = $this->_new_supporting_field($file_id_key);
     // Check standard data_to_save data
     $id_val = isset($this->field->data_to_save[$file_id_key]) ? $this->field->data_to_save[$file_id_key] : null;
     // If there is no ID saved yet, try to get it from the url
     if ($this->value && !$id_val) {
         $id_val = cmb2_utils()->image_id_from_url($this->value);
     }
     return $id_field->save_field($id_val);
 }
开发者ID:markbiek,项目名称:Silencio,代码行数:15,代码来源:CMB2_Sanitize.php


注:本文中的cmb2_utils函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。