本文整理汇总了PHP中RGFormsModel::prepare_value方法的典型用法代码示例。如果您正苦于以下问题:PHP RGFormsModel::prepare_value方法的具体用法?PHP RGFormsModel::prepare_value怎么用?PHP RGFormsModel::prepare_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RGFormsModel
的用法示例。
在下文中一共展示了RGFormsModel::prepare_value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_input_value
public static function get_input_value($form, $field, &$lead, $input_id)
{
$input_name = 'input_' . str_replace('.', '_', $input_id);
$value = gwpost($input_name);
if (empty($value) && gwar($field, "adminOnly") && !IS_ADMIN) {
$value = GFFormsModel::get_default_value($field, $input_id);
}
//processing values so that they are in the correct format for each input type
$value = RGFormsModel::prepare_value($form, $field, $value, $input_name, gwar($lead, "id"));
if (!empty($value) || $value === "0") {
$value = apply_filters("gform_save_field_value", $value, $lead, $field, $form, $input_id);
}
return $value;
}
示例2: 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');
}
}
示例3: update_post_image
/**
* Handle updating the Post Image field
*
* Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
*
* @since 1.17
*
* @uses GFFormsModel::media_handle_upload
* @uses set_post_thumbnail
*
* @param array $form GF Form array
* @param GF_Field $field GF Field
* @param string $field_id Numeric ID of the field
* @param string $value
* @param array $entry GF Entry currently being edited
* @param int $post_id ID of the Post being edited
*
* @return mixed|string
*/
private function update_post_image($form, $field, $field_id, $value, $entry, $post_id)
{
$input_name = 'input_' . $field_id;
if (!empty($_FILES[$input_name]['name'])) {
// We have a new image
$value = RGFormsModel::prepare_value($form, $field, $value, $input_name, $entry['id']);
$ary = !empty($value) ? explode('|:|', $value) : array();
$img_url = rgar($ary, 0);
$img_title = count($ary) > 1 ? $ary[1] : '';
$img_caption = count($ary) > 2 ? $ary[2] : '';
$img_description = count($ary) > 3 ? $ary[3] : '';
$image_meta = array('post_excerpt' => $img_caption, 'post_content' => $img_description);
//adding title only if it is not empty. It will default to the file name if it is not in the array
if (!empty($img_title)) {
$image_meta['post_title'] = $img_title;
}
/**
* todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class.
* Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
*/
require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
$media_id = GravityView_GFFormsModel::media_handle_upload($img_url, $post_id, $image_meta);
// is this field set as featured image?
if ($media_id && $field->postFeaturedImage) {
set_post_thumbnail($post_id, $media_id);
}
} elseif (!empty($_POST[$input_name]) && is_array($value)) {
// Same image although the image title, caption or description might have changed
$ary = array();
if (!empty($entry[$field_id])) {
$ary = is_array($entry[$field_id]) ? $entry[$field_id] : explode('|:|', $entry[$field_id]);
}
$img_url = rgar($ary, 0);
// is this really the same image or something went wrong ?
if ($img_url === $_POST[$input_name]) {
$img_title = rgar($value, $field_id . '.1');
$img_caption = rgar($value, $field_id . '.4');
$img_description = rgar($value, $field_id . '.7');
$value = !empty($img_url) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
if ($field->postFeaturedImage) {
$image_meta = array('ID' => get_post_thumbnail_id($post_id), 'post_title' => $img_title, 'post_excerpt' => $img_caption, 'post_content' => $img_description);
// update image title, caption or description
wp_update_post($image_meta);
}
}
} else {
// if we get here, image was removed or not set.
$value = '';
if ($field->postFeaturedImage) {
delete_post_thumbnail($post_id);
}
}
return $value;
}