本文整理汇总了PHP中wpcf_fields_get_field_by_slug函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_fields_get_field_by_slug函数的具体用法?PHP wpcf_fields_get_field_by_slug怎么用?PHP wpcf_fields_get_field_by_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_fields_get_field_by_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf_fields_select_view
/**
* View function.
*
* @param type $params
*/
function wpcf_fields_select_view($params)
{
$field = wpcf_fields_get_field_by_slug($params['field']['slug']);
$output = '';
if (!empty($field['data']['options'])) {
$field_value = $params['field_value'];
foreach ($field['data']['options'] as $option_key => $option) {
if (isset($option['value']) && $option['value'] == $params['field_value']) {
$field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
}
}
$output = $field_value;
}
return $output;
}
示例2: get_field_label
/**
* Get the TYPES field label from the custom field name.
*
* @param $custom_field_name
*
* @return mixed
*/
public function get_field_label($custom_field_name)
{
$result = $custom_field_name;
if (!isset($this->_options['display_types_label_on_facet']) || !(self::CONST_TYPES_FIELD_PREFIX === substr($custom_field_name, 0, strlen(self::CONST_TYPES_FIELD_PREFIX)))) {
// No need to replace custom field name by types field label
return $result;
}
$custom_field_name_without_prefix = substr($custom_field_name, strlen(self::CONST_TYPES_FIELD_PREFIX));
$field = wpcf_fields_get_field_by_slug($custom_field_name_without_prefix);
// Retrieve field among TYPES fields
if (isset($field)) {
$result = $field['name'];
}
return $result;
}
示例3: wpcf_fields_select_view
/**
* View function.
*
* @param type $params
*/
function wpcf_fields_select_view($params)
{
if (isset($params['usermeta']) && !empty($params['usermeta'])) {
$field = wpcf_fields_get_field_by_slug($params['field']['slug'], 'wpcf-usermeta');
} else {
$field = wpcf_fields_get_field_by_slug($params['field']['slug']);
}
$output = '';
if (!empty($field['data']['options'])) {
$field_value = $params['field_value'];
foreach ($field['data']['options'] as $option_key => $option) {
if (isset($option['value']) && $option['value'] == $params['field_value']) {
// We need to translate here because the stored value is on the original language
// When updaing the value in the Field group, we might have problems
$field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
}
}
$output = $field_value;
}
return $output;
}
示例4: wpcf_fields_checkbox_view
/**
* View function.
*
* @param type $params
*/
function wpcf_fields_checkbox_view($params)
{
$output = '';
$option_name = 'wpcf-fields';
if (isset($params['usermeta']) && !empty($params['usermeta'])) {
$option_name = 'wpcf-usermeta';
}
if (isset($params['option_name'])) {
$option_name = $params['option_name'];
}
if (isset($params['state']) && $params['state'] == 'unchecked' && empty($params['field_value'])) {
if (empty($params['#content'])) {
return '__wpcf_skip_empty';
}
return htmlspecialchars_decode($params['#content']);
} elseif (isset($params['state']) && $params['state'] == 'unchecked') {
return '__wpcf_skip_empty';
}
if (isset($params['state']) && $params['state'] == 'checked' && !empty($params['field_value'])) {
if (empty($params['#content'])) {
return '__wpcf_skip_empty';
}
return htmlspecialchars_decode($params['#content']);
} elseif (isset($params['state']) && $params['state'] == 'checked') {
return '__wpcf_skip_empty';
}
if (!empty($params['#content']) && !empty($params['field_value'])) {
return htmlspecialchars_decode($params['#content']);
}
// Check if 'save_empty' is yes and if value is 0 - set value to empty string
if (isset($params['field']['data']['save_empty']) && $params['field']['data']['save_empty'] == 'yes' && $params['field_value'] == '0' && 'db' != $params['field']['data']['display']) {
$params['field_value'] = '';
}
if ('db' == $params['field']['data']['display'] && $params['field_value'] != '') {
$output = $params['field_value'];
// Show the translated value if we have one.
$field = wpcf_fields_get_field_by_slug($params['field']['slug'], $option_name);
$output = wpcf_translate('field ' . $field['id'] . ' checkbox value', $output);
} elseif ($params['field']['data']['display'] == 'value' && $params['field_value'] != '') {
if (!empty($params['field']['data']['display_value_selected'])) {
$output = $params['field']['data']['display_value_selected'];
$output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value selected', $output);
}
} elseif ($params['field']['data']['display'] == 'value' && !empty($params['field']['data']['display_value_not_selected'])) {
$output = $params['field']['data']['display_value_not_selected'];
$output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value not selected', $output);
} else {
return '__wpcf_skip_empty';
}
return $output;
}
示例5: wpcf_admin_post_save_post_hook
//.........这里部分代码省略.........
}
$_temp = new WPCF_Field();
$_temp->set($wpcf->post, $v['wpcf-id']);
$_not_valid[$k]['_field'] = $_temp;
}
/*
*
* Allow interaction here.
* Conditional will set $error to false if field is conditional
* and not submitted.
*/
$error = apply_filters('wpcf_post_form_error', $_error, $_not_valid, $all_fields);
$not_valid = apply_filters('wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields);
// Notify user about error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
/*
* Save invalid elements so user can be informed after redirect.
*/
if (!empty($not_valid)) {
update_post_meta($post_ID, 'wpcf-invalid-fields', $not_valid);
}
/*
*
*
*
*
* Save meta fields
*/
if (!empty($_POST['wpcf'])) {
foreach ($_POST['wpcf'] as $field_slug => $field_value) {
// Get field by slug
$field = wpcf_fields_get_field_by_slug($field_slug);
if (empty($field)) {
continue;
}
// Set field
$wpcf->field->set($post_ID, $field);
// Skip copied fields
// CHECKPOINT
if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
continue;
}
// Don't save invalid
// CHECKPOINT
if (isset($not_valid[$field['slug']])) {
continue;
}
/*
*
*
* Saving fields
* @since 1.2
*
* We changed way repetitive fields are saved.
* On each save fields are rewritten and order is saved in
* '_$slug-sort-order' meta field.
*/
/*
*
* We marked fields as repetitive in POST['__wpcf_repetitive']
* Without this check we won't save any.
* @see WPCF_Repeater::get_fields_form()
*/
if (isset($_POST['__wpcf_repetitive'][$wpcf->field->slug])) {
示例6: validate
/**
* New validation using API calls from toolset-forms.
*
* Uses API cals
* @uses wptoolset_form_validate_field()
* @uses wptoolset_form_conditional_check()
*
* @todo Make it work with other fields (generic)
*
* @param type $post_id
* @param type $values
* @return boolean
*/
function validate($post_id, $values)
{
$form_id = $this->form_id;
$valid = true;
// Loop over fields
$form_source_data = $this->_formData->getForm()->post_content;
preg_match_all("/\\[cred_show_group.*cred_show_group\\]/Uism", $form_source_data, $res);
$conditional_group_fields = array();
if (count($res[0]) > 0) {
for ($i = 0, $res_limit = count($res[0]); $i < $res_limit; $i++) {
preg_match_all("/field=\"([^\"]+)\"/Uism", $res[0][$i], $parsed_fields);
if (count($parsed_fields[1]) > 0) {
for ($j = 0, $count_parsed_fields = count($parsed_fields); $j < $count_parsed_fields; $j++) {
if (!empty($parsed_fields[1][$j])) {
$conditional_group_fields[] = trim($parsed_fields[1][$j]);
}
}
}
}
}
foreach ($this->form_properties['fields'] as $field) {
if (in_array(str_replace('wpcf-', '', $field['name']), $conditional_group_fields)) {
continue;
}
// If Types field
if (isset($field['plugin_type']) && $field['plugin_type'] == 'types') {
$field_name = $field['name'];
if (!isset($_POST[$field_name])) {
continue;
}
/*
// Adjust field ID
$field['id'] = strpos( $field['name'], 'wpcf-' ) === 0 ? substr( $field['name'], 5 ) : $field['name'];
// CRED have synonym 'text' for textfield
if ( $field['type'] == 'text' ) {
$field['type'] = 'textfield';
} */
$field = wpcf_fields_get_field_by_slug(str_replace('wpcf-', '', $field['name']));
if (empty($field)) {
continue;
}
// Skip copied fields
if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
continue;
}
// Set field config
$config = wptoolset_form_filter_types_field($field, $post_id);
//Add custom colorpicer hexadecimal backend validator
//Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/193712665/comments
//Todo in future add hexadecimal check in types
if ($field['type'] == 'colorpicker') {
$config['validation']['hexadecimal'] = array('args' => array('$value', '1'), 'message' => 'Enter valid hexadecimal value');
}
if (isset($config['conditional']['values'])) {
foreach ($config['conditional']['values'] as $post_key => $post_value) {
if (isset($this->form_properties['fields'][$post_key])) {
$config['conditional']['values'][$post_key] = $this->form_properties['fields'][$post_key]['value'];
}
}
}
// Set values to loop over
$_values = !empty($values[$field_name]) ? $values[$field_name]['value'] : null;
if (empty($config['repetitive'])) {
$_values = array($_values);
}
// Loop over each value
if (is_array($_values)) {
foreach ($_values as $value) {
$validation = wptoolset_form_validate_field($form_id, $config, $value);
$conditional = wptoolset_form_conditional_check($config);
/**
* add form_errors messages
*/
if (is_wp_error($validation) && $conditional) {
$error_data = $validation->get_error_data();
if (isset($error_data[0])) {
$this->add_top_message($error_data[0], $config['id']);
} else {
$this->add_top_message($validation->get_error_message(), $config['id']);
}
$valid = false;
if (empty($ret_validation)) {
continue;
}
// foreach( $errors as $error ) {
// $error = explode( ' ', $error );
// $key = array_shift($error);
//.........这里部分代码省略.........
示例7: save_child
//.........这里部分代码省略.........
*
*
*
*
*
* UPDATE POST
*/
$cf = new WPCF_Field();
if (isset($_POST['wpcf_post_relationship'][$parent_id]) && isset($_POST['wpcf_post_relationship'][$parent_id][$child_id])) {
$_POST['wpcf'] = array();
foreach ($_POST['wpcf_post_relationship'][$parent_id][$child_id] as $slug => $value) {
$_POST['wpcf'][$cf->__get_slug_no_prefix($slug)] = $value;
$_POST['wpcf'][$slug] = $value;
}
}
unset($cf);
/**
* avoid filters for children
* /
global $wp_filter;
$save_post = $wp_filter['save_post'];
$wp_filter['save_post'] = array();
*/
$updated_id = wp_update_post($post_data);
/*
$wp_filter['save_post'] = $save_post;
*/
unset($save_post);
if (empty($updated_id)) {
return new WP_Error('relationship-update-post-failed', 'Updating post failed');
}
// Save parents
if (!empty($save_fields['parents'])) {
foreach ($save_fields['parents'] as $parent_post_type => $parent_post_id) {
update_post_meta($child->ID, '_wpcf_belongs_' . $parent_post_type . '_id', $parent_post_id);
}
}
// Update taxonomies
if (!empty($save_fields['taxonomies']) && is_array($save_fields['taxonomies'])) {
$_save_data = array();
foreach ($save_fields['taxonomies'] as $taxonomy => $t) {
if (!is_taxonomy_hierarchical($taxonomy)) {
$_save_data[$taxonomy] = strval($t);
continue;
}
foreach ($t as $term_id) {
if ($term_id != '-1') {
$term = get_term($term_id, $taxonomy);
if (empty($term)) {
continue;
}
$_save_data[$taxonomy][] = $term_id;
}
}
}
wp_delete_object_term_relationships($child->ID, array_keys($save_fields['taxonomies']));
foreach ($_save_data as $_taxonomy => $_terms) {
wp_set_post_terms($child->ID, $_terms, $_taxonomy, $append = false);
}
}
// Unset non-types
unset($save_fields['_wp_title'], $save_fields['_wp_body'], $save_fields['parents'], $save_fields['taxonomies']);
/*
*
*
*
*
*
*
* UPDATE Loop over fields
*/
foreach ($save_fields as $slug => $value) {
if (defined('WPTOOLSET_FORMS_VERSION')) {
// Get field by slug
$field = wpcf_fields_get_field_by_slug(str_replace(WPCF_META_PREFIX, '', $slug));
if (empty($field)) {
continue;
}
// Set config
$config = wptoolset_form_filter_types_field($field, $child->ID);
// Check if valid
$valid = wptoolset_form_validate_field('post', $config, $value);
if (is_wp_error($valid)) {
$errors = $valid->get_error_data();
$msg = sprintf(__('Child post "%s" field "%s" not updated:', 'wpcf'), $child->post_title, $field['name']);
wpcf_admin_message_store($msg . ' ' . implode(', ', $errors), 'error');
continue;
}
}
$this->cf->set($child, $field);
$this->cf->context = 'post_relationship';
$this->cf->save($value);
}
do_action('wpcf_relationship_save_child', $child, $parent);
clean_post_cache($parent->ID);
clean_post_cache($child->ID);
// Added because of caching meta 1.5.4
wp_cache_flush();
return true;
}
示例8: remove_conditions
/**
* Remove all conditions.
*
* @param $id
*/
public function remove_conditions($id, $group_conditions = false)
{
if ($group_conditions) {
delete_post_meta($id, '_wpcf_conditional_display');
} else {
$field = wpcf_fields_get_field_by_slug($id);
if (empty($field)) {
return;
}
$all_types_fields = get_option('wpcf-fields', array());
$all_types_fields[$id]['data']['conditional_display'] = array();
update_option('wpcf-fields', $all_types_fields);
}
}
示例9: wpcf_admin_userprofilesave_init
function wpcf_admin_userprofilesave_init($user_id)
{
if (defined('WPTOOLSET_FORMS_VERSION')) {
global $wpcf;
$errors = false;
/**
* check checkbox type fields to delete or save empty if needed
*/
$groups = wpcf_admin_usermeta_get_groups_fields();
foreach ($groups as $group) {
if (!array_key_exists('fields', $group) || empty($group['fields'])) {
continue;
}
foreach ($group['fields'] as $field) {
switch ($field['type']) {
case 'checkboxes':
if (!array_key_exists('wpcf', $_POST) || !array_key_exists($field['slug'], $_POST['wpcf'])) {
delete_user_meta($user_id, $field['meta_key']);
}
break;
case 'checkbox':
if (!array_key_exists('wpcf', $_POST) || !array_key_exists($field['slug'], $_POST['wpcf'])) {
if ('yes' == $field['data']['save_empty']) {
$_POST['wpcf'][$field['slug']] = 0;
} else {
delete_user_meta($user_id, $field['meta_key']);
}
}
break;
}
}
}
// Save meta fields
if (!empty($_POST['wpcf'])) {
foreach ($_POST['wpcf'] as $field_slug => $field_value) {
// Get field by slug
$field = wpcf_fields_get_field_by_slug($field_slug, 'wpcf-usermeta');
if (empty($field)) {
continue;
}
// Skip copied fields
if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
continue;
}
$_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
// Set config
$config = wptoolset_form_filter_types_field($field, $user_id);
foreach ($_field_value as $_k => $_val) {
// Check if valid
$valid = wptoolset_form_validate_field('your-profile', $config, $_val);
if (is_wp_error($valid)) {
$errors = true;
$_errors = $valid->get_error_data();
$_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
if (types_is_repetitive($field)) {
unset($field_value[$_k]);
} else {
break;
}
}
}
// Save field
if (types_is_repetitive($field)) {
$wpcf->usermeta_repeater->set($user_id, $field);
$wpcf->usermeta_repeater->save($field_value);
} else {
$wpcf->usermeta_field->set($user_id, $field);
$wpcf->usermeta_field->usermeta_save($field_value);
}
do_action('wpcf_user_field_saved', $user_id, $field);
// TODO Move to checkboxes
if ($field['type'] == 'checkboxes') {
$field_data = wpcf_admin_fields_get_field($field['id'], false, false, false, 'wpcf-usermeta');
if (!empty($field_data['data']['options'])) {
$update_data = array();
foreach ($field_data['data']['options'] as $option_id => $option_data) {
if (!isset($_POST['wpcf'][$field['id']][$option_id])) {
if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
$update_data[$option_id] = 0;
}
} else {
$update_data[$option_id] = $_POST['wpcf'][$field['id']][$option_id];
}
}
update_user_meta($user_id, $field['meta_key'], $update_data);
}
}
}
}
if ($errors) {
update_post_meta($user_id, '__wpcf-invalid-fields', true);
}
do_action('wpcf_user_saved', $user_id);
return;
}
global $wpcf;
$all_fields = array();
$_not_valid = array();
$_error = false;
//.........这里部分代码省略.........
示例10: short_code_menu_callback
function short_code_menu_callback($index, $cf_key, $function_name, $menu, $shortcode)
{
global $link_layout_number, $wpdb;
static $fields_started = false;
static $templates_started = false;
if ($menu == __('View template', 'wpv-views') && !$templates_started) {
$templates_started = true;
echo '</tr><td> </td><tr>';
echo '</tr><tr><td><strong>' . __('View templates', 'wpv-views') . '</strong></td>';
echo '</tr><tr>';
$link_layout_number = 0;
}
if ($menu != '' && $menu != __('View template', 'wpv-views') && !$fields_started) {
$fields_started = true;
echo '</tr><td> </td><tr>';
echo '</tr><tr><td><strong>' . __('Fields', 'wpv-views') . '</strong></td>';
echo '</tr><tr>';
$link_layout_number = 0;
}
if (!($link_layout_number % 2)) {
if ($link_layout_number != 0) {
echo '</tr><tr>';
}
}
if ($menu == __('View template', 'wpv-views')) {
// get the View template title.
$field_name = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE post_type='view-template' AND post_name=%s", $cf_key));
if (!$field_name) {
$field_name = $cf_key;
}
} else {
$field_name = $cf_key;
if (function_exists('wpcf_types_get_meta_prefix')) {
// we have types.
// Get the field name for display
$types_prefix = wpcf_types_get_meta_prefix();
if (strpos($cf_key, $types_prefix) === 0) {
$field_info = wpcf_fields_get_field_by_slug(substr($cf_key, strlen($types_prefix)));
if (isset($field_info['name'])) {
$field_name = $field_info['name'];
}
}
}
}
echo '<td><a style="cursor: pointer" onclick="on_add_field_wpv(\'' . $menu . '\', \'' . esc_js($cf_key) . '\', \'' . base64_encode($field_name) . '\')">';
echo $field_name;
echo '</a></td>';
$link_layout_number++;
}
示例11: wpcf_admin_post_save_post_hook
/**
* The save_post hook.
*
* @param int $post_ID
* @param WP_Post $post
* @since unknown
*/
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
// Apparently, some things are *slightly* different when saving a child post in the Post relationships metabox.
// Ugly hack that will go away with m2m.
//
// Note: The types_updating_child_post filter is needed for a situation when user clicks on the Update button
// for the parent post. In that case we don't get enough information to determine if a child post is being updated.
$is_child_post_update = 'wpcf_ajax' == wpcf_getget('action') && 'pr_save_child_post' == wpcf_getget('wpcf_action') || apply_filters('types_updating_child_post', false);
global $wpcf;
$errors = false;
// Do not save post if is type of
if (in_array($post->post_type, array('revision', 'view', 'view-template', 'cred-form', 'cred-user-form', 'nav_menu_item', 'mediapage'))) {
return;
}
$_post_wpcf = array();
if (!empty($_POST['wpcf'])) {
$_post_wpcf = $_POST['wpcf'];
}
// handle checkbox
if (array_key_exists('_wptoolset_checkbox', $_POST) && is_array($_POST['_wptoolset_checkbox'])) {
foreach ($_POST['_wptoolset_checkbox'] as $key => $field_value) {
$field_slug = preg_replace('/^wpcf\\-/', '', $key);
if (array_key_exists($field_slug, $_post_wpcf)) {
continue;
}
$_post_wpcf[$field_slug] = false;
}
}
// handle radios
if (array_key_exists('_wptoolset_radios', $_POST) && is_array($_POST['_wptoolset_radios'])) {
foreach ($_POST['_wptoolset_radios'] as $key => $field_value) {
$field_slug = preg_replace('/^wpcf\\-/', '', $key);
if (array_key_exists($field_slug, $_post_wpcf)) {
continue;
}
$_post_wpcf[$field_slug] = false;
}
}
if (count($_post_wpcf)) {
$add_error_message = true;
if (isset($_POST['post_id']) && $_POST['post_id'] != $post_ID) {
$add_error_message = false;
}
// check some attachment to delete
$delete_attachments = apply_filters('wpcf_delete_attachments', true);
$images_to_delete = array();
if ($delete_attachments && isset($_POST['wpcf']) && array_key_exists('delete-image', $_POST['wpcf']) && is_array($_POST['wpcf']['delete-image'])) {
foreach ($_POST['wpcf']['delete-image'] as $image) {
$images_to_delete[$image] = 1;
}
}
foreach ($_post_wpcf as $field_slug => $field_value) {
// Get field by slug
$field = wpcf_fields_get_field_by_slug($field_slug);
if (empty($field)) {
continue;
}
// Skip copied fields
if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
continue;
}
// This is (apparently) expected for repetitive fields...
if ($is_child_post_update && types_is_repetitive($field)) {
$field_value = array($field_value);
}
$_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
// Set config
$config = wptoolset_form_filter_types_field($field, $post_ID, $_post_wpcf);
// remove from images_to_delete if user add again
if ($delete_attachments && 'image' == $config['type']) {
$images = $_field_value;
if (!is_array($images)) {
$images = array($images);
}
foreach ($images as $image) {
if (array_key_exists($image, $images_to_delete)) {
unset($images_to_delete[$image]);
}
}
}
// add filter to remove field name from error message
// This filter is toolset-common/toolset-forms/classes/class.validation.php
add_filter('toolset_common_validation_add_field_name_to_error', '__return_false', 1234, 1);
foreach ($_field_value as $_k => $_val) {
// Check if valid
$validation = wptoolset_form_validate_field('post', $config, $_val);
$conditional = wptoolset_form_conditional_check($config);
$not_valid = is_wp_error($validation) || !$conditional;
if ($add_error_message && is_wp_error($validation)) {
$errors = true;
$_errors = $validation->get_error_data();
$_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
//.........这里部分代码省略.........
示例12: types_render_field
/**
* Calls view function for specific field type.
*
* @param type $field
* @param type $atts
* @return type
*/
function types_render_field($field, $params, $content = null, $code = '')
{
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
// Count fields (if there are duplicates)
static $count = array();
// Get field
$field = wpcf_fields_get_field_by_slug($field);
if (empty($field)) {
return '';
}
// Count it
if (!isset($count[$field['slug']])) {
$count[$field['slug']] = 1;
} else {
$count[$field['slug']] += 1;
}
// Get post field value
global $post;
$value = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
if ($value == '' && $field['type'] != 'checkbox') {
return '';
}
// Load type
$type = wpcf_fields_type_action($field['type']);
// Apply filters to field value
$value = apply_filters('wpcf_fields_value_display', $value);
$value = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_display', $value);
$value = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_display', $value);
// To make sure
if (is_string($value)) {
$value = addslashes(stripslashes($value));
}
// Set values
$field['name'] = wpcf_translate('field ' . $field['id'] . ' name', $field['name']);
$params['field'] = $field;
$params['post'] = $post;
$params['field_value'] = $value;
// Get output
$params['#content'] = htmlspecialchars($content);
$params['#code'] = $code;
$output = wpcf_fields_type_action($field['type'], 'view', $params);
// Convert to string
if (!empty($output)) {
$output = strval($output);
}
// @todo Reconsider if ever changing this (works fine now)
// If no output or 'raw' return default
if (($params['raw'] == 'true' || empty($output)) && !empty($value)) {
$field_name = '';
if ($params['show_name'] == 'true') {
$field_name = wpcf_frontend_wrap_field_name($field, $field['name'], $params);
}
$field_value = wpcf_frontend_wrap_field_value($field, $value, $params);
$output = wpcf_frontend_wrap_field($field, $field_name . $field_value);
}
// Apply filters
$output = strval(apply_filters('types_view', $output, $value, $field['type'], $field['slug'], $field['name'], $params));
// Add count
if (isset($count[$field['slug']]) && intval($count[$field['slug']]) > 1) {
$add = '-' . intval($count[$field['slug']]);
$output = str_replace('id="wpcf-field-' . $field['slug'] . '"', 'id="wpcf-field-' . $field['slug'] . $add . '"', $output);
}
return htmlspecialchars_decode(stripslashes($output));
}
示例13: wpcf_fields_checkbox_view
/**
* View function.
*
* @param type $params
*/
function wpcf_fields_checkbox_view($params)
{
$output = '';
$option_name = 'wpcf-fields';
if (isset($params['usermeta']) && !empty($params['usermeta'])) {
$option_name = 'wpcf-usermeta';
} else {
if (isset($params['termmeta']) && !empty($params['termmeta'])) {
$option_name = 'wpcf-termmeta';
}
}
if (isset($params['option_name'])) {
$option_name = $params['option_name'];
}
if (isset($params['state']) && $params['state'] == 'unchecked' && empty($params['field_value'])) {
if (empty($params['#content'])) {
return '__wpcf_skip_empty';
}
return htmlspecialchars_decode($params['#content']);
} elseif (isset($params['state']) && $params['state'] == 'unchecked') {
return '__wpcf_skip_empty';
}
if (isset($params['state']) && $params['state'] == 'checked' && !empty($params['field_value'])) {
if (empty($params['#content'])) {
return '__wpcf_skip_empty';
}
return htmlspecialchars_decode($params['#content']);
} elseif (isset($params['state']) && $params['state'] == 'checked') {
return '__wpcf_skip_empty';
}
if (!empty($params['#content']) && !empty($params['field_value'])) {
return htmlspecialchars_decode($params['#content']);
}
// Check if 'save_empty' is yes and if value is 0 - set value to empty string
if (isset($params['field']['data']['save_empty']) && $params['field']['data']['save_empty'] == 'yes' && $params['field_value'] == '0' && 'db' != $params['field']['data']['display']) {
$params['field_value'] = '';
}
if ('db' == $params['field']['data']['display'] && $params['field_value'] != '') {
// We need to translate here because the stored value is on the original language
// When updaing the value in the Field group, we might have problems
$output = $params['field_value'];
// Show the translated value if we have one.
$field = wpcf_fields_get_field_by_slug($params['field']['slug'], $option_name);
if (is_array($field) && isset($field['id'])) {
$output = wpcf_translate('field ' . $field['id'] . ' checkbox value', $output);
}
} elseif ($params['field']['data']['display'] == 'value' && $params['field_value'] != '') {
if (!empty($params['field']['data']['display_value_selected'])) {
// We need to translate here because the stored value is on the original language
// When updaing the value in the Field group, we might have problems
$output = $params['field']['data']['display_value_selected'];
$output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value selected', $output);
}
} elseif ($params['field']['data']['display'] == 'value' && !empty($params['field']['data']['display_value_not_selected'])) {
// We need to translate here because the stored value is on the original language
// When updaing the value in the Field group, we might have problems
$output = $params['field']['data']['display_value_not_selected'];
$output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value not selected', $output);
} else {
return '__wpcf_skip_empty';
}
return $output;
}
示例14: file
</p>
<!-- TYPES TIP: Custom code to load Types function and render a REPEATING custom field "House Photos" but with each output thumbnail image also linking to the full-size image file (for lightbox effect, for example). -->
<p><strong>Property Photos</strong></p>
<?php
// Do nothing if we don't have Types.
if (apply_filters('types_is_active', false)) {
$output = '';
// ID of the current post
$post_id = get_the_ID();
// Slug of a Types repeating image field, without the "wpcf-" prefix.
$field_slug = 'house-photos';
// TODO set the field slug you want to display
// Parameters that define the field
$field_definition = wpcf_fields_get_field_by_slug($field_slug);
if (!empty($field_definition)) {
// Get the raw field data.
$images = get_post_meta($post_id, "wpcf-{$field_slug}");
foreach ($images as $image_index => $image) {
// Parameters for the Types field rendering mechanism.
$image_parameters = array('proportional' => 'true', 'url' => 'true', 'field_value' => $image);
// Get an image of specific (maximum) proportions.
// NOTE: Update image size to your needs
$thumbnail_parameters = array_merge($image_parameters, array('width' => '200', 'height' => '200'));
$thumbnail_url = types_render_field_single($field_definition, $thumbnail_parameters, null, '', $image_index);
// Get the image in full size.
$fullsize_parameters = array_merge($image_parameters, array('size' => 'full'));
$fullsize_url = types_render_field_single($field_definition, $fullsize_parameters, null, '', $image_index);
// Append the markup (a thumbnail linking to the full image) to existing content.
// NOTE: Customize the output to your needs
示例15: wpcf_admin_post_save_post_hook
/**
* save_post hook.
*
* @param type $post_ID
* @param type $post
*/
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) {
return false;
}
if (in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) {
return false;
}
// Get groups
$groups = wpcf_admin_post_get_post_groups_fields($post);
if (empty($groups)) {
return false;
}
$all_fields = array();
foreach ($groups as $group) {
// Process fields
$fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation');
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
$error = $form->isError();
// Trigger form error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
}
// Save invalid elements so user can be informed after redirect
if (!empty($all_fields)) {
update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields);
}
// Save meta fields
if (!empty($_POST['wpcf'])) {
foreach ($_POST['wpcf'] as $field_slug => $field_value) {
// Skip copied fields
if (isset($_POST['wpcf_repetitive_copy'][$field_slug])) {
continue;
}
$field = wpcf_fields_get_field_by_slug($field_slug);
if (empty($field)) {
continue;
}
$meta_key = wpcf_types_get_meta_prefix($field) . $field_slug;
// Don't save invalid
if (isset($all_fields[$meta_key]['#error'])) {
continue;
}
// Repetitive fields
if (isset($_POST['wpcf_repetitive'][$field_slug])) {
delete_post_meta($post_ID, $meta_key);
foreach ($field_value as $temp_id => $repetitive_data) {
// Skype specific
if ($field['type'] == 'skype') {
unset($repetitive_data['old_value']);
wpcf_admin_post_save_field($post_ID, $meta_key, $field, $repetitive_data, true);
} else {
wpcf_admin_post_save_field($post_ID, $meta_key, $field, $repetitive_data['new_value'], true);
}
}
} else {
wpcf_admin_post_save_field($post_ID, $meta_key, $field, $field_value);
}
}
}
// Process checkboxes
foreach ($all_fields as $field) {
if (!isset($field['#type'])) {
continue;
}
if ($field['#type'] == 'checkbox' && !isset($_POST['wpcf'][$field['wpcf-slug']])) {
$field_data = wpcf_admin_fields_get_field($field['wpcf-id']);
if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], 0);
} else {
delete_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug']);
}
}
if ($field['#type'] == 'checkboxes') {
$field_data = wpcf_admin_fields_get_field($field['wpcf-id']);
if (!empty($field_data['data']['options'])) {
$update_data = array();
foreach ($field_data['data']['options'] as $option_id => $option_data) {
if (!isset($_POST['wpcf'][$field['wpcf-slug']][$option_id])) {
if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
$update_data[$option_id] = 0;
}
} else {
$update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id];
}
}
update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data);
}
}
}
}