/** * Editor callback form. */ function wpcf_fields_url_editor_callback($field, $settings) { if (empty($settings['target'])) { $settings['target'] = '_self'; } $settings['target_options'] = array('_blank' => __('_blank: Opens in a new window or tab', 'wpcf'), '_self' => __('_self: Opens in the same frame as it was clicked', 'wpcf'), '_parent' => __('_parent: Opens in the parent frame', 'wpcf'), '_top' => __('_top: Opens in the full body of the window', 'wpcf'), 'framename' => __('framename: Opens in a named frame', 'wpcf')); return array('supports' => array('styling', 'style'), 'tabs' => array('display' => array('menu_title' => __('Display options', 'wpcf'), 'title' => __('Display options for this field:', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-url', $settings)), 'target' => array('menu_title' => __('Target', 'wpcf'), 'title' => __('Target', 'wpcf'), 'content' => '<div data-bind="template: {name:\'tpl-types-modal-url-target\'}"></div>'))); }
public static function init($settings = array()) { self::$__settings = (array) $settings; self::__registerScripts(); self::__registerStyles(); self::__toolset(); add_action('admin_print_scripts', array('WPCF_Loader', 'renderJsSettings'), 5); add_filter('the_posts', array('WPCF_Loader', 'wpcf_cache_complete_postmeta')); }
/** * Editor callback form. */ function wpcf_fields_checkboxes_editor_callback($field, $settings) { $data = array(); if (!empty($field['data']['options'])) { $index = 0; foreach ($field['data']['options'] as $option_key => $option) { $data['checkboxes'][$option_key] = array('id' => $option_key, 'title' => $option['title'], 'selected' => isset($settings['options'][$index]['selected']) ? $settings['options'][$index]['selected'] : htmlspecialchars(stripslashes(strval($option['display_value_selected']))), 'not_selected' => isset($settings['options'][$index]['not_selected']) ? $settings['options'][$index]['not_selected'] : htmlspecialchars(stripslashes(strval($option['display_value_not_selected'])))); $index++; } } return array('supports' => array('style'), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-checkboxes', $data)))); }
/** * Editor callback form. */ function wpcf_fields_checkbox_editor_callback($field, $settings) { $value_not_selected = ''; $value_selected = ''; if (isset($field['data']['display_value_not_selected'])) { $value_not_selected = $field['data']['display_value_not_selected']; } if (isset($field['data']['display_value_selected'])) { $value_selected = $field['data']['display_value_selected']; } $data = array_merge(array('selected' => WPCF_Editor::sanitizeParams($value_selected), 'not_selected' => WPCF_Editor::sanitizeParams($value_not_selected)), $settings); return array('supports' => array('style'), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-checkbox', $data)))); }
/** * Editor callback form. */ function wpcf_fields_entry_editor_callback($field, $settings) { $post_type = get_post_type_object($field['data']['post_type']); if (null == $post_type) { return; } $data = wpcf_fields_entry_get_options(); foreach ($data['options'] as $key => $field_data) { if (wpcf_fields_entry_check_is_available($field['data']['post_type'], $field_data)) { continue; } unset($data['options'][$key]); } return array('supports' => array('style'), 'tabs' => array('display' => array('menu_title' => __('Display options', 'wpcf'), 'title' => __('Display options for this field:', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-entry', $data)))); }
/** * Editor callback form. */ function wpcf_fields_radio_editor_callback($field, $data) { if (!isset($data['options'])) { $data['options'] = array(); } if (!empty($field['data']['options'])) { foreach ($field['data']['options'] as $option_id => $option) { if ($option_id == 'default') { continue; } if (isset($data['options'][$option_id])) { $value = $data['options'][$option_id]; $data['options'][$option_id] = array('title' => $option['title'], 'value' => $value); continue; } $value = isset($option['display_value']) ? $option['display_value'] : $option['value']; $data['options'][$option_id] = array('title' => $option['title'], 'value' => $value); } } return array('supports' => array('style'), 'tabs' => array('display' => array('menu_title' => __('Display options', 'wpcf'), 'title' => __('Display options for this field:', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-radio', $data)))); }
/** * Editor callback form. */ function wpcf_fields_embed_editor_callback($field, $data, $meta_type, $post) { // Get attachment $attachment_id = false; if (!empty($post->ID)) { $file = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if (empty($file)) { $user_id = wpcf_usermeta_get_user(); $file = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true); } if (!empty($file)) { // Get attachment by guid global $wpdb; $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\n WHERE post_type = 'attachment' AND guid=%s", $file)); } } // Set data $data['attachment_id'] = $attachment_id; $data['file'] = !empty($file) ? $file : ''; return array('supports' => array(), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-embed', $data))), 'settings' => $data); }
/** * Set current post and field. * * @param type $post * @param type $cf */ function set($user_id, $cf) { global $wpcf; /* * * Check if $cf is string */ if (is_string($cf)) { WPCF_Loader::loadInclude('fields'); $cf = wpcf_admin_fields_get_field($this->__get_slug_no_prefix($cf)); if (empty($cf)) { $this->_reset(); return false; } } $this->currentUID = $user_id; $this->ID = $cf['id']; $this->cf = $cf; $this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug']; $this->meta = $this->_get_meta(); $this->config = $this->_get_config(); $this->unique_id = wpcf_unique_id(serialize((array) $this)); $this->cf['value'] = $this->meta; // Debug $wpcf->debug->fieds[$this->unique_id] = $this->cf; $wpcf->debug->meta[$this->slug][] = $this->meta; // Load files if (isset($this->cf['type'])) { $file = WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php'; if (file_exists($file)) { include_once $file; } if (defined('WPCF_INC_ABSPATH')) { $file = WPCF_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php'; if (file_exists($file)) { include_once $file; } } } }
/** * Main conditinal evaluation function. * * @since 1.2 * @version 0.2 * @param type $o * @return boolean */ public static function evaluate($o) { // Set vars $post = $o->post; $field = $o->cf; /* * * Since Types 1.2 * We force initial value to be FALSE. * Better to have restricted than allowed because of sensitive data. * If conditional is set on field and it goes wrong - better to abort * so user can report bug without exposing his content. */ $passed = false; if (empty($post->ID)) { /* * * Keep all forbidden if post is not saved. */ $passed = false; /* * * * * * * * * * * VIEWS * * Custom call uses Views code * wpv_filter_parse_date() * wpv_condition() */ } else { if (isset($field['data']['conditional_display']['custom_use'])) { /* * * * More malformed forbids */ if (empty($field['data']['conditional_display']['custom'])) { return false; } /* * * * Filter meta values (switch them with $_POST values) * Used by Views, Types do not need it. */ if ($o->context == 'relationship') { add_filter('get_post_metadata', array('WPCF_Evaluate', 'relationship_custom_statement_meta_ajax_validation_filter'), 10, 4); } else { add_filter('get_post_metadata', array('WPCF_Evaluate', 'meta_ajax_validation_filter'), 10, 4); } do_action('types_custom_conditional_statement', $o); /* * * Set statement */ $evaluate = trim(stripslashes($field['data']['conditional_display']['custom'])); // Check dates $evaluate = wpv_filter_parse_date($evaluate); // Add quotes = > < >= <= === <> !== $strings_count = preg_match_all('/[=|==|===|<=|<==|<===|>=|>==|>===|\\!===|\\!==|\\!=|<>]\\s(?!\\$)(\\w*)[\\)|\\$|\\W]/', $evaluate, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $temp_match) { $temp_replace = is_numeric($temp_match) ? $temp_match : '\'' . $temp_match . '\''; $evaluate = str_replace(' ' . $temp_match . ')', ' ' . $temp_replace . ')', $evaluate); } } preg_match_all('/\\$([^\\s]*)/', $field['data']['conditional_display']['custom'], $matches); if (empty($matches)) { /* * * If statement false */ $passed = false; } else { /* * * * If statement right, check condition */ $fields = array(); foreach ($matches[1] as $field_name) { /* * * * This field value is checked */ $f = wpcf_admin_fields_get_field(trim(strval($field_name))); if (empty($f)) { return false; } $c = new WPCF_Field(); $c->set($post, $f); // Set field $fields[$field_name] = $c->slug; } $fields['evaluate'] = $evaluate; $check = wpv_condition($fields, $post); /* * * * Views return string malformed, * boolean if call completed. */ if (!is_bool($check)) { $passed = false; } else { $passed = $check; } } /* * * * Remove filter meta values */ if ($o->context == 'relationship') { remove_filter('get_post_metadata', array('WPCF_Evaluate', 'relationship_custom_statement_meta_ajax_validation_filter'), 10, 4); } else { remove_filter('get_post_metadata', array('WPCF_Evaluate', 'meta_ajax_validation_filter'), 10, 4); } } else { /* * * * * * * * * * TYPES * * If not custom code, use Types built-in check. * wpcf_cd_admin_compare() */ $passed_all = true; $passed_one = false; // Basic check if (empty($field['data']['conditional_display']['conditions'])) { return false; } // Keep count to see if OR/AND relation needed $count = count($field['data']['conditional_display']['conditions']); foreach ($field['data']['conditional_display']['conditions'] as $condition) { /* * * * Malformed condition and should be treated as forbidden */ if (!isset($condition['field']) || !isset($condition['operation']) || !isset($condition['value'])) { $passed_one = false; continue; } /* * * * This field value is checked */ $f = wpcf_admin_fields_get_field(trim(strval($condition['field']))); if (empty($f)) { return false; } $c = new WPCF_Field(); $c->set($post, $f); /* * * Since Types 1.2 * meta is property of WPCF_Field::$__meta * * BREAKPOINT * This is where values for evaluation are set. * Please do not allow other places - use hooks. * * TODO Monitor this * 1.3 Change use of $c->_get_meta( 'POST' ) * to $c->get_submitted_data() */ // $value = defined( 'DOING_AJAX' ) ? $c->_get_meta( 'POST' ) : $c->__meta; $value = defined('DOING_AJAX') ? $c->get_submitted_data() : $c->__meta; /* * * Apply filters */ $value = apply_filters('wpcf_conditional_display_compare_meta_value', $value, $c->cf['id'], $condition['operation'], $c->slug, $post); $condition['value'] = apply_filters('wpcf_conditional_display_compare_condition_value', $condition['value'], $c->cf['id'], $condition['operation'], $c->slug, $post); /* * * * Call built-in Types compare func */ WPCF_Loader::loadInclude('conditional-display'); $passed = wpcf_cd_admin_compare($condition['operation'], $value, $condition['value']); if (!$passed) { $passed_all = false; } else { $passed_one = true; } } /* * * * Check OR/AND relation */ if ($count > 1) { if ($field['data']['conditional_display']['relation'] == 'AND') { $passed = $passed_all; } else { if ($field['data']['conditional_display']['relation'] == 'OR') { $passed = $passed_one; } } } } } return (bool) $passed; }
/** * TinyMCE editor form. */ function wpcf_fields_date_editor_callback($field, $settings) { $data = array('date_formats' => array()); $date_formats = apply_filters('date_formats', array(__('F j, Y', 'wpcf'), 'Y/m/d', 'm/d/Y', 'd/m/Y', 'd/m/y')); // Custom format $data['custom'] = isset($settings['custom']) ? $settings['custom'] : get_option('date_format'); /** * date with hour and minutes */ if (isset($field['data']) && isset($field['data']['date_and_time']) && 'and_time' == $field['data']['date_and_time']) { $date_formats = apply_filters('date_formats', array(__('F j, Y g:i a', 'wpcf'), 'Y/m/d g:i a', 'm/d/Y h:i a', 'd/m/Y G:i', 'd/m/y H:i')); // Custom format $data['custom'] = sprintf('%s %s', get_option('date_format'), get_option('time_format')); } $data['default'] = 'custom'; foreach ($date_formats as $k => $format) { $title = date($format, time()); $data['date_formats'][$k] = array('id' => sanitize_title($format), 'title' => $title, 'format' => $format, 'default' => isset($settings['format']) && $format == $settings['format'] ? true : false); if ($data['date_formats'][$k]['default']) { $data['default'] = $data['date_formats'][$k]['id']; } } return array('supports' => array('styling'), 'tabs' => array('display' => array('menu_title' => __('Display options', 'wpcf'), 'title' => __('Display options for this field:', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-date', $data)))); }
/** * Process AJAX conditional verify. * * @global type $wpcf * @param type $data * @return boolean|string */ public static function conditionalVerify($data) { WPCF_Loader::loadInclude('fields'); WPCF_Loader::loadInclude('fields-post'); WPCF_Loader::loadInclude('conditional-display'); global $wpcf; $js_execute = ''; $_flag_relationship = false; /* * * Determine post. */ if (empty($data['wpcf']) && !empty($data['wpcf_post_relationship'])) { /* * Relationship case */ $_temp = $data['wpcf_post_relationship']; $parent_id = key($_temp); $_data = array_shift($_temp); $post_id = key($_data); $post = get_post($post_id); $posted_fields = $_data[$post_id]; $_flag_relationship = true; /* * * Regular submission */ } else { if (isset($data['wpcf_main_post_id'])) { $post_id = intval($data['wpcf_main_post_id']); $post = get_post($post_id); } } // No post if (empty($post->ID)) { return false; } // Get Groups (Fields) for current post $groups = wpcf_admin_post_get_post_groups_fields($post); $_processed = array(); foreach ($groups as $group) { if (!empty($group['fields'])) { foreach ($group['fields'] as $field_id => $field) { // Check if already processed if (isset($_processed[$field_id])) { continue; } if ($wpcf->conditional->is_conditional($field_id)) { if ($_flag_relationship) { // Process only submitted fields if (!isset($posted_fields[WPCF_META_PREFIX . $field_id])) { continue; } $wpcf->conditional->set($post, $field_id); $wpcf->conditional->context = 'relationship'; $_relationship_name = false; // Set name and other values processed by hooks $parent = get_post($parent_id); if (!empty($parent->ID)) { $wpcf->relationship->set($parent, $post); $wpcf->relationship->cf->set($post, $field_id); $_child = $wpcf->relationship->get_child(); $_child->form->cf->set($post, $field_id); $_relationship_name = $_child->form->alter_form_name('wpcf[' . $wpcf->conditional->cf['id'] . ']'); } if (!$_relationship_name) { continue; } /* * BREAKPOINT * Adds filtering regular evaluation (not wpv_conditional) */ add_filter('types_field_get_submitted_data', 'wpcf_relationship_ajax_data_filter', 10, 2); $name = $_relationship_name; } else { $wpcf->conditional->set($post, $field_id); $name = 'wpcf[' . $wpcf->conditional->cf['id'] . ']'; } // Evaluate $passed = $wpcf->conditional->evaluate(); if ($passed) { $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.' . 'wpcf-conditional' . '\').show().removeClass(\'' . 'wpcf-conditional' . '-failed\').addClass(\'' . 'wpcf-conditional' . '-passed\');' . " "; $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.wpcf-repetitive-wrapper\').show();'; } else { $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.wpcf-repetitive-wrapper\').hide();'; $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.' . 'wpcf-conditional' . '\').hide().addClass(\'' . 'wpcf-conditional' . '-failed\').removeClass(\'' . 'wpcf-conditional' . '-passed\');' . " "; } } $_processed[$field_id] = true; } } } return $js_execute; }
/** * All AJAX calls go here. * * @todo auth */ function wpcf_ajax_embedded() { if (isset($_REQUEST['_typesnonce'])) { if (!wp_verify_nonce($_REQUEST['_typesnonce'], '_typesnonce')) { die('Verification failed'); } } else { if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action'])) { die('Verification failed'); } } global $wpcf; switch ($_REQUEST['wpcf_action']) { case 'insert_skype_button': if (!current_user_can('edit_posts')) { die('Authentication failed'); } require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/skype.php'; wpcf_fields_skype_meta_box_ajax(); break; case 'editor_callback': if (!current_user_can('edit_posts')) { die('Authentication failed'); } // Determine Field type and context $views_usermeta = false; $field_id = sanitize_text_field($_GET['field_id']); // todo this could be written in like four lines if (isset($_GET['field_type']) && $_GET['field_type'] == 'usermeta') { // Group filter wp_enqueue_script('suggest'); $field = types_get_field($field_id, 'usermeta'); $meta_type = 'usermeta'; } elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'views-usermeta') { $field = types_get_field($field_id, 'usermeta'); $meta_type = 'usermeta'; $views_usermeta = true; } else { $field = types_get_field($field_id); $meta_type = 'postmeta'; } $parent_post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : null; $shortcode = isset($_GET['shortcode']) ? urldecode($_GET['shortcode']) : null; $callback = isset($_GET['callback']) ? sanitize_text_field($_GET['callback']) : false; if (!empty($field)) { // Editor WPCF_Loader::loadClass('editor'); $editor = new WPCF_Editor(); $editor->frame($field, $meta_type, $parent_post_id, $shortcode, $callback, $views_usermeta); } break; case 'dismiss_message': if (!is_user_logged_in()) { die('Authentication failed'); } if (isset($_GET['id'])) { $messages = get_option('wpcf_dismissed_messages', array()); $messages[] = sanitize_text_field($_GET['id']); update_option('wpcf_dismissed_messages', $messages); } break; case 'pr_add_child_post': $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['post_id']) && isset($_GET['post_type_child']) && isset($_GET['post_type_parent'])) { $relationships = get_option('wpcf_post_relationship', array()); $parent_post_id = intval($_GET['post_id']); $parent_post = get_post($parent_post_id); if (!empty($parent_post->ID)) { $post_type = sanitize_text_field($_GET['post_type_child']); $parent_post_type = sanitize_text_field($_GET['post_type_parent']); // @todo isset & error handling $data = $relationships[$parent_post_type][$post_type]; /* * Since Types 1.1.5 * * We save new post * CHECKPOINT */ $id = $wpcf->relationship->add_new_child($parent_post->ID, $post_type); if (is_wp_error($id)) { $output = $id->get_error_message(); } else { /* * Here we set Relationship * CHECKPOINT */ $parent = get_post($parent_post_id); $child = get_post($id); if (!empty($parent->ID) && !empty($child->ID)) { // Set post $wpcf->post = $child; // Set relationship :) $wpcf->relationship->_set($parent, $child, $data); // Render new row $output = $wpcf->relationship->child_row($parent_post->ID, $id, $data); } else { $output = __('Error creating post relationship', 'wpcf'); } } } else { $output = __('Error getting parent post', 'wpcf'); } } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output . wpcf_form_render_js_validation('#post', false), 'child_id' => $id)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')), 'child_id' => $id)); } break; case 'pr_save_all': $output = ''; if (current_user_can('edit_posts') && isset($_POST['post_id'])) { $parent_id = intval($_POST['post_id']); $post_type = sanitize_text_field($_POST['post_type']); if (isset($_POST['wpcf_post_relationship'][$parent_id])) { $children = wpcf_sanitize_post_realtionship_input((array) $_POST['wpcf_post_relationship'][$parent_id]); $wpcf->relationship->save_children($parent_id, $children); $output = $wpcf->relationship->child_meta_form($parent_id, strval($post_type)); } } if (!defined('WPTOOLSET_FORMS_VERSION')) { // TODO Move to conditional $output .= '<script type="text/javascript">wpcfConditionalInit();</script>'; } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; case 'pr_save_child_post': ob_start(); // Try to catch any errors $output = ''; if (current_user_can('edit_posts') && isset($_GET['post_id']) && isset($_GET['parent_id']) && isset($_GET['post_type_parent']) && isset($_GET['post_type_child']) && isset($_POST['wpcf_post_relationship'])) { $parent_id = intval($_GET['parent_id']); $child_id = intval($_GET['post_id']); $parent_post_type = sanitize_text_field($_GET['post_type_parent']); $child_post_type = sanitize_text_field($_GET['post_type_child']); if (isset($_POST['wpcf_post_relationship'][$parent_id][$child_id])) { $fields = wpcf_sanitize_post_relationship_input_fields((array) $_POST['wpcf_post_relationship'][$parent_id][$child_id]); $wpcf->relationship->save_child($parent_id, $child_id, $fields); $output = $wpcf->relationship->child_row($parent_id, $child_id, $wpcf->relationship->settings($parent_post_type, $child_post_type)); if (!defined('WPTOOLSET_FORMS_VERSION')) { // TODO Move to conditional $output .= '<script type="text/javascript">wpcfConditionalInit(\'#types-child-row-' . $child_id . '\');</script>'; } } } $errors = ob_get_clean(); if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output, 'errors' => $errors)); } else { echo json_encode(array('output' => $output, 'errors' => $errors, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; case 'pr_delete_child_post': require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php'; $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['post_id'])) { $output = wpcf_pr_admin_delete_child_item(intval($_GET['post_id'])); } echo json_encode(array('output' => $output)); break; case 'pr-update-belongs': require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php'; $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_POST['post_id']) && isset($_POST['wpcf_pr_belongs'][$_POST['post_id']])) { $parent_post_id = intval($_POST['post_id']); $belongs_assignments = array(); foreach ($_POST['wpcf_pr_belongs'][$parent_post_id] as $post_type_raw => $post_id_raw) { $belongs_assignments[sanitize_text_field($post_type_raw)] = intval($post_id_raw); } $updated = wpcf_pr_admin_update_belongs($parent_post_id, $belongs_assignments); $output = is_wp_error($updated) ? $updated->get_error_message() : $updated; } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; case 'pr_pagination': require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php'; $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['post_id']) && isset($_GET['post_type'])) { global $wpcf; $parent = get_post(intval($_GET['post_id'])); $child_post_type = sanitize_text_field($_GET['post_type']); if (!empty($parent->ID)) { // Set post in loop $wpcf->post = $parent; // Save items_per_page $wpcf->relationship->save_items_per_page($parent->post_type, $child_post_type, intval($_GET[$wpcf->relationship->items_per_page_option_name])); $output = $wpcf->relationship->child_meta_form($parent->ID, $child_post_type); } } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; case 'pr_sort': $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['field']) && isset($_GET['sort']) && isset($_GET['post_id']) && isset($_GET['post_type'])) { $output = $wpcf->relationship->child_meta_form(intval($_GET['post_id']), sanitize_text_field($_GET['post_type'])); } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; // Not used anywhere /*case 'pr_sort_parent': $output = 'Passed wrong parameters'; if ( isset( $_GET['field'] ) && isset( $_GET['sort'] ) && isset( $_GET['post_id'] ) && isset( $_GET['post_type'] ) ) { $output = $wpcf->relationship->child_meta_form( intval( $_GET['post_id'] ), strval( $_GET['post_type'] ) ); } if ( !defined( 'WPTOOLSET_FORMS_VERSION' ) ) { echo json_encode( array( 'output' => $output, ) ); } else { echo json_encode( array( 'output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data( 'post' )), ) ); } break;*/ /* Usermeta */ // Not used anywhere /*case 'pr_sort_parent': $output = 'Passed wrong parameters'; if ( isset( $_GET['field'] ) && isset( $_GET['sort'] ) && isset( $_GET['post_id'] ) && isset( $_GET['post_type'] ) ) { $output = $wpcf->relationship->child_meta_form( intval( $_GET['post_id'] ), strval( $_GET['post_type'] ) ); } if ( !defined( 'WPTOOLSET_FORMS_VERSION' ) ) { echo json_encode( array( 'output' => $output, ) ); } else { echo json_encode( array( 'output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data( 'post' )), ) ); } break;*/ /* Usermeta */ case 'um_repetitive_add': if (isset($_GET['user_id'])) { $user_id = $_GET['user_id']; } else { $user_id = wpcf_usermeta_get_user(); } if (isset($_GET['field_id']) && current_user_can('edit_user', $user_id)) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php'; $field = wpcf_admin_fields_get_field(sanitize_text_field($_GET['field_id']), false, false, false, 'wpcf-usermeta'); global $wpcf; $wpcf->usermeta_repeater->set($user_id, $field); /* * * Force empty values! */ $wpcf->usermeta_repeater->cf['value'] = null; $wpcf->usermeta_repeater->meta = null; $form = $wpcf->usermeta_repeater->get_field_form(null, true); echo json_encode(array('output' => wpcf_form_simple($form) . wpcf_form_render_js_validation('#your-profile', false))); } else { echo json_encode(array('output' => 'params missing')); } break; case 'um_repetitive_delete': if (isset($_POST['user_id']) && isset($_POST['field_id']) && current_user_can('edit_user', intval($_POST['user_id']))) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; $user_id = intval($_POST['user_id']); $field = wpcf_admin_fields_get_field(sanitize_text_field($_POST['field_id']), false, false, false, 'wpcf-usermeta'); $meta_id = intval($_POST['meta_id']); if (!empty($field) && !empty($user_id) && !empty($meta_id)) { /* * * * Changed. * Since Types 1.2 */ global $wpcf; $wpcf->usermeta_repeater->set($user_id, $field); $wpcf->usermeta_repeater->delete($meta_id); echo json_encode(array('output' => 'deleted')); } else { echo json_encode(array('output' => 'field or post not found')); } } else { echo json_encode(array('output' => 'params missing')); } break; /* End Usermeta */ /* End Usermeta */ case 'repetitive_add': if (current_user_can('edit_posts') && isset($_GET['field_id'])) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; $field = wpcf_admin_fields_get_field(sanitize_text_field($_GET['field_id'])); $parent_post_id = intval($_GET['post_id']); /* * When post is new - post_id is 0 * We can safely set post_id to 1 cause * values compared are filtered anyway. */ if ($parent_post_id == 0) { $parent_post_id = 1; } $parent_post = get_post($parent_post_id); global $wpcf; $wpcf->repeater->set($parent_post, $field); /* * * Force empty values! */ $wpcf->repeater->cf['value'] = null; $wpcf->repeater->meta = null; $form = $wpcf->repeater->get_field_form(null, true); echo json_encode(array('output' => wpcf_form_simple($form) . wpcf_form_render_js_validation('#post', false))); } else { echo json_encode(array('output' => 'params missing')); } break; case 'repetitive_delete': if (current_user_can('edit_posts') && isset($_POST['post_id']) && isset($_POST['field_id'])) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; $post_id = intval($_POST['post_id']); $parent_post = get_post($post_id); $field = wpcf_admin_fields_get_field(sanitize_text_field($_POST['field_id'])); $meta_id = intval($_POST['meta_id']); if (!empty($field) && !empty($parent_post->ID) && !empty($meta_id)) { /* * * * Changed. * Since Types 1.2 */ global $wpcf; $wpcf->repeater->set($parent_post, $field); $wpcf->repeater->delete($meta_id); echo json_encode(array('output' => 'deleted')); } else { echo json_encode(array('output' => 'field or post not found')); } } else { echo json_encode(array('output' => 'params missing')); } break; case 'cd_verify': if (!current_user_can('edit_posts') || empty($_POST['wpcf']) && empty($_POST['wpcf_post_relationship'])) { die; } WPCF_Loader::loadClass('helper.ajax'); $js_execute = WPCF_Helper_Ajax::conditionalVerify($_POST); // Render JSON if (!empty($js_execute)) { echo json_encode(array('output' => '', 'execute' => $js_execute, 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute'))); } die; break; case 'cd_group_verify': require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/conditional-display.php'; $group = wpcf_admin_fields_get_group(sanitize_text_field($_POST['group_id'])); if (!current_user_can('edit_posts') || empty($group)) { echo json_encode(array('output' => '')); die; } $execute = ''; $group['conditional_display'] = get_post_meta($group['id'], '_wpcf_conditional_display', true); // Filter meta values (switch them with $_POST values) add_filter('get_post_metadata', 'wpcf_cd_meta_ajax_validation_filter', 10, 4); $parent_post = false; if (isset($_SERVER['HTTP_REFERER'])) { $split = explode('?', $_SERVER['HTTP_REFERER']); if (isset($split[1])) { parse_str($split[1], $vars); if (isset($vars['post'])) { $parent_post = get_post($vars['post']); } } } // Dummy post if (!$parent_post) { $parent_post = new stdClass(); $parent_post->ID = 1; } if (!empty($group['conditional_display']['conditions'])) { $result = wpcf_cd_post_groups_filter(array(0 => $group), $parent_post, 'group'); if (!empty($result)) { $result = array_shift($result); $passed = $result['_conditional_display'] == 'passed' ? true : false; } else { $passed = false; } if (!$passed) { $execute = 'jQuery("#wpcf-group-' . $group['slug'] . '").slideUp().find(".wpcf-cd-group")' . '.addClass(\'wpcf-cd-group-failed\')' . '.removeClass(\'wpcf-cd-group-passed\').hide();'; } else { $execute = 'jQuery("#wpcf-group-' . $group['slug'] . '").show().find(".wpcf-cd-group")' . '.addClass(\'wpcf-cd-group-passed\')' . '.removeClass(\'wpcf-cd-group-failed\').slideDown();'; } } // Remove filter meta values (switch them with $_POST values) remove_filter('get_post_metadata', 'wpcf_cd_meta_ajax_validation_filter', 10, 4); echo json_encode(array('output' => '', 'execute' => $execute, 'wpcf_nonce_ajax_callback' => wp_create_nonce('execute'))); break; default: break; } if (function_exists('wpcf_ajax')) { wpcf_ajax(); } die; }
/** * 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']; }
/** * Evaluates if check passed. * * @return type */ function evaluate() { WPCF_Loader::loadClass('evaluate'); $this->passed = WPCF_Evaluate::evaluate($this); return $this->passed; }
/** * Edit Skype button AJAX call. */ function wpcf_fields_skype_meta_box_ajax() { if (isset($_POST['_wpnonce_wpcf_form']) && wp_verify_nonce($_POST['_wpnonce_wpcf_form'], 'wpcf-form')) { add_action('admin_head_wpcf_ajax', 'wpcf_fields_skype_meta_box_submit'); } wp_enqueue_script('jquery'); wpcf_admin_ajax_head(__('Insert skype button', 'wpcf')); ?> <form method="post" action=""> <h2><?php _e('Enter your Skype Name', 'wpcf'); ?> </h2> <p> <input id="btn-skypename" name="skypename" value="<?php esc_attr_e($_GET['skypename']); ?> " type="text" /> </p> <?php echo WPCF_Loader::template('skype-select-button', $_GET); ?> <?php wp_nonce_field('wpcf-form', '_wpnonce_wpcf_form'); ?> <br /><br /> <input type="submit" class="button-primary" value="<?php _e('Insert skype button', 'wpcf'); ?> " /> </form> <?php $update = esc_attr($_GET['update']); ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready(function(){ jQuery('#btn-skypename').val(window.parent.jQuery('#<?php echo $update; ?> -skypename').val()); }); //]]> </script> <?php wpcf_admin_ajax_footer(); }
/** * Returns path to attachment relative to upload_dir. * * @param type $abspath * @return string '2014/01/img.jpg' */ function wpcf_image_normalize_attachment($abspath) { WPCF_Loader::loadView('image'); return Types_Image_Utils::getInstance()->normalizeAttachment($abspath); }
_e('Crop images, so that they fill the specified dimensions exactly.', 'wpcf'); ?> </label> </p> </div> </div> <p class="form-inline"> <input id="image-url" type="checkbox" name="url" value="1" data-bind="checked: imageUrl, click: imageUrlDisable" /> <label for="image-url"><?php _e('Output only the URL of the re-sized image instead of the img tag', 'wpcf'); ?> </label> </p> <!--<input id="image-onload" type="text" name="onload" value="<?php echo $data['onload']; ?> " /> <label for="image-onload"><?php _e('Onload callback', 'wpcf'); ?> </label>--> </script><!--END TYPES MODAL IMAGE--> <?php WPCF_Loader::loadInclude('fields/colorpicker'); wpcf_fields_colorpicker_enqueue_scripts(); wpcf_fields_colorpicker_render_js();
/** * Editor callback form. */ function wpcf_fields_email_editor_callback($field, $settings) { return array('supports' => array('styling', 'style'), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-email', $settings)))); }
public static function getImgObject($img, $width, $height, $type, $mime) { if ($cached = self::$__cache->getCache("imgobj_{$img}")) { return $cached; } if (self::inUploadAbsPath($img)) { $url = self::normalizeAttachmentUrl($img); } else { WPCF_Loader::loadClass('path'); $url = WPCF_Path::getFileUrl($img, false) . '/' . basename($img); } $data = array('width' => $width, 'height' => $height, 'imagetype' => $type, 'mime' => $mime, 'url' => $url, 'path' => $img, 'pathinfo' => pathinfo($img)); $imgData = new Types_Image_Model((object) $data); return self::$__cache->setCache("imgobj_{$img}", $imgData->getImg()); }
/** * Set current post and field. * * @param type $post * @param type $cf */ function set($post, $cf) { global $wpcf; /* * * Check if $cf is string */ if (is_string($cf)) { WPCF_Loader::loadInclude('fields'); $_cf = wpcf_admin_fields_get_field($this->__get_slug_no_prefix($cf)); // Check if found without prefix if (empty($_cf)) { $_cf = wpcf_admin_fields_get_field($cf); } if (empty($_cf)) { /* * TODO Check what happens if field is not found */ $this->_reset(); return false; } $cf = $_cf; } $this->post = is_integer($post) ? get_post($post) : $post; // If empty post it is new if (empty($this->post->ID)) { $this->post = new stdClass(); $this->post->ID = 0; } $this->ID = $cf['id']; $this->cf = $cf; $this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug']; $this->meta = $this->_get_meta(); $this->config = $this->_get_config(); $this->unique_id = wpcf_unique_id(serialize((array) $this)); $this->cf['value'] = $this->meta; // Debug $wpcf->debug->fields[$this->unique_id] = $this->cf; $wpcf->debug->meta[$this->slug][] = $this->meta; // Load files $this->_include_file_by_field_type($this->cf['type']); if (defined('WPCF_INC_ABSPATH')) { $file = WPCF_INC_ABSPATH . '/fields/' . preg_replace('/[^\\w]+/', '', $this->cf['type']) . '.php'; if (file_exists($file)) { include_once $file; } } }
/** * Editor callback form. */ function wpcf_fields_numeric_editor_callback($field, $settings) { return array('supports' => array('style'), 'tabs' => array('display' => array('menu_title' => __('Display options', 'wpcf'), 'title' => __('Display options for this field:', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-numeric', $settings)))); }
/** * Gets posts that belongs to current post. * * @global type $post * @param type $post_type * @param type $args * @return type */ function types_child_posts($post_type, $args = array()) { static $cache = array(); if (isset($args['post_id'])) { $post = $args['post_id'] != '0' ? get_post($args['post_id']) : null; } else { global $post; } if (empty($post->ID)) { return array(); } $cache_key = md5($post->ID . serialize(func_get_args())); if (isset($cache[$cache_key])) { return $cache[$cache_key]; } global $wp_post_types; // WP allows querying inactive post types if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) { return array(); } $defaults = array('post_status' => array('publish')); $args = wp_parse_args($args, $defaults); WPCF_Loader::loadModel('relationship'); WPCF_Loader::loadInclude('fields-post'); $child_posts = WPCF_Relationship_Model::getChildrenByPostType($post, $post_type, array(), array(), $args); foreach ($child_posts as $child_post_key => $child_post) { $child_posts[$child_post_key]->fields = array(); $groups = wpcf_admin_post_get_post_groups_fields($child_post); foreach ($groups as $group) { if (!empty($group['fields'])) { // Process fields foreach ($group['fields'] as $k => $field) { $data = null; if (types_is_repetitive($field)) { $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false); // get all field instances } else { $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true); // get single field instance // handle checkboxes which are one value serialized if ($field['type'] == 'checkboxes' && !empty($data)) { $data = maybe_unserialize($data); } } if (!is_null($data)) { $child_posts[$child_post_key]->fields[$k] = $data; } } } } } $cache[$cache_key] = $child_posts; return $child_posts; }
/** * Editor callback form. */ function wpcf_fields_audio_editor_callback($field, $data, $meta_type, $post) { return array('supports' => array(), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-audio', $data))), 'settings' => $data); }
/** * Returns HTML formatted Taxonomy form. * * @param type $taxonomy * @return type */ function taxonomy_form($taxonomy, $simple = false) { // SIMPLIFIED VERSION if ($simple) { $terms = wp_get_post_terms($this->child->ID, $taxonomy->name, array()); $selected = !empty($terms) ? array_shift($terms)->term_id : -1; $output = wp_dropdown_categories(array('taxonomy' => $taxonomy->name, 'selected' => $selected, 'echo' => false, 'hide_empty' => false, 'hide_if_empty' => true, 'show_option_none' => sprintf(__('No %s', 'wpcf'), $taxonomy->name), 'name' => 'wpcf_post_relationship[' . $this->parent->ID . '][' . $this->child->ID . '][taxonomies][' . $taxonomy->name . ']', 'id' => 'wpcf_pr_' . $this->child->ID . '_' . $taxonomy->name, 'hierarchical' => true, 'depth' => 9999)); return empty($output) ? sprintf(__('No %s', 'wpcf'), $taxonomy->label) : $output; } $data = array('post' => $this->child, 'taxonomy' => $taxonomy->name); if ($taxonomy->name == 'category') { $data['_wpcf_name'] = "wpcf_post_relationship[{$this->parent->ID}][{$this->child->ID}][taxonomies][{$taxonomy->name}][]"; $output = WPCF_Loader::template('child-tax-category', $data); // Reduce JS processing return str_replace("name=\"post_category[]", "name=\"{$data['_wpcf_name']}", $output); } if ($taxonomy->hierarchical) { $data['_wpcf_name'] = "wpcf_post_relationship[{$this->parent->ID}][{$this->child->ID}][taxonomies][{$taxonomy->name}][]"; $output = WPCF_Loader::template('child-tax-category', $data); // Reduce JS processing return str_replace("name=\"tax_input[{$taxonomy->name}][]", "name=\"{$data['_wpcf_name']}", $output); } $data['_wpcf_name'] = "wpcf_post_relationship[{$this->parent->ID}][{$this->child->ID}][taxonomies][{$taxonomy->name}]"; $output = WPCF_Loader::template('child-tax-tag', $data); // Reduce JS processing return str_replace("name=\"tax_input[{$taxonomy->name}]", "name=\"{$data['_wpcf_name']}", $output); }
/** * TinyMCE editor form. */ function wpcf_fields_date_editor_callback($field, $settings) { $data = array('date_formats' => array()); $date_formats = apply_filters('date_formats', array(__('F j, Y'), 'Y/m/d', 'm/d/Y', 'd/m/Y', 'd/m/y')); // Custom format $data['custom'] = isset($settings['custom']) ? $settings['custom'] : get_option('date_format'); $data['default'] = 'custom'; foreach ($date_formats as $k => $format) { $title = date($format, time()); $data['date_formats'][$k] = array('id' => sanitize_title($format), 'title' => $title, 'format' => $format, 'default' => isset($settings['format']) && $format == $settings['format'] ? true : false); if ($data['date_formats'][$k]['default']) { $data['default'] = $data['date_formats'][$k]['id']; } } return array('supports' => array('styling'), 'tabs' => array('display' => array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => WPCF_Loader::template('editor-modal-date', $data)))); }
/** * Main init hook. * * All rest of init processes are continued here. * Sets locale, constants, includes... * * @todo Make sure plugin AND embedded code are calling this function on 'init' * @todo Test priorities */ function wpcf_embedded_init() { global $types_instances, $wp_current_filter; // Record hook $types_instances['hook'] = $wp_current_filter; $types_instances['init_queued'] = '#' . did_action('init'); $types_instances['init_priority'] = TYPES_INIT_PRIORITY; $types_instances['forced_embedded'] = defined('TYPES_LOAD_EMBEDDED') && TYPES_LOAD_EMBEDDED; // Loader require_once WPCF_EMBEDDED_ABSPATH . '/classes/loader.php'; do_action('wpcf_before_init'); do_action('types_before_init'); // Define necessary constants if plugin is not present // This ones are skipped if used as embedded code! if (!defined('WPCF_VERSION')) { define('WPCF_VERSION', '1.6.6.3'); define('WPCF_META_PREFIX', 'wpcf-'); } // If forced embedded mode use path to __FILE__ if (defined('TYPES_LOAD_EMBEDDED') && TYPES_LOAD_EMBEDDED || !defined('WPCF_RELPATH')) { define('WPCF_EMBEDDED_RELPATH', wpcf_get_file_url(__FILE__, false)); } else { define('WPCF_EMBEDDED_RELPATH', WPCF_RELPATH . '/embedded'); } // Define embedded paths define('WPCF_EMBEDDED_INC_RELPATH', WPCF_EMBEDDED_RELPATH . '/includes'); define('WPCF_EMBEDDED_RES_RELPATH', WPCF_EMBEDDED_RELPATH . '/resources'); // TODO INCLUDES! // // Please add all required includes here // Since Types 1.2 we can consider existing code as core. // All new functionalities should be added as includes HERE // and marked with @since Types $version. // // Thanks! // // Basic /* * * Mind class extensions queue */ require_once WPCF_EMBEDDED_ABSPATH . '/classes/fields.php'; require_once WPCF_EMBEDDED_ABSPATH . '/classes/field.php'; require_once WPCF_EMBEDDED_ABSPATH . '/classes/usermeta_field.php'; // Added by Gen, usermeta fields class // Repeater require_once WPCF_EMBEDDED_ABSPATH . '/classes/repeater.php'; require_once WPCF_EMBEDDED_ABSPATH . '/classes/usermeta_repeater.php'; // Added by Gen, usermeta repeater class require_once WPCF_EMBEDDED_INC_ABSPATH . '/repetitive-fields-ordering.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/repetitive-usermetafields-ordering.php'; // Relationship require_once WPCF_EMBEDDED_ABSPATH . '/classes/relationship.php'; // Conditional require_once WPCF_EMBEDDED_ABSPATH . '/classes/conditional.php'; // API require_once WPCF_EMBEDDED_INC_ABSPATH . '/api.php'; // Validation require_once WPCF_EMBEDDED_ABSPATH . '/classes/validation.php'; // Post Types require_once WPCF_EMBEDDED_ABSPATH . '/classes/class.wpcf-post-types.php'; // Import Export require_once WPCF_EMBEDDED_ABSPATH . '/classes/class.wpcf-import-export.php'; // Module manager require_once WPCF_EMBEDDED_INC_ABSPATH . '/module-manager.php'; // WPML specific code require_once WPCF_EMBEDDED_INC_ABSPATH . '/wpml.php'; // CRED specific code. if (defined('CRED_FE_VERSION')) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/cred.php'; } /* * * * TODO This is a must for now. * See if any fields need to be loaded. * * 1. Checkboxes - may be missing when submitted */ require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/checkbox.php'; /* * * * Use this call to load basic scripts and styles if necesary * wpcf_enqueue_scripts(); */ require_once WPCF_EMBEDDED_ABSPATH . '/usermeta-init.php'; // Include frontend or admin code if (is_admin()) { require_once WPCF_EMBEDDED_ABSPATH . '/admin.php'; /* * TODO Check if called twice * * Watch this! This is actually called twice everytime * in both modes (plugin or embedded) */ wpcf_embedded_admin_init_hook(); } else { require_once WPCF_EMBEDDED_ABSPATH . '/frontend.php'; } global $wpcf; // TODO since Types 1.2 Continue adding new functionalities HERE /* * Consider code already there as core. * Use hooks to add new functionalities * * Introduced new global object $wpcf * Holds useful objects like: * $wpcf->field - Field object (base item object) * $wpcf->repeater - Repetitive field object */ // Set debugging if (!defined('WPCF_DEBUG')) { define('WPCF_DEBUG', false); } else { if (WPCF_DEBUG) { wp_enqueue_script('jquery'); } } $wpcf->debug = new stdClass(); require WPCF_EMBEDDED_INC_ABSPATH . '/debug.php'; add_action('wp_footer', 'wpcf_debug', PHP_INT_MAX); add_action('admin_footer', 'wpcf_debug', PHP_INT_MAX); // Set field object $wpcf->field = new WPCF_Field(); // Set fields object $wpcf->fields = new WPCF_Fields(); // Set usermeta field object $wpcf->usermeta_field = new WPCF_Usermeta_Field(); // Set repeater object $wpcf->usermeta_repeater = new WPCF_Usermeta_Repeater(); // Set repeater object $wpcf->repeater = new WPCF_Repeater(); // Set relationship object $wpcf->relationship = new WPCF_Relationship(); // Set conditional object $wpcf->conditional = new WPCF_Conditional(); // Set validate object $wpcf->validation = new WPCF_Validation(); // Set import export objects $wpcf->import = new WPCF_Import_Export(); $wpcf->export = new WPCF_Import_Export(); // Set post object $wpcf->post = new stdClass(); // Set post types object $wpcf->post_types = new WPCF_Post_Types(); // Define exceptions - privileged plugins and their data $wpcf->toolset_post_types = array('view', 'view-template', 'cred-form'); // 'attachment' = Media // $wpcf->excluded_post_types = array('dd_layouts', 'cred-form', 'mediapage', 'nav_menu_item', 'revision', 'view', 'view-template', 'wp-types-group', 'wp-types-user-group'); // Init loader WPCF_Loader::init(); /* * TODO Check why we enabled this * * I think because of CRED or Views using Types admin functions on frontend * Does this need review? */ if (defined('DOING_AJAX')) { require_once WPCF_EMBEDDED_ABSPATH . '/frontend.php'; } // Check if import/export request is going on wpcf_embedded_check_import(); do_action('types_after_init'); do_action('wpcf_after_init'); }
/** * Processes AJAX call 'cd_verify'. * * @param type $data * @return type */ function ajaxVerify($data) { WPCF_Loader::loadClass('helper.ajax'); return WPCF_Helper_Ajax::conditionalVerify($data); }
/** * Validation wrapper. * * @param type $method * @param type $args * @return boolean */ function types_validate($method, $args) { WPCF_Loader::loadClass('validation-cakephp'); if (is_callable(array('Wpcf_Cake_Validation', $method))) { if (!is_array($args)) { $args = array($args); } return @call_user_func_array(array('Wpcf_Cake_Validation', $method), $args); } return false; }
/** * All AJAX calls go here. * * @todo auth */ function wpcf_ajax_embedded() { if (isset($_REQUEST['_typesnonce'])) { if (!wp_verify_nonce($_REQUEST['_typesnonce'], '_typesnonce')) { die('Verification failed (1)'); } } else { if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['wpcf_action'])) { die('Verification failed (2)'); } } global $wpcf; switch ($_REQUEST['wpcf_action']) { case 'insert_skype_button': if (!current_user_can('edit_posts')) { die('Authentication failed'); } require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/skype.php'; wpcf_fields_skype_meta_box_ajax(); break; case 'editor_callback': if (!current_user_can('edit_posts')) { die('Authentication failed'); } // Determine Field type and context $views_meta = false; $field_id = sanitize_text_field($_GET['field_id']); // todo this could be written in like four lines if (isset($_GET['field_type']) && $_GET['field_type'] == 'usermeta') { // Group filter wp_enqueue_script('suggest'); $field = types_get_field($field_id, 'usermeta'); $meta_type = 'usermeta'; } elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'views-usermeta') { $field = types_get_field($field_id, 'usermeta'); $meta_type = 'usermeta'; $views_meta = true; } elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'termmeta') { // Group filter wp_enqueue_script('suggest'); $field = types_get_field($field_id, 'termmeta'); $meta_type = 'termmeta'; } elseif (isset($_GET['field_type']) && $_GET['field_type'] == 'views-termmeta') { $field = types_get_field($field_id, 'termmeta'); $meta_type = 'termmeta'; $views_meta = true; } else { $field = types_get_field($field_id); $meta_type = 'postmeta'; } $parent_post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : null; $shortcode = isset($_GET['shortcode']) ? urldecode($_GET['shortcode']) : null; $callback = isset($_GET['callback']) ? sanitize_text_field($_GET['callback']) : false; if (!empty($field)) { // Editor WPCF_Loader::loadClass('editor'); $editor = new WPCF_Editor(); $editor->frame($field, $meta_type, $parent_post_id, $shortcode, $callback, $views_meta); } break; case 'dismiss_message': if (!is_user_logged_in()) { die('Authentication failed'); } if (isset($_GET['id'])) { $messages = get_option('wpcf_dismissed_messages', array()); $messages[] = sanitize_text_field($_GET['id']); update_option('wpcf_dismissed_messages', $messages); } break; case 'pr_add_child_post': global $current_user; $output = '<tr>' . __('Passed wrong parameters', 'wpcf') . '</tr>'; $id = 0; $target_post_type = isset($_GET['post_type_child']) ? sanitize_text_field($_GET['post_type_child']) : ''; $has_permissions = current_user_can('publish_posts'); $has_permissions = apply_filters('toolset_access_api_get_post_type_permissions', $has_permissions, $target_post_type, 'publish'); if (!$has_permissions) { $output = '<tr><td>' . __('You do not have rights to create new items', 'wpcf') . '</td></tr>'; } else { if (isset($_GET['post_id']) && isset($_GET['post_type_child']) && isset($_GET['post_type_parent'])) { $relationships = get_option('wpcf_post_relationship', array()); $parent_post_id = intval($_GET['post_id']); $parent_post = get_post($parent_post_id); if (!empty($parent_post->ID)) { $post_type = sanitize_text_field($_GET['post_type_child']); $parent_post_type = sanitize_text_field($_GET['post_type_parent']); // @todo isset & error handling $data = $relationships[$parent_post_type][$post_type]; /* * Since Types 1.1.5 * * We save new post * CHECKPOINT */ $id = $wpcf->relationship->add_new_child($parent_post->ID, $post_type); if (is_wp_error($id)) { $output = '<tr>' . $id->get_error_message() . '</tr>'; } else { /* * Here we set Relationship * CHECKPOINT */ $parent = get_post($parent_post_id); $child = get_post($id); if (!empty($parent->ID) && !empty($child->ID)) { // Set post $wpcf->post = $child; // Set relationship :) $wpcf->relationship->_set($parent, $child, $data); // Render new row $output = $wpcf->relationship->child_row($parent_post->ID, $id, $data); } else { $output = '<tr>' . __('Error creating post relationship', 'wpcf') . '</tr>'; } } } else { $output = '<tr>' . __('Error getting parent post', 'wpcf') . '</tr>'; } } } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output . wpcf_form_render_js_validation('#post', false), 'child_id' => $id)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')), 'child_id' => $id)); } break; case 'pr_save_all': ob_start(); // Try to catch any errors $output = ''; if (current_user_can('edit_posts') && isset($_POST['post_id'])) { $parent_id = intval($_POST['post_id']); $post_type = sanitize_text_field($_POST['post_type']); if (isset($_POST['wpcf_post_relationship'][$parent_id])) { $children = wpcf_sanitize_post_realtionship_input((array) $_POST['wpcf_post_relationship'][$parent_id]); $wpcf->relationship->save_children($parent_id, $children); $output = $wpcf->relationship->child_meta_form($parent_id, strval($post_type)); } } if (!defined('WPTOOLSET_FORMS_VERSION')) { // TODO Move to conditional $output .= '<script type="text/javascript">wpcfConditionalInit();</script>'; } wpcf_show_admin_messages('echo'); $errors = ob_get_clean(); if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output, 'errors' => $errors)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')), 'errors' => $errors)); } break; case 'pr_save_child_post': ob_start(); // Try to catch any errors $output = ''; if (current_user_can('edit_posts') && isset($_GET['post_id']) && isset($_GET['parent_id']) && isset($_GET['post_type_parent']) && isset($_GET['post_type_child']) && isset($_POST['wpcf_post_relationship'])) { $parent_id = intval($_GET['parent_id']); $child_id = intval($_GET['post_id']); $parent_post_type = sanitize_text_field($_GET['post_type_parent']); $child_post_type = sanitize_text_field($_GET['post_type_child']); if (isset($_POST['wpcf_post_relationship'][$parent_id][$child_id])) { $fields = wpcf_sanitize_post_relationship_input_fields((array) $_POST['wpcf_post_relationship'][$parent_id][$child_id]); $wpcf->relationship->save_child($parent_id, $child_id, $fields); $output = $wpcf->relationship->child_row($parent_id, $child_id, $wpcf->relationship->settings($parent_post_type, $child_post_type)); if (!defined('WPTOOLSET_FORMS_VERSION')) { // TODO Move to conditional $output .= '<script type="text/javascript">wpcfConditionalInit(\'#types-child-row-' . $child_id . '\');</script>'; } } } wpcf_show_admin_messages('echo'); $errors = ob_get_clean(); if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output, 'errors' => $errors)); } else { echo json_encode(array('output' => $output, 'errors' => $errors, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; case 'pr_delete_child_post': require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php'; $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['post_id'])) { $output = wpcf_pr_admin_delete_child_item(intval($_GET['post_id'])); } echo json_encode(array('output' => $output)); break; case 'pr_pagination': require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_ABSPATH . '/includes/post-relationship.php'; $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['post_id']) && isset($_GET['post_type'])) { global $wpcf; $parent = get_post(intval($_GET['post_id'])); $child_post_type = sanitize_text_field($_GET['post_type']); if (!empty($parent->ID)) { // Set post in loop $wpcf->post = $parent; // Save items_per_page $wpcf->relationship->save_items_per_page($parent->post_type, $child_post_type, intval($_GET[$wpcf->relationship->items_per_page_option_name])); $output = $wpcf->relationship->child_meta_form($parent->ID, $child_post_type); } } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; case 'pr_sort': $output = 'Passed wrong parameters'; if (current_user_can('edit_posts') && isset($_GET['field']) && isset($_GET['sort']) && isset($_GET['post_id']) && isset($_GET['post_type'])) { $output = $wpcf->relationship->child_meta_form(intval($_GET['post_id']), sanitize_text_field($_GET['post_type'])); } if (!defined('WPTOOLSET_FORMS_VERSION')) { echo json_encode(array('output' => $output)); } else { echo json_encode(array('output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data('post')))); } break; // Not used anywhere /*case 'pr_sort_parent': $output = 'Passed wrong parameters'; if ( isset( $_GET['field'] ) && isset( $_GET['sort'] ) && isset( $_GET['post_id'] ) && isset( $_GET['post_type'] ) ) { $output = $wpcf->relationship->child_meta_form( intval( $_GET['post_id'] ), strval( $_GET['post_type'] ) ); } if ( !defined( 'WPTOOLSET_FORMS_VERSION' ) ) { echo json_encode( array( 'output' => $output, ) ); } else { echo json_encode( array( 'output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data( 'post' )), ) ); } break;*/ /* Usermeta */ // Not used anywhere /*case 'pr_sort_parent': $output = 'Passed wrong parameters'; if ( isset( $_GET['field'] ) && isset( $_GET['sort'] ) && isset( $_GET['post_id'] ) && isset( $_GET['post_type'] ) ) { $output = $wpcf->relationship->child_meta_form( intval( $_GET['post_id'] ), strval( $_GET['post_type'] ) ); } if ( !defined( 'WPTOOLSET_FORMS_VERSION' ) ) { echo json_encode( array( 'output' => $output, ) ); } else { echo json_encode( array( 'output' => $output, 'conditionals' => array('#post' => wptoolset_form_get_conditional_data( 'post' )), ) ); } break;*/ /* Usermeta */ case 'um_repetitive_add': if (isset($_GET['user_id'])) { $user_id = (int) $_GET['user_id']; } else { $user_id = wpcf_usermeta_get_user(); } if (isset($_GET['field_id']) && current_user_can('edit_user', $user_id)) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php'; $field = wpcf_admin_fields_get_field(sanitize_text_field($_GET['field_id']), false, false, false, 'wpcf-usermeta'); global $wpcf; $wpcf->usermeta_repeater->set($user_id, $field); /* * * Force empty values! */ $wpcf->usermeta_repeater->cf['value'] = null; $wpcf->usermeta_repeater->meta = null; $form = $wpcf->usermeta_repeater->get_field_form(null, true); echo json_encode(array('output' => wpcf_form_simple($form) . wpcf_form_render_js_validation('#your-profile', false))); } else { echo json_encode(array('output' => 'params missing')); } break; case 'um_repetitive_delete': if (isset($_POST['user_id']) && isset($_POST['field_id']) && current_user_can('edit_user', intval($_POST['user_id']))) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; $user_id = intval($_POST['user_id']); $field = wpcf_admin_fields_get_field(sanitize_text_field($_POST['field_id']), false, false, false, 'wpcf-usermeta'); $meta_id = intval($_POST['meta_id']); if (!empty($field) && !empty($user_id) && !empty($meta_id)) { /* * * * Changed. * Since Types 1.2 */ global $wpcf; $wpcf->usermeta_repeater->set($user_id, $field); $wpcf->usermeta_repeater->delete($meta_id); echo json_encode(array('output' => 'deleted')); } else { echo json_encode(array('output' => 'field or post not found')); } } else { echo json_encode(array('output' => 'params missing')); } break; /* End Usermeta */ /* End Usermeta */ case 'repetitive_add': if (current_user_can('edit_posts') && isset($_GET['field_id'])) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; $field = wpcf_admin_fields_get_field(sanitize_text_field($_GET['field_id'])); $parent_post_id = intval($_GET['post_id']); /* * When post is new - post_id is 0 * We can safely set post_id to 1 cause * values compared are filtered anyway. */ if ($parent_post_id == 0) { $parent_post_id = 1; } $parent_post = get_post($parent_post_id); global $wpcf; $wpcf->repeater->set($parent_post, $field); /* * * Force empty values! */ $wpcf->repeater->cf['value'] = null; $wpcf->repeater->meta = null; $form = $wpcf->repeater->get_field_form(null, true); echo json_encode(array('output' => wpcf_form_simple($form) . wpcf_form_render_js_validation('#post', false))); } else { echo json_encode(array('output' => 'params missing')); } break; case 'repetitive_delete': if (current_user_can('edit_posts') && isset($_POST['post_id']) && isset($_POST['field_id'])) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; $post_id = intval($_POST['post_id']); $parent_post = get_post($post_id); $field = wpcf_admin_fields_get_field(sanitize_text_field($_POST['field_id'])); $meta_id = intval($_POST['meta_id']); if (!empty($field) && !empty($parent_post->ID) && !empty($meta_id)) { /* * * * Changed. * Since Types 1.2 */ global $wpcf; $wpcf->repeater->set($parent_post, $field); $wpcf->repeater->delete($meta_id); echo json_encode(array('output' => 'deleted')); } else { echo json_encode(array('output' => 'field or post not found')); } } else { echo json_encode(array('output' => 'params missing')); } break; case 'wpcf_entry_search': if (current_user_can('edit_posts') && isset($_REQUEST['post_type'])) { $posts_per_page = apply_filters('wpcf_pr_belongs_post_numberposts', 10); $args = array('posts_per_page' => apply_filters('wpcf_pr_belongs_post_posts_per_page', $posts_per_page), 'post_status' => apply_filters('wpcf_pr_belongs_post_status', array('publish', 'private')), 'post_type' => sanitize_text_field($_REQUEST['post_type']), 'suppress_filters' => 1); if (isset($_REQUEST['s'])) { $args['s'] = $_REQUEST['s']; } if (isset($_REQUEST['page']) && preg_match('/^\\d+$/', $_REQUEST['page'])) { $args['paged'] = intval($_REQUEST['page']); } $the_query = new WP_Query($args); $posts = array('items' => array(), 'total_count' => $the_query->found_posts, 'incomplete_results' => $the_query->found_posts > $posts_per_page, 'posts_per_page' => $posts_per_page); if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); $post_title = get_the_title(); if (empty($post_title)) { $post_title = sprintf(__('[empty title] ID: %d', 'wpcf'), get_the_ID()); } $posts['items'][] = array('ID' => get_the_ID(), 'post_title' => $post_title); } } /* Restore original Post Data */ wp_reset_postdata(); echo json_encode($posts); } else { echo json_encode(array('output' => 'params missing')); } break; case 'wpcf_entry_entry': if (current_user_can('edit_posts') && isset($_REQUEST['p'])) { $wpcf_post = get_post((int) $_REQUEST['p'], ARRAY_A); if (isset($wpcf_post['ID'])) { $post_title = $wpcf_post['post_title']; if (empty($post_title)) { $post_title = sprintf(__('[empty title] ID: %d', 'wpcf'), $wpcf_post['ID']); } echo json_encode(array('ID' => $wpcf_post['ID'], 'post_title' => $wpcf_post['post_title'])); } else { echo json_encode(array('output' => 'params missing')); } } else { echo json_encode(array('output' => 'params missing')); } break; default: break; } if (function_exists('wpcf_ajax')) { wpcf_ajax(); } die; }
/** * Renders Thickbox content. * * Field should provide callback function * that will be called automatically. * * Function should be named like: * 'wpcf_fields_' . $field_type . '_editor_callback' * e.g. 'wpcf_fields_checkbox__editor_callback' * * Function should return array with elements: * 'supports' - parameters or other feature supported, e.g. 'styling' will * enable 'Styling' options * * Tabs is array with elements: * 'menu_title' - used for menu title * 'title' - used for main title * 'content' - HTML content of tab * * @param type $field * @param type $meta_type * @param type $post_id * @param string $shortcode */ function frame($field, $meta_type = 'postmeta', $post_id = -1, $shortcode = null, $callback = false, $views_usermeta = false) { global $wp_version, $wpcf; // Queue rendering JS settings add_action('admin_print_footer_scripts', array($this, 'renderTedSettings'), 1); wp_enqueue_script('types'); wp_enqueue_script('types-knockout'); wp_enqueue_script('types-editor'); wp_enqueue_script('wp-pointer'); wp_enqueue_style('types-editor'); wp_enqueue_style('wp-pointer'); wp_enqueue_style('toolset-font-awesome'); // Load cloned WP Media Modal CSS if (version_compare($wp_version, '3.5', '<')) { wp_enqueue_style('types-editor-cloned'); } $this->field = $field; $this->_meta_type = $meta_type; $this->_post = get_post($post_id); $this->_settings = is_null($shortcode) ? array() : $this->shortcodeToParameters($shortcode); $this->callback = $callback; $this->_data = array('meta_type' => $meta_type, 'field' => $field, 'field_type_data' => WPCF_Fields::getFieldTypeData($field['type']), 'settings' => array(), 'tabs' => array(), 'supports' => array(), 'post' => $this->_post, 'post_types' => get_post_types(array('show_ui' => true)), 'style' => isset($this->_settings['style']) ? $this->_settings['style'] : '', 'class' => isset($this->_settings['class']) ? $this->_settings['class'] : '', 'output' => 'html', 'user_form' => ''); // Set title if updated if (!is_null($shortcode)) { $this->_data['title'] = sprintf(__('Update %s', 'wpcf'), $this->_data['field_type_data']['title']); $this->_data['submit_button_title'] = __('Update shortcode', 'wpcf'); } // Exclude post types foreach ($wpcf->excluded_post_types as $_post_type) { unset($this->_data['post_types'][$_post_type]); } /* * Callback */ $function = 'wpcf_fields_' . $field['type'] . '_editor_callback'; if (function_exists($function)) { // Main callback $callback = call_user_func($function, $field, $this->_settings, $this->_meta_type, $this->_post); // Add supports if (!empty($callback['supports']) && is_array($callback['supports'])) { $this->_data['supports'] = $callback['supports']; } // Add tabs if (!empty($callback['tabs']) && is_array($callback['tabs'])) { $this->_data['tabs'] = $callback['tabs']; } // Unify settings if (!empty($callback['settings']) && is_array($callback['settings'])) { $this->_settings = array_merge($this->_settings, self::sanitizeParams($callback['settings'], 'array')); } } // If no tabs if (empty($this->_data['tabs'])) { $this->_data['tabs']['display'] = array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => sprintf(__('There are no additional display options for the %s field.', 'wpcf'), $this->_data['field_type_data']['title'])); } // Add User ID form if ($this->_meta_type == 'usermeta') { if (!$views_usermeta) { $this->_data['user_form'] = wpcf_form_simple(wpcf_get_usermeta_form_addon($this->_settings)); $this->_data['supports'][] = 'user_id'; } } else { // Add Post ID form $this->_data['supports'][] = 'post_id'; } // Get parents if (!empty($this->_post->ID)) { $this->_data['parents'] = WPCF_Relationship::get_parents($this->_post); } // Set icons $icons = array('audio' => 'icon-music', 'checkbox' => 'icon-check', 'checkboxes' => 'icon-checkboxes', 'colorpicker' => 'icon-tint', 'date' => 'icon-calendar', 'email' => 'icon-envelope-alt', 'embed' => 'icon-youtube-play', 'file' => 'icon-file-alt', 'image' => 'icon-picture', 'map' => 'icon-map-marker', 'numeric' => 'icon-numeric', 'phone' => 'icon-phone', 'radio' => 'icon-radio-button', 'select' => 'icon-select-box', 'skype' => 'icon-skype', 'textarea' => 'icon-text-area', 'textfield' => 'icon-text-field', 'url' => 'icon-link', 'video' => 'icon-film', 'wysiwyg' => 'icon-wysiwyg'); $this->_data['icon_class'] = isset($icons[$field['type']]) ? $icons[$field['type']] : 'icon-text-field'; // Is repetitive $this->_data['is_repetitive'] = (bool) types_is_repetitive($field); if ($this->_data['is_repetitive']) { $this->_data['supports'][] = 'separator'; } // Render header wpcf_admin_ajax_head(); // Check if submitted $this->_thickbox_check_submit(); // Render form echo '<form method="post" action="" id="types-editor-modal-form">'; echo WPCF_Loader::view('editor-modal-window', $this->_data); wp_nonce_field('types_editor_frame', '__types_editor_nonce'); echo '</form>'; // Render footer wpcf_admin_ajax_footer(); }