本文整理汇总了PHP中types_get_field函数的典型用法代码示例。如果您正苦于以下问题:PHP types_get_field函数的具体用法?PHP types_get_field怎么用?PHP types_get_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了types_get_field函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_ajax_embedded
/**
* All AJAX calls go here.
*
* @todo auth
*/
function wpcf_ajax_embedded()
{
if (isset($_REQUEST['_typesnonce'])) {
if (!wp_verify_nonce($_REQUEST['_typesnonce'], '_typesnonce')) {
die('Verification failed (1)');
}
} else {
if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action'])) {
die('Verification failed (2)');
}
}
global $wpcf;
switch ($_REQUEST['wpcf_action']) {
case 'insert_skype_button':
if (!current_user_can('edit_posts')) {
die('Authentication failed');
}
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/skype.php';
wpcf_fields_skype_meta_box_ajax();
break;
case 'editor_callback':
if (!current_user_can('edit_posts')) {
die('Authentication failed');
}
// Determine Field type and context
$views_meta = false;
$field_id = sanitize_text_field($_GET['field_id']);
// todo this could be written in like four lines
if (isset($_GET['field_type']) && $_GET['field_type'] == 'usermeta') {
// Group filter
wp_enqueue_script('suggest');
$field = types_get_field($field_id, 'usermeta');
$meta_type = 'usermeta';
} elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'views-usermeta') {
$field = types_get_field($field_id, 'usermeta');
$meta_type = 'usermeta';
$views_meta = true;
} elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'termmeta') {
// Group filter
wp_enqueue_script('suggest');
$field = types_get_field($field_id, 'termmeta');
$meta_type = 'termmeta';
} elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'views-termmeta') {
$field = types_get_field($field_id, 'termmeta');
$meta_type = 'termmeta';
$views_meta = true;
} else {
$field = types_get_field($field_id);
$meta_type = 'postmeta';
}
$parent_post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : null;
$shortcode = isset($_GET['shortcode']) ? urldecode($_GET['shortcode']) : null;
$callback = isset($_GET['callback']) ? sanitize_text_field($_GET['callback']) : false;
if (!empty($field)) {
// Editor
WPCF_Loader::loadClass('editor');
$editor = new WPCF_Editor();
$editor->frame($field, $meta_type, $parent_post_id, $shortcode, $callback, $views_meta);
}
break;
case 'dismiss_message':
if (!is_user_logged_in()) {
die('Authentication failed');
}
if (isset($_GET['id'])) {
$messages = get_option('wpcf_dismissed_messages', array());
$messages[] = sanitize_text_field($_GET['id']);
update_option('wpcf_dismissed_messages', $messages);
}
break;
case 'pr_add_child_post':
global $current_user;
$output = '<tr>' . __('Passed wrong parameters', 'wpcf') . '</tr>';
$id = 0;
$target_post_type = isset($_GET['post_type_child']) ? sanitize_text_field($_GET['post_type_child']) : '';
$has_permissions = current_user_can('publish_posts');
$has_permissions = apply_filters('toolset_access_api_get_post_type_permissions', $has_permissions, $target_post_type, 'publish');
if (!$has_permissions) {
$output = '<tr><td>' . __('You do not have rights to create new items', 'wpcf') . '</td></tr>';
} else {
if (isset($_GET['post_id']) && isset($_GET['post_type_child']) && isset($_GET['post_type_parent'])) {
$relationships = get_option('wpcf_post_relationship', array());
$parent_post_id = intval($_GET['post_id']);
$parent_post = get_post($parent_post_id);
if (!empty($parent_post->ID)) {
$post_type = sanitize_text_field($_GET['post_type_child']);
$parent_post_type = sanitize_text_field($_GET['post_type_parent']);
// @todo isset & error handling
$data = $relationships[$parent_post_type][$post_type];
/*
* Since Types 1.1.5
*
* We save new post
* CHECKPOINT
*/
//.........这里部分代码省略.........
示例3: set
/**
* Set current post and field.
*
* @param type $post
* @param type $cf
*/
function set($term_id, $cf)
{
global $wpcf;
/*
*
* Check if $cf is string
*/
if (is_string($cf)) {
WPCF_Loader::loadInclude('fields');
$cf = types_get_field($this->__get_slug_no_prefix($cf), 'termmeta');
if (empty($cf)) {
$this->_reset();
return false;
}
}
$this->term_id = $term_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_render_usermeta
/**
* Calls view function for specific usermeta field type.
*
* @global object $wpdb
*
* @param type $field
* @param type $atts (additional attributes: user_id, user_name, user_is_author, user_current)
* @return type
*/
function types_render_usermeta($field_id, $params, $content = null, $code = '')
{
global $wpcf, $post, $wpdb, $WP_Views;
// HTML var holds actual output
$html = '';
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
// Set post ID
// user_id, user_name, user_is_author, user_current
if (is_object($post)) {
$post_id = $post->ID;
} else {
$post_id = 0;
}
if (isset($params['post_id']) && !empty($params['post_id'])) {
$post_id = $params['post_id'];
}
//Get User id from views loop
if (isset($WP_Views->users_data['term']->ID) && !empty($WP_Views->users_data['term']->ID)) {
$params['user_id'] = $WP_Views->users_data['term']->ID;
}
//print_r($params);exit;
//Get user By ID
if (isset($params['user_id'])) {
$user_id = $params['user_id'];
} else {
if (isset($params['user_name'])) {
//Get user by login
$user_id = $wpdb->get_var($wpdb->prepare("SELECT * FROM " . $wpdb->users . " WHERE user_login = %s", $params['user_name']));
} 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 = $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 === '') {
//.........这里部分代码省略.........
示例5: wpcf_conditional_evaluate
/**
* Used for processing conditional statements.
*
* Wrapper for wpcf_cd_post_edit_field_filter()
* core function.
*
* @param type $element
* @param type $field
* @param type $post
* @param string $context
* @return type
*/
function wpcf_conditional_evaluate($post = null, $field)
{
// Set post
if (is_null($post)) {
global $post;
} else {
$post = get_post($post);
}
if (empty($post->ID)) {
return NULL;
}
// Get field
if (!is_array($field)) {
$field = types_get_field($field);
if (empty($field)) {
return NULL;
}
}
global $wpcf;
$e = clone $wpcf->conditional;
$e->set($post, $field);
return $e->evaluate();
}
示例6: wpcf_ajax_embedded
/**
* All AJAX calls go here.
*
* @todo auth
*/
function wpcf_ajax_embedded()
{
if (isset($_REQUEST['_typesnonce'])) {
if (!wp_verify_nonce($_REQUEST['_typesnonce'], '_typesnonce')) {
die('Verification failed');
}
} else {
if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action'])) {
die('Verification failed');
}
}
global $wpcf;
switch ($_REQUEST['wpcf_action']) {
case 'insert_skype_button':
if (!current_user_can('edit_posts')) {
die('Authentication failed');
}
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/skype.php';
wpcf_fields_skype_meta_box_ajax();
break;
case 'editor_callback':
if (!current_user_can('edit_posts')) {
die('Authentication failed');
}
// Determine Field type and context
$views_usermeta = false;
$field_id = sanitize_text_field($_GET['field_id']);
// todo this could be written in like four lines
if (isset($_GET['field_type']) && $_GET['field_type'] == 'usermeta') {
// Group filter
wp_enqueue_script('suggest');
$field = types_get_field($field_id, 'usermeta');
$meta_type = 'usermeta';
} elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'views-usermeta') {
$field = types_get_field($field_id, 'usermeta');
$meta_type = 'usermeta';
$views_usermeta = true;
} else {
$field = types_get_field($field_id);
$meta_type = 'postmeta';
}
$parent_post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : null;
$shortcode = isset($_GET['shortcode']) ? urldecode($_GET['shortcode']) : null;
$callback = isset($_GET['callback']) ? sanitize_text_field($_GET['callback']) : false;
if (!empty($field)) {
// Editor
WPCF_Loader::loadClass('editor');
$editor = new WPCF_Editor();
$editor->frame($field, $meta_type, $parent_post_id, $shortcode, $callback, $views_usermeta);
}
break;
case 'dismiss_message':
if (!is_user_logged_in()) {
die('Authentication failed');
}
if (isset($_GET['id'])) {
$messages = get_option('wpcf_dismissed_messages', array());
$messages[] = sanitize_text_field($_GET['id']);
update_option('wpcf_dismissed_messages', $messages);
}
break;
case 'pr_add_child_post':
$output = 'Passed wrong parameters';
if (current_user_can('edit_posts') && isset($_GET['post_id']) && isset($_GET['post_type_child']) && isset($_GET['post_type_parent'])) {
$relationships = get_option('wpcf_post_relationship', array());
$parent_post_id = intval($_GET['post_id']);
$parent_post = get_post($parent_post_id);
if (!empty($parent_post->ID)) {
$post_type = sanitize_text_field($_GET['post_type_child']);
$parent_post_type = sanitize_text_field($_GET['post_type_parent']);
// @todo isset & error handling
$data = $relationships[$parent_post_type][$post_type];
/*
* Since Types 1.1.5
*
* We save new post
* CHECKPOINT
*/
$id = $wpcf->relationship->add_new_child($parent_post->ID, $post_type);
if (is_wp_error($id)) {
$output = $id->get_error_message();
} else {
/*
* Here we set Relationship
* CHECKPOINT
*/
$parent = get_post($parent_post_id);
$child = get_post($id);
if (!empty($parent->ID) && !empty($child->ID)) {
// Set post
$wpcf->post = $child;
// Set relationship :)
$wpcf->relationship->_set($parent, $child, $data);
// Render new row
$output = $wpcf->relationship->child_row($parent_post->ID, $id, $data);
//.........这里部分代码省略.........
示例7: types_render_field
/**
* Calls view function for specific field type.
*
* @param type $field
* @param type $atts
* @return type
*/
function types_render_field($field_id = null, $params = array(), $content = null, $code = '')
{
if (empty($field_id)) {
return '';
}
global $wpcf;
// HTML var holds actual output
$html = '';
// Set post ID to global
$post_id = get_the_ID();
// Check if other post required
if (isset($params['post_id'])) {
// If numeric value
if (is_numeric($params['post_id'])) {
$post_id = intval($params['post_id']);
// WP parent
} else {
if ($params['post_id'] == '$parent') {
$current_post = get_post($post_id);
if (empty($current_post->post_parent)) {
return '';
}
$post_id = $current_post->post_parent;
// Types parent
} else {
if (strpos($params['post_id'], '$') === 0) {
$post_id = intval(WPCF_Relationship::get_parent($post_id, trim($params['post_id'], '$')));
}
}
}
}
if (empty($post_id)) {
return '';
}
// Set post
$post = get_post($post_id);
if (empty($post)) {
return '';
}
// Get field
$field = types_get_field($field_id);
// If field not found return empty string
if (empty($field)) {
// Log
if (!function_exists('wplogger')) {
require_once WPCF_EMBEDDED_ABSPATH . '/common/wplogger.php';
}
global $wplogger;
$wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG);
return '';
}
// Set field
$wpcf->field->set($post, $field);
// See if repetitive
if (types_is_repetitive($field)) {
$wpcf->repeater->set($post_id, $field);
$_meta = $wpcf->repeater->_get_meta();
$meta = $_meta['custom_order'];
// Sometimes if meta is empty - array(0 => '') is returned
if (count($meta) == 1 && reset($meta) == '') {
return '';
}
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']) && $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) {
//.........这里部分代码省略.........