本文整理汇总了PHP中wpcf_types_get_meta_prefix函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_types_get_meta_prefix函数的具体用法?PHP wpcf_types_get_meta_prefix怎么用?PHP wpcf_types_get_meta_prefix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_types_get_meta_prefix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf_cd_post_groups_filter
/**
* Filters groups on post edit page.
*
* @param type $groups
* @param type $post
* @return type
*/
function wpcf_cd_post_groups_filter($groups, $post, $context)
{
if ($context != 'group') {
return $groups;
}
foreach ($groups as $key => &$group) {
$conditions = null;
if (array_key_exists('conditional_display', $group) && array_key_exists('conditions', $group['conditional_display'])) {
$conditions = $group['conditional_display'];
} else {
$conditions = get_post_meta($group['id'], '_wpcf_conditional_display', true);
}
if (!empty($conditions['conditions'])) {
$meta_box_id = "wpcf-group-{$group['slug']}";
$prefix = 'wpcf-';
$suffix = '';
$cond = array();
if (isset($post->ID)) {
$cond_values = get_post_custom($post->ID);
} else {
$cond_values = array();
}
$_cond_values = array();
foreach ($cond_values as $k => $v) {
$v = maybe_unserialize($v[0]);
$_cond_values[$k . $suffix] = is_array($v) ? strval(array_shift($v)) : $v;
}
unset($cond_values);
$cond = array();
if (!empty($conditions['custom_use'])) {
if (!empty($conditions['custom'])) {
$custom = WPToolset_Types::getCustomConditional($conditions['custom']);
$passed = WPToolset_Forms_Conditional::evaluateCustom($custom['custom'], $_cond_values);
$cond = array('custom' => $custom['custom'], 'custom_use' => true);
}
} else {
$cond = array('relation' => $conditions['relation'], 'conditions' => array(), 'values' => $_cond_values);
foreach ($conditions['conditions'] as $d) {
$c_field = types_get_field($d['field']);
if (!empty($c_field)) {
$_c = array('id' => wpcf_types_get_meta_prefix($c_field) . $d['field'] . $suffix, 'type' => $c_field['type'], 'operator' => $d['operation'], 'args' => array($d['value']));
$cond['conditions'][] = $_c;
}
}
$passed = wptoolset_form_conditional_check(array('conditional' => $cond));
}
$data = array('id' => $meta_box_id, 'conditional' => $cond);
wptoolset_form_add_conditional('post', $data);
if (!$passed) {
$group['_conditional_display'] = 'failed';
} else {
$group['_conditional_display'] = 'passed';
}
}
}
return $groups;
}
示例2: wpcf_fields_embed_editor_callback
/**
* Editor callback form.
*/
function wpcf_fields_embed_editor_callback($field, $data, $meta_type, $post)
{
// Get attachment
$attachment_id = false;
if (!empty($post->ID)) {
$file = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
if (empty($file)) {
$user_id = wpcf_usermeta_get_user();
$file = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
}
if (!empty($file)) {
// Get attachment by guid
global $wpdb;
$attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\n WHERE post_type = 'attachment' AND guid=%s", $file));
}
}
// Set data
$data['attachment_id'] = $attachment_id;
$data['file'] = !empty($file) ? $file : '';
return array('supports' => array(), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-embed', $data))), 'settings' => $data);
}
示例3: set
/**
* Set current post and field.
*
* @param type $post
* @param type $cf
*/
function set($user_id, $cf)
{
global $wpcf;
/*
*
* Check if $cf is string
*/
if (is_string($cf)) {
WPCF_Loader::loadInclude('fields');
$cf = wpcf_admin_fields_get_field($this->__get_slug_no_prefix($cf));
if (empty($cf)) {
$this->_reset();
return false;
}
}
$this->currentUID = $user_id;
$this->ID = $cf['id'];
$this->cf = $cf;
$this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug'];
$this->meta = $this->_get_meta();
$this->config = $this->_get_config();
$this->unique_id = wpcf_unique_id(serialize((array) $this));
$this->cf['value'] = $this->meta;
// Debug
$wpcf->debug->fieds[$this->unique_id] = $this->cf;
$wpcf->debug->meta[$this->slug][] = $this->meta;
// Load files
if (isset($this->cf['type'])) {
$file = WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php';
if (file_exists($file)) {
include_once $file;
}
if (defined('WPCF_INC_ABSPATH')) {
$file = WPCF_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php';
if (file_exists($file)) {
include_once $file;
}
}
}
}
示例4: types_child_posts
/**
* Gets posts that belongs to current post.
*
* @global type $post
* @param type $post_type
* @param type $args
* @return type
*/
function types_child_posts($post_type, $args = array())
{
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
global $post, $wp_post_types;
// WP allows querying inactive post types
if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) {
return array();
}
$defaults = array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => null, 'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id', 'meta_value' => $post->ID, 'suppress_filters' => false);
$args = wp_parse_args($args, $defaults);
$args = apply_filters('types_child_posts_args', $args);
$child_posts = get_posts($args);
foreach ($child_posts as $child_post_key => $child_post) {
$child_posts[$child_post_key]->fields = array();
$groups = wpcf_admin_post_get_post_groups_fields($child_post);
foreach ($groups as $group) {
if (!empty($group['fields'])) {
// Process fields
foreach ($group['fields'] as $k => $field) {
$child_posts[$child_post_key]->fields[$k] = get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
}
}
}
}
return $child_posts;
}
示例5: set
/**
* Set current post and field.
*
* @param type $post
* @param type $cf
*/
function set($post, $cf)
{
global $wpcf;
/*
*
* Check if $cf is string
*/
if (is_string($cf)) {
WPCF_Loader::loadInclude('fields');
$_cf = wpcf_admin_fields_get_field($this->__get_slug_no_prefix($cf));
// Check if found without prefix
if (empty($_cf)) {
$_cf = wpcf_admin_fields_get_field($cf);
}
if (empty($_cf)) {
/*
* TODO Check what happens if field is not found
*/
$this->_reset();
return false;
}
$cf = $_cf;
}
$this->post = is_integer($post) ? get_post($post) : $post;
// If empty post it is new
if (empty($this->post->ID)) {
$this->post = new stdClass();
$this->post->ID = 0;
}
$this->ID = $cf['id'];
$this->cf = $cf;
$this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug'];
$this->meta = $this->_get_meta();
$this->config = $this->_get_config();
$this->unique_id = wpcf_unique_id(serialize((array) $this));
$this->cf['value'] = $this->meta;
// Debug
$wpcf->debug->fields[$this->unique_id] = $this->cf;
$wpcf->debug->meta[$this->slug][] = $this->meta;
// Load files
$this->_include_file_by_field_type($this->cf['type']);
if (defined('WPCF_INC_ABSPATH')) {
$file = WPCF_INC_ABSPATH . '/fields/' . preg_replace('/[^\\w]+/', '', $this->cf['type']) . '.php';
if (file_exists($file)) {
include_once $file;
}
}
}
示例6: wpcf_fields_image_editor_callback
/**
* Editor callback form.
*
* @global object $wpdb
*
*/
function wpcf_fields_image_editor_callback($field, $data, $context, $post)
{
// Get post_ID
$post_ID = !empty($post->ID) ? $post->ID : false;
// Get attachment
$image = false;
$attachment_id = false;
if ($post_ID) {
$image = get_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
if (empty($image)) {
$user_id = wpcf_usermeta_get_user();
$image = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
}
if (!empty($image)) {
// Get attachment by guid
global $wpdb;
$attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND guid=%s", $image));
}
}
$data['image'] = $image;
$data['attachment_id'] = $attachment_id;
// Set post type
$post_type = !empty($post->post_type) ? $post->post_type : '';
// Set image_data
$image_data = wpcf_fields_image_get_data($image);
if (!in_array($post_type, array('view', 'view-template'))) {
// We must ignore errors here and treat image as outsider
if (!empty($image_data['error'])) {
$image_data['is_outsider'] = 1;
$image_data['is_attachment'] = 0;
}
} else {
if (!empty($image_data['error'])) {
$image_data['is_outsider'] = 0;
$image_data['is_attachment'] = 0;
}
}
$data['preview'] = $attachment_id ? wp_get_attachment_image($attachment_id, 'thumbnail') : '';
// Title and Alt
if ($attachment_id) {
$alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
$attachment_post = get_post($attachment_id);
if (!empty($attachment_post)) {
$title = trim(strip_tags($attachment_post->post_title));
} else {
if (!empty($alt)) {
$title = $alt;
}
}
if (empty($alt)) {
$alt = $title;
}
if (!isset($data['title'])) {
$data['title'] = $title;
}
if (!isset($data['alt'])) {
$data['alt'] = $alt;
}
}
// Align options
$data['alignment_options'] = array('none' => __('None', 'wpcf'), 'left' => __('Left', 'wpcf'), 'center' => __('Center', 'wpcf'), 'right' => __('Right', 'wpcf'));
// Remote images settings
$fetch_remote = (bool) wpcf_get_settings('images_remote');
$data['warning_remote'] = false;
if (!types_is_repetitive($field) && $image_data['is_outsider'] && !$fetch_remote && !empty($data['image'])) {
$data['warning_remote'] = true;
}
// Size settings
$data['size_options'] = array('thumbnail' => sprintf(__('Thumbnail - %s', 'wpcf'), get_option('thumbnail_size_w') . 'x' . get_option('thumbnail_size_h')), 'medium' => sprintf(__('Medium - %s', 'wpcf'), get_option('medium_size_w') . 'x' . get_option('medium_size_h')), 'large' => sprintf(__('Large - %s', 'wpcf'), get_option('large_size_w') . 'x' . get_option('large_size_h')), 'full' => __('Original image', 'wpcf'));
$wp_image_sizes = (array) get_intermediate_image_sizes();
foreach ($wp_image_sizes as $wp_size) {
if ($wp_size != 'post-thumbnail' && !array_key_exists($wp_size, $data['size_options'])) {
$data['size_options'][$wp_size] = $wp_size;
}
}
$data['size_options']['wpcf-custom'] = __('Custom size...', 'wpcf');
// Get saved settings
$data = array_merge(wpcf_admin_fields_get_field_last_settings($field['id']), $data);
return array('supports' => array('styling', 'style'), 'tabs' => array('display' => array('menu_title' => __('Display options', 'wpcf'), 'title' => __('Display options for this field:', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-image', $data))), 'settings' => $data);
}
示例7: wpcf_admin_fields_get_fields
/**
* Gets all fields.
*
* @todo Move to WPCF_Fields
* @param bool $only_active
* @param bool $disabled_by_type
* @param bool $strictly_active
* @param string $option_name
* @param bool $use_cache
* @param bool $clear_cache
* @return array
*
* added param $use_cache by Gen (used when adding new fields to group)
* added param $use_cache by Gen (used when adding new fields to group)
*/
function wpcf_admin_fields_get_fields($only_active = false, $disabled_by_type = false, $strictly_active = false, $option_name = 'wpcf-fields', $use_cache = true, $clear_cache = false)
{
static $cache = array();
if ($clear_cache) {
$cache = array();
}
/**
* Sanitize option name
*/
switch ($option_name) {
case 'wpcf-usermeta':
case 'wpcf-fields':
case WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION:
break;
default:
$option_name = 'wpcf-fields';
break;
}
$cache_key = md5($only_active . $disabled_by_type . $strictly_active . $option_name . $use_cache);
if (isset($cache[$cache_key]) && $use_cache == true) {
return $cache[$cache_key];
}
$required_data = array('id', 'name', 'type', 'slug');
$fields = (array) get_option($option_name, array());
foreach ($fields as $k => $v) {
$failed = false;
foreach ($required_data as $required) {
if (!isset($v[$required])) {
$failed = true;
continue;
}
if (is_numeric($v[$required]) === true) {
$failed = true;
continue;
}
}
if (is_numeric($k) === true || $failed) {
unset($fields[$k]);
continue;
}
// This call loads config file
$data = wpcf_fields_type_action($v['type']);
if (empty($data)) {
unset($fields[$k]);
continue;
}
if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'], '<')) {
unset($fields[$k]);
continue;
}
if ($strictly_active) {
if (!empty($v['data']['disabled']) || !empty($v['data']['disabled_by_type'])) {
unset($fields[$k]);
continue;
}
} else {
if ($only_active && !empty($v['data']['disabled'])) {
unset($fields[$k]);
continue;
}
if (!$disabled_by_type && !empty($v['data']['disabled_by_type'])) {
unset($fields[$k]);
continue;
}
}
$v['id'] = $k;
$v['meta_key'] = wpcf_types_get_meta_prefix($v) . $k;
$option_name_to_meta_type = array('wpcf-fields' => 'postmeta', 'wpcf-usermeta' => 'usermeta', WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION => 'termmeta');
$v['meta_type'] = $option_name_to_meta_type[$option_name];
$fields[$k] = wpcf_sanitize_field($v);
}
$cache[$cache_key] = apply_filters('types_fields', $fields);
return $cache[$cache_key];
}
示例8: wpcf_admin_import_data_from_xmlstring
//.........这里部分代码省略.........
if ($context == 'types' || $context == 'modman') {
if (!isset($_POST['items']['groups']['__fields__' . $field['slug']])) {
continue;
}
}
if (isset($field['add']) && !$field['add'] && !$overwrite_fields) {
continue;
}
if (empty($field['id']) || empty($field['name']) || empty($field['slug'])) {
continue;
}
$_new_field = !isset($fields_existing[$field_id]);
if ($_new_field) {
$result['new'] += 1;
} else {
$_checksum = $wpcf->import->checksum('field', $fields_existing[$field_id]['slug'], $field['checksum']);
if (!$_checksum) {
$result['updated'] += 1;
}
}
$field_data = array();
$field_data['description'] = isset($field['description']) ? $field['description'] : '';
$field_data['data'] = isset($field['data']) && is_array($field['data']) ? $field['data'] : array();
foreach (array('id', 'name', 'type', 'slug', 'meta_key', 'meta_type') as $key) {
if (array_key_exists($key, $field)) {
$field_data[$key] = $field[$key];
}
}
$fields_existing[$field_id] = $field_data;
$fields_check[] = $field_id;
// WPML
global $iclTranslationManagement;
if (!empty($iclTranslationManagement) && isset($field['wpml_action'])) {
$iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id] = $field['wpml_action'];
$iclTranslationManagement->save_settings();
}
}
update_option('wpcf-fields', $fields_existing);
}
}
// Process types
if (!empty($data->types) && 'types' == $_type) {
$imported = true;
$types_existing = get_option('wpcf-custom-types', array());
$types = array();
$types_check = array();
// Set insert data from XML
foreach ($data->types->type as $type) {
$type = (array) $type;
$type = wpcf_admin_import_export_simplexml2array($type);
// TODO 1.2.1 Remove
// $_id = wpcf_modman_get_submitted_id( _TYPES_MODULE_MANAGER_KEY_,
// $type['id'] );
$_id = strval($type['__types_id']);
// If Types check if exists in $_POST
if ($context == 'types' || $context == 'modman') {
if (!isset($_POST['items']['types'][$_id])) {
continue;
}
}
$types[$_id] = $type;
}
// Insert types
foreach ($types as $type_id => $type) {
if (isset($type['add']) && !$type['add']) {
continue;
示例9: types_render_usermeta
//.........这里部分代码省略.........
//Get current logged user
$user_id = $current_user_id;
} else {
//If empty get post author, if no post, return empty
if (!empty($post_id)) {
$user_id = $post->post_author;
} else {
return;
}
}
}
}
}
if (empty($user_id)) {
return;
}
// Get field
$field = types_get_field($field_id, 'usermeta');
// If field not found return empty string
if (empty($field)) {
// Log
if (!function_exists('wplogger')) {
require_once WPCF_EMBEDDED_TOOLSET_ABSPATH . '/toolset-common/wplogger.php';
}
global $wplogger;
$wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG);
return '';
}
// See if repetitive
if (wpcf_admin_is_repetitive($field)) {
$wpcf->usermeta_repeater->set($user_id, $field);
$_meta = $wpcf->usermeta_repeater->_get_meta();
$meta = '';
if (isset($_meta['custom_order'])) {
$meta = $_meta['custom_order'];
}
if (count($meta) == 1) {
$meta_id = key($meta);
$_temp = array_shift($meta);
if (strval($_temp) == '') {
return '';
} else {
$params['field_value'] = $_temp;
return types_render_field_single($field, $params, $content, $code, $meta_id);
}
} else {
if (!empty($meta)) {
$output = '';
if (isset($params['index'])) {
$index = $params['index'];
} else {
$index = '';
}
// Allow wpv-for-each shortcode to set the index
$index = apply_filters('wpv-for-each-index', $index);
if ($index === '') {
$output = array();
foreach ($meta as $temp_key => $temp_value) {
$params['field_value'] = $temp_value;
$temp_output = types_render_field_single($field, $params, $content, $code, $temp_key);
if (!empty($temp_output)) {
$output[] = $temp_output;
}
}
if (!empty($output) && isset($params['separator'])) {
$output = implode(html_entity_decode($params['separator']), $output);
} else {
if (!empty($output)) {
$output = implode('', $output);
} else {
return '';
}
}
} else {
// Make sure indexed right
$_index = 0;
foreach ($meta as $temp_key => $temp_value) {
if ($_index == $index) {
$params['field_value'] = $temp_value;
$output = types_render_field_single($field, $params, $content, $code, $temp_key);
}
$_index++;
}
}
$html = $output;
} else {
return '';
}
}
} else {
$params['field_value'] = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
if ($params['field_value'] == '' && $field['type'] != 'checkbox') {
return '';
}
$html = types_render_field_single($field, $params, $content, $code);
}
// API filter
$wpcf->usermeta_field->set($user_id, $field);
return $wpcf->usermeta_field->html($html, $params);
}
示例10: types_render_usermeta_field
//.........这里部分代码省略.........
//Get user by login
$user_id = $wpdb->get_var("SELECT * FROM " . $wpdb->prefix . "users WHERE user_login = '" . $params['user_name'] . "'", 0, 0);
} else {
if (isset($params['user_is_author'])) {
//Get Post author
$user_id = $post->post_author;
} else {
if (isset($params['user_current'])) {
//Get current logged user
$user_id = wpcf_usermeta_get_user();
} else {
//If empty get post author, if no post, return empty
if (!empty($post_id)) {
$user_id = $post->post_author;
} else {
return;
}
}
}
}
}
if (empty($user_id)) {
return;
}
// Set field
$wpcf->usermeta_field->set($user_id, $field);
// See if repetitive
if (wpcf_admin_is_repetitive($field)) {
$wpcf->usermeta_repeater->set($user_id, $field);
$_meta = $wpcf->usermeta_repeater->_get_meta();
$meta = $_meta['custom_order'];
// $meta = get_post_meta( $post_id,
// wpcf_types_get_meta_prefix( $field ) . $field['slug'], false );
// Sometimes if meta is empty - array(0 => '') is returned
if (count($meta) == 1) {
$meta_id = key($meta);
$_temp = array_shift($meta);
if (strval($_temp) == '') {
return '';
} else {
$params['field_value'] = $_temp;
return types_render_field_single($field, $params, $content, $code, $meta_id);
}
} else {
if (!empty($meta)) {
$output = '';
if (isset($params['index'])) {
$index = $params['index'];
} else {
$index = '';
}
// Allow wpv-for-each shortcode to set the index
$index = apply_filters('wpv-for-each-index', $index);
if ($index === '') {
$output = array();
foreach ($meta as $temp_key => $temp_value) {
$params['field_value'] = $temp_value;
$temp_output = types_render_field_single($field, $params, $content, $code, $temp_key);
if (!empty($temp_output)) {
$output[] = $temp_output;
}
}
if (!empty($output) && isset($params['separator'])) {
$output = implode(html_entity_decode($params['separator']), $output);
} else {
if (!empty($output)) {
$output = implode('', $output);
} else {
return '';
}
}
} else {
// Make sure indexed right
$_index = 0;
foreach ($meta as $temp_key => $temp_value) {
if ($_index == $index) {
$params['field_value'] = $temp_value;
return types_render_field_single($field, $params, $content, $code, $temp_key);
}
$_index++;
}
// If missed index
return '';
}
$html = $output;
} else {
return '';
}
}
} else {
$params['field_value'] = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
if ($params['field_value'] == '' && $field['type'] != 'checkbox') {
return '';
}
$html = types_render_field_single($field, $params, $content, $code, $wpcf->usermeta_field->meta_object->umeta_id);
}
// API filter
// $wpcf->usermeta_field->set( $user_id, $field );
return $wpcf->usermeta_field->html($html, $params);
}
示例11: types_meta_prefix
/**
* Returns meta prefix.
*
* @param array $field
*/
function types_meta_prefix($field = array())
{
return wpcf_types_get_meta_prefix($field);
}
示例12: wpcf_admin_fields_delete_field
/**
* Deletes field.
*
* @param type $field_id
*/
function wpcf_admin_fields_delete_field($field_id)
{
global $wpdb;
$fields = get_option('wpcf-fields', array());
if (isset($fields[$field_id])) {
// Remove from groups
$groups = wpcf_admin_fields_get_groups();
foreach ($groups as $key => $group) {
wpcf_admin_fields_remove_field_from_group($group['id'], $field_id);
}
// Remove from posts
if (!wpcf_types_cf_under_control('check_outsider', $field_id)) {
$results = $wpdb->get_results("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE meta_key = '" . wpcf_types_get_meta_prefix($fields[$field_id]) . strval($field_id) . "'");
foreach ($results as $result) {
delete_post_meta($result->post_id, $result->meta_key);
}
}
unset($fields[$field_id]);
wpcf_admin_fields_save_fields($fields, true);
return true;
} else {
return false;
}
}
示例13: _wpv_initialize_url_param_controls
/**
* Initialize any url param controls that haven't been set already
* This is for Views that were created before we had front end filters.
*
*/
function _wpv_initialize_url_param_controls($view_settings)
{
if (function_exists('wpcf_admin_fields_get_fields')) {
$fields = wpcf_admin_fields_get_fields();
} else {
$fields = array();
}
if (!isset($view_settings['filter_controls_param'])) {
$view_settings['filter_controls_field_name'] = array();
$view_settings['filter_controls_param'] = array();
$view_settings['filter_controls_enable'] = array();
$view_settings['filter_controls_label'] = array();
$view_settings['filter_controls_values'] = array();
$view_settings['filter_controls_type'] = array();
$view_settings['filter_controls_mode'] = array();
}
$url_params = wpv_custom_fields_get_url_params($view_settings);
$url_params = array_merge($url_params, wpv_taxonomy_get_url_params($view_settings));
$search_param = wpv_search_get_url_params($view_settings);
$url_params = array_merge($url_params, $search_param);
foreach ($url_params as $url_param) {
// see if it's already set
$exists = false;
foreach ($view_settings['filter_controls_param'] as $param) {
if ($param == $url_param['param']) {
$exists = true;
break;
}
}
if (!$exists) {
// Doesn't exist so we add the control.
$view_settings['filter_controls_field_name'][] = $url_param['name'];
$view_settings['filter_controls_param'][] = $url_param['param'];
$view_settings['filter_controls_enable'][] = 0;
$label = $url_param['param'];
$type = 'text';
switch ($url_param['mode']) {
case 'cf':
foreach ($fields as $field) {
if ($url_param['name'] == wpcf_types_get_meta_prefix($field) . $field['slug']) {
$label = $field['name'];
$type = 'types-auto';
break;
}
}
break;
case 'tax':
$label = $url_param['cat']->labels->name;
break;
case 'search':
$label = $url_param['name'];
break;
}
$view_settings['filter_controls_label'][] = $label;
$view_settings['filter_controls_values'][] = '';
$view_settings['filter_controls_type'][] = $type;
$view_settings['filter_controls_mode'][] = $url_param['mode'];
}
}
return $view_settings;
}
示例14: wpcf_admin_import_data
//.........这里部分代码省略.........
}
}
// Set insert data from POST
if (!empty($_POST['fields'])) {
foreach ($_POST['fields'] as $field_id => $field) {
if (empty($fields[$field_id])) {
continue;
}
$fields[$field_id]['add'] = !empty($field['add']);
$fields[$field_id]['update'] = isset($field['update']) && $field['update'] == 'update' ? true : false;
}
}
// Insert fields
foreach ($fields as $field_id => $field) {
if (isset($field['add']) && !$field['add'] && !$overwrite_fields) {
continue;
}
if (empty($field['id']) || empty($field['name']) || empty($field['slug'])) {
continue;
}
$field_data = array();
$field_data['description'] = isset($field['description']) ? $field['description'] : '';
$field_data['data'] = isset($field['data']) && is_array($field['data']) ? $field['data'] : array();
foreach (array('id', 'name', 'type', 'slug', 'meta_key', 'meta_type') as $key) {
if (array_key_exists($key, $field)) {
$field_data[$key] = $field[$key];
}
}
$fields_existing[$field_id] = $field_data;
$fields_check[] = $field_id;
// WPML
global $iclTranslationManagement;
if (!empty($iclTranslationManagement) && isset($field['wpml_action'])) {
$iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id] = $field['wpml_action'];
$iclTranslationManagement->save_settings();
}
wpcf_admin_message_store(sprintf(__('Field "%s" added/updated', 'wpcf'), $field['name']));
}
}
// Delete fields
if ($delete_fields) {
foreach ($fields_existing as $k => $v) {
if (!empty($v['data']['controlled'])) {
continue;
}
if (!in_array($k, $fields_check)) {
wpcf_admin_message_store(sprintf(__('Field "%s" deleted', 'wpcf'), $fields_existing[$k]['name']));
unset($fields_existing[$k]);
}
}
} else {
if (!empty($_POST['fields-to-be-deleted'])) {
foreach ($_POST['fields-to-be-deleted'] as $field_to_delete) {
wpcf_admin_message_store(sprintf(__('Field "%s" deleted', 'wpcf'), $fields_existing[$field_to_delete]['name']));
unset($fields_existing[$field_to_delete]);
}
}
}
update_option('wpcf-fields', $fields_existing);
// Process user groups
//print_r($data->user_groups);exit;
$groups_check = array();
if (!empty($data->user_groups) && isset($data->user_groups->group)) {
$groups = array();
// Set insert data from XML
foreach ($data->user_groups->group as $group) {
示例15: wpcf_admin_fields_checkboxes_migrate_empty
/**
* Update posts checkboxes fields.
*
* @param type $field
* @param type $action
* @return boolean|int
*/
function wpcf_admin_fields_checkboxes_migrate_empty($field, $action)
{
$field = wpcf_admin_fields_get_field($field);
if (empty($field) || $field['type'] != 'checkboxes' || empty($field['data']['options'])) {
return false;
}
$option = get_option('wpcf_checkboxes_migration', array());
$meta_key = wpcf_types_get_meta_prefix($field) . $field['id'];
if (empty($option[$action])) {
$posts = wpcf_admin_fields_checkboxes_migrate_empty_check($field['id'], $action . '_check');
} else {
$posts = $option[$action];
}
if (!empty($posts)) {
if ($action == 'do_not_save') {
$count = 0;
foreach ($posts as $temp_key => $post_id) {
if ($count == 1000) {
$option[$action] = $posts;
update_option('wpcf_checkboxes_migration', $option);
$data = array('offset' => $temp_key);
return $data;
}
$meta_saved = get_post_meta($post_id, $meta_key);
if (!empty($meta_saved)) {
foreach ($meta_saved as $key => $value) {
if (!is_array($value)) {
$value_check = array();
} else {
$value_check = $value;
}
foreach ($field['data']['options'] as $option_id => $option_data) {
if (isset($value_check[$option_id])) {
unset($value_check[$option_id]);
}
}
update_post_meta($post_id, $meta_key, $value_check, $value);
}
}
unset($posts[$temp_key]);
$count++;
}
unset($option[$action]);
update_option('wpcf_checkboxes_migration', $option);
return $posts;
} else {
if ($action == 'save') {
$count = 0;
foreach ($posts as $temp_key => $post_id) {
if ($count == 1000) {
$option[$action] = $posts;
update_option('wpcf_checkboxes_migration', $option);
$data = array('offset' => $temp_key);
return $data;
}
$meta_saved = get_post_meta($post_id, $meta_key);
if (!empty($meta_saved)) {
foreach ($meta_saved as $key => $value) {
if (!is_array($value)) {
$value_check = array();
} else {
$value_check = $value;
}
$set_value = array();
foreach ($field['data']['options'] as $option_id => $option_data) {
if (!isset($value_check[$option_id])) {
$set_value[$option_id] = 0;
}
}
$updated_value = $value_check + $set_value;
update_post_meta($post_id, $meta_key, $updated_value, $value);
}
}
unset($posts[$temp_key]);
$count++;
}
unset($option[$action]);
update_option('wpcf_checkboxes_migration', $option);
return $posts;
}
}
}
return false;
}