• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP cmb_Meta_Box类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: intercept_post_id

 /**
  * Get data before saving to CMB.
  */
 public function intercept_post_id()
 {
     // Check for $_POST data
     if (empty($_POST)) {
         return false;
     }
     // Check nonce
     if (!(isset($_POST['submit-cmb'], $_POST['wp_meta_box_nonce']) && wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce()))) {
         return;
     }
     // Setup and sanitize data
     if (isset($_POST[$this->prefix . 'place_name'])) {
         $this->new_submission = wp_insert_post(array('post_title' => sanitize_text_field($_POST[$this->prefix . 'place_name']), 'post_author' => get_current_user_id(), 'post_status' => 'draft', 'post_type' => 'accommodations', 'post_content' => wp_kses($_POST[$this->prefix . 'place_notes'], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span>')), true);
         // If no errors, save the data into a new post draft
         if (!is_wp_error($this->new_submission)) {
             $address = sanitize_text_field($_POST['address']);
             $lat = sanitize_text_field($_POST['lat']);
             $lng = sanitize_text_field($_POST['lng']);
             $formatted_address = sanitize_text_field($_POST['formatted_address']);
             // Update the meta field in the database.
             update_post_meta($this->new_submission, 'address', $address);
             update_post_meta($this->new_submission, 'lat', $lat);
             update_post_meta($this->new_submission, 'lng', $lng);
             update_post_meta($this->new_submission, 'formatted_address', $formatted_address);
             update_post_meta($this->new_submission, 'place_image_id', $_POST['place_image_id']);
             //update post parent in place_image_id
             $image = array('ID' => get_post_meta($this->new_submission, 'place_image_id', 1), 'post_parent' => $this->new_submission);
             wp_update_post($image);
             set_post_thumbnail($this->new_submission, get_post_meta($this->new_submission, 'place_image_id', 1));
             return $this->new_submission;
         }
     }
     return false;
 }
开发者ID:bulini,项目名称:booking-wp,代码行数:37,代码来源:accommodation.php


示例2: do_save

 /**
  * Handles saving of the $_POST data
  * @since  0.1.3
  * @param  int $term_id Term's ID
  */
 public function do_save($term_id)
 {
     if (!class_exists('cmb_Meta_Box')) {
         return;
     }
     if (!isset($_POST['term_opt_name'], $_POST['wp_meta_box_nonce'], $_POST['action']) || !wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce())) {
         return;
     }
     $this->do_override_filters($term_id);
     // Save the metabox if it's been submitted
     cmb_save_metabox_fields($this->fields(), $this->id());
 }
开发者ID:ryscript,项目名称:Scinttek-Decade-Project,代码行数:17,代码来源:Taxonomy_MetaData_CMB.php


示例3: check_page_template

 /**
  * Add metaboxes for an specific Page Template
  * @since  1.0.0
  * @param  bool  $display  To display or not
  * @param  array $meta_box Metabox config array
  * @return bool            Whether to display this metabox on the current page.
  */
 public static function check_page_template($display, $meta_box)
 {
     if (!isset($meta_box['show_on']['key']) || 'page-template' !== $meta_box['show_on']['key']) {
         return $display;
     }
     $object_id = cmb_Meta_Box::get_object_id();
     if (!$object_id || cmb_Meta_Box::get_object_type() !== 'post') {
         return false;
     }
     // Get current template
     $current_template = get_post_meta($object_id, '_wp_page_template', true);
     // See if there's a match
     if ($current_template && in_array($current_template, (array) $meta_box['show_on']['value'])) {
         return true;
     }
     return false;
 }
开发者ID:Inteleck,项目名称:hwc,代码行数:24,代码来源:cmb_Meta_Box_Show_Filters.php


示例4: hijack_oembed_cache_set

 /**
  * Hijacks saving of cached oEmbed.
  * Saves cached data to relevant object metadata (vs postmeta)
  *
  * @since  0.9.5
  * @param  boolean $check Whether to continue setting postmeta
  * @param  int $object_id Object ID to get postmeta from
  * @param  string $meta_key Postmeta's key
  * @param  mixed $meta_value Value of the postmeta to be saved
  * @return boolean             Whether to continue setting
  */
 public static function hijack_oembed_cache_set($check, $object_id, $meta_key, $meta_value)
 {
     if (!self::$hijack || self::$object_id != $object_id && 1987645321 !== $object_id) {
         return $check;
     }
     // Cache the result to our metadata
     if ('options-page' === self::$object_type) {
         // Set the option
         cmb_Meta_Box::update_option(self::$object_id, self::$embed_args['cache_key'], $meta_value, array('type' => 'oembed'));
         // Save the option
         cmb_Meta_Box::save_option(self::$object_id);
     } else {
         update_metadata(self::$object_type, self::$object_id, $meta_key, $meta_value);
     }
     // Anything other than `null` to cancel saving to postmeta
     return true;
 }
开发者ID:Telemedellin,项目名称:feriadelasfloresmedellin,代码行数:28,代码来源:cmb_Meta_Box_ajax.php


示例5: intercept_post_id

 /**
  * Get data before saving to CMB.
  */
 public function intercept_post_id()
 {
     // Check for $_POST data
     if (empty($_POST)) {
         return false;
     }
     // Check nonce
     if (!(isset($_POST['submit-cmb'], $_POST['wp_meta_box_nonce']) && wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce()))) {
         return;
     }
     // Setup and sanitize data
     if (isset($_POST[$this->prefix . 'memorial_first_name'])) {
         add_filter('user_has_cap', array($this, 'grant_publish_caps'), 0, 3);
         $this->new_submission = wp_insert_post(array('post_title' => sanitize_text_field($_POST[$this->prefix . 'memorial_first_name'] . ' ' . $_POST[$this->prefix . 'memorial_last_name']), 'post_author' => get_current_user_id(), 'post_status' => 'draft', 'post_type' => 'memorials', 'post_content_filtered' => wp_kses($_POST[$this->prefix . 'memorial_story'], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span>')), true);
         // If no errors, save the data into a new post draft
         if (!is_wp_error($this->new_submission)) {
             return $this->new_submission;
         }
     }
     return false;
 }
开发者ID:devd123,项目名称:wpaam,代码行数:24,代码来源:custom-post.php


示例6: file

 public function file()
 {
     $meta_value = $this->field->escaped_value();
     $allow = $this->field->args('allow');
     $input_type = 'url' == $allow || is_array($allow) && in_array('url', $allow) ? 'text' : 'hidden';
     echo $this->input(array('type' => $input_type, 'class' => 'cmb_upload_file', 'size' => 45, 'desc' => '')), '<input class="cmb_upload_button button" type="button" value="' . __('Add or Upload File', 'cmb') . '" />', $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 cmb_Meta_Box_field($args, $this->field->group);
     // 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 = cmb_Meta_Box::image_id_from_url(esc_url_raw($meta_value));
     }
     echo $this->input(array('type' => 'hidden', 'class' => 'cmb_upload_file_id', 'value' => $_id_value, 'desc' => '')), '<div id="', $this->_id('_status'), '" class="cmb_media_status">';
     if (!empty($meta_value)) {
         if ($this->is_valid_img_ext($meta_value)) {
             echo '<div class="img_status">';
             echo '<img style="max-width: 350px; width: 100%; height: auto;" src="', $meta_value, '" alt="" />';
             echo '<p class="cmb_remove_wrapper"><a href="#" class="cmb_remove_file_button" rel="', $cached_id, '">' . __('Remove Image', 'cmb') . '</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 __('File:', 'cmb'), ' <strong>', $title, '</strong>&nbsp;&nbsp;&nbsp; (<a href="', $meta_value, '" target="_blank" rel="external">' . __('Download', 'cmb') . '</a> / <a href="#" class="cmb_remove_file_button" rel="', $cached_id, '">' . __('Remove', 'cmb') . '</a>)';
         }
     }
     echo '</div>';
 }
开发者ID:de190909,项目名称:WPTest,代码行数:37,代码来源:cmb_Meta_Box_types.php


示例7: 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 cmb_Meta_Box::timezone_offset($this->field_timezone());
 }
开发者ID:Nirajjcu,项目名称:minime3d,代码行数:9,代码来源:cmb_Meta_Box_field.php


示例8: file

 public static function file($field, $meta, $object_id, $object_type)
 {
     $input_type_url = 'hidden';
     if ('url' == $field['allow'] || is_array($field['allow']) && in_array('url', $field['allow'])) {
         $input_type_url = 'text';
     }
     echo '<input class="cmb_upload_file" type="' . $input_type_url . '" size="45" id="', $field['id'], '" name="', $field['id'], '" value="', $meta, '" />';
     echo '<input class="cmb_upload_button button" type="button" value="' . __('Add or Upload File', 'cmb') . '" />';
     $_id_name = $field['id'] . '_id';
     $_id_meta = get_metadata($object_type, $object_id, $_id_name, !isset($field['multiple']) || !$field['multiple']);
     // If there is no ID saved yet, try to get it from the url
     if ($meta && !$_id_meta) {
         $_id_meta = cmb_Meta_Box::image_id_from_url(esc_url_raw($meta));
     }
     echo '<input class="cmb_upload_file_id" type="hidden" id="', $_id_name, '" name="', $_id_name, '" value="', $_id_meta, '" />', self::desc($field['desc'], true), '<div id="', $field['id'], '_status" class="cmb_media_status">';
     if (!empty($meta)) {
         if (self::is_valid_img_ext($meta)) {
             echo '<div class="img_status">';
             echo '<img style="max-width: 350px; width: 100%; height: auto;" src="', $meta, '" alt="" />';
             echo '<p><a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">' . __('Remove Image', 'cmb') . '</a></p>';
             echo '</div>';
         } else {
             // $file_ext = self::get_file_ext( $meta );
             $parts = explode('/', $meta);
             for ($i = 0; $i < count($parts); ++$i) {
                 $title = $parts[$i];
             }
             echo __('File:', 'cmb'), ' <strong>', $title, '</strong>&nbsp;&nbsp;&nbsp; (<a href="', $meta, '" target="_blank" rel="external">' . __('Download', 'cmb') . '</a> / <a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">' . __('Remove', 'cmb') . '</a>)';
         }
     }
     echo '</div>';
 }
开发者ID:PlanoBWeb,项目名称:BDA,代码行数:32,代码来源:cmb_Meta_Box_types.php


示例9: oembed_cache_set

 /**
  * Saves the cached oEmbed value to relevant object metadata (vs postmeta)
  *
  * @since  1.3.0
  * @param  string  $meta_key   Postmeta's key
  * @param  mixed   $meta_value Value of the postmeta to be saved
  */
 public static function oembed_cache_set($meta_key, $meta_value)
 {
     // Cache the result to our metadata
     if ('options-page' === self::$object_type) {
         // Set the option
         cmb_Meta_Box::update_option(self::$object_id, self::$embed_args['cache_key'], $meta_value, array('type' => 'oembed'));
         // Save the option
         cmb_Meta_Box::save_option(self::$object_id);
     } else {
         update_metadata(self::$object_type, self::$object_id, $meta_key, $meta_value);
     }
 }
开发者ID:ryansm,项目名称:saud,代码行数:19,代码来源:cmb_Meta_Box_ajax.php


示例10: _save_file_id

 /**
  * Peforms saving of `file` attachement's ID
  * @since  1.1.0
  * @param  string $value File url
  */
 public function _save_file_id($value)
 {
     $group = $this->field->group;
     $args = $this->field->args();
     $args['id'] = $args['_id'] . '_id';
     unset($args['_id'], $args['_name']);
     // And get new field object
     $field = new cmb_Meta_Box_field($args, $group);
     $id_key = $field->_id();
     $id_val_old = $field->escaped_value('absint');
     if ($group) {
         // Check group $_POST data
         $i = $group->index;
         $base_id = $group->_id();
         $id_val = isset($_POST[$base_id][$i][$id_key]) ? absint($_POST[$base_id][$i][$id_key]) : 0;
     } else {
         // Check standard $_POST data
         $id_val = isset($_POST[$field->id()]) ? $_POST[$field->id()] : null;
     }
     // If there is no ID saved yet, try to get it from the url
     if ($value && !$id_val) {
         $id_val = cmb_Meta_Box::image_id_from_url($value);
     }
     if ($group) {
         return array('attach_id' => $id_val, 'field_id' => $id_key);
     }
     if ($id_val && $id_val != $id_val_old) {
         return $field->update_data($id_val);
     } elseif (empty($id_val) && $id_val_old) {
         return $field->remove_data($old);
     }
 }
开发者ID:Kang8M,项目名称:gaonhat,代码行数:37,代码来源:cmb_Meta_Box_Sanitize.php


示例11: default_sanitization

 /**
  * Default fallback sanitization method. Applies filters.
  * @since  1.0.2
  * @param  mixed $meta_value Meta value
  * @param  array $field      Field config array
  */
 public static function default_sanitization($meta_value, $field)
 {
     $object_type = cmb_Meta_Box::get_object_type();
     $object_id = cmb_Meta_Box::get_object_id();
     // Allow field type validation via filter
     $updated = apply_filters('cmb_validate_' . $field['type'], null, $meta_value, $object_id, $field, $object_type);
     if (null != $updated) {
         return $updated;
     }
     // we'll fallback to 'sanitize_text_field', or 'wp_kses_post`
     switch ($field['type']) {
         case 'wysiwyg':
             // $cb = 'wp_kses';
             // break;
         // $cb = 'wp_kses';
         // break;
         case 'textarea_small':
             $cb = array('cmb_Meta_Box_Sanitize', 'textarea');
             break;
         default:
             $cb = 'sanitize_text_field';
             break;
     }
     // Handle repeatable fields array
     if (is_array($meta_value)) {
         foreach ($meta_value as $key => $value) {
             $meta_value[$key] = call_user_func($cb, $value);
         }
     } else {
         $meta_value = call_user_func($cb, $meta_value);
     }
     return $meta_value;
 }
开发者ID:aguerojahannes,项目名称:aguerojahannes.com,代码行数:39,代码来源:cmb_Meta_Box_Sanitize.php


示例12: save_fields

 /**
  * Loops through and saves field data
  * @since  1.0.0
  *
  * @param array $meta_box Metabox config array
  * @param  int $object_id Object ID
  * @param  string $object_type Type of object being saved. (e.g., post, user, or comment)
  */
 public static function save_fields($meta_box, $object_id, $object_type = '')
 {
     $meta_box = self::set_mb_defaults($meta_box);
     $meta_box['show_on'] = empty($meta_box['show_on']) ? array('key' => false, 'value' => false) : $meta_box['show_on'];
     self::set_object_id($object_id);
     // Set/get type
     $object_type = self::set_object_type($object_type ? $object_type : self::set_mb_type($meta_box));
     if (!apply_filters('cmb_show_on', true, $meta_box)) {
         return;
     }
     // save field ids of those that are updated
     self::$updated = array();
     foreach ($meta_box['fields'] as $field_args) {
         if ('group' == $field_args['type']) {
             self::save_group($field_args);
         } else {
             // Save default fields
             $field = new cmb_Meta_Box_field($field_args);
             self::save_field(self::sanitize_field($field), $field);
         }
     }
     // If options page, save the updated options
     if ($object_type == 'options-page') {
         self::save_option($object_id);
     }
     do_action("cmb_save_{$object_type}_fields", $object_id, $meta_box['id'], self::$updated, $meta_box);
 }
开发者ID:eugene-gromky-co,项目名称:mindfulnesssummit,代码行数:35,代码来源:init.php


示例13: __call

 /**
  * Default fallback if field's 'sanitization_cb' is NOT defined, or field type does not have a corresponding validation method
  * @since  1.0.0
  * @param  string $name      Non-existent method name
  * @param  array  $arguments All arguments passed to the method
  */
 public function __call($name, $arguments)
 {
     list($meta_value, $field) = $arguments;
     // Handle repeatable fields array
     if (is_array($meta_value)) {
         foreach ($meta_value as $key => $value) {
             // Allow field type validation via filter
             $updated = apply_filters('cmb_validate_' . $field['type'], $value, cmb_Meta_Box::get_object_id(), $field, cmb_Meta_Box::get_object_type());
             if ($updated === $value) {
                 // If nothing changed, we'll fallback to 'sanitize_text_field'
                 $updated = sanitize_text_field($value);
             }
             $meta_value[$key] = $updated;
         }
     } else {
         switch ($field['type']) {
             case 'wysiwyg':
             case 'textarea_small':
                 return self::textarea($meta_value);
             default:
                 // Allow field type validation via filter
                 $updated = apply_filters('cmb_validate_' . $field['type'], $meta_value, cmb_Meta_Box::get_object_id(), $field, cmb_Meta_Box::get_object_type());
                 if ($updated === $meta_value) {
                     // If nothing changed, we'll fallback to 'sanitize_text_field'
                     return sanitize_text_field($meta_value);
                 }
                 return $updated;
         }
     }
     return $meta_value;
 }
开发者ID:Sweetcoder,项目名称:badgeos,代码行数:37,代码来源:cmb_Meta_Box_Sanitize.php


示例14: text_datetime_timestamp_timezone

 /**
  * Datetime to imestamp with timezone
  * @since  1.0.1
  * @param  string $value Meta value
  * @return string       Timestring
  */
 public function text_datetime_timestamp_timezone($value, $repeat = false)
 {
     $test = is_array($value) ? array_filter($value) : '';
     if (empty($test)) {
         return '';
     }
     if ($repeat_value = $this->_check_repeat($value, __FUNCTION__, $repeat)) {
         return $repeat_value;
     }
     $tzstring = null;
     if (is_array($value) && array_key_exists('timezone', $value)) {
         $tzstring = $value['timezone'];
     }
     if (empty($tzstring)) {
         $tzstring = cmb_Meta_Box::timezone_string();
     }
     $offset = cmb_Meta_Box::timezone_offset($tzstring, true);
     if (substr($tzstring, 0, 3) === 'UTC') {
         $tzstring = timezone_name_from_abbr('', $offset, 0);
     }
     $value = new DateTime($value['date'] . ' ' . $value['time'], new DateTimeZone($tzstring));
     $value = serialize($value);
     return $value;
 }
开发者ID:plusplusminus,项目名称:mto,代码行数:30,代码来源:cmb_Meta_Box_Sanitize.php


示例15: set_object_type

 /**
  * Sets the object type
  * @since  1.0.0
  * @return string Object type
  */
 public static function set_object_type($object_type)
 {
     return self::$object_type = $object_type;
 }
开发者ID:Inteleck,项目名称:hwc,代码行数:9,代码来源:init.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP cmsActions类代码示例发布时间:2022-05-23
下一篇:
PHP cm_info类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap