本文整理汇总了PHP中wpcf_fields_type_action函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_fields_type_action函数的具体用法?PHP wpcf_fields_type_action怎么用?PHP wpcf_fields_type_action使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_fields_type_action函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: types_get_field_type
/**
* Returns meta_key type for specific field type.
*
* @param type $type
* @return type
*/
function types_get_field_type($type)
{
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
$data = wpcf_fields_type_action($type);
if (!empty($data['meta_key_type'])) {
return $data['meta_key_type'];
}
return 'CHAR';
}
示例2: wpcf_fields_get_field_form_data
/**
* Processes field form data.
*
* @param type $type
* @param type $form_data
* @return type
*/
function wpcf_fields_get_field_form_data($type, $form_data = array())
{
// Get field type data
$field_data = wpcf_fields_type_action($type);
if (!empty($field_data)) {
// require_once $filename;
$form = array();
// Set right ID if existing field
if (isset($form_data['submitted_key'])) {
$id = $form_data['submitted_key'];
} else {
$id = $type . '-' . rand();
}
// Set remove link
$remove_link = isset($form_data['group_id']) ? admin_url('admin-ajax.php?' . 'wpcf_ajax_callback=wpcfFieldsFormDeleteElement&wpcf_warning=' . __('Are you sure?', 'wpcf') . '&action=wpcf_ajax&wpcf_action=remove_field_from_group' . '&group_id=' . intval($form_data['group_id']) . '&field_id=' . $form_data['id']) . '&_wpnonce=' . wp_create_nonce('remove_field_from_group') : admin_url('admin-ajax.php?' . 'wpcf_ajax_callback=wpcfFieldsFormDeleteElement&wpcf_warning=' . __('Are you sure?', 'wpcf') . '&action=wpcf_ajax&wpcf_action=remove_field_from_group') . '&_wpnonce=' . wp_create_nonce('remove_field_from_group');
// Set move button
$form['wpcf-' . $id . '-control'] = array('#type' => 'markup', '#markup' => '<img src="' . WPCF_RES_RELPATH . '/images/move.png" class="wpcf-fields-form-move-field" alt="' . __('Move this field', 'wpcf') . '" /><a href="' . $remove_link . '" ' . 'class="wpcf-form-fields-delete wpcf-ajax-link">' . '<img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" alt="' . __('Delete this field', 'wpcf') . '" /></a>');
// Set fieldset
$collapsed = wpcf_admin_fields_form_fieldset_is_collapsed('fieldset-' . $id);
// Set collapsed on AJAX call (insert)
$collapsed = defined('DOING_AJAX') ? false : $collapsed;
// Set title
$title = !empty($form_data['name']) ? $form_data['name'] : __('Untitled', 'wpcf');
$title = '<span class="wpcf-legend-update">' . $title . '</span> - ' . sprintf(__('%s field', 'wpcf'), $field_data['title']);
$form['wpcf-' . $id] = array('#type' => 'fieldset', '#title' => $title, '#id' => 'fieldset-' . $id, '#collapsible' => true, '#collapsed' => $collapsed);
// Get init data
$field_init_data = wpcf_fields_type_action($type);
// See if field inherits some other
$inherited_field_data = false;
if (isset($field_init_data['inherited_field_type'])) {
$inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
}
$form_field = array();
// Force name and description
$form_field['name'] = array('#type' => 'textfield', '#name' => 'name', '#attributes' => array('class' => 'wpcf-forms-set-legend', 'style' => 'width:100%;margin:10px 0 10px 0;'), '#validate' => array('required' => array('value' => true)), '#inline' => true, '#value' => __('Enter field name', 'wpcf'));
if (empty($form_data['name'])) {
$form_field['name']['#attributes']['onclick'] = 'if (jQuery(this).val() == \'' . __('Enter field name', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
$form_field['name']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter field name', 'wpcf') . '\') }';
}
$form_field['slug'] = array('#type' => 'textfield', '#name' => 'slug', '#attributes' => array('style' => 'width:100%;margin:0 0 10px 0;'), '#validate' => array('nospecialchars' => array('value' => true)), '#inline' => true, '#value' => __('Enter field slug', 'wpcf'));
if (empty($form_data['slug'])) {
$form_field['slug']['#attributes']['onclick'] = 'if (jQuery(this).val() == \'' . __('Enter field slug', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
$form_field['slug']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter field slug', 'wpcf') . '\') }';
}
// If insert form callback is not provided, use generic form data
if (function_exists('wpcf_fields_' . $type . '_insert_form')) {
$form_field_temp = call_user_func('wpcf_fields_' . $type . '_insert_form', $form_data, 'wpcf[fields][' . $id . ']');
if (is_array($form_field_temp)) {
unset($form_field_temp['name'], $form_field_temp['slug']);
$form_field = $form_field + $form_field_temp;
}
}
$form_field['description'] = array('#type' => 'textarea', '#name' => 'description', '#attributes' => array('rows' => 5, 'cols' => 1, 'style' => 'margin:0 0 10px 0;'), '#inline' => true, '#value' => __('Describe this field', 'wpcf'));
if (empty($form_data['description'])) {
$form_field['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Describe this field', 'wpcf') . '\') { jQuery(this).val(\'\'); }';
$form_field['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Describe this field', 'wpcf') . '\') }';
}
// Process all form fields
foreach ($form_field as $k => $field) {
$form['wpcf-' . $id][$k] = $field;
// Check if nested
if (isset($field['#name']) && strpos($field['#name'], '[') === false) {
$form['wpcf-' . $id][$k]['#name'] = 'wpcf[fields][' . $id . '][' . $field['#name'] . ']';
} else {
if (isset($field['#name'])) {
$form['wpcf-' . $id][$k]['#name'] = 'wpcf[fields][' . $id . ']' . $field['#name'];
}
}
if (!isset($field['#id'])) {
$form['wpcf-' . $id][$k]['#id'] = $type . '-' . $field['#type'] . '-' . rand();
}
if (isset($field['#name']) && isset($form_data[$field['#name']])) {
$form['wpcf-' . $id][$k]['#value'] = $form_data[$field['#name']];
$form['wpcf-' . $id][$k]['#default_value'] = $form_data[$field['#name']];
// Check if it's in 'data'
} else {
if (isset($field['#name']) && isset($form_data['data'][$field['#name']])) {
$form['wpcf-' . $id][$k]['#value'] = $form_data['data'][$field['#name']];
$form['wpcf-' . $id][$k]['#default_value'] = $form_data['data'][$field['#name']];
}
}
}
// Set type
$form['wpcf-' . $id]['type'] = array('#type' => 'hidden', '#name' => 'wpcf[fields][' . $id . '][type]', '#value' => $type, '#id' => $id . '-type');
// Add validation box
$form_validate = wpcf_admin_fields_form_validation('wpcf[fields][' . $id . '][validate]', call_user_func('wpcf_fields_' . $type), $form_data);
foreach ($form_validate as $k => $v) {
$form['wpcf-' . $id][$k] = $v;
}
// WPML Translation Preferences
if (function_exists('wpml_cf_translation_preferences')) {
$custom_field = !empty($form_data['slug']) ? wpcf_types_get_meta_prefix($form_data) . $form_data['slug'] : false;
$translatable = array('textfield', 'textarea', 'wysiwyg');
//.........这里部分代码省略.........
示例3: wpcf_admin_post_add_usermeta_to_editor_js
/**
* Add User Fields to editor
*
* @author Gen gen.i@icanlocalize.com
* @since Types 1.3
*/
function wpcf_admin_post_add_usermeta_to_editor_js($items, $views_callback = false)
{
global $wpcf;
$post = wpcf_admin_get_edited_post();
if (empty($post)) {
$post = (object) array('ID' => -1);
}
$groups = wpcf_admin_fields_get_groups('wp-types-user-group');
$user_id = wpcf_usermeta_get_user();
$add = array();
if (!empty($groups)) {
$item_styles = array();
foreach ($groups as $group_id => $group) {
if (empty($group['is_active'])) {
continue;
}
$group['name'] .= ' (User meta fields)';
$fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
if (!empty($fields)) {
foreach ($fields as $field_id => $field) {
// Use field class
$wpcf->usermeta_field->set($user_id, $field);
// Get field data
$data = (array) $wpcf->usermeta_field->config;
// Get inherited field
if (isset($data['inherited_field_type'])) {
$inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
}
$callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'usermeta\', ' . $post->ID . ')';
// Added for Views:users filter Vicon popup
if ($views_callback) {
$callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', ' . $post->ID . ')';
}
$add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_usermeta_get_shortcode($field), '[]'), $group['name'], $callback);
}
/*
* Since Types 1.2
* We use field class to enqueue JS and CSS
*/
$wpcf->usermeta_field->enqueue_script();
$wpcf->usermeta_field->enqueue_style();
}
}
}
$items = $items + $add;
return $items;
}
示例4: get_field_form_data
/**
* @param $type
* @param array $form_data
*
* @return array
*/
protected function get_field_form_data($type, $form_data = array())
{
/**
* this function replace: wpcf_fields_get_field_form_data()
*/
require_once WPCF_ABSPATH . '/includes/conditional-display.php';
$form = array();
/**
* row fir field data
*/
$table_row_typeproof = '<tr class="js-wpcf-fields-typeproof"><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
$table_row = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
// Get field type data
if (empty($field_data)) {
$field_data = wpcf_fields_type_action($type);
if (empty($field_data)) {
return $form;
}
}
// Set right ID if existing field
if (isset($form_data['submitted_key'])) {
$id = $form_data['submitted_key'];
} else {
$id = $type . '-' . rand();
}
// Sanitize
$form_data = wpcf_sanitize_field($form_data);
$required = isset($form_data['data']['validate']['required']['active']) && $form_data['data']['validate']['required']['active'] === "1" ? __('- required', 'wpcf') : '';
$form_data['id'] = $id;
/**
* Set title
*/
$title = !empty($form_data['name']) ? $form_data['name'] : __('Untitled', 'wpcf');
$title = sprintf('<span class="wpcf-legend-update">%s</span> <span class="description">(%s)</span> <span class="wpcf_required_data">%s</span>', $title, $field_data['title'], $required);
// Get init data
$field_init_data = wpcf_fields_type_action($type);
// See if field inherits some other
$inherited_field_data = false;
if (isset($field_init_data['inherited_field_type'])) {
$inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
}
$form_field = array();
/**
* Font Awesome Icon
*/
$icon = '';
$icon = $this->render_field_icon($field_init_data);
/**
* box id & class
*/
$closed_postboxes = $this->get_closed_postboxes();
$clasess = array('postbox');
// close all elements except new added fields
if (!isset($_REQUEST['type'])) {
$clasess[] = 'closed';
}
$box_id = sprintf('types-custom-field-%s', $id);
/* Only close boxes which user closed manually
if ( !empty($closed_postboxes) ) {
if ( in_array($box_id, $closed_postboxes) ) {
$clasess[] = 'closed';
}
}
*/
/**
* box title
*/
$form_field['box-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="%s" class="%s"><div class="handlediv" title="%s"><br></div><h3 class="hndle ui-sortable-handle">%s%s</h3>', esc_attr($box_id), esc_attr(implode(' ', $clasess)), esc_attr__('Click to toggle', 'wpcf'), $icon, $title));
$form_field['table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat inside js-wpcf-slugize-container">');
// Force name and description
$form_field['name'] = array('#type' => 'textfield', '#name' => 'name', '#attributes' => array('class' => 'widefat wpcf-forms-set-legend wpcf-forms-field-name js-wpcf-slugize-source', 'placeholder' => __('Enter field name', 'wpcf'), 'tooltip' => __('This will be the label for the field in the post editor.', 'wpcf')), '#validate' => array('required' => array('value' => true)), '#inline' => true, '#pattern' => $table_row_typeproof, '#title' => __('Field name', 'wpcf'));
$form_field['slug'] = array('#type' => 'textfield', '#name' => 'slug', '#attributes' => array('class' => 'widefat wpcf-forms-field-slug js-wpcf-slugize', 'maxlength' => 255, 'placeholder' => __('Enter field slug', 'wpcf'), 'tooltip' => __('This is the machine name of the field.', 'wpcf')), '#validate' => array('nospecialchars' => array('value' => true)), '#inline' => true, '#pattern' => $table_row_typeproof, '#title' => __('Field slug', 'wpcf'));
// existing field
if (isset($form_data['submitted_key'])) {
$form_field['slug-pre-save'] = array('#type' => 'hidden', '#name' => 'slug-pre-save');
}
$options = $this->get_available_types($type);
if (empty($options)) {
$form_field['type'] = array('#type' => 'markup', '#markup' => wpautop($type));
} else {
$form_field['type'] = array('#type' => 'select', '#name' => 'type', '#options' => $options, '#default_value' => $type, '#description' => __('Options for this filed will be available after group save.', 'wpcf'), '#attributes' => array('class' => 'js-wpcf-fields-type', 'data-message-after-change' => esc_attr__('Field options will be available after you save this group.', 'wpcf')));
}
$form_field['type']['#title'] = __('Field type', 'wpcf');
$form_field['type']['#inline'] = true;
$form_field['type']['#pattern'] = $table_row_typeproof;
// If insert form callback is not provided, use generic form data
if (function_exists('wpcf_fields_' . $type . '_insert_form')) {
$form_field_temp = call_user_func('wpcf_fields_' . $type . '_insert_form', $form_data, 'wpcf[fields][' . $id . ']');
if (is_array($form_field_temp)) {
unset($form_field_temp['name'], $form_field_temp['slug']);
/**
* add default patter
*/
foreach ($form_field_temp as $key => $data) {
//.........这里部分代码省略.........
示例5: 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];
}
示例6: wpcf_fields_get_field_form_data
/**
* Processes field form data.
*
* @param type $type
* @param type $form_data
* @return type
*/
function wpcf_fields_get_field_form_data($type, $form_data = array())
{
// Get field type data
$field_data = wpcf_fields_type_action($type);
if (!empty($field_data)) {
$form = array();
// Set right ID if existing field
if (isset($form_data['submitted_key'])) {
$id = $form_data['submitted_key'];
} else {
$id = $type . '-' . rand();
}
// Sanitize
$form_data = wpcf_sanitize_field($form_data);
// Set remove link
$remove_link = isset($form_data['group_id']) ? admin_url('admin-ajax.php?' . 'wpcf_ajax_callback=wpcfFieldsFormDeleteElement&wpcf_warning=' . __('Are you sure?', 'wpcf') . '&action=wpcf_ajax&wpcf_action=remove_field_from_group' . '&group_id=' . intval($form_data['group_id']) . '&field_id=' . $form_data['id']) . '&_wpnonce=' . wp_create_nonce('remove_field_from_group') : admin_url('admin-ajax.php?' . 'wpcf_ajax_callback=wpcfFieldsFormDeleteElement&wpcf_warning=' . __('Are you sure?', 'wpcf') . '&action=wpcf_ajax&wpcf_action=remove_field_from_group') . '&_wpnonce=' . wp_create_nonce('remove_field_from_group');
// Set move button
$form['wpcf-' . $id . '-control'] = array('#type' => 'markup', '#markup' => '<img src="' . WPCF_RES_RELPATH . '/images/move.png" class="wpcf-fields-form-move-field" alt="' . __('Move this field', 'wpcf') . '" /><a href="' . $remove_link . '" ' . 'class="wpcf-form-fields-delete wpcf-ajax-link">' . '<img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" alt="' . __('Delete this field', 'wpcf') . '" /></a>');
// Set fieldset
$collapsed = wpcf_admin_fields_form_fieldset_is_collapsed('fieldset-' . $id);
// Set collapsed on AJAX call (insert)
$collapsed = defined('DOING_AJAX') ? false : $collapsed;
// Set title
$title = !empty($form_data['name']) ? $form_data['name'] : __('Untitled', 'wpcf');
$title = '<span class="wpcf-legend-update">' . $title . '</span> - ' . sprintf(__('%s field', 'wpcf'), $field_data['title']);
// Do not display on Usermeta Group edit screen
if (!isset($_GET['page']) || $_GET['page'] != 'wpcf-edit-usermeta') {
if (!empty($form_data['data']['conditional_display']['conditions'])) {
$title .= ' ' . __('(conditional)', 'wpcf');
}
}
$form['wpcf-' . $id] = array('#type' => 'fieldset', '#title' => $title, '#id' => 'fieldset-' . $id, '#collapsible' => true, '#collapsed' => $collapsed);
// Get init data
$field_init_data = wpcf_fields_type_action($type);
// See if field inherits some other
$inherited_field_data = false;
if (isset($field_init_data['inherited_field_type'])) {
$inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
}
$form_field = array();
// Force name and description
$form_field['name'] = array('#type' => 'textfield', '#name' => 'name', '#attributes' => array('class' => 'wpcf-forms-set-legend wpcf-forms-field-name', 'style' => 'width:100%;margin:10px 0 10px 0;', 'placeholder' => __('Enter field name', 'wpcf')), '#validate' => array('required' => array('value' => true)), '#inline' => true);
$form_field['slug'] = array('#type' => 'textfield', '#name' => 'slug', '#attributes' => array('class' => 'wpcf-forms-field-slug', 'style' => 'width:100%;margin:0 0 10px 0;', 'maxlength' => 255, 'placeholder' => __('Enter field slug', 'wpcf')), '#validate' => array('nospecialchars' => array('value' => true)), '#inline' => true);
// If insert form callback is not provided, use generic form data
if (function_exists('wpcf_fields_' . $type . '_insert_form')) {
$form_field_temp = call_user_func('wpcf_fields_' . $type . '_insert_form', $form_data, 'wpcf[fields][' . $id . ']');
if (is_array($form_field_temp)) {
unset($form_field_temp['name'], $form_field_temp['slug']);
$form_field = $form_field + $form_field_temp;
}
}
$form_field['description'] = array('#type' => 'textarea', '#name' => 'description', '#attributes' => array('rows' => 5, 'cols' => 1, 'style' => 'margin:0 0 10px 0;', 'placeholder' => __('Describe this field', 'wpcf')), '#inline' => true);
/**
* add placeholder field
*/
switch ($type) {
case 'audio':
case 'colorpicker':
case 'date':
case 'email':
case 'embed':
case 'file':
case 'image':
case 'numeric':
case 'phone':
case 'skype':
case 'textarea':
case 'textfield':
case 'url':
case 'video':
$form_field['placeholder'] = array('#type' => 'textfield', '#name' => 'placeholder', '#inline' => true, '#title' => __('Placeholder', 'wpcf'), '#attributes' => array('style' => 'width:100%;margin:0 0 10px 0;', 'placeholder' => __('Enter placeholder', 'wpcf')));
break;
}
if (wpcf_admin_can_be_repetitive($type)) {
$temp_warning_message = '';
$form_field['repetitive'] = array('#type' => 'radios', '#name' => 'repetitive', '#title' => __('Single or repeating field?', 'wpcf'), '#options' => array('repeat' => array('#title' => __('Allow multiple-instances of this field', 'wpcf'), '#value' => '1', '#attributes' => array('onclick' => 'jQuery(this).parent().parent().find(\'.wpcf-cd-warning\').hide(); jQuery(this).parent().find(\'.wpcf-cd-repetitive-warning\').show();')), 'norepeat' => array('#title' => __('This field can have only one value', 'wpcf'), '#value' => '0', '#attributes' => array('onclick' => 'jQuery(this).parent().parent().find(\'.wpcf-cd-warning\').show(); jQuery(this).parent().find(\'.wpcf-cd-repetitive-warning\').hide();'))), '#default_value' => isset($form_data['data']['repetitive']) ? $form_data['data']['repetitive'] : '0', '#after' => wpcf_admin_is_repetitive($form_data) ? '<div class="wpcf-message wpcf-cd-warning wpcf-error" style="display:none;"><p>' . __("There may be multiple instances of this field already. When you switch back to single-field mode, all values of this field will be updated when it's edited.", 'wpcf') . '</p></div>' . $temp_warning_message : $temp_warning_message);
}
// Process all form fields
foreach ($form_field as $k => $field) {
$form['wpcf-' . $id][$k] = $field;
// Check if nested
if (isset($field['#name']) && strpos($field['#name'], '[') === false) {
$form['wpcf-' . $id][$k]['#name'] = 'wpcf[fields][' . $id . '][' . $field['#name'] . ']';
} else {
if (isset($field['#name'])) {
$form['wpcf-' . $id][$k]['#name'] = 'wpcf[fields][' . $id . ']' . $field['#name'];
}
}
if (!isset($field['#id'])) {
$form['wpcf-' . $id][$k]['#id'] = $type . '-' . $field['#type'] . '-' . rand();
}
if (isset($field['#name']) && isset($form_data[$field['#name']])) {
$form['wpcf-' . $id][$k]['#value'] = $form_data[$field['#name']];
//.........这里部分代码省略.........
示例7: 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));
}
示例8: wpcf_field_enqueue_scripts
/**
* Load JS and CSS for field type.
*
* Core function. Works and stable. Do not move or change.
* If required, add hooks only.
*
* @staticvar array $cache
* @param string $type
* @return string
*/
function wpcf_field_enqueue_scripts($type)
{
global $wpcf;
static $cache = array();
$config = wpcf_fields_type_action($type);
if (!empty($config)) {
// Check if cached
if (isset($cache[$config['id']])) {
return $cache[$config['id']];
}
// Use field object
$wpcf->field->enqueue_script($config);
$wpcf->field->enqueue_style($config);
$cache[$config['id']] = $config;
return $config;
} else {
$wpcf->debug->errors['missing_type_config'][] = $type;
return array();
}
}
示例9: types_render_field_single
/**
* Calls view function for specific field type by single field.
*
* @param type $field
* @param type $atts
* @return type
*/
function types_render_field_single($field, $params, $content = null, $code = '')
{
global $post;
// Count fields (if there are duplicates)
static $count = array();
// Count it
if (!isset($count[$field['slug']])) {
$count[$field['slug']] = 1;
} else {
$count[$field['slug']] += 1;
}
// Load type
$type = wpcf_fields_type_action($field['type']);
// If 'class' or 'style' parameters are set - force HTML output
if ((!empty($params['class']) || !empty($params['style'])) && $field['type'] != 'date') {
$params['output'] = 'html';
}
// Apply filters to field value
$params['field_value'] = apply_filters('wpcf_fields_value_display', $params['field_value'], $params);
$params['field_value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_display', $params['field_value'], $params);
$params['field_value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_display', $params['field_value'], $params);
// To make sure
if (is_string($params['field_value'])) {
$params['field_value'] = addslashes(stripslashes($params['field_value']));
}
// Set values
$field['name'] = wpcf_translate('field ' . $field['id'] . ' name', $field['name']);
$params['field'] = $field;
$params['#content'] = htmlspecialchars($content);
$params['#code'] = $code;
$output = '';
if (isset($params['raw']) && $params['raw'] == 'true') {
// Skype is array
if ($field['type'] == 'skype' && isset($params['field_value']['skypename'])) {
$output = $params['field_value']['skypename'];
} else {
$output = $params['field_value'];
}
} else {
$output = wpcf_fields_type_action($field['type'], 'view', $params);
// Convert to string
if (!empty($output)) {
$output = strval($output);
}
// If no output
if (empty($output) && !empty($params['field_value'])) {
$output = wpcf_frontend_wrap_field_value($field, $params['field_value'], $params);
$output = wpcf_frontend_wrap_field($field, $output, $params);
} else {
if ($output != '__wpcf_skip_empty') {
$output = wpcf_frontend_wrap_field_value($field, $output, $params);
$output = wpcf_frontend_wrap_field($field, $output, $params);
} else {
$output = '';
}
}
// 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);
}
}
// Apply filters
$output = strval(apply_filters('types_view', $output, $params['field_value'], $field['type'], $field['slug'], $field['name'], $params));
return htmlspecialchars_decode(stripslashes($output));
}
示例10: wpcf_admin_post_editor_addon_menus_filter
/**
* Adds items to view dropdown.
*
* @param type $items
* @return type
*/
function wpcf_admin_post_editor_addon_menus_filter($items)
{
$groups = wpcf_admin_fields_get_groups();
$add = array();
if (!empty($groups)) {
// $group_id is blank therefore not equal to $group['id']
// use array for item key and CSS class
$item_styles = array();
$all_post_types = implode(' ', get_post_types(array('public' => true)));
foreach ($groups as $group_id => $group) {
$fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true);
if (!empty($fields)) {
// code from Types used here without breaking the flow
// get post types list for every group or apply all
$post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true);
if ($post_types == 'all') {
$post_types = $all_post_types;
}
$post_types = trim(str_replace(',', ' ', $post_types));
$item_styles[$group['name']] = $post_types;
foreach ($fields as $field_id => $field) {
// Get field data
$data = wpcf_fields_type_action($field['type']);
// Get inherited field
if (isset($data['inherited_field_type'])) {
$inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
}
$callback = '';
if (isset($data['editor_callback'])) {
$callback = sprintf($data['editor_callback'], $field['id']);
} else {
// Set callback if function exists
$function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
$callback = function_exists($function) ? 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\')' : '';
}
$add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback);
// Process JS
if (!empty($data['meta_box_js'])) {
foreach ($data['meta_box_js'] as $handle => $data_script) {
if (isset($data_script['inline'])) {
add_action('admin_footer', $data_script['inline']);
continue;
}
$deps = !empty($data_script['deps']) ? $data_script['deps'] : array();
wp_enqueue_script($handle, $data_script['src'], $deps, WPCF_VERSION);
}
}
// Process CSS
if (!empty($data['meta_box_css'])) {
foreach ($data['meta_box_css'] as $handle => $data_script) {
$deps = !empty($data_script['deps']) ? $data_script['deps'] : array();
if (isset($data_script['inline'])) {
add_action('admin_header', $data_script['inline']);
continue;
}
wp_enqueue_style($handle, $data_script['src'], $deps, WPCF_VERSION);
}
}
}
}
}
}
$search_key = '';
// Iterate all items to be displayed in the "V" menu
foreach ($items as $key => $item) {
if ($key == __('Basic', 'wpv-views')) {
$search_key = 'found';
continue;
}
if ($search_key == 'found') {
$search_key = $key;
}
if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) {
unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]);
}
}
if (empty($search_key) || $search_key == 'found') {
$search_key = count($items);
}
$insert_position = array_search($search_key, array_keys($items));
$part_one = array_slice($items, 0, $insert_position);
$part_two = array_slice($items, $insert_position);
$items = $part_one + $add + $part_two;
// apply CSS styles to each item based on post types
foreach ($items as $key => $value) {
if (isset($item_styles[$key])) {
$items[$key]['css'] = $item_styles[$key];
} else {
$items[$key]['css'] = $all_post_types;
}
}
return $items;
}
示例11: 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) {
$meta_conditional = !isset($group['conditional_display']) ? get_post_meta($group['id'], '_wpcf_conditional_display', true) : $group['conditional_display'];
if (!empty($meta_conditional['conditions'])) {
$group['conditional_display'] = $meta_conditional;
add_action('admin_head', 'wpcf_cd_add_group_js');
if (empty($post->ID)) {
$group['_conditional_display'] = 'failed';
continue;
}
$passed = true;
if (isset($group['conditional_display']['custom_use'])) {
if (empty($group['conditional_display']['custom'])) {
$group['_conditional_display'] = 'failed';
continue;
}
$evaluate = trim(stripslashes($group['conditional_display']['custom']));
// Check dates
$evaluate = wpv_filter_parse_date($evaluate);
// Add quotes = > < >= <= === <> !==
$strings_count = preg_match_all('/[=|==|===|<=|<==|<===|>=|>==|>===|\\!===|\\!==|\\!=|<>]\\s(?!\\$)(\\w*)[\\)|\\$|\\W]/', $evaluate, $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $temp_match) {
$temp_replace = is_numeric($temp_match) ? $temp_match : '\'' . $temp_match . '\'';
$evaluate = str_replace(' ' . $temp_match . ')', ' ' . $temp_replace . ')', $evaluate);
}
}
preg_match_all('/\\$([^\\s]*)/', $group['conditional_display']['custom'], $matches);
if (empty($matches)) {
$group['_conditional_display'] = 'failed';
continue;
}
$fields = array();
foreach ($matches[1] as $key => $field_name) {
$fields[$field_name] = wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_name)) . $field_name;
wpcf_cd_add_group_js('add', $field_name, '', '', $group['id']);
}
$fields['evaluate'] = $evaluate;
$check = wpv_condition($fields);
$passed = $check;
if (!is_bool($check)) {
$passed = false;
$group['_conditional_display'] = 'failed';
} else {
if ($check) {
$group['_conditional_display'] = 'passed';
} else {
$group['_conditional_display'] = 'failed';
}
}
} else {
$passed_all = true;
$passed_one = false;
foreach ($group['conditional_display']['conditions'] as $condition) {
// Load field
$field = wpcf_admin_fields_get_field($condition['field']);
wpcf_fields_type_action($field['type']);
wpcf_cd_add_group_js('add', $condition['field'], $condition['value'], $condition['operation'], $group['id']);
$value = get_post_meta($post->ID, wpcf_types_get_meta_prefix($condition['field']) . $condition['field'], true);
$value = apply_filters('wpcf_conditional_display_compare_meta_value', $value, $condition['field'], $condition['operation'], $key, $post);
$condition['value'] = apply_filters('wpcf_conditional_display_compare_condition_value', $condition['value'], $condition['field'], $condition['operation'], $key, $post);
$check = wpcf_cd_admin_compare($condition['operation'], $value, $condition['value']);
if (!$check) {
$passed_all = false;
} else {
$passed_one = true;
}
}
if (!$passed_all && $group['conditional_display']['relation'] == 'AND') {
$passed = false;
}
if (!$passed_one && $group['conditional_display']['relation'] == 'OR') {
$passed = false;
}
}
if (!$passed) {
$group['_conditional_display'] = 'failed';
} else {
$group['_conditional_display'] = 'passed';
}
}
}
return $groups;
}
示例12: 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 type
*
* 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();
}
$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;
$v['meta_type'] = $option_name == 'wpcf-fields' ? 'postmeta' : 'usermeta';
$fields[$k] = wpcf_sanitize_field($v);
}
$cache[$cache_key] = apply_filters('types_fields', $fields);
return $cache[$cache_key];
}
示例13: wpcf_pr_admin_post_meta_box_has_form
//.........这里部分代码省略.........
} else {
$items = get_posts('post_type=' . $post_type . '&numberposts=-1&post_status=null&meta_key=' . '_wpcf_belongs_' . $parent_post_type . '_id&meta_value=' . $post->ID);
}
// Pagination
$total_items = count($items);
$per_page = 5;
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$numberposts = $page == 1 ? 1 : ($page - 1) * $per_page;
$slice = $page == 1 ? 0 : ($page - 1) * $per_page;
$next = count($items) >= $numberposts + $per_page;
$prev = $page == 1 ? false : true;
if ($total_items > $per_page) {
$items = array_splice($items, $slice, $per_page);
}
$headers = array();
$wpcf_fields = wpcf_admin_fields_get_fields(true);
if ($data['fields_setting'] == 'specific') {
$title_dir = $sort_field == '_wp_title' ? $dir : 'ASC';
$_wp_title = '';
$_wp_title .= $sort_field == '_wp_title' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$_wp_title .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . '_wp_title&sort=' . $title_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . __('Post Title') . '</a>';
$keys = array_keys($data['fields']);
foreach ($keys as $k => $header) {
if ($header == '_wp_title' || $header == '_wpcf_pr_parents') {
continue;
}
if ($header == '_wp_body') {
$body_dir = $sort_field == '_wp_body' ? $dir : $dir_default;
$headers[$k] = '';
$headers[$k] .= $sort_field == '_wp_body' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$k] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . '_wp_body&sort=' . $body_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . __('Post Body') . '</a>';
} else {
if (strpos($header, WPCF_META_PREFIX) === 0 && isset($wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)])) {
wpcf_admin_post_field_load_js_css(wpcf_fields_type_action($wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)]['type']));
$field_dir = $sort_field == $header ? $dir : $dir_default;
$headers[$k] = '';
$headers[$k] .= $sort_field == $header ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$k] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . $header . '&sort=' . $field_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . $wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)]['name'] . '</a>';
} else {
$field_dir = $sort_field == $header ? $dir : $dir_default;
$headers[$k] = '';
$headers[$k] .= $sort_field == $header ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$k] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . $header . '&sort=' . $field_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . $header . '</a>';
}
}
}
if (!empty($data['fields']['_wpcf_pr_parents'])) {
foreach ($data['fields']['_wpcf_pr_parents'] as $temp_parent => $temp_data) {
if ($temp_parent == $parent_post_type) {
continue;
}
$temp_parent_type = get_post_type_object($temp_parent);
if (empty($temp_parent_type)) {
continue;
}
$parent_dir = $sort_field == '_wpcf_pr_parent' ? $dir : $dir_default;
$headers['_wpcf_pr_parent_' . $temp_parent] = '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . '_wpcf_pr_parent&sort=' . $parent_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&post_type_sort_parent=' . $temp_parent . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . $temp_parent_type->label . '</a>';
}
}
array_unshift($headers, $_wp_title);
} else {
$item = new stdClass();
$item->ID = 'new_' . mt_rand();
$item->post_title = '';
$item->post_content = '';
$item->post_type = $post_type;
示例14: headers
/**
* Header HTML formatted output.
*
* Each header <th> is array element. Sortable.
*
* @return array 'header_id' => html
*/
function headers()
{
// Sorting
$dir = isset($_GET['sort']) && $_GET['sort'] == 'ASC' ? 'DESC' : 'ASC';
$dir_default = 'ASC';
$sort_field = isset($_GET['field']) ? $_GET['field'] : '';
// Set values
$post = $this->parent;
$post_type = $this->child_post_type;
$parent_post_type = $this->parent_post_type;
$data = $this->data;
$wpcf_fields = wpcf_admin_fields_get_fields(true);
$headers = array();
foreach ($this->headers as $k => $header) {
if ($k === '__parents') {
continue;
}
if ($header == '_wp_title') {
$title_dir = $sort_field == '_wp_title' ? $dir : 'ASC';
$headers[$header] = '';
$headers[$header] .= $sort_field == '_wp_title' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$header] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . '_wp_title&sort=' . $title_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . __('Post Title') . '</a>';
} else {
if ($header == '_wp_body') {
$body_dir = $sort_field == '_wp_body' ? $dir : $dir_default;
$headers[$header] = '';
$headers[$header] .= $sort_field == '_wp_body' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$header] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . '_wp_body&sort=' . $body_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . __('Post Body') . '</a>';
} else {
if (strpos($header, WPCF_META_PREFIX) === 0 && isset($wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)])) {
wpcf_admin_post_field_load_js_css($post, wpcf_fields_type_action($wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)]['type']));
$field_dir = $sort_field == $header ? $dir : $dir_default;
$headers[$header] = '';
$headers[$header] .= $sort_field == $header ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$header] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . $header . '&sort=' . $field_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . stripslashes($wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)]['name']) . '</a>';
if (wpcf_admin_is_repetitive($wpcf_fields[str_replace(WPCF_META_PREFIX, '', $header)])) {
$repetitive_warning = true;
}
} else {
$field_dir = $sort_field == $header ? $dir : $dir_default;
$headers[$header] = '';
$headers[$header] .= $sort_field == $header ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers[$header] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . $header . '&sort=' . $field_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . stripslashes($header) . '</a>';
}
}
}
}
if (!empty($this->headers['__parents'])) {
foreach ($this->headers['__parents'] as $_parent => $data) {
if ($_parent == $parent_post_type) {
continue;
}
$temp_parent_type = get_post_type_object($_parent);
if (empty($temp_parent_type)) {
continue;
}
$parent_dir = $sort_field == '_wpcf_pr_parent' ? $dir : $dir_default;
$headers['_wpcf_pr_parent_' . $_parent] = $sort_field == '_wpcf_pr_parent' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : '';
$headers['_wpcf_pr_parent_' . $_parent] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . '_wpcf_pr_parent&sort=' . $parent_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&post_type_sort_parent=' . $_parent . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . $temp_parent_type->label . '</a>';
}
}
return $headers;
}
示例15: wpcf_admin_post_add_usermeta_to_editor_js
/**
* Add User Fields to editor
*
* @author Gen gen.i@icanlocalize.com
* @since Types 1.3
*/
function wpcf_admin_post_add_usermeta_to_editor_js($menu, $views_callback = false)
{
global $wpcf;
$post = apply_filters('wpcf_filter_wpcf_admin_get_current_edited_post', null);
if (!$post) {
$post = (object) array('ID' => -1);
}
$groups = wpcf_admin_fields_get_groups(TYPES_USER_META_FIELD_GROUP_CPT_NAME);
$user_id = wpcf_usermeta_get_user();
if (!empty($groups)) {
$item_styles = array();
foreach ($groups as $group_id => $group) {
if (empty($group['is_active'])) {
continue;
}
$group_name = sprintf(__('%s (Usermeta fields)', 'wpcf'), $group['name']);
$fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
if (!empty($fields)) {
foreach ($fields as $field_id => $field) {
// Use field class
$wpcf->usermeta_field->set($user_id, $field);
// Get field data
$data = (array) $wpcf->usermeta_field->config;
// Get inherited field
if (isset($data['inherited_field_type'])) {
$inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']);
}
$callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'usermeta\', ' . $post->ID . ')';
// Added for Views:users filter Vicon popup
if ($views_callback) {
$callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', ' . $post->ID . ')';
}
$menu[$group_name][stripslashes($field['name'])] = array(stripslashes(wp_kses_post($field['name'])), trim(wpcf_usermeta_get_shortcode($field), '[]'), $group_name, $callback);
}
/*
* Since Types 1.2
* We use field class to enqueue JS and CSS
*/
$wpcf->usermeta_field->enqueue_script();
$wpcf->usermeta_field->enqueue_style();
}
}
}
return $menu;
}