/** * Gets repetitive meta value. * * @global type $wpcf * @param type $field * @param type $post_id * @param type $meta_id * @return type */ function wpcf_api_field_meta_value_repetitive($field, $post_id = null, $meta_id = null) { global $wpcf; // Set post $post = $wpcf->api->set_post($post_id); // Set field $wpcf->repeater->set($post, $field); $meta = $wpcf->repeater->meta; // See if single if (!wpcf_admin_is_repetitive($field)) { return isset($meta['single']) ? $meta['single'] : null; } // Return single repetitive field value if meta_id specified if (!is_null($meta_id) && isset($meta['by_meta_id'][$meta_id])) { return $meta['by_meta_id'][$meta_id]; } // Return ordered if (isset($wpcf->repeater->meta['custom_order'])) { return $wpcf->repeater->meta['custom_order']; } // Return by_meta_id if (isset($wpcf->repeater->meta['by_meta_id'])) { return $wpcf->repeater->meta['by_meta_id']; } return array(); }
/** * Summary. * * Description. * * @since x.x.x * @access (for functions: only use if private) * * @see Function/method/class relied on * @link URL * @global type $varname Description. * @global type $varname Description. * * @param type $var Description. * @param type $var Optional. Description. * @return type Description. */ public function prepare_field_select_screen() { /** * check nonce */ if (0 || !isset($_REQUEST['_wpnonce']) || !isset($_REQUEST['parent']) || !isset($_REQUEST['child']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $this->get_nonce('child-post-fields', $_REQUEST['parent'], $_REQUEST['child']))) { $this->verification_failed_and_die(); } $parent = $_REQUEST['parent']; $child = $_REQUEST['child']; $post_type_parent = get_post_type_object($parent); $post_type_child = get_post_type_object($child); if (empty($post_type_parent) || empty($post_type_child)) { die(__('Wrong post types', 'wpcf')); } $relationships = get_option('wpcf_post_relationship', array()); if (!isset($relationships[$parent][$child])) { $this->print_notice_and_die(__('Please save Post Type first to edit these fields.', 'wpcf')); } $repetitive_warning_markup = array(); $data = $relationships[$parent][$child]; $form = array(); $form['repetitive_warning_markup'] = $repetitive_warning_markup; $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('Do not show management options for this post type', 'wpcf') => 'only_list', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#attributes' => array('display' => 'ul'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']); /** * check default, to avoid missing configuration */ if (!in_array($form['select']['#default_value'], $form['select']['#options'])) { $form['select']['#default_value'] = 'all_cf'; } /** * Specific options */ $groups = wpcf_admin_get_groups_by_post_type($child); $options_cf = array(); $repetitive_warning = false; $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf'); foreach ($groups as $group) { $fields = wpcf_admin_fields_get_fields_by_group($group['id']); foreach ($fields as $key => $cf) { $__key = wpcf_types_cf_under_control('check_outsider', $key) ? $key : WPCF_META_PREFIX . $key; $options_cf[$__key] = array('#title' => $cf['name'], '#name' => 'fields[' . $__key . ']', '#default_value' => isset($data['fields'][$__key]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>'); // Repetitive warning if (wpcf_admin_is_repetitive($cf)) { if (!$repetitive_warning) { $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>'); } $repetitive_warning = true; $options_cf[$__key]['#after'] = !isset($data['fields'][$__key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>'; $options_cf[$__key]['#after'] .= $repetitive_warning_txt; $options_cf[$__key]['#after'] .= '</p></div></li>'; $options_cf[$__key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();', 'disabled' => 'disabled'); } } } /** * build options for "Specific fields" */ $options = array(); /** * check and add built-in properites */ require_once WPCF_INC_ABSPATH . '/post-relationship.php'; $supports = wpcf_post_relationship_get_supported_fields_by_post_type($child); foreach ($supports as $child_field_key => $child_field_data) { $options[$child_field_data['name']] = array('#title' => $child_field_data['title'], '#name' => sprintf('fields[%s]', $child_field_data['name']), '#default_value' => isset($data['fields'][$child_field_data['name']]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>'); } /** * add custom fields */ $options = $options + $options_cf; $temp_belongs = wpcf_pr_admin_get_belongs($child); foreach ($temp_belongs as $temp_parent => $temp_data) { if ($temp_parent == $parent) { continue; } $temp_parent_type = get_post_type_object($temp_parent); $options[$temp_parent] = array('#title' => $temp_parent_type->label, '#name' => 'fields[_wpcf_pr_parents][' . $temp_parent . ']', '#default_value' => isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>'); } /** * remove "Specific fields" if there is no fields */ if (empty($options)) { unset($form['select']['#options'][__('Specific fields', 'wpcf')]); if ('specific' == $form['select']['#default_value']) { $form['select']['#default_value'] = 'all_cf'; } } // Taxonomies $taxonomies = get_object_taxonomies($post_type_child->name, 'objects'); if (!empty($taxonomies)) { foreach ($taxonomies as $tax_id => $taxonomy) { $options[$tax_id] = array('#title' => sprintf(__('Taxonomy - %s', 'wpcf'), $taxonomy->label), '#name' => 'fields[_wpcf_pr_taxonomies][' . $tax_id . ']', '#default_value' => isset($data['fields']['_wpcf_pr_taxonomies'][$tax_id]) ? 1 : 0, '#inline' => true, '#before' => '<li>', '#after' => '</li>'); } } $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => sprintf('<ul id="wpcf-specific" class="%s">', 'specific' == $form['select']['#default_value'] ? '' : 'hidden'), '#after' => '</ul>'); $form['nonce'] = array('#type' => 'hidden', '#value' => wp_create_nonce($this->get_nonce('child-post-fields-save', $parent, $child)), '#name' => 'wpcf-fields-save-nonce', '#id' => 'wpcf-fields-save-nonce'); $form['parent'] = array('#type' => 'hidden', '#value' => esc_attr($parent), '#name' => 'wpcf-parent', '#id' => 'wpcf-parent'); $form['child'] = array('#type' => 'hidden', '#value' => esc_attr($child), '#name' => 'wpcf-child', '#id' => 'wpcf-child'); echo wpcf_form_simple($form); die; }
/** * Processes single field. * * Since Types 1.2 this function changed. It handles single form element. * Form element is already fetched, also meta values using class WPCF_Field. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @todo gradually remove usage of inherited fields * @todo Cleanup * * @staticvar array $repetitive_started * @param type $field_object * @return mixed boolean|array */ function wpcf_admin_post_process_field($field_object) { /* * Since Types 1.2 * All data we need is stored in global $wpcf */ global $wpcf; $post = $wpcf->post; $field_unedited = $field = (array) $field_object->cf; $context = $field_object->context; $invalid_fields = $wpcf->field->invalid_fields; if (!empty($field)) { /* * TODO Move to WPML code separate files * For now leave WPML action here */ $field['wpml_action'] = isset($field_unedited['wpml_action']) ? $field_unedited['wpml_action'] : ''; /* * Set Unique ID */ $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . wpcf_unique_id(serialize($field_object->__current_form_element)); /* * Get inherited field * * TODO Deprecated * * Since Types 1.2 we encourage developers to completely define fields. */ $inherited_field_data = false; if (isset($field_object->config->inherited_field_type)) { $_allowed = array('image' => 'file', 'numeric' => 'textfield', 'email' => 'textfield', 'phone' => 'textfield', 'url' => 'textfield'); if (!array_key_exists($field_object->cf['type'], $_allowed)) { _deprecated_argument('inherited_field_type', '1.2', 'Since Types 1.2 we encourage developers to completely define fields'); } $inherited_field_data = wpcf_fields_type_action($field_object->config->inherited_field_type); } /* * CHECKPOINT * APPLY FILTERS * * * Moved to WPCF_Field * Field value should be already filtered * * Explanation: * When WPCF_Field::set() is called, all these properties are set. * WPCF_Field::$cf['value'] * WPCF_Field::$__meta (single value from DB) * WPCF_Field::$meta (single or multiple values if single/repetitive) * * TODO Make sure value is already filtered and not overwritten */ /* * Set generic values * * FUTURE BREAKPOINT * Since Types 1.2 we do not encourage relying on generic field data. * Only core fields should use this. * * TODO Open 3rd party fields dir */ $_element = array('#type' => isset($field_object->config->inherited_field_type) ? $field_object->config->inherited_field_type : $field['type'], '#id' => $field_id, '#title' => $field['name'], '#name' => 'wpcf[' . $field['slug'] . ']', '#value' => isset($field['value']) ? $field['value'] : '', 'wpcf-id' => $field['id'], 'wpcf-slug' => $field['slug'], 'wpcf-type' => $field['type']); /* * TODO Add explanation about creating duplicated fields * * NOT USED YET * * Explain users that fields are added if slug is changed */ wpcf_admin_add_js_settings('wpcfFieldNewInstanceWarning', __('If you change slug, new field will be created', 'wpcf')); /* * Merge with default element * * Deprecated from Types 1.2 * Only core fields use this. */ $element = array_merge($_element, $field_object->__current_form_element); /* * * * * * * * * * * * * * * * * TODO From this point code should be simplified. */ if (isset($field['description_extra'])) { $element['#description'] .= wpautop($field['description_extra']); } // Set atributes #1 if (isset($field['disable'])) { $field['#disable'] = $field['disable']; } if (!empty($field['disable'])) { $field['#attributes']['disabled'] = 'disabled'; } if (!empty($field['readonly'])) { $field['#attributes']['readonly'] = 'readonly'; } // Format description if (!empty($element['#description'])) { $element['#description'] = wpautop($element['#description']); } // Set validation element if (isset($field['data']['validate'])) { /* * * * TODO First two check are not needed anymore */ // If array has more than one field - see which one is marked if ($field_object->__multiple && isset($element['#_validate_this'])) { $element['#validate'] = $field['data']['validate']; } else { if (!$field_object->__multiple) { $element['#validate'] = $field['data']['validate']; } } } // Set atributes #2 (override) if (isset($field['disable'])) { $element['#disable'] = $field['disable']; } if (!empty($field['disable'])) { $element['#attributes']['disabled'] = 'disabled'; } if (!empty($field['readonly'])) { $element['#attributes']['readonly'] = 'readonly'; if (!empty($element['#options'])) { foreach ($element['#options'] as $key => $option) { if (!is_array($option)) { $element['#options'][$key] = array('#title' => $key, '#value' => $option); } $element['#options'][$key]['#attributes']['readonly'] = 'readonly'; if ($element['#type'] == 'select') { $element['#options'][$key]['#attributes']['disabled'] = 'disabled'; } } } if ($element['#type'] == 'select') { $element['#attributes']['disabled'] = 'disabled'; } } // Check if it was invalid on submit and add error message if ($post && !empty($invalid_fields)) { if (isset($invalid_fields[$element['#id']]['#error'])) { $element['#error'] = $invalid_fields[$element['#id']]['#error']; } } // Set WPML locked icon if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') { $element['#title'] .= '<img src="' . WPCF_EMBEDDED_RES_RELPATH . '/images/locked.png" alt="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" title="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" style="position:relative;left:2px;top:2px;" />'; } // Add repetitive class // TODO Check if this is covered by Repeater and move/remove 1.1.5 // TODO Check why not add repetitive class if copied 1.1.5 if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) { if (!empty($element['#options']) && $element['#type'] != 'select') { foreach ($element['#options'] as $temp_key => $temp_value) { $element['#options'][$temp_key]['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive'; } } else { $element['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive'; } /* * * * Since Types 1.2 we allow same field values * * TODO Remove * * wpcf_admin_add_js_settings('wpcfFormRepetitiveUniqueValuesCheckText', '\'' . __('Warning: same values set', 'wpcf') . '\''); */ } // Set read-only if copied by WPML // TODO Move this to separate WPML code and use only hooks 1.1.5 if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') { if (isset($element['#options'])) { foreach ($element['#options'] as $temp_key => $temp_value) { if (isset($temp_value['#attributes'])) { $element['#options'][$temp_key]['#attributes']['readonly'] = 'readonly'; } else { $element['#options'][$temp_key]['#attributes'] = array('readonly' => 'readonly'); } } } if ($field['type'] == 'select') { if (isset($element['#attributes'])) { $element['#attributes']['disabled'] = 'disabled'; } else { $element['#attributes'] = array('disabled' => 'disabled'); } } else { if (isset($element['#attributes'])) { $element['#attributes']['readonly'] = 'readonly'; } else { $element['#attributes'] = array('readonly' => 'readonly'); } } } return array('field' => $field, 'element' => $element); } return false; }
/** * Calls view function for specific field type. * * @param type $field * @param type $atts * @return type */ function types_render_usermeta_field($field_id, $params, $content = null, $code = '') { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; global $wpcf, $post; // HTML var holds actual output $html = ''; // Set post ID $post_id = $post->ID; if (isset($params['post_id']) && !empty($params['post_id'])) { $post_id = $params['post_id']; } // Get field $field = wpcf_fields_get_field_by_slug($field_id, 'wpcf-usermeta'); // 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_usermeta_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG); return ''; } //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("SELECT * FROM " . $wpdb->prefix . "users WHERE user_login = '******'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); }
/** * Edit fields form. * * @global type $wpdb * @param type $parent * @param type $child */ function wpcf_pr_admin_edit_fields($parent, $child) { global $wpdb; $post_type_parent = get_post_type_object($parent); $post_type_child = get_post_type_object($child); if (empty($post_type_parent) || empty($post_type_child)) { die(__('Wrong post types')); } $relationships = get_option('wpcf_post_relationship', array()); if (!isset($relationships[$parent][$child])) { die(__('Relationship do not exist')); } $data = $relationships[$parent][$child]; wp_enqueue_script('jquery'); wpcf_admin_ajax_head('Edit fields', 'wpcf'); // Process submit if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) { $relationships[$parent][$child]['fields_setting'] = $_POST['fields_setting']; $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array(); update_option('wpcf_post_relationship', $relationships); ?> <script type="text/javascript"> window.parent.jQuery('#TB_closeWindowButton').trigger('click'); window.parent.location.reload(); </script> <?php die; } $groups = wpcf_admin_get_groups_by_post_type($child); $options_cf = array(); $repetitive_warning = false; $repetitive_warning_markup = array(); $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf'); foreach ($groups as $group) { $fields = wpcf_admin_fields_get_fields_by_group($group['id']); foreach ($fields as $key => $cf) { $options_cf[WPCF_META_PREFIX . $key] = array(); $options_cf[WPCF_META_PREFIX . $key]['#title'] = $cf['name']; $options_cf[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']'; $options_cf[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0; // Repetitive warning if (wpcf_admin_is_repetitive($cf)) { if (!$repetitive_warning) { $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>'); } $repetitive_warning = true; $options_cf[WPCF_META_PREFIX . $key]['#after'] = !isset($data['fields'][WPCF_META_PREFIX . $key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>'; $options_cf[WPCF_META_PREFIX . $key]['#after'] .= $repetitive_warning_txt; $options_cf[WPCF_META_PREFIX . $key]['#after'] .= '</p></div>'; $options_cf[WPCF_META_PREFIX . $key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();'); } } } $form = array(); $form['repetitive_warning_markup'] = $repetitive_warning_markup; $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']); $options = array(); $options['_wp_title'] = array('#title' => __('Post title', 'wpcf'), '#name' => 'fields[_wp_title]', '#default_value' => isset($data['fields']['_wp_title']) ? 1 : 0); $options['_wp_body'] = array('#title' => __('Post body', 'wpcf'), '#name' => 'fields[_wp_body]', '#default_value' => isset($data['fields']['_wp_body']) ? 1 : 0); $options = $options + $options_cf; $temp_belongs = wpcf_pr_admin_get_belongs($child); foreach ($temp_belongs as $temp_parent => $temp_data) { if ($temp_parent == $parent) { continue; } $temp_parent_type = get_post_type_object($temp_parent); $options[$temp_parent] = array(); $options[$temp_parent]['#title'] = $temp_parent_type->label; $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']'; $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0; } $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>'); $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary')); echo '<form method="post" action="">'; echo wpcf_form_simple($form); echo wp_nonce_field('pt_edit_fields'); echo '</form>'; ?> <script type="text/javascript"> jQuery(document).ready(function(){ if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') { jQuery('#wpcf-specific').show(); } else { <?php if ($repetitive_warning) { ?> jQuery('#wpcf-repetitive-warning').show(); <?php } ?> } jQuery('input[name="fields_setting"]').change(function(){ if (jQuery(this).val() == 'specific') { jQuery('#wpcf-specific').slideDown(); } else { jQuery('#wpcf-specific').slideUp(); <?php if ($repetitive_warning) { ?> jQuery('#wpcf-repetitive-warning').show(); <?php } ?> } }); }); </script> <?php wpcf_admin_ajax_footer(); }
/** * Returns shortcode for specified field. * * @param type $field * @param type $add Additional attributes */ function wpcf_fields_get_shortcode($field, $add = '') { $shortcode = '['; $shortcode .= 'types field="' . $field['slug'] . '"' . $add; if (in_array($field['type'], array('textfield', 'textarea', 'wysiwyg'))) { $shortcode .= ' class="" style=""'; } // If repetitive add separator if (wpcf_admin_is_repetitive($field)) { $shortcode .= ' separator=", "'; } $shortcode .= '][/types]'; $shortcode = apply_filters('wpcf_fields_shortcode', $shortcode, $field); $shortcode = apply_filters('wpcf_fields_shortcode_type_' . $field['type'], $shortcode, $field); $shortcode = apply_filters('wpcf_fields_shortcode_slug_' . $field['slug'], $shortcode, $field); return $shortcode; }
/** * Add here various triggers for field */ function _field_triggers() { /* * Check if repetitive - add warning */ if (wpcf_admin_is_repetitive($this->cf->cf)) { $this->repetitive_warning = true; } /* * Check if date - trigger it * TODO Move to date */ if ($this->cf->cf['type'] == 'date') { $this->trigger_date = true; } }
/** * 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 === '') { $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); }
/** * 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']]; $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; $suppress_errors = $custom_field == false ? true : false; $translatable = array('textfield', 'textarea', 'wysiwyg'); $action = in_array($type, $translatable) ? 'translate' : 'copy'; $form['wpcf-' . $id]['wpml-preferences'] = array('#type' => 'fieldset', '#title' => __('Translation preferences', 'wpcf'), '#collapsed' => true); $wpml_prefs = wpml_cf_translation_preferences($id, $custom_field, 'wpcf', false, $action, false, $suppress_errors); $wpml_prefs = str_replace('<span style="color:#FF0000;">', '<span class="wpcf-form-error">', $wpml_prefs); $form['wpcf-' . $id]['wpml-preferences']['form'] = array('#type' => 'markup', '#markup' => $wpml_prefs); } if (empty($form_data) || isset($form_data['is_new'])) { $form['wpcf-' . $id]['is_new'] = array('#type' => 'hidden', '#name' => 'wpcf[fields][' . $id . '][is_new]', '#value' => '1', '#attributes' => array('class' => 'wpcf-is-new')); } $form_data['id'] = $id; $form['wpcf-' . $id] = apply_filters('wpcf_form_field', $form['wpcf-' . $id], $form_data); return $form; } return false; }
/** * Calls view function for specific field type. * * @param type $field * @param type $atts * @return type */ function types_render_field($field_id, $params, $content = null, $code = '') { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; global $post; // Get field $field = wpcf_fields_get_field_by_slug($field_id); if (empty($field)) { 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 ''; } // See if repetitive if (wpcf_admin_is_repetitive($field)) { $meta = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false); 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); if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator'])) { $output = implode($params['separator'], $output); } else { if (!empty($output)) { $output = implode('', $output); } else { return ''; } } } else { if (isset($meta[$index])) { $params['field_value'] = $meta[$index]; return types_render_field_single($field, $params, $content, $code); } else { return ''; } } return $output; } else { return ''; } } else { $params['field_value'] = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if ($params['field_value'] == '' && $field['type'] != 'checkbox') { return ''; } return types_render_field_single($field, $params, $content, $code); } }
/** * Processes single field. * * @staticvar array $repetitive_started * @param type $post * @param type $field * @param type $use_cache * @param type $add_to_editor * @param type $context * @param type $original_cf * @param type $invalid_fields * @return mixed boolean|array */ function wpcf_admin_post_process_field($post = false, $field_unedited = array(), $use_cache = true, $add_to_editor = true, $context = 'group', $original_cf = array(), $invalid_fields = array()) { $field = wpcf_admin_fields_get_field($field_unedited['id']); if (!empty($field)) { // Set values $field['value'] = isset($field_unedited['value']) ? $field_unedited['value'] : ''; $field['wpml_action'] = isset($field_unedited['wpml_action']) ? $field_unedited['wpml_action'] : ''; if (isset($count[$field['type'] . '-' . $field['slug']])) { $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . $count[$field['type'] . '-' . $field['slug']] . '-' . mt_rand(); $count[$field['type'] . '-' . $field['slug']] += 1; } else { $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . mt_rand(); $count[$field['type'] . '-' . $field['slug']] = 1; } $field_init_data = wpcf_fields_type_action($field['type']); // Get inherited field $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']); } // Mark any field that is going to be copied. if (!empty($original_cf['fields'])) { foreach ($original_cf['fields'] as $cf_id) { if (wpcf_types_get_meta_prefix($field) . $field['slug'] == $cf_id) { $field['readonly'] = true; $field['wpml_action'] = 'copy'; break; } } } // Apply filters $field['value'] = apply_filters('wpcf_fields_value_get', $field['value'], $field, $field_init_data); $field['value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_get', $field['value'], $field, $field_init_data); $field['value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_get', $field['value'], $field, $field_init_data); wpcf_admin_post_field_load_js_css($field_init_data); $element = array(); // Set generic values $element = array('#type' => isset($field_init_data['inherited_field_type']) ? $field_init_data['inherited_field_type'] : $field['type'], '#id' => $field_id, '#title' => wpcf_translate('field ' . $field['id'] . ' name', $field['name']), '#description' => wpautop(wpcf_translate('field ' . $field['id'] . ' description', $field['description'])), '#name' => 'wpcf[' . $field['slug'] . ']', '#value' => isset($field['value']) ? $field['value'] : '', 'wpcf-id' => $field['id'], 'wpcf-slug' => $field['slug'], 'wpcf-type' => $field['type']); // Set inherited values $element_inherited = array(); if ($inherited_field_data) { if (function_exists('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form')) { $element_inherited = call_user_func_array('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form', array($field, $element)); } } $element = array_merge($element, $element_inherited); if (isset($field['description_extra'])) { $element['#description'] .= wpautop($field['description_extra']); } // Set atributes #1 if (isset($field['disable'])) { $field['#disable'] = $field['disable']; } if (!empty($field['disable'])) { $field['#attributes']['disabled'] = 'disabled'; } if (!empty($field['readonly'])) { $field['#attributes']['readonly'] = 'readonly'; } // Set specific values if (defined('WPCF_INC_ABSPATH') && file_exists(WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php')) { require_once WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php'; } // Load field if (function_exists('wpcf_fields_' . $field['type'] . '_meta_box_form')) { $element_specific = call_user_func_array('wpcf_fields_' . $field['type'] . '_meta_box_form', array($field, $element)); // Check if it's single if (isset($element_specific['#type'])) { // Format description if (!empty($element_specific['#description'])) { $element_specific['#description'] = wpautop($element_specific['#description']); } $element = array_merge($element, $element_specific); // Set validation element if (isset($field['data']['validate'])) { $element['#validate'] = $field['data']['validate']; } // Repetitive fields if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) { $element = wpcf_admin_post_process_repetitive_field($post, $field, $element); } } else { // More fields, loop all // Only Skype for now have multiple fields, so process only that if ($field['type'] == 'skype') { $skype_element = array(); foreach ($element_specific as $element_specific_fields_key => $element_specific_fields_value) { $element_specific_fields_value['__element_key'] = $element_specific_fields_key; // Format description if (!empty($element_specific_fields_value['#description'])) { $element_specific_fields_value['#description'] = wpautop($element_specific_fields_value['#description']); } // If no ID if (!isset($element_specific_fields_value['#id'])) { $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . mt_rand(); } // Set validation element if (!empty($element_specific_fields_value['#_validate_this']) && isset($field['data']['validate'])) { $element_specific_fields_value['#validate'] = $field['data']['validate']; } if ($element_specific_fields_key != 'skypename') { if (!isset($element_specific_fields_value['#name'])) { $element_specific_fields_value['#name'] = 'wpcf[ignore][' . mt_rand() . ']'; } $skype_element[$element_specific_fields_value['#id']] = $element_specific_fields_value; continue; } // This one is actually value and keep it (#name is required) $element = array_merge($element, $element_specific_fields_value); // Add it here to keep order $skype_element[$element['#id']] = $element; } // Repetitive fields if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) { list($element, $skype_element) = wpcf_admin_post_process_repetitive_field_skype($post, $field, $skype_element); } } } } else { // Repetitive fields if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) { $element = wpcf_admin_post_process_repetitive_field($post, $field, $element); } } // Set atributes #2 (override) if (isset($field['disable'])) { $element['#disable'] = $field['disable']; } if (!empty($field['disable'])) { $element['#attributes']['disabled'] = 'disabled'; } if (!empty($field['readonly'])) { $element['#attributes']['readonly'] = 'readonly'; if (!empty($element['#options'])) { foreach ($element['#options'] as $key => $option) { if (!is_array($option)) { $element['#options'][$key] = array('#title' => $key, '#value' => $option); } $element['#options'][$key]['#attributes']['readonly'] = 'readonly'; if ($element['#type'] == 'select') { $element['#options'][$key]['#attributes']['disabled'] = 'disabled'; } } } if ($element['#type'] == 'select') { $element['#attributes']['disabled'] = 'disabled'; } } // Set validation element if ($field['type'] != 'skype' && empty($element['#validate']) && isset($field['data']['validate'])) { $element['#validate'] = $field['data']['validate']; } // Check if it was invalid no submit and add error message if ($post && !empty($invalid_fields)) { if (isset($invalid_fields[$element['#id']]['#error'])) { $element['#error'] = $invalid_fields[$element['#id']]['#error']; } } // Set WPML locked icon if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') { $element['#title'] .= '<img src="' . WPCF_EMBEDDED_RES_RELPATH . '/images/locked.png" alt="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" title="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" style="position:relative;left:2px;top:2px;" />'; } // Add to editor if ($add_to_editor) { wpcf_admin_post_add_to_editor($field); } // Add repetitive class if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) { if (!empty($element['#options']) && $element['#type'] != 'select') { foreach ($element['#options'] as $temp_key => $temp_value) { $element['#options'][$temp_key]['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive'; } } else { $element['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive'; } wpcf_admin_add_js_settings('wpcfFormRepetitiveUniqueValuesCheckText', '\'' . __('Warning: same values set', 'wpcf') . '\''); } // Set read-only if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') { if (isset($element['#options'])) { foreach ($element['#options'] as $temp_key => $temp_value) { if (isset($temp_value['#attributes'])) { $element['#options'][$temp_key]['#attributes']['readonly'] = 'readonly'; } else { $element['#options'][$temp_key]['#attributes'] = array('readonly' => 'readonly'); } } } if ($field['type'] == 'select') { if (isset($element['#attributes'])) { $element['#attributes']['disabled'] = 'disabled'; } else { $element['#attributes'] = array('disabled' => 'disabled'); } } else { if (isset($element['#attributes'])) { $element['#attributes']['readonly'] = 'readonly'; } else { $element['#attributes'] = array('readonly' => 'readonly'); } } } // Specific for Skype if ($field['type'] == 'skype') { $skype_element[$element['#id']] = $element; $element = $skype_element; } return array('field' => $field, 'element' => $element); } return false; }
function types_render_termmeta($field_id, $params, $content = null, $code = '') { global $wpcf, $wpdb, $WP_Views; // HTML var holds actual output $html = ''; //Get User id from views loop if (isset($WP_Views->taxonomy_data['term']->term_id) && !empty($WP_Views->taxonomy_data['term']->term_id)) { $params['term_id'] = $WP_Views->taxonomy_data['term']->term_id; } if (!isset($params['term_id']) && (is_tax() || is_category() || is_tag())) { global $wp_query; $term = $wp_query->get_queried_object(); if ($term && isset($term->term_id)) { $params['term_id'] = $term->term_id; } } //print_r($params);exit; //Get user By ID if (isset($params['term_id'])) { $term_id = $params['term_id']; } else { return; } if (empty($term_id)) { return; } // Get field $field = types_get_field($field_id, 'termmeta'); // 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->termmeta_repeater->set($term_id, $field); $_meta = $wpcf->termmeta_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 (!Toolset_Utils::is_field_value_truly_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_term_meta($term_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->termmeta_field->set($term_id, $field); return $wpcf->termmeta_field->html($html, $params); }
/** * 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; }
/** * Gets repetitive meta value. * * @global type $wpcf * @param type $field * @param type $post_id * @param type $meta_id * @return type */ function wpcf_api_field_meta_value_repetitive($field, $post_id = null, $meta_id = null) { static $cache = array(); $cache_key = md5(serialize(func_get_args())); if (isset($cache[$cache_key])) { return $cache[$cache_key]; } global $wpcf; // Get field if (!is_array($field)) { $field = types_get_field($field); if (empty($field)) { return NULL; } } // Set post if (!is_null($post_id)) { if (!($post_id = absint($post_id))) { return NULL; } $post = get_post($post_id); } else { global $post; } if (empty($post->ID)) { return NULL; } // Set field $wpcf->repeater->set($post, $field); $meta = $wpcf->repeater->meta; $values = array(); // See if single if (!wpcf_admin_is_repetitive($field)) { $values = isset($meta['single']) ? $meta['single'] : NULL; } else { if (!is_null($meta_id) && isset($meta['by_meta_id'][$meta_id])) { // Return single repetitive field value if meta_id specified $values = $meta['by_meta_id'][$meta_id]; } else { if (isset($wpcf->repeater->meta['custom_order'])) { // Return ordered $values = $wpcf->repeater->meta['custom_order']; } else { if (isset($wpcf->repeater->meta['by_meta_id'])) { // Return by_meta_id $values = $wpcf->repeater->meta['by_meta_id']; } } } } $cache[$cache_key] = $values; return $values; }
/** * Single condition form elements. * * @param type $data * @param type $condition * @param type $key * @return string */ function wpcf_cd_admin_form_single_filter($data, $condition, $key = null, $group = false, $force_multi = false) { if ($group) { $name = 'wpcf[group][conditional_display]'; } else { $name = 'wpcf[fields][' . $data['id'] . '][conditional_display]'; } $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : false; if ($group_id && !$group) { // Allow group to use other fields $fields = wpcf_admin_fields_get_fields_by_group($group_id); } else { $fields = wpcf_admin_fields_get_fields(); } $options = array(); foreach ($fields as $field_id => $field) { if (!$group && $data['id'] == $field_id) { continue; } if (wpcf_admin_is_repetitive($field)) { continue; } $options[$field_id] = array('#value' => $field_id, '#title' => $field['name'], '#attributes' => array('class' => 'wpcf-conditional-select-' . $field['type'])); } if (!$group && empty($options)) { return array('cd' => array('#type' => 'markup', '#markup' => '<p>' . __('You will be able to set conditional field display when you save more fields.', 'wpcf') . '</p>')); } $id = !is_null($key) ? $key : strval('condition_' . mt_rand()); $form = array(); $before = '<div class="wpcf-cd-entry"><br />'; $form['cd']['field_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][field]', '#options' => $options, '#inline' => true, '#before' => $before, '#default_value' => isset($condition['field']) ? $condition['field'] : null, '#attributes' => array('class' => 'wpcf-cd-field')); $form['cd']['operation_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][operation]', '#options' => array_flip(wpcf_cd_admin_operations()), '#inline' => true, '#default_value' => isset($condition['operation']) ? $condition['operation'] : null, '#attributes' => array('class' => 'wpcf-cd-operation')); $form['cd']['value_' . $id] = array('#type' => 'textfield', '#name' => $name . '[conditions][' . $id . '][value]', '#options' => wpcf_cd_admin_operations(), '#inline' => true, '#value' => isset($condition['value']) ? $condition['value'] : '', '#attributes' => array('class' => 'wpcf-cd-value')); $form['cd']['remove_' . $id] = array('#type' => 'button', '#name' => 'remove', '#value' => __('Remove condition', 'wpcf'), '#attributes' => array('onclick' => 'wpcfCdRemoveCondition(jQuery(this));', 'class' => 'wpcf-add-condition'), '#before' => '<br />', '#after' => '</div>'); return $form['cd']; }
/** * Creates form elements. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @param type $post * @param type $fields * @return type */ function wpcf_admin_usermeta_process_fields($user_id, $fields = array(), $use_cache = true, $add_to_editor = true, $context = 'group') { global $wpcf; $wpcf->usermeta_field->use_cache = $use_cache; $wpcf->usermeta_field->add_to_editor = $add_to_editor; $wpcf->usermeta_repeater->use_cache = $use_cache; $wpcf->usermeta_repeater->add_to_editor = $add_to_editor; if (is_object($user_id)) { $user_id = $user_id->ID; } // Get cached static $cache = array(); $cache_key = !empty($user_id) ? $user_id . md5(serialize($fields)) : false; if ($use_cache && $cache_key && isset($cache[$cache_key])) { return $cache[$cache_key]; } $fields_processed = array(); $invalid_fields = array(); foreach ($fields as $field) { if (!empty($user_id)) { $invalid_fields = update_user_meta($user_id, 'wpcf-invalid-fields', true); delete_user_meta($user_id, 'wpcf-invalid-fields'); $wpcf->usermeta_field->invalid_fields = $invalid_fields; } // Repetitive fields if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship') { $wpcf->usermeta_repeater->set($user_id, $field); $fields_processed = $fields_processed + $wpcf->usermeta_repeater->get_fields_form(1); } else { $wpcf->usermeta_field->set($user_id, $field); /* * From Types 1.2 use complete form setup */ $fields_processed = $fields_processed + $wpcf->usermeta_field->_get_meta_form(); } } // Cache results if ($cache_key) { $cache[$cache_key] = $fields_processed; } return $fields_processed; }
/** * @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) { if (isset($data['#pattern'])) { continue; } $form_field_temp[$key]['#pattern'] = $table_row; } $form_field = $form_field + $form_field_temp; } } $form_field['description'] = array('#type' => 'textarea', '#name' => 'description', '#attributes' => array('rows' => 5, 'cols' => 1, 'placeholder' => __('Enter field description', 'wpcf'), 'class' => 'widefat', 'tooltip' => __('This optional text appears next to the field and helps users understand what this field is for.', 'wpcf')), '#inline' => true, '#pattern' => $table_row, '#title' => __('Description', 'wpcf')); /** * 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('placeholder' => __('Enter placeholder', 'wpcf'), 'class' => 'widefat', 'tooltip' => __('This value is being displayed when the field is empty in the post editor.', 'wpcf')), '#pattern' => preg_replace('/<tr>/', '<tr class="wpcf-border-top">', $table_row)); break; } /** * add default value */ switch ($type) { case 'audio': case 'email': case 'embed': case 'file': case 'image': case 'numeric': case 'phone': case 'textfield': case 'url': case 'video': $form_field['user_default_value'] = array('#type' => 'textfield', '#name' => 'user_default_value', '#inline' => true, '#title' => __('Default Value', 'wpcf'), '#attributes' => array('placeholder' => __('Enter default value', 'wpcf'), 'class' => 'widefat', 'tooltip' => __('This is the initial value of the field.', 'wpcf')), '#pattern' => $table_row); break; case 'textarea': case 'wysiwyg': $form_field['user_default_value'] = array('#type' => 'textarea', '#name' => 'user_default_value', '#inline' => true, '#title' => __('Default Value', 'wpcf'), '#attributes' => array('style' => 'width:100%;margin:0 0 10px 0;', 'placeholder' => __('Enter default value', 'wpcf')), '#pattern' => $table_row); break; } switch ($type) { case 'audio': case 'file': case 'image': case 'embed': case 'url': case 'video': $form_field['user_default_value']['#validate'] = array('url' => array()); break; case 'email': $form_field['user_default_value']['#validate'] = array('email' => array()); break; case 'numeric': $form_field['user_default_value']['#validate'] = array('number' => array()); break; } if (wpcf_admin_can_be_repetitive($type)) { $temp_warning_message = ''; // We need to set the "repetitive" setting to a string '0' or '1', not numbers, because it will be used // again later in this method (which I'm not going to refactor now) and because the form renderer // is oversensitive. $is_repetitive_as_string = 1 == wpcf_getnest($form_data, array('data', 'repetitive'), '0') ? '1' : '0'; if (!array_key_exists('data', $form_data) || !is_array($form_data['data'])) { $form_data['data'] = array(); } $form_data['data']['repetitive'] = $is_repetitive_as_string; $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();'), '#before' => '<li>', '#after' => '</li>', '#inline' => true), '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();'), '#before' => '<li>', '#after' => '</li>', '#inline' => true)), '#default_value' => $is_repetitive_as_string, '#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, '#pattern' => preg_replace('/<tr>/', '<tr class="wpcf-border-top">', $table_row), '#inline' => true, '#before' => '<ul>', '#after' => '</ul>'); } /** /* Add validation box */ $validate_function = sprintf('wpcf_fields_%s', $type); if (is_callable($validate_function)) { $form_validate = $this->form_validation('wpcf[fields][' . $id . '][validate]', call_user_func($validate_function), $form_data); foreach ($form_validate as $k => $v) { if ('hidden' != $v['#type'] && !isset($v['#pattern'])) { $v['#pattern'] = $table_row; } $form_field['wpcf-' . $id . $k] = $v; } } /** * WPML Translation Preferences * * only for post meta * */ $form_field += $this->wpml($form_data); // Conditional display, Relevanssi integration and other modifications can be added here. // Note that form_data may contain only meta_key when the field is newly $form_field = apply_filters('wpcf_form_field', $form_field, $form_data, $type); /** * add Remove button */ $form_field['remove-field'] = array('#type' => 'markup', '#markup' => sprintf('<a href="#" class="js-wpcf-field-remove wpcf-field-remove" data-message-confirm="%s"><i class="fa fa-trash"></i> %s</a>', esc_attr__('Are you sure?', 'wpcf'), __('Remove field', 'wpcf')), '#pattern' => '<tfoot><tr><td colspan="2"><ELEMENT></td></tr></tfoot>'); /** * close table */ $form_field[$id . 'table-close'] = array('#type' => 'markup', '#markup' => '</table>'); /** * close foldable field div */ $form_field['box-close'] = array('#type' => 'markup', '#markup' => '</div>'); // Process all form fields foreach ($form_field as $k => $field) { $name = sprintf('wpcf-%s[%s]', $id, $k); $form[$name] = $field; // Check if nested if (isset($field['#name']) && strpos($field['#name'], '[') === false) { $form[$name]['#name'] = 'wpcf[fields][' . $id . '][' . $field['#name'] . ']'; } else { if (isset($field['#name']) && strpos($field['#name'], 'wpcf[fields]') === false) { $form[$name]['#name'] = 'wpcf[fields][' . $id . ']' . $field['#name']; } else { if (isset($field['#name'])) { $form[$name]['#name'] = $field['#name']; } } } if (!isset($field['#id'])) { $form[$name]['#id'] = $type . '-' . $field['#type'] . '-' . rand(); } if (isset($field['#name']) && isset($form_data[$field['#name']])) { $form[$name]['#value'] = $form_data[$field['#name']]; $form[$name]['#default_value'] = $form_data[$field['#name']]; if (!isset($form[$name]['#pattern'])) { $form[$name]['#pattern'] = $table_row; } // Check if it's in 'data' } else { if (isset($field['#name']) && isset($form_data['data'][$field['#name']])) { $form[$name]['#value'] = $form_data['data'][$field['#name']]; $form[$name]['#default_value'] = $form_data['data'][$field['#name']]; if (!isset($form[$name]['#pattern'])) { $form[$name]['#pattern'] = $table_row; } } } if ($k == 'slug-pre-save') { $form[$name]['#value'] = $form_data['slug']; } } /** * last setup of form */ if (empty($form_data) || isset($form_data['is_new'])) { $form['wpcf-' . $id]['is_new'] = array('#type' => 'hidden', '#name' => 'wpcf[fields][' . $id . '][is_new]', '#value' => '1', '#attributes' => array('class' => 'wpcf-is-new')); } // Set type $form['wpcf-' . $id]['type'] = array('#type' => 'hidden', '#name' => 'wpcf[fields][' . $id . '][type]', '#value' => $type, '#id' => $id . '-type'); /** * just return this form */ return $form; }
/** * Creates form elements. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @param type $post * @param type $fields * @return type */ function wpcf_admin_post_process_fields($post = false, $fields = array(), $use_cache = true, $add_to_editor = true, $context = 'group') { global $wpcf; $wpcf->field->use_cache = $use_cache; $wpcf->field->add_to_editor = $add_to_editor; $wpcf->repeater->use_cache = $use_cache; $wpcf->repeater->add_to_editor = $add_to_editor; // Get cached static $cache = array(); $cache_key = !empty($post->ID) ? $post->ID . md5(serialize($fields)) : false; if ($use_cache && $cache_key && isset($cache[$cache_key])) { return $cache[$cache_key]; } $fields_processed = array(); // Get invalid fields (if submitted) $invalid_fields = array(); if (!empty($post->ID)) { $invalid_fields = get_post_meta($post->ID, 'wpcf-invalid-fields', true); delete_post_meta($post->ID, 'wpcf-invalid-fields'); /* * * Add it to global $wpcf * From now on take it there. */ $wpcf->field->invalid_fields = $invalid_fields; } // TODO WPML Get WPML original fields $original_cf = array(); if (function_exists('wpml_get_copied_fields_for_post_edit') && !wpcf_wpml_post_is_original($post)) { $__fields_slugs = array(); foreach ($fields as $_f) { $__fields_slugs[] = $_f['meta_key']; } $original_cf = wpml_get_copied_fields_for_post_edit($__fields_slugs); } foreach ($fields as $field) { // Repetitive fields if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship') { // First check if repetitive fields are copied using WPML /* * TODO All WPML specific code needs moving to * /embedded/includes/wpml.php * * @since Types 1.2 */ // TODO WPML move if (!empty($original_cf['fields']) && in_array(wpcf_types_get_meta_prefix($field) . $field['slug'], $original_cf['fields'])) { /* * See if repeater can handle copied fields */ $wpcf->repeater->set(get_post($original_cf['original_post_id']), $field); $fields_processed = $fields_processed + $wpcf->repeater->get_fields_form(); } else { // Set repeater /* * * * @since Types 1.2 * Now we're using repeater class to handle repetitive forms. * Main change is - use form from $field_meta_box_form() without * re-processing form elements. * * Field should pass form as array: * 'my_checkbox' => array('#type' => 'checkbox' ...), * 'my_textfield' => array('#type' => 'textfield' ...), * * In form it should set values to be stored. * Use hooks to adjust saved data. */ $wpcf->repeater->set($post, $field); $fields_processed = $fields_processed + $wpcf->repeater->get_fields_form(); } /* * * * * * * * * * * * * * * * * Non-repetitive fields */ } else { /* * meta_form will be treated as normal form. * See if any obstacles prevent us from using completed * form from config files. * * Main change is - use form from $field_meta_box_form() without * re-processing form elements. * * Field should pass form as array: * 'my_checkbox' => array('#type' => 'checkbox' ...), * 'my_textfield' => array('#type' => 'textfield' ...), * * In form it should set values to be stored. * Use hooks to adjust saved data. */ $wpcf->field->set($post, $field); // TODO WPML move Check if repetitive field is copied using WPML if (!empty($original_cf['fields'])) { if (in_array($wpcf->field->slug, $original_cf['fields'])) { // Switch to parent post $wpcf->field->set(get_post($original_cf['original_post_id']), $field); } } /* * From Types 1.2 use complete form setup */ $fields_processed = $fields_processed + $wpcf->field->_get_meta_form(); } } // Cache results if ($cache_key) { $cache[$cache_key] = $fields_processed; } return $fields_processed; }
/** * Single condition form elements. * * @param type $data * @param type $condition * @param type $key * @return string */ function wpcf_cd_admin_form_single_filter($data, $condition, $key = null, $group = false, $force_multi = false) { global $wpcf; if ($group) { $name = 'wpcf[group][conditional_display]'; } else { $name = 'wpcf[fields][' . $data['id'] . '][conditional_display]'; } $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : false; /* * * * TODO Review this allowing fields from same group as conditional (self loop) * I do not remember allowing fields from same group as conditional (self loop) * on Group Fields edit screen. */ // if ( $group_id && !$group ) {// Allow group to use other fields // $fields = wpcf_admin_fields_get_fields_by_group( $group_id ); // } else { $fields = wpcf_admin_fields_get_fields(true, false, true); ksort($fields, SORT_STRING); // } if ($group) { $_distinct = wpcf_admin_fields_get_fields_by_group($group_id); foreach ($_distinct as $_field_id => $_field) { if (isset($fields[$_field_id])) { unset($fields[$_field_id]); } } } $options = array(); $ignore_field_type_array = array('audio', 'checkboxes', 'embed', 'file', 'image', 'video', 'wysiwyg'); $flag_repetitive = false; foreach ($fields as $field_id => $field) { if (!$group && $data['id'] == $field_id) { continue; } // WE DO NOT ALLOW repetitive fields to be compared. if (wpcf_admin_is_repetitive($field)) { $flag_repetitive = true; continue; } /** * Skip some files */ if (in_array($field['type'], $ignore_field_type_array)) { continue; } /** * build options */ $options[$field_id] = array('#value' => $field_id, '#title' => stripslashes($field['name']), '#attributes' => array('class' => 'wpcf-conditional-select-' . $field['type'])); } /* * Special case * https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/153565054/comments * * When field is new and only one diff field in list - that * means one field is saved but other not yet. */ $is_new = isset($data['id']) && isset($fields[$data['id']]) ? false : true; $special_stop = false; if ($is_new) { if (count($options) == 1) { $special_stop = true; } } /* * * This means all fields are repetitive and no one left to compare with. * WE DO NOT ALLOW repetitive fields to be compared. */ if (!$group && empty($options) && $flag_repetitive) { return array('cd' => array('#type' => 'markup', '#markup' => '<p class="wpcf-error">' . __('Conditional display is only working based on non-repeating fields. All fields in this group are repeating, so you cannot set their display based on other fields.', 'wpcf') . '</p>' . wpcf_conditional_disable_add_js($data['id']))); } else { if (!$group && (empty($options) || $special_stop)) { return array('cd' => array('#type' => 'markup', '#markup' => '<p>' . __('You will be able to set conditional field display when you save more fields.', 'wpcf') . '</p>')); } } $id = !is_null($key) ? $key : strval('condition_' . wpcf_unique_id(serialize($data) . serialize($condition) . $key . $group)); $form = array(); $before = '<div class="wpcf-cd-entry"><br />'; $form['cd']['field_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][field]', '#options' => $options, '#inline' => true, '#before' => $before, '#default_value' => isset($condition['field']) ? $condition['field'] : null, '#attributes' => array('class' => 'wpcf-cd-field')); $form['cd']['operation_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][operation]', '#options' => array_flip(wpcf_cd_admin_operations()), '#inline' => true, '#default_value' => isset($condition['operation']) ? $condition['operation'] : null, '#attributes' => array('class' => 'wpcf-cd-operation')); $form['cd']['value_' . $id] = array('#type' => 'textfield', '#name' => $name . '[conditions][' . $id . '][value]', '#inline' => true, '#value' => isset($condition['value']) ? $condition['value'] : '', '#attributes' => array('class' => 'wpcf-cd-value')); /* * * Adjust for date */ if (!empty($condition['value'])) { WPCF_Loader::loadInclude('fields/date/functions.php'); $timestamp = wpcf_fields_date_convert_datepicker_to_timestamp($condition['value']); if ($timestamp !== false) { $date_value = adodb_date('d', $timestamp) . ',' . adodb_date('m', $timestamp) . ',' . adodb_date('Y', $timestamp); $date_function = 'date'; } else { if (wpcf_fields_date_timestamp_is_valid($condition['value'])) { $date_value = adodb_date('d', $condition['value']) . ',' . adodb_date('m', $condition['value']) . ',' . adodb_date('Y', $condition['value']); $date_function = 'date'; } } } if (empty($date_value)) { $date_value = ''; $date_function = false; } $form['cd']['value_date_' . $id] = array('#type' => 'markup', '#markup' => '<br />' . wpcf_conditional_add_date_controls($date_function, $date_value, $name . '[conditions][' . $id . ']'), '#attributes' => array('class' => 'wpcf-cd-value-date')); $form['cd']['remove_' . $id] = array('#type' => 'button', '#name' => 'remove', '#value' => __('Remove condition', 'wpcf'), '#attributes' => array('onclick' => 'wpcfCdRemoveCondition(jQuery(this));', 'class' => 'wpcf-add-condition'), '#after' => '</div><br />'); return $form['cd']; }
/** * Edit fields form. * * @param type $parent * @param type $child */ function wpcf_pr_admin_edit_fields($parent, $child) { $post_type_parent = get_post_type_object($parent); $post_type_child = get_post_type_object($child); if (empty($post_type_parent) || empty($post_type_child)) { die(__('Wrong post types', 'wpcf')); } $relationships = get_option('wpcf_post_relationship', array()); if (!isset($relationships[$parent][$child])) { die(__('Relationship do not exist', 'wpcf')); } $data = $relationships[$parent][$child]; wp_enqueue_script('jquery'); wp_enqueue_style('types'); wpcf_admin_ajax_head('Edit fields', 'wpcf'); // Process submit if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) { $relationships[$parent][$child]['fields_setting'] = sanitize_text_field($_POST['fields_setting']); // @todo Maybe sanitization here $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array(); update_option('wpcf_post_relationship', $relationships); ?> <script type="text/javascript"> window.parent.jQuery('#TB_closeWindowButton').trigger('click'); window.parent.location.reload(); </script> <?php die; } $groups = wpcf_admin_get_groups_by_post_type($child); $options_cf = array(); $repetitive_warning = false; $repetitive_warning_markup = array(); $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf'); foreach ($groups as $group) { $fields = wpcf_admin_fields_get_fields_by_group($group['id']); foreach ($fields as $key => $cf) { $__key = wpcf_types_cf_under_control('check_outsider', $key) ? $key : WPCF_META_PREFIX . $key; $options_cf[$__key] = array(); $options_cf[$__key]['#title'] = $cf['name']; $options_cf[$__key]['#name'] = 'fields[' . $__key . ']'; $options_cf[$__key]['#default_value'] = isset($data['fields'][$__key]) ? 1 : 0; // Repetitive warning if (wpcf_admin_is_repetitive($cf)) { if (!$repetitive_warning) { $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>'); } $repetitive_warning = true; $options_cf[$__key]['#after'] = !isset($data['fields'][$__key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>'; $options_cf[$__key]['#after'] .= $repetitive_warning_txt; $options_cf[$__key]['#after'] .= '</p></div>'; $options_cf[$__key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();', 'disabled' => 'disabled'); } } } $form = array(); $form['repetitive_warning_markup'] = $repetitive_warning_markup; $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('Do not show management options for this post type', 'wpcf') => 'only_list', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']); /** * check default, to avoid missing configuration */ if (!in_array($form['select']['#default_value'], $form['select']['#options'])) { $form['select']['#default_value'] = 'all_cf'; } /** * build options for "Specific fields" */ $options = array(); /** * check and add build-in properites */ $check_support = array('title' => array('name' => '_wp_title', 'title' => __('Post title', 'wpcf')), 'editor' => array('name' => '_wp_body', 'title' => __('Post body', 'wpcf')), 'excerpt' => array('name' => '_wp_excerpt', 'title' => __('Post excerpt', 'wpcf')), 'thumbnail' => array('name' => '_wp_featured_image', 'title' => __('Post featured image', 'wpcf'))); foreach ($check_support as $child_field_key => $child_field_data) { if (!post_type_supports($child, $child_field_key)) { continue; } $options[$child_field_data['name']] = array('#title' => $child_field_data['title'], '#name' => sprintf('fields[%s]', $child_field_data['name']), '#default_value' => isset($data['fields'][$child_field_data['name']]) ? 1 : 0); } /** * add custom fields */ $options = $options + $options_cf; $temp_belongs = wpcf_pr_admin_get_belongs($child); foreach ($temp_belongs as $temp_parent => $temp_data) { if ($temp_parent == $parent) { continue; } $temp_parent_type = get_post_type_object($temp_parent); $options[$temp_parent] = array(); $options[$temp_parent]['#title'] = $temp_parent_type->label; $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']'; $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0; } /** * remove "Specific fields" if there is no fields */ if (empty($options)) { unset($form['select']['#options'][__('Specific fields', 'wpcf')]); if ('specific' == $form['select']['#default_value']) { $form['select']['#default_value'] = 'all_cf'; } } // Taxonomies $taxonomies = get_object_taxonomies($post_type_child->name, 'objects'); if (!empty($taxonomies)) { foreach ($taxonomies as $tax_id => $taxonomy) { $options[$tax_id] = array(); $options[$tax_id]['#title'] = sprintf(__('Taxonomy - %s', 'wpcf'), $taxonomy->label); $options[$tax_id]['#name'] = 'fields[_wpcf_pr_taxonomies][' . $tax_id . ']'; $options[$tax_id]['#default_value'] = isset($data['fields']['_wpcf_pr_taxonomies'][$tax_id]) ? 1 : 0; } } $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>'); $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary')); echo '<form method="post" action="" class="types-select-child-fields">'; echo wpcf_form_simple($form); echo wp_nonce_field('pt_edit_fields'); echo '</form>'; ?> <script type="text/javascript"> jQuery(document).ready(function(){ if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') { jQuery('#wpcf-specific').show(); } else { <?php if ($repetitive_warning && 'only_list' != $form['select']['#default_value']) { ?> jQuery('#wpcf-repetitive-warning').show(); <?php } ?> } jQuery('input[name="fields_setting"]').change(function(){ if (jQuery(this).val() == 'specific') { jQuery('#wpcf-specific').slideDown(); } else { jQuery('#wpcf-specific').slideUp(); <?php if ($repetitive_warning) { ?> if ( 'only_list' != jQuery('input[name="fields_setting"]:checked').val()) { jQuery('#wpcf-repetitive-warning').show(); } <?php } ?> } }); }); </script> <?php wpcf_admin_ajax_footer(); }
/** * Post relationship has form headers. * * @global type $wpcf_post_relationship_headers * @param type $post * @param type $post_type * @param type $parent_post_type * @param type $data * @return string */ function wpcf_pr_admin_post_meta_box_has_form_headers($post, $post_type, $parent_post_type, $data) { // Sorting $dir = isset($_GET['sort']) && $_GET['sort'] == 'ASC' ? 'DESC' : 'ASC'; $dir_default = 'ASC'; $sort_field = isset($_GET['field']) ? $_GET['field'] : ''; $headers = array(); $wpcf_fields = wpcf_admin_fields_get_fields(true); if (empty($data['fields_setting'])) { $data['fields_setting'] = 'all_cf'; } if ($data['fields_setting'] == 'specific') { $keys = array_keys($data['fields']); foreach ($keys as $k => $header) { if ($header == '_wpcf_pr_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(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($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] = $sort_field == '_wpcf_pr_parent' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : ''; $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>'; } } } else { $item = new stdClass(); $item->ID = 'new_' . wpcf_unique_id(serialize($post)); $item->post_title = ''; $item->post_content = ''; $item->post_type = $post_type; $groups = wpcf_admin_post_get_post_groups_fields($item, 'post_relationships_header'); $title_dir = $sort_field == '_wp_title' ? $dir : $dir_default; $headers['_wp_title'] = ''; $headers['_wp_title'] .= $sort_field == '_wp_title' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : ''; $headers['_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>'; if ($data['fields_setting'] == 'all_cf_standard') { $body_dir = $sort_field == '_wp_body' ? $dir : $dir_default; $headers['_wp_body'] = ''; $headers['_wp_body'] .= $sort_field == '_wp_body' ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : ''; $headers['_wp_body'] = '<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>'; } foreach ($groups as $group) { foreach ($group['fields'] as $field) { if (wpcf_admin_is_repetitive($field)) { $repetitive_warning = true; } $header_key = wpcf_types_get_meta_prefix($field) . $field['slug']; wpcf_admin_post_field_load_js_css(wpcf_fields_type_action($field['type'])); $field_dir = $sort_field == wpcf_types_get_meta_prefix($field) . $field['slug'] ? $dir : $dir_default; $headers[$header_key] = ''; $headers[$header_key] .= $sort_field == wpcf_types_get_meta_prefix($field) . $field['slug'] ? '<div class="wpcf-pr-sort-' . $dir . '"></div>' : ''; $headers[$header_key] .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pr_sort&field=' . wpcf_types_get_meta_prefix($field) . $field['slug'] . '&sort=' . $field_dir . '&post_id=' . $post->ID . '&post_type=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_sort')) . '">' . stripslashes($field['name']) . '</a>'; } } // Get all parents $item_parents = wpcf_pr_admin_get_belongs($post_type); if ($item_parents) { foreach ($item_parents as $temp_parent => $temp_data) { if ($temp_parent == $parent_post_type) { continue; } $temp_parent_type = get_post_type_object($temp_parent); $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>'; } } } return $headers; }