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


PHP GVCommon::get_field_array方法代码示例

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


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

示例1: maybe_update_post_fields

 /**
  * Loop through the fields being edited and if they include Post fields, update the Entry's post object
  *
  * @param array $form Gravity Forms form
  *
  * @return void
  */
 function maybe_update_post_fields($form)
 {
     $post_id = $this->entry['post_id'];
     // Security check
     if (false === GVCommon::has_cap('edit_post', $post_id)) {
         do_action('gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id);
         return;
     }
     $update_entry = false;
     $updated_post = $original_post = get_post($post_id);
     foreach ($this->entry as $field_id => $value) {
         //todo: only run through the edit entry configured fields
         $field = RGFormsModel::get_field($form, $field_id);
         if (class_exists('GF_Fields')) {
             $field = GF_Fields::create($field);
         }
         if (GFCommon::is_post_field($field)) {
             // Get the value of the field, including $_POSTed value
             $value = RGFormsModel::get_field_value($field);
             // Convert the field object in 1.9 to an array for backward compatibility
             $field_array = GVCommon::get_field_array($field);
             switch ($field_array['type']) {
                 case 'post_title':
                 case 'post_content':
                 case 'post_excerpt':
                     $updated_post->{$field_array['type']} = $value;
                     break;
                 case 'post_tags':
                     wp_set_post_tags($post_id, $value, false);
                     break;
                 case 'post_category':
                     $categories = is_array($value) ? array_values($value) : (array) $value;
                     $categories = array_filter($categories);
                     wp_set_post_categories($post_id, $categories, false);
                     // prepare value to be saved in the entry
                     $field = GFCommon::add_categories_as_choices($field, '');
                     // if post_category is type checkbox, then value is an array of inputs
                     if (isset($value[strval($field_id)])) {
                         foreach ($value as $input_id => $val) {
                             $input_name = 'input_' . str_replace('.', '_', $input_id);
                             $this->entry[strval($input_id)] = RGFormsModel::prepare_value($form, $field, $val, $input_name, $this->entry['id']);
                         }
                     } else {
                         $input_name = 'input_' . str_replace('.', '_', $field_id);
                         $this->entry[strval($field_id)] = RGFormsModel::prepare_value($form, $field, $value, $input_name, $this->entry['id']);
                     }
                     break;
                 case 'post_custom_field':
                     $input_type = RGFormsModel::get_input_type($field);
                     $custom_field_name = $field_array['postCustomFieldName'];
                     // Only certain custom field types are supported
                     if (!in_array($input_type, array('list', 'fileupload'))) {
                         update_post_meta($post_id, $custom_field_name, $value);
                     }
                     break;
                 case 'post_image':
                     $value = '';
                     break;
             }
             //ignore fields that have not changed
             if ($value === rgget((string) $field_id, $this->entry)) {
                 continue;
             }
             // update entry
             if ('post_category' !== $field->type) {
                 $this->entry[strval($field_id)] = $value;
             }
             $update_entry = true;
         }
     }
     if ($update_entry) {
         $return_entry = GFAPI::update_entry($this->entry);
         if (is_wp_error($return_entry)) {
             do_action('gravityview_log_error', 'Updating the entry post fields failed', $return_entry);
         } else {
             do_action('gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded');
         }
     }
     $return_post = wp_update_post($updated_post, true);
     if (is_wp_error($return_post)) {
         do_action('gravityview_log_error', 'Updating the post content failed', $return_post);
     } else {
         do_action('gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded');
     }
 }
开发者ID:hansstam,项目名称:makerfaire,代码行数:92,代码来源:class-edit-entry-render.php


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