/** * Init function. * * Enqueues styles and scripts on post edit page. * * @param type $post_type * @param type $post * @param type $groups * @param type $wpcf_active */ function wpcf_pr_admin_post_init_action($post_type, $post, $groups, $wpcf_active) { // See if any data $has = wpcf_pr_admin_get_has($post_type); $belongs = wpcf_pr_admin_get_belongs($post_type); /* * Enqueue styles and scripts */ if (!empty($has) || !empty($belongs)) { $output = wpcf_pr_admin_post_meta_box_output($post, array('post_type' => $post_type, 'has' => $has, 'belongs' => $belongs)); add_meta_box('wpcf-post-relationship', __('Post Relationship', 'wpcf'), 'wpcf_pr_admin_post_meta_box', $post_type, 'normal', 'default', array('output' => $output)); if (!empty($output)) { wp_enqueue_script('wpcf-post-relationship', WPCF_EMBEDDED_RELPATH . '/resources/js/post-relationship.js', array('jquery', 'select2'), WPCF_VERSION); wp_enqueue_style('wpcf-post-relationship', WPCF_EMBEDDED_RELPATH . '/resources/css/post-relationship.css', array(), WPCF_VERSION); if (!$wpcf_active) { wpcf_enqueue_scripts(); wp_enqueue_style('wpcf-pr-post', WPCF_EMBEDDED_RES_RELPATH . '/css/fields-post.css', array(), WPCF_VERSION); wp_enqueue_script('wpcf-form-validation', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/jquery.validate.min.js', array('jquery'), WPCF_VERSION); wp_enqueue_script('wpcf-form-validation-additional', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/additional-methods.min.js', array('jquery'), WPCF_VERSION); } wpcf_admin_add_js_settings('wpcf_pr_del_warning', '\'' . __('Are you sure about deleting this post?', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_pagination_warning', '\'' . __('If you continue without saving your changes, they might get lost.', 'wpcf') . '\''); } } }
/** * Init functions for post edit pages. * * @param type $upgrade */ function wpcf_admin_post_init($post = false) { wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); // Get post_type if ($post) { $post_type = get_post_type($post); } else { if (!isset($_GET['post_type'])) { $post_type = 'post'; } else { if (in_array($_GET['post_type'], get_post_types(array('show_ui' => true)))) { $post_type = $_GET['post_type']; } else { return false; } } } // Add items to View dropdown if (in_array($post_type, array('view', 'view-template'))) { add_filter('editor_addon_menus_wpv-views', 'wpcf_admin_post_editor_addon_menus_filter'); add_action('admin_footer', 'wpcf_admin_post_js_validation'); } // Never show on 'Views' and 'View Templates' if (in_array($post_type, array('view', 'view-template'))) { return false; } // Get groups $groups = wpcf_admin_post_get_post_groups_fields($post); $wpcf_active = false; foreach ($groups as $key => $group) { if (!empty($group['fields'])) { $wpcf_active = true; // Process fields $group['fields'] = wpcf_admin_post_process_fields($post, $group['fields']); } // Add meta boxes add_meta_box($group['slug'], wpcf_translate('group ' . $group['id'] . ' name', $group['name']), 'wpcf_admin_post_meta_box', $post_type, $group['meta_box_context'], 'high', $group); } // Activate scripts if ($wpcf_active) { wp_enqueue_script('wpcf-fields-post', WPCF_EMBEDDED_RES_RELPATH . '/js/fields-post.js', array('jquery'), WPCF_VERSION); wp_enqueue_script('wpcf-form-validation', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/jquery.validate.min.js', array('jquery'), WPCF_VERSION); wp_enqueue_script('wpcf-form-validation-additional', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/additional-methods.min.js', array('jquery'), WPCF_VERSION); wp_enqueue_style('wpcf-fields-basic', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION); wp_enqueue_style('wpcf-fields-post', WPCF_EMBEDDED_RES_RELPATH . '/css/fields-post.css', array('wpcf-fields-basic'), WPCF_VERSION); add_action('admin_footer', 'wpcf_admin_post_js_validation'); } do_action('wpcf_admin_post_init', $post_type, $post, $groups, $wpcf_active); }
/** * 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 init_admin() { $this->post_type = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME; $this->init_hooks(); $this->boxes = array('submitdiv' => array('callback' => array($this, 'box_submitdiv'), 'title' => __('Save', 'wpcf'), 'default' => 'side', 'priority' => 'high')); /** Admin styles **/ $this->current_user_can_edit = WPCF_Roles::user_can_create('custom-field'); if (defined('TYPES_USE_STYLING_EDITOR') && TYPES_USE_STYLING_EDITOR && $this->current_user_can_edit) { $this->boxes['types_styling_editor'] = array('callback' => array($this, 'types_styling_editor'), 'title' => __('Fields Styling Editor'), 'default' => 'normal'); } $this->boxes = apply_filters('wpcf_meta_box_order_defaults', $this->boxes, $this->post_type); $this->boxes = apply_filters('wpcf_meta_box_custom_field', $this->boxes, $this->post_type); wp_enqueue_script(__CLASS__, WPCF_RES_RELPATH . '/js/' . 'taxonomy-form.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-tabs'), WPCF_VERSION); wp_enqueue_style('wp-jquery-ui-dialog'); wpcf_admin_add_js_settings('wpcfFormAlertOnlyPreview', sprintf("'%s'", __('Sorry, but this is only preview!', 'wpcf'))); }
/** * Renders JS settings. * * @return type */ function wpcf_admin_render_js_settings() { $settings = wpcf_admin_add_js_settings('get'); if (empty($settings)) { return ''; } ?> <script type="text/javascript"> //<![CDATA[ <?php foreach ($settings as $id => $setting) { echo 'var ' . $id . ' = ' . $setting . ';' . "\r\n"; } ?> //]]> </script> <?php }
/** * Generates form data. */ function wpcf_admin_usermeta_form() { global $wpcf; wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); $default = array(); global $wpcf_button_style; global $wpcf_button_style30; // If it's update, get data $update = false; if (isset($_REQUEST['group_id'])) { $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id']), 'wp-types-user-group'); if (empty($update)) { $update = false; wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id']))); } else { $update['fields'] = wpcf_admin_fields_get_fields_by_group($_REQUEST['group_id'], 'slug', false, true, false, 'wp-types-user-group', 'wpcf-usermeta'); $update['show_for'] = wpcf_admin_get_groups_showfor_by_group($_REQUEST['group_id']); $update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group($_REQUEST['group_id']); } } $form = array(); $form['#form']['callback'] = array('wpcf_admin_save_usermeta_groups_submit'); // Form sidebars $form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">'); // Set help icon $form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" /> <a href="http://wp-types.com/documentation/user-guides/using-custom-fields/" target="_blank">' . __('Usermeta help', 'wpcf') . '</a></div>'); $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf')); // Get field types $fields_registered = wpcf_admin_fields_get_available_types(); foreach ($fields_registered as $filename => $data) { $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit-usermeta') . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> '); // Process JS if (!empty($data['group_form_js'])) { foreach ($data['group_form_js'] as $handle => $script) { if (isset($script['inline'])) { add_action('admin_footer', $script['inline']); continue; } $deps = !empty($script['deps']) ? $script['deps'] : array(); $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false; wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer); wp_enqueue_script($handle); } } // Process CSS if (!empty($data['group_form_css'])) { foreach ($data['group_form_css'] as $handle => $script) { if (isset($script['src'])) { $deps = !empty($script['deps']) ? $script['deps'] : array(); wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION); } else { if (isset($script['inline'])) { add_action('admin_head', $script['inline']); } } } } } // Get fields created by user $fields = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta'); if (!empty($fields)) { $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields'); foreach ($fields as $key => $field) { if (isset($update['fields']) && array_key_exists($key, $update['fields'])) { continue; } if (!empty($field['data']['removed_from_history'])) { continue; } $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&page=wpcf-edit' . '&wpcf_action=usermeta_insert_existing' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('usermeta_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . 'data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history2' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history2') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>'); } } $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); // Group data $form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main">'); $form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : __('Enter group title', 'wpcf'), '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;'), '#validate' => array('required' => array('value' => true))); if (!$update) { $form['title']['#attributes']['data-label'] = addcslashes(__('Enter group title', 'wpcf'), '"'); $form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }'; $form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }'; } $form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : __('Enter a description for this group', 'wpcf')); if (!$update) { $form['description']['#attributes']['data-label'] = addcslashes(__('Enter a description for this group', 'wpcf'), '"'); $form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == jQuery(this).data(\'label\')) { jQuery(this).val(\'\'); }'; $form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(jQuery(this).data(\'label\')) }'; } // Show Fields for global $wp_roles; $options = array(); $users_currently_supported = array(); $form_types = array(); foreach ($wp_roles->role_names as $role => $name) { $options[$role]['#name'] = 'wpcf[group][supports][' . $role . ']'; $options[$role]['#title'] = ucwords($role); $options[$role]['#default_value'] = $update && !empty($update['show_for']) && in_array($role, $update['show_for']) ? 1 : 0; $options[$role]['#value'] = $role; $options[$role]['#inline'] = TRUE; $options[$role]['#suffix'] = '<br />'; $options[$role]['#id'] = 'wpcf-form-groups-show-for-' . $role; $options[$role]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type'); if ($update && !empty($update['show_for']) && in_array($role, $update['show_for'])) { $users_currently_supported[] = ucwords($role); } } if (empty($users_currently_supported)) { $users_currently_supported[] = __('Displayed for all users roles', 'wpcf'); } /* * Show for FILTER */ $temp = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true); /* * * Here we use unique function for all filters * Since Types 1.1.4 */ $form_users = _wpcf_filter_wrap('custom_post_types', __('Show For:', 'wpcf'), implode(', ', $users_currently_supported), __('Displayed for all users roles', 'wpcf'), $temp); /* * Now starting form */ $access_notification = ''; if (function_exists('wpcf_access_register_caps')) { $access_notification = '<div class="message custom wpcf-notif"><span class="wpcf-notif-congrats">' . __('This groups visibility is also controlled by the Access plugin.', 'wpcf') . '</span></div>'; } $form['supports-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat"><thead><tr><th>' . __('Where to display this group', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Each usermeta group can display different fields for user roles.', 'wpcf') . $access_notification . '</p>'); /* * Join filter forms */ // User Roles $form['p_wrap_1_' . wpcf_unique_id(serialize($form_users))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">'); $form = $form + $form_users; $form['supports-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />'); /** Admin styles**/ $form['adminstyles-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat" id="wpcf-admin-styles-box"><thead><tr><th>' . __('Styling Editor', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Customize Fields for admin panel.', 'wpcf') . '</p>'); $admin_styles_value = $preview_profile = $edit_profile = ''; if (isset($update['admin_styles'])) { $admin_styles_value = $update['admin_styles']; } $temp = ''; if ($update) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php'; $user_id = wpcf_usermeta_get_user(); $preview_profile = wpcf_usermeta_preview_profile($user_id, $update, 1); $group = $update; $group['fields'] = wpcf_admin_usermeta_process_fields($user_id, $group['fields'], true, false); $edit_profile = wpcf_admin_render_fields($group, $user_id, 1); add_action('admin_enqueue_scripts', 'wpcf_admin_fields_form_fix_styles', PHP_INT_MAX); } $temp[] = array('#type' => 'radio', '#suffix' => '<br />', '#value' => 'edit_mode', '#title' => 'Edit mode', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#before' => '<div class="wpcf-admin-css-preview-style-edit">', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'editmode\')', 'checked' => 'checked')); $temp[] = array('#type' => 'radio', '#title' => 'Read Only', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#after' => '</div>', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'readonly\')')); $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_html_preview]', '#inline' => true, '#value' => '', '#id' => 'wpcf-form-groups-admin-html-preview', '#before' => '<h3>Field group HTML</h3>'); $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_styles]', '#inline' => true, '#value' => $admin_styles_value, '#default_value' => '', '#id' => 'wpcf-form-groups-css-fields-editor', '#after' => ' <div class="wpcf-update-preview-btn"><input type="button" value="Update preview" onclick="wpcfPreviewHtml()" style="float:right;" class="button-secondary"></div> <h3>Field group preview</h3> <div id="wpcf-update-preview-div">Preview here</div> <script type="text/javascript"> var wpcfReadOnly = ' . json_encode($preview_profile) . '; var wpcfEditMode = ' . json_encode($edit_profile) . '; var wpcfDefaultCss = ' . json_encode($admin_styles_value) . '; </script> ', '#before' => '<h3>Your CSS</h3>'); $admin_styles = _wpcf_filter_wrap('admin_styles', __('Admin styles for fields:', 'wpcf'), '', '', $temp, __('Open style editor', 'wpcf')); $form['p_wrap_1_' . wpcf_unique_id(serialize($admin_styles))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">'); $form = $form + $admin_styles; $form['adminstyles-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />'); /** End admin Styles **/ // Group fields $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>'); $show_under_title = true; $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">'); // If it's update, display existing fields $existing_fields = array(); if ($update && isset($update['fields'])) { foreach ($update['fields'] as $slug => $field) { $field['submitted_key'] = $slug; $field['group_id'] = $update['id']; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } $existing_fields[] = $slug; $show_under_title = false; } } // Any new fields submitted but failed? (Don't double it) if (!empty($_POST['wpcf']['fields'])) { foreach ($_POST['wpcf']['fields'] as $key => $field) { if (in_array($key, $existing_fields)) { continue; } $field['submitted_key'] = $key; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } } $show_under_title = false; } $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>'); if ($show_under_title) { $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>'; } // If update, create ID field if ($update) { $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true); } $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); // Close main div $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); wpcf_admin_add_js_settings('wpcf_filters_association_or', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% or View Template is: %vt%', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_and', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% and View Template is: %vt%', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_pages', '\'' . __('all', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_taxonomies', '\'' . __('any', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_templates', '\'' . __('any', 'wpcf') . '\''); // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); return $form; }
/** * Basic scripts */ function wpcf_enqueue_scripts() { if (!is_admin()) { return; } if (!wpcf_is_embedded()) { /** * Basic JS */ wp_register_script('wpcf-js', WPCF_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs', 'toolset-colorbox'), WPCF_VERSION); wp_localize_script('wpcf-js', 'wpcf_js', array('close' => __('Close', 'wpcf'))); wp_enqueue_script('wpcf-js'); if (function_exists('wpcf_admin_add_js_settings')) { wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); } } /** * Basic JS */ wp_enqueue_script('wpcf-js-embedded', WPCF_EMBEDDED_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs', 'select2'), WPCF_VERSION); wp_localize_script('wpcf-js-embedded', 'WPCF_basic', array('field_already_in_use' => sprintf(__('%s This field is locked because the same field is added multiple times to this post. %s%s%s you can set the value%s', 'wpcf'), '<small style="display: block;">', '<a href="#" class="focus_correct_field" data-field-slug="##DATA-FIELD-ID##" >', 'Here', '</a>', '</small>'))); /* * * Basic CSS */ wp_enqueue_style('wpcf-css-embedded'); /* * * Other components */ if (!defined('WPTOOLSET_FORMS_ABSPATH')) { // Repetitive wp_enqueue_script('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/js/repetitive.js', array('wpcf-js-embedded'), WPCF_VERSION); wp_enqueue_style('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/css/repetitive.css', array('wpcf-css-embedded'), WPCF_VERSION); } // Conditional wp_enqueue_script('types-conditional'); // RTL if (is_rtl()) { wp_enqueue_style('wpcf-rtl', WPCF_EMBEDDED_RES_RELPATH . '/css/rtl.css', array('wpcf-css-embedded'), WPCF_VERSION); } /** * select2 */ $select2_version = '3.5.2'; if (!wp_script_is('select2', 'registered')) { wp_register_script('select2', WPCF_EMBEDDED_TOOLSET_RELPATH . '/toolset-common/res/lib/select2/select2.min.js', array('jquery'), $select2_version); } if (!wp_style_is('select2', 'registered')) { wp_register_style('select2', WPCF_EMBEDDED_TOOLSET_RELPATH . '/toolset-common/res/lib/select2/select2.css', array(), $select2_version); } if (!wp_style_is('select2')) { wp_enqueue_style('select2'); } // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUsedOrReservedSlug', '\'' . __('You cannot use this slug because it is already used or a reserved word. Please choose a different slug.', 'wpcf') . '\''); }
/** * Basic scripts */ function wpcf_enqueue_scripts() { if (!is_admin()) { return; } if (!wpcf_is_embedded()) { /** * Basic JS */ wp_register_script('wpcf-js', WPCF_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs', 'toolset-colorbox'), WPCF_VERSION); wp_localize_script('wpcf-js', 'wpcf_js', array('close' => __('Close', 'wpcf'))); wp_enqueue_script('wpcf-js'); if (function_exists('wpcf_admin_add_js_settings')) { wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); } } /** * Basic JS */ wp_enqueue_script('wpcf-js-embedded', WPCF_EMBEDDED_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs', 'select2'), WPCF_VERSION); /* * * Basic CSS */ wp_enqueue_style('wpcf-css-embedded'); /* * * Other components */ if (!defined('WPTOOLSET_FORMS_ABSPATH')) { // Repetitive wp_enqueue_script('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/js/repetitive.js', array('wpcf-js-embedded'), WPCF_VERSION); wp_enqueue_style('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/css/repetitive.css', array('wpcf-css-embedded'), WPCF_VERSION); } // Conditional wp_enqueue_script('types-conditional'); // RTL if (is_rtl()) { wp_enqueue_style('wpcf-rtl', WPCF_EMBEDDED_RES_RELPATH . '/css/rtl.css', array('wpcf-css-embedded'), WPCF_VERSION); } /** * select2 */ $select2_version = '3.5.2'; if (!wp_script_is('select2', 'registered')) { wp_register_script('select2', WPCF_EMBEDDED_RELPATH . '/toolset/toolset-common/utility/js/select2.min.js', array('jquery'), $select2_version); } if (!wp_style_is('select2', 'registered')) { wp_register_style('select2', WPCF_EMBEDDED_RELPATH . '/toolset/toolset-common/utility/css/select2/select2.css', array(), $select2_version); } if (!wp_style_is('select2')) { wp_enqueue_style('select2'); } // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUsedOrReservedSlug', '\'' . __('You cannot use this slug because it is already used or a reserved word. Please choose a different slug.', 'wpcf') . '\''); }
/** * Generates form data. * * @deprecated Possibly deprecated, no usage found in Types. Possibly identical code in Types_Admin_Edit_Fields::get_field_form_data() */ function wpcf_admin_fields_form() { /** * include common functions */ include_once dirname(__FILE__) . '/common-functions.php'; wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); $default = array(); global $wpcf_button_style; global $wpcf_button_style30; global $wpcf; $form = array(); $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit'); // Form sidebars if ($current_user_can_edit) { $form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">'); // Set help icon $form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_TOOLSET_RELPATH . '/toolset-common/res/images/question.png" style="position:relative;top:2px;" /> <a href="' . Types_Helper_Url::get_url('using-post-fields', 'fields-editor', 'fields-help', Types_Helper_Url::UTM_MEDIUM_HELP) . '" target="_blank">' . __('Custom fields help', 'wpcf') . '</a></div>'); $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf')); // Get field types $fields_registered = wpcf_admin_fields_get_available_types(); foreach ($fields_registered as $filename => $data) { $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit') . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> '); // Process JS if (!empty($data['group_form_js'])) { foreach ($data['group_form_js'] as $handle => $script) { if (isset($script['inline'])) { add_action('admin_footer', $script['inline']); continue; } $deps = !empty($script['deps']) ? $script['deps'] : array(); $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false; wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer); wp_enqueue_script($handle); } } // Process CSS if (!empty($data['group_form_css'])) { foreach ($data['group_form_css'] as $handle => $script) { if (isset($script['src'])) { $deps = !empty($script['deps']) ? $script['deps'] : array(); wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION); } else { if (isset($script['inline'])) { add_action('admin_head', $script['inline']); } } } } } // Get fields created by user $fields = wpcf_admin_fields_get_fields(true, true); if (!empty($fields)) { $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields'); foreach ($fields as $key => $field) { if (isset($update['fields']) && array_key_exists($key, $update['fields'])) { continue; } if (!empty($field['data']['removed_from_history'])) { continue; } $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=fields_insert_existing' . '&page=wpcf-edit' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . ' data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>'); } } $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); } // Group data $form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main" class="wpcf-form-fields-main">'); /** * Now starting form */ /** End admin Styles * */ // Group fields $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>'); $show_under_title = true; $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">'); // If it's update, display existing fields $existing_fields = array(); if ($update && isset($update['fields'])) { foreach ($update['fields'] as $slug => $field) { $field['submitted_key'] = $slug; $field['group_id'] = $update['id']; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } $existing_fields[] = $slug; $show_under_title = false; } } // Any new fields submitted but failed? (Don't double it) if (!empty($_POST['wpcf']['fields'])) { foreach ($_POST['wpcf']['fields'] as $key => $field) { if (in_array($key, $existing_fields)) { continue; } $field['submitted_key'] = $key; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } } $show_under_title = false; } $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>'); if ($show_under_title) { $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>'; } // If update, create ID field if ($update) { $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true); } $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); // Close main div $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); $form = apply_filters('wpcf_form_fields', $form, $update); // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormAlertOnlyPreview', sprintf("'%s'", __('Sorry, but this is only preview!', 'wpcf'))); $form['form-close'] = array('#type' => 'markup', '#markup' => '</div>'); /** * return form if current_user_can edit */ if ($current_user_can_edit) { return $form; } return wpcf_admin_common_only_show($form); }
/** * Collapsible scripts. */ function wpcf_admin_load_collapsible() { wp_enqueue_script('wpcf-collapsible', WPCF_RES_RELPATH . '/js/collapsible.js', array('jquery'), WPCF_VERSION); wp_enqueue_style('wpcf-collapsible', WPCF_RES_RELPATH . '/css/collapsible.css', array(), WPCF_VERSION); $option = get_option('wpcf_toggle', array()); if (!empty($option)) { $setting = 'new Array("' . implode('", "', array_keys($option)) . '")'; wpcf_admin_add_js_settings('wpcf_collapsed', $setting); } }
/** * Basic scripts */ function wpcf_enqueue_scripts() { if (!wpcf_is_embedded()) { /* * * Basic JS */ wp_enqueue_script('wpcf-js', WPCF_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs'), WPCF_VERSION); /* * * Basic CSS */ wp_enqueue_style('wpcf-css', WPCF_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION); } /* * * Basic JS */ wp_enqueue_script('wpcf-js-embedded', WPCF_EMBEDDED_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs'), WPCF_VERSION); /* * * Basic CSS */ wp_enqueue_style('wpcf-css-embedded', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION); /* * * Other components */ if (!defined('WPTOOLSET_FORMS_ABSPATH')) { // Repetitive wp_enqueue_script('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/js/repetitive.js', array('wpcf-js-embedded'), WPCF_VERSION); wp_enqueue_style('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/css/repetitive.css', array('wpcf-css-embedded'), WPCF_VERSION); } // Conditional wp_enqueue_script('types-conditional'); wpcf_admin_add_js_settings('wpcfConditionalVerify_nonce', wp_create_nonce('cd_verify')); wpcf_admin_add_js_settings('wpcfConditionalVerifyGroup', wp_create_nonce('cd_group_verify')); // RTL if (is_rtl()) { wp_enqueue_style('wpcf-rtl', WPCF_EMBEDDED_RES_RELPATH . '/css/rtl.css', array('wpcf-css-embedded'), WPCF_VERSION); } }
/** * Enqueues scripts. */ function add_js() { wp_enqueue_script('wpcf-conditional', WPCF_EMBEDDED_RES_RELPATH . '/js/conditional.js', array('jquery'), WPCF_VERSION); wpcf_admin_add_js_settings('wpcfConditionalVerify_nonce', wp_create_nonce('cd_verify')); }
/** * Generates form data. */ function wpcf_admin_fields_form() { wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); $default = array(); global $wpcf_button_style; global $wpcf_button_style30; global $wpcf; // If it's update, get data $update = false; if (isset($_REQUEST['group_id'])) { $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id'])); if (empty($update)) { $update = false; wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id']))); } else { $update['fields'] = wpcf_admin_fields_get_fields_by_group(sanitize_text_field($_REQUEST['group_id']), 'slug', false, true); $update['post_types'] = wpcf_admin_get_post_types_by_group(sanitize_text_field($_REQUEST['group_id'])); $update['taxonomies'] = wpcf_admin_get_taxonomies_by_group(sanitize_text_field($_REQUEST['group_id'])); $update['templates'] = wpcf_admin_get_templates_by_group(sanitize_text_field($_REQUEST['group_id'])); $update['admin_styles'] = wpcf_admin_get_groups_admin_styles_by_group(sanitize_text_field($_REQUEST['group_id'])); } } $form = array(); $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit'); // Form sidebars $form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">'); // Set help icon $form['help-icon'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-admin-fields-help"><img src="' . WPCF_EMBEDDED_RELPATH . '/common/res/images/question.png" style="position:relative;top:2px;" /> <a href="http://wp-types.com/documentation/user-guides/using-custom-fields/?utm_source=typesplugin&utm_medium=help&utm_term=fields-help&utm_content=fields-editor&utm_campaign=types" target="_blank">' . __('Custom fields help', 'wpcf') . '</a></div>'); $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf')); // Get field types $fields_registered = wpcf_admin_fields_get_available_types(); foreach ($fields_registered as $filename => $data) { $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php') . '&page=wpcf-edit') . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> '); // Process JS if (!empty($data['group_form_js'])) { foreach ($data['group_form_js'] as $handle => $script) { if (isset($script['inline'])) { add_action('admin_footer', $script['inline']); continue; } $deps = !empty($script['deps']) ? $script['deps'] : array(); $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false; wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer); wp_enqueue_script($handle); } } // Process CSS if (!empty($data['group_form_css'])) { foreach ($data['group_form_css'] as $handle => $script) { if (isset($script['src'])) { $deps = !empty($script['deps']) ? $script['deps'] : array(); wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION); } else { if (isset($script['inline'])) { add_action('admin_head', $script['inline']); } } } } } // Get fields created by user $fields = wpcf_admin_fields_get_fields(true, true); if (!empty($fields)) { $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields'); foreach ($fields as $key => $field) { if (isset($update['fields']) && array_key_exists($key, $update['fields'])) { continue; } if (!empty($field['data']['removed_from_history'])) { continue; } $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=fields_insert_existing' . '&page=wpcf-edit' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();" ' . ' data-slug="' . $field['id'] . '">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>'); } } $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); // Group data $form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main">'); $form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : '', '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;', 'placeholder' => __('Enter group title', 'wpcf')), '#validate' => array('required' => array('value' => true))); $form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : '', '#attributes' => array('placeholder' => __('Enter a description for this group', 'wpcf'))); /** * * FILTER BOX * Since Types 1.2 we moved JS to /embedded/resources/js/custom-fields-form-filter.js * */ // Support post types and taxonomies $post_types = get_post_types('', 'objects'); $options = array(); $post_types_currently_supported = array(); $form_types = array(); foreach ($post_types as $post_type_slug => $post_type) { if (in_array($post_type_slug, $wpcf->excluded_post_types) || !$post_type->show_ui) { continue; } $options[$post_type_slug]['#name'] = 'wpcf[group][supports][' . $post_type_slug . ']'; $options[$post_type_slug]['#title'] = $post_type->label; $options[$post_type_slug]['#default_value'] = $update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types']) ? 1 : 0; $options[$post_type_slug]['#value'] = $post_type_slug; $options[$post_type_slug]['#inline'] = TRUE; $options[$post_type_slug]['#suffix'] = '<br />'; $options[$post_type_slug]['#id'] = 'wpcf-form-groups-support-post-type-' . $post_type_slug; $options[$post_type_slug]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type'); if ($update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types'])) { $post_types_currently_supported[] = $post_type->label; } } if (empty($post_types_currently_supported)) { $post_types_currently_supported[] = __('Displayed on all content types', 'wpcf'); } /** * POST TYPE FILTER */ $temp = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true); /** * Here we use unique function for all filters * Since Types 1.2 */ $form_types = _wpcf_filter_wrap('custom_post_types', __('Post Types:', 'wpcf'), implode(',', $post_types_currently_supported), __('Displayed on all content types', 'wpcf'), $temp); /** * TAXONOMIES FILTER QUERY */ $taxonomies = apply_filters('wpcf_group_form_filter_taxonomies', get_taxonomies('', 'objects')); $options = array(); $tax_currently_supported = array(); $form_tax = array(); $form_tax_single = array(); /** * Filter toxonomies */ foreach ($taxonomies as $category_slug => $category) { if ($category_slug == 'nav_menu' || $category_slug == 'link_category' || $category_slug == 'post_format') { continue; } $terms = apply_filters('wpcf_group_form_filter_terms', get_terms($category_slug, array('hide_empty' => false))); if (!empty($terms)) { $options = array(); $add_title = '<div class="taxonomy-title">' . $category->labels->name . '</div>'; $title = ''; foreach ($terms as $term) { $checked = 0; if ($update && !empty($update['taxonomies']) && array_key_exists($category_slug, $update['taxonomies'])) { if (array_key_exists($term->term_taxonomy_id, $update['taxonomies'][$category_slug])) { $checked = 1; $tax_currently_supported[$term->term_taxonomy_id] = $term->name; $title = ''; } } $options[$term->term_taxonomy_id]['#name'] = 'wpcf[group][taxonomies][' . $category_slug . '][' . $term->term_taxonomy_id . ']'; $options[$term->term_taxonomy_id]['#title'] = $term->name; $options[$term->term_taxonomy_id]['#default_value'] = $checked; $options[$term->term_taxonomy_id]['#value'] = $term->term_taxonomy_id; $options[$term->term_taxonomy_id]['#inline'] = true; $options[$term->term_taxonomy_id]['#prefix'] = $add_title; $options[$term->term_taxonomy_id]['#suffix'] = '<br />'; $options[$term->term_taxonomy_id]['#id'] = 'wpcf-form-groups-support-tax-' . $term->term_taxonomy_id; $options[$term->term_taxonomy_id]['#attributes'] = array('class' => 'wpcf-form-groups-support-tax'); $add_title = ''; } $form_tax_single['taxonomies-' . $category_slug] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][taxonomies][' . $category_slug . ']', '#suffix' => '<br />', '#inline' => true); } } if (empty($tax_currently_supported)) { $tax_currently_supported[] = __('Not Selected', 'wpcf'); } /** * Since Types 1.2 we use unique function */ $form_tax = _wpcf_filter_wrap('custom_taxonomies', __('Terms:', 'wpcf'), implode(', ', array_values($tax_currently_supported)), __('Not Selected', 'wpcf'), $form_tax_single); /** * TEMPLATES */ // Choose templates $templates = get_page_templates(); $templates_views = get_posts('post_type=view-template&numberposts=-1&status=publish'); $options = array(); $options['default-template'] = array('#title' => __('Default Template'), '#default_value' => !empty($update['templates']) && in_array('default', $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => 'default', '#inline' => true, '#after' => '<br />'); foreach ($templates as $template_name => $template_filename) { $options[$template_filename] = array('#title' => $template_name, '#default_value' => !empty($update['templates']) && in_array($template_filename, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_filename, '#inline' => true, '#after' => '<br />'); } foreach ($templates_views as $template_view) { $options[$template_view->post_name] = array('#title' => 'View Template ' . $template_view->post_title, '#default_value' => !empty($update['templates']) && in_array($template_view->ID, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_view->ID, '#inline' => true, '#after' => '<br />'); $templates_view_list_text[$template_view->ID] = $template_view->post_title; } $text = ''; if (!empty($update['templates'])) { $text = array(); $templates = array_flip($templates); foreach ($update['templates'] as $template) { if ($template == 'default') { $template = __('Default Template'); } else { if (strpos($template, '.php') !== false) { $template = $templates[$template]; } else { $template = 'View Template ' . $templates_view_list_text[$template]; } } $text[] = $template; } $text = implode(', ', $text); } else { $text = __('Not Selected', 'wpcf'); } // Add class foreach ($options as $_k => $_option) { $options[$_k]['#attributes'] = array('class' => 'wpcf-form-groups-support-templates'); } $form_templates = array('#type' => 'checkboxes', '#name' => 'wpcf[group][templates]', '#options' => $options, '#inline' => true); /** * Since Types 1.2 we use unique function */ $form_templates = _wpcf_filter_wrap('templates', __('Templates:', 'wpcf'), $text, __('Not Selected', 'wpcf'), $form_templates); /** * Now starting form */ $form['supports-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat"><thead><tr><th>' . __('Where to display this group', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Each custom fields group can display on different content types or different taxonomy.', 'wpcf') . '</p>'); /** * Join filter forms */ // Types $form['p_wrap_1_' . wpcf_unique_id(serialize($form_types))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">'); $form = $form + $form_types; // Terms $form['p_wrap_2_' . wpcf_unique_id(serialize($form_tax))] = array('#type' => 'markup', '#markup' => '</p><p class="wpcf-filter-wrap">'); $form = $form + $form_tax; // Templates $form['p_wrap_3_' . wpcf_unique_id(serialize($form_templates))] = array('#type' => 'markup', '#markup' => '</p><p class="wpcf-filter-wrap">'); $form = $form + $form_templates; $form['p_wrap_4_' . wpcf_unique_id(serialize($form_templates))] = array('#type' => 'markup', '#markup' => '</p>'); /** * TODO Code from now on should be revised */ $count = 0; $count += !empty($update['post_types']) ? 1 : 0; $count += !empty($update['taxonomies']) ? 1 : 0; $count += !empty($update['templates']) ? 1 : 0; $display = $count > 1 ? '' : ' style="display:none;"'; $form['filters_association'] = array('#type' => 'radios', '#name' => 'wpcf[group][filters_association]', '#id' => 'wpcf-fields-form-filters-association', '#options' => array(__('Display this group when ANY of the above conditions is met', 'wpcf') => 'any', __('Display this group when ALL the above conditions is met', 'wpcf') => 'all'), '#default_value' => !empty($update['filters_association']) ? $update['filters_association'] : 'any', '#inline' => true, '#before' => '<div id="wpcf-fields-form-filters-association-form"' . $display . '>', '#after' => '<div id="wpcf-fields-form-filters-association-summary" style="margin-top:10px;font-style:italic;margin-bottom:15px;"></div></div>'); wpcf_admin_add_js_settings('wpcf_filters_association_or', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% or View Template is: %vt%', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_and', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% and View Template is: %vt%', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_pages', '\'' . __('all', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_taxonomies', '\'' . __('any', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_templates', '\'' . __('any', 'wpcf') . '\''); $additional_filters = apply_filters('wpcf_fields_form_additional_filters', array(), $update); $form = $form + $additional_filters; $form['supports-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />'); /** Admin styles* */ $form['adminstyles-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat" id="wpcf-admin-styles-box"><thead><tr><th>' . __('Styling Editor', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . '<p>' . __('Customize Fields for admin panel.', 'wpcf') . '</p>'); $admin_styles_value = $preview_profile = $edit_profile = ''; if (isset($update['admin_styles'])) { $admin_styles_value = $update['admin_styles']; } $temp = ''; if ($update) { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/usermeta-post.php'; //Get sample post $post = query_posts('posts_per_page=1'); if (!empty($post) && count($post) != '') { $post = $post[0]; } $preview_profile = wpcf_admin_post_meta_box_preview($post, $update, 1); $group = $update; $group['fields'] = wpcf_admin_post_process_fields($post, $group['fields'], true, false); $edit_profile = wpcf_admin_post_meta_box($post, $group, 1, true); add_action('admin_enqueue_scripts', 'wpcf_admin_fields_form_fix_styles', PHP_INT_MAX); } $temp[] = array('#type' => 'radio', '#suffix' => '<br />', '#value' => 'edit_mode', '#title' => 'Edit mode', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#before' => '<div class="wpcf-admin-css-preview-style-edit">', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'editmode\')', 'checked' => 'checked')); $temp[] = array('#type' => 'radio', '#title' => 'Read Only', '#name' => 'wpcf[group][preview]', '#default_value' => '', '#after' => '</div>', '#inline' => true, '#attributes' => array('onclick' => 'changePreviewHtml(\'readonly\')')); $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_html_preview]', '#inline' => true, '#id' => 'wpcf-form-groups-admin-html-preview', '#before' => '<h3>Field group HTML</h3>'); $temp[] = array('#type' => 'textarea', '#name' => 'wpcf[group][admin_styles]', '#inline' => true, '#value' => $admin_styles_value, '#default_value' => '', '#id' => 'wpcf-form-groups-css-fields-editor', '#after' => ' <div class="wpcf-update-preview-btn"><input type="button" value="Update preview" onclick="wpcfPreviewHtml()" style="float:right;" class="button-secondary"></div> <h3>Field group preview</h3> <div id="wpcf-update-preview-div">Preview here</div> <script type="text/javascript"> var wpcfReadOnly = ' . json_encode($preview_profile) . '; var wpcfEditMode = ' . json_encode($edit_profile) . '; var wpcfDefaultCss = ' . json_encode($admin_styles_value) . '; </script> ', '#before' => '<h3>Your CSS</h3>'); $admin_styles = _wpcf_filter_wrap('admin_styles', __('Admin styles for fields:', 'wpcf'), '', '', $temp, __('Open style editor', 'wpcf')); $form['p_wrap_1_' . wpcf_unique_id(serialize($admin_styles))] = array('#type' => 'markup', '#markup' => '<p class="wpcf-filter-wrap">'); $form = $form + $admin_styles; $form['adminstyles-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />'); /** End admin Styles * */ // Group fields $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>'); $show_under_title = true; $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">'); // If it's update, display existing fields $existing_fields = array(); if ($update && isset($update['fields'])) { foreach ($update['fields'] as $slug => $field) { $field['submitted_key'] = $slug; $field['group_id'] = $update['id']; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } $existing_fields[] = $slug; $show_under_title = false; } } // Any new fields submitted but failed? (Don't double it) if (!empty($_POST['wpcf']['fields'])) { foreach ($_POST['wpcf']['fields'] as $key => $field) { if (in_array($key, $existing_fields)) { continue; } $field['submitted_key'] = $key; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } } $show_under_title = false; } $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>'); if ($show_under_title) { $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>'; } // If update, create ID field if ($update) { $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true); } $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary wpcf-disabled-on-submit')); // Close main div $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); $form = apply_filters('wpcf_form_fields', $form, $update); // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueNamesCheckText', '\'' . __('Warning: field name already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormUniqueSlugsCheckText', '\'' . __('Warning: field slug already used', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcfFormAlertOnlyPreview', sprintf("'%s'", __('Sorry, but this is only preview!', 'wpcf'))); return $form; }
* * These hooks check if conditional failed * but form allowed to be saved * Since Types 1.2 */ add_filter('wpcf_post_form_error', 'wpcf_conditional_post_form_error_filter', 10, 2); /* * Logger */ if (!function_exists('wplogger')) { require_once WPCF_EMBEDDED_ABSPATH . '/common/wplogger.php'; } if (!function_exists('wpv_filter_parse_date')) { require_once WPCF_EMBEDDED_ABSPATH . '/common/wpv-filter-date-embedded.php'; } wpcf_admin_add_js_settings('wpcfConditionalVerifyGroup', wp_create_nonce('cd_group_verify')); /* * since Types 1.2 Filter validation JS */ add_filter('wpcf_validation_js_invalid_handler', 'wpcf_conditional_validation_js_invalid_handler_filter', 10, 3); /** * Filters groups on post edit page. * * @param type $groups * @param type $post * @return type */ function wpcf_cd_post_groups_filter($groups, $post, $context) { if ($context != 'group') { return $groups;
/** * Basic scripts */ function wpcf_enqueue_scripts() { if (!wpcf_is_embedded()) { /* * * Basic JS */ wp_enqueue_script('wpcf-js', WPCF_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs'), WPCF_VERSION); /* * * Basic CSS */ wp_enqueue_style('wpcf-css', WPCF_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION); /* * Settings */ // _nonce for editor callback wpcf_admin_add_js_settings('wpcfEditorCallbackNonce', wp_create_nonce('editor_callback')); // Thickbox generic title wpcf_admin_add_js_settings('wpcfEditorTbTitle', esc_js(__('Insert field', 'wpcf'))); } /* * * Basic JS */ wp_enqueue_script('wpcf-js-embedded', WPCF_EMBEDDED_RES_RELPATH . '/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs'), WPCF_VERSION); /* * * Basic CSS */ wp_enqueue_style('wpcf-css-embedded', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION); /* * * Other components */ // Repetitive wp_enqueue_script('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/js/repetitive.js', array('wpcf-js-embedded'), WPCF_VERSION); wp_enqueue_style('wpcf-repeater', WPCF_EMBEDDED_RES_RELPATH . '/css/repetitive.css', array('wpcf-css-embedded'), WPCF_VERSION); // Conditional wp_enqueue_script('wpcf-conditional', WPCF_EMBEDDED_RES_RELPATH . '/js/conditional.js', array('wpcf-js-embedded'), WPCF_VERSION); wpcf_admin_add_js_settings('wpcfConditionalVerify_nonce', wp_create_nonce('cd_verify')); wpcf_admin_add_js_settings('wpcfConditionalVerifyGroup', wp_create_nonce('cd_group_verify')); // RTL if (is_rtl()) { wp_enqueue_style('wpcf-rtl', WPCF_EMBEDDED_RES_RELPATH . '/css/rtl.css', array('wpcf-css-embedded'), WPCF_VERSION); } }
/** * Processes repetitive Skype field. * * @staticvar array $repetitive_started * @staticvar array $repetitive_index * @param type $post * @param string $field * @param type $skype_element * @return string */ function wpcf_admin_post_process_repetitive_field_skype($post, $field, $skype_element) { static $repetitive_started = array(); static $repetitive_index = array(); $repetitive_form = ''; if (defined('DOING_AJAX')) { $field['value'] = '__wpcf_repetitive_new_field'; } if (!isset($repetitive_index[$field['id']])) { if (defined('DOING_AJAX') && isset($_POST['count'])) { $repetitive_index[$field['id']] = $_POST['count']; } else { $repetitive_index[$field['id']] = 1; } } foreach ($skype_element as $element_key_temp => &$element) { $element_key = $element['__element_key']; if (!isset($field['value'][$element_key])) { $field['value'][$element_key] = ''; } if ($element_key == 'skypename') { // Add hidden fields old_value and mark field repetitive $repetitive_form .= '<input type="hidden" name="wpcf_repetitive[' . $field['id'] . ']" value="1" />'; $repetitive_form .= '<input type="hidden" name="wpcf[' . $field['slug'] . '][' . $repetitive_index[$field['id']] . '][old_value]" value="' . base64_encode(serialize($field['value'])) . '" />'; } if ($element_key != 'markup') { // Alter element name $element['#name'] = 'wpcf[' . $field['slug'] . '][' . $repetitive_index[$field['id']] . '][' . $element_key . ']'; } if ($element_key == 'skypename' && !isset($repetitive_started[$field['id']]) && !defined('DOING_AJAX')) { // Add 'Add' button $repetitive_form .= '<div class="wpcf-repetitive-buttons" style="margin-top:10px;">'; $repetitive_form .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=repetitive_add&_wpnonce=' . wp_create_nonce('repetitive_add')) . '&field_id=' . $field['id'] . '&field_id_md5=' . md5($field['id']) . '" class="wpcf-repetitive-add button-primary">Add Another Field</a>'; $repetitive_form .= '</div>'; } else { if ($element_key == 'skypename') { $repetitive_form .= '<div class="wpcf-repetitive-buttons" style="margin-top:10px;">'; // Add 'Delete' button if ($post || !defined('DOING_AJAX')) { $repetitive_form .= ' <a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=repetitive_delete&_wpnonce=' . wp_create_nonce('repetitive_delete') . '&post_id=' . $post->ID . '&field_id=' . $field['id'] . '&field_id_md5=' . md5($field['id']) . '&old_value=' . base64_encode(serialize($field['value']))) . '&wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-repetitive-delete button-secondary">Delete Field</a>'; } else { $repetitive_form .= ' <a href="javascript:void(0);" onclick="jQuery(this).parent().parent().fadeOut(function(){jQuery(this).remove();});" class="wpcf-repetitive-delete button-secondary">Delete Field</a>'; } $repetitive_form .= '</div>'; } } // Prepend to form element if ($element_key == 'skypename' && isset($element['#before'])) { $element['#before'] .= $repetitive_form; } else { if ($element_key == 'skypename') { $element['#before'] = $repetitive_form; } } // Append AJAX response area to element if ($element_key == 'markup' && !isset($repetitive_started[$field['id']]) && !defined('DOING_AJAX')) { $element['#markup'] .= '<div class="wpcf-repetitive-response"></div>'; } if ($element_key == 'skypename') { $main_element = $element; } } // Mark that first repetitive field is processed $repetitive_started[$field['id']] = true; $repetitive_index[$field['id']] += 1; // Set JS var for counting repetitive fields wpcf_admin_add_js_settings('wpcf_repetitive_count_' . md5($field['id']), $repetitive_index[$field['id']]); return array($main_element, $skype_element); }
/** * 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 = (array) $field_object->cf; $context = $field_object->context; $invalid_fields = $wpcf->field->invalid_fields; if (!empty($field)) { /* * 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']; } } // TODO WPML move Set WPML locked icon if (wpcf_wpml_field_is_copied($field)) { $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 WPML move if (types_is_repetitive($field) && $context != 'post_relationship' && wpcf_wpml_field_is_copied($field)) { 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 WPML Move this to separate WPML code and use only hooks 1.1.5 if (wpcf_wpml_field_is_copied($field)) { 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'); } } } // Final filter for disabled if readonly if (isset($element['#attributes']['readonly']) || isset($element['#attributes']['disabled'])) { if (types_is_repetitive($field)) { $element['#name'] .= '[]'; } if ($field['type'] == 'checkboxes') { if (isset($element['#options'])) { foreach ($element['#options'] as $temp_key => $temp_value) { $value = isset($temp_value['#default_value']) ? $temp_value['#default_value'] : $temp_value['#value']; $_after = "<input type=\"hidden\" name=\"{$temp_value['#name']}\" value=\"{$value}\" />"; $temp_value['#after'] = isset($temp_value['#after']) ? $temp_value['#after'] . $_after : $_after; $temp_value['#name'] = "wpcf-disabled[{$field['id']}_{$temp_value['#id']}]"; $temp_value['#attributes']['disabled'] = 'disabled'; $element['#options'][$temp_key] = $temp_value; } } } else { if (in_array($element['#type'], array('checkbox', 'checkboxes', 'radios'))) { if (isset($element['#options'])) { foreach ($element['#options'] as $temp_key => $temp_value) { $element['#options'][$temp_key]['#attributes']['disabled'] = 'disabled'; } } $value = isset($element['#default_value']) ? $element['#default_value'] : $element['#value']; $_after = "<input type=\"hidden\" name=\"{$element['#name']}\" value=\"{$value}\" />"; $element['#after'] = isset($element['#after']) ? $element['#after'] . $_after : $_after; $element['#attributes']['disabled'] = 'disabled'; $element['#name'] = "wpcf-disabled[{$field['id']}_{$element['#id']}]"; } else { $element['#attributes']['disabled'] = 'disabled'; if (is_array($element['#value'])) { //$field['type'] == 'skype' ) { $element['#value'] = array_shift($element['#value']); } $value = htmlentities($element['#value']); $_after = "<input type=\"hidden\" name=\"{$element['#name']}\" value=\"{$value}\" />"; $element['#after'] = isset($element['#after']) ? $element['#after'] . $_after : $_after; $element['#name'] = "wpcf-disabled[{$field['id']}_{$element['#id']}]"; } } } return array('field' => $field, 'element' => $element); } return false; }
function wpcf_admin_metabox_relationship($post_type) { $form = array(); $form['table-pr-open'] = wpcf_admin_metabox_begin(__('Post Relationship', 'wpcf'), 'relationship', 'wpcf-types-form-pr-table', false); /** * belongs/children section */ $has = wpcf_pr_admin_get_has($post_type['slug']); $belongs = wpcf_pr_admin_get_belongs($post_type['slug']); $post_types = get_post_types('', 'objects'); if (empty($has) || empty($post_type['slug'])) { $txt_has = __("Children: None", 'wpcf'); } else { $txt_has = array(); foreach ($has as $pr_key => $pr_data) { $txt_has[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key; } $txt_has = sprintf(__("Children: %s", 'wpcf'), implode(', ', $txt_has)); } if (!empty($belongs)) { $txt_belongs = array(); foreach ($belongs as $pr_key => $pr_data) { $txt_belongs[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key; } $txt_belongs = sprintf(__("Parent: %s", 'wpcf'), implode(', ', $txt_belongs)); } else { $txt_belongs = __("Parent: None", 'wpcf'); } // Others belonging to if (!empty($belongs)) { $txt_belongs = array(); foreach ($belongs as $pr_key => $pr_data) { $txt_belongs[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key; } $txt_belongs = sprintf(__("Parent: %s", 'wpcf'), implode(', ', $txt_belongs)); } else { $txt_belongs = __("Parent: None", 'wpcf'); } $form['table-pr-belongs'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 10px 0;"><span class="wpcf-pr-belongs-summary">' . $txt_belongs . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-belongs-edit" class="button-secondary wpcf-pr-edit">' . __('Edit', 'wpcf') . '</a>'); $options = array(); /** * build excluded post types */ global $wpcf; $excluded_post_types = $wpcf->excluded_post_types; $excluded_post_types[] = $post_type['slug']; foreach ($post_types as $temp_post_type_slug => $temp_post_type) { if (in_array($temp_post_type_slug, $excluded_post_types) || !$temp_post_type->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) { continue; } // Check if it's in has if (isset($has[$temp_post_type_slug])) { continue; } $options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][belongs][' . $temp_post_type_slug . ']'; $options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name; $options[$temp_post_type_slug]['#default_value'] = isset($belongs[$temp_post_type_slug]); $options[$temp_post_type_slug]['#inline'] = true; $options[$temp_post_type_slug]['#after'] = ' '; if (is_rtl()) { $options[$temp_post_type_slug]['#before'] = '<div style="float:right;margin-left:10px;">'; $options[$temp_post_type_slug]['#after'] .= '</div>'; } } $form['table-pr-has-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-belongs-apply">' . __('Apply', 'wpcf') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-belongs-cancel">' . __('Cancel', 'wpcf') . '</a></div></div>', '#inline' => true); $form['table-pr-has'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 5px 0;"><span class="wpcf-pr-has-summary">' . $txt_has . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-has-edit" class="button-secondary wpcf-pr-edit">' . __('Edit', 'wpcf') . '</a>'); $options = array(); foreach ($post_types as $temp_post_type_slug => $temp_post_type) { if (in_array($temp_post_type_slug, $excluded_post_types) || !$temp_post_type->show_ui && !apply_filters('wpcf_show_ui_hide_in_relationships', true)) { continue; } // Check if it already belongs if (isset($belongs[$temp_post_type_slug])) { continue; } $options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][has][' . $temp_post_type_slug . ']'; $options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name; $options[$temp_post_type_slug]['#default_value'] = isset($has[$temp_post_type_slug]); $options[$temp_post_type_slug]['#inline'] = true; $options[$temp_post_type_slug]['#after'] = isset($has[$temp_post_type_slug]) ? '' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pt_edit_fields&child=' . $temp_post_type_slug . '&parent=' . $post_type['slug'] . '&_wpnonce=' . wp_create_nonce('pt_edit_fields') . '&KeepThis=true&TB_iframe=true') . '" class="thickbox" title="' . __('Select child fields to be displayed', 'wpcf') . '">(' . __('Edit fields', 'wpcf') . ')</a> ' : '' . '<a href="javascript:void(0);" style="color:Gray;" title="' . __('Please save the page first, before you can edit the child items', 'wpcf') . '">(' . __('Edit fields', 'wpcf') . ')</a> '; if (is_rtl()) { $options[$temp_post_type_slug]['#before'] = '<div style="float:right;margin-left:10px;">'; $options[$temp_post_type_slug]['#after'] .= '</div>'; } } $form['table-pr-belongs-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-has-apply">' . __('Apply', 'wpcf') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-has-cancel">' . __('Cancel', 'wpcf') . '</a></div></div>', '#inline' => true); $form['table-pr-explanation'] = array('#type' => 'markup', '#markup' => '<p>' . __("You can choose which fields will show when editing parent pages.", 'wpcf') . '<br />' . __("Click on the 'edit' button to select them for each parent.", 'wpcf') . '<br />' . sprintf(__('Learn about %sPost Type Relationships%s', 'wpcf'), '<a href="http://wp-types.com/documentation/user-guides/creating-post-type-relationships/" target="_blank">', ' »</a>') . '</p>'); /** * close form */ $form['table-pr-close'] = wpcf_admin_metabox_end(); /** * additional settings */ wpcf_admin_add_js_settings('wpcf_pr_has_empty_txt', '\'' . __("Children: None", 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_has_txt', '\'' . __("Children: %s", 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_belongs_empty_txt', '\'' . __("Parent: None", 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_belongs_txt', '\'' . __("Parent: %s", 'wpcf') . '\''); return $form; }
/** * Renders JS settings. * * @return type */ function wpcf_admin_render_js_settings() { $settings = wpcf_admin_add_js_settings('get'); if (empty($settings)) { return ''; } ?> <script type="text/javascript"> //<![CDATA[ <?php foreach ($settings as $id => $setting) { if (is_string($setting)) { $setting = trim($setting, '\''); $setting = "'" . esc_js($setting) . "'"; } else { $setting = intval($setting); } echo 'var ' . $id . ' = ' . $setting . ';' . "\r\n"; } ?> //]]> </script> <?php }
/** * Sete repetitive form for single field. * * @param type $meta * @return string */ function get_field_form($meta_value = null, $meta_id = null) { $form = array(); if (is_null($meta_value)) { $key = 'wpcf_field_' . wpcf_unique_id(md5($this->index) . $meta_id); } else { $key = 'wpcf_field_' . md5(maybe_serialize($meta_value) . $meta_id); } /* * * * TODO We prevented array because of some fails we had before. * Now it should work fine * Add debug log if meta_value['custom_order'] passed. * That means setting meta_value did not went well. */ // if ( is_null( $meta_value ) || is_array( $meta_value ) ) { if (is_null($meta_value) || is_array($meta_value) && isset($meta_value['custom_order'])) { $meta_value = $this->meta['single']; } // Open drag div $form[$key . '_drag_open'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-repetitive-drag-and-drop">'); // Use WPCF_Field::get_field_form() $field_form = parent::_get_meta_form($meta_value, $meta_id, false); /* * * Apply filters to each form element. * Here we add specific properties * e.g. Skype alters fields. */ $_loop = false; foreach ($field_form as $k => $field) { /* * * IMPORTANT * We change name to hold array */ if (isset($field['#name'])) { $temp = explode('[' . $this->cf['slug'] . ']', $field['#name']); // Assign new name $field['#name'] = $temp[0] . '[' . $this->cf['slug'] . ']' . '[' . $key . ']'; // Append rest if any if (isset($temp[1])) { $field['#name'] .= $temp[1]; } } // Apply filters $field_form[$k] = apply_filters('wpcf_repetitive_field', $field, $this->post, $this->cf, $k); // BREAKPOINT /* * This is place where we clean display. * First item is displayed as it is, each after is reduced. * If called via AJAX - that means it added and should be reduced. */ // if ( $_loop == true || defined( 'DOING_AJAX' ) ) { /* * See if field has Repeater pattern defined */ if (isset($field['__repeater_restricted']) && is_array($field['__repeater_restricted'])) { foreach ($field['__repeater_restricted'] as $_e => $_v) { if (isset($field[$_e])) { unset($field[$_e]); } } } else { unset($field['#title'], $field['#description']); } // Set main $field_form[$k] = $field; // } // $_loop = true; } // Just append form $form = $form + $field_form; // Open control div $form[$key . '_control_open'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-repetitive-control">'); // Drag button $form[$key . '_drag_button'] = array('#type' => 'markup', '#markup' => wpcf_repetitive_drag_button($this->cf, $this->post)); // 'Delete' button $form[$key . '_delete_button'] = array('#type' => 'markup', '#markup' => wpcf_repetitive_delete_button($this->cf, $this->post, $meta_id)); // Close control div $form[$key . '_control_close'] = array('#type' => 'markup', '#markup' => '</div>'); // Close drag div $form[$key . '_drag_close'] = array('#type' => 'markup', '#markup' => '</div>'); // Count it and set JS var $this->_set_form_count(); wpcf_admin_add_js_settings('wpcf_repetitive_count_' . md5($this->cf['id']), $this->index); return $form; }
/** * Adds Post relationship table to form. * * @param type $form * @param type $post_type * @return string */ function wpcf_pr_post_type_form_filter($form, $post_type) { $has = wpcf_pr_admin_get_has($post_type['slug']); $belongs = wpcf_pr_admin_get_belongs($post_type['slug']); $post_types = get_post_types('', 'objects'); if (empty($has) || empty($post_type['slug'])) { $txt_has = __("Children: None", 'wpcf'); // $txt_has = __("None post type belongs to this post type", 'wpcf'); } else { $txt_has = array(); foreach ($has as $pr_key => $pr_data) { $txt_has[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key; } $txt_has = sprintf(__("Children: %s", 'wpcf'), implode(', ', $txt_has)); // if (count($txt_has) < 2) { // $txt_has = sprintf(__("%s belong to this post type", 'wpcf'), // implode(', ', $txt_has)); // } else { // $txt_has = sprintf(__("%s belongs to this post type", 'wpcf'), // implode(', ', $txt_has)); // } } wpcf_admin_add_js_settings('wpcf_pr_has_empty_txt', '\'' . __("Children: None", 'wpcf') . '\''); // wpcf_admin_add_js_settings('wpcf_pr_has_empty_txt', // '\'' . __("None post type belongs to this post type", 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_has_txt', '\'' . __("Children: %s", 'wpcf') . '\''); // wpcf_admin_add_js_settings('wpcf_pr_has_txt', // '\'' . __("%s belong to this post type", 'wpcf') . '\''); // Others belonging to if (!empty($belongs)) { $txt_belongs = array(); foreach ($belongs as $pr_key => $pr_data) { $txt_belongs[] = isset($post_types[$pr_key]) ? $post_types[$pr_key]->labels->singular_name : $pr_key; } $txt_belongs = sprintf(__("Parent: %s", 'wpcf'), implode(', ', $txt_belongs)); // if (count($txt_belongs) > 1) { // $txt_belongs = sprintf(__("This post type belongs to %s", 'wpcf'), // implode(', ', $txt_belongs)); // } else { // $txt_belongs = sprintf(__("This post type belongs to %s", 'wpcf'), // $txt_belongs[0]); // } } else { // $txt_belongs = __("This post type belongs to none", 'wpcf'); $txt_belongs = __("Parent: None", 'wpcf'); } // wpcf_admin_add_js_settings('wpcf_pr_belongs_empty_txt', // '\'' . __("This post type belongs to none", 'wpcf') . '\''); // wpcf_admin_add_js_settings('wpcf_pr_belongs_txt', // '\'' . __("This post type belongs to %s", 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_belongs_empty_txt', '\'' . __("Parent: None", 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_pr_belongs_txt', '\'' . __("Parent: %s", 'wpcf') . '\''); $form['table-pr-open'] = array('#type' => 'markup', '#markup' => '<table id="wpcf-types-form-pr-table" class="wpcf-types-form-table widefat"><thead><tr><th>' . __('Post Relationship', 'wpcf') . '</th></tr></thead><tbody><tr><td>'); $form['table-pr-belongs'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 10px 0;"><span class="wpcf-pr-belongs-summary">' . $txt_belongs . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-belongs-edit" class="button-secondary wpcf-pr-edit">' . __('Edit') . '</a>'); $options = array(); foreach ($post_types as $temp_post_type_slug => $temp_post_type) { if (in_array($temp_post_type_slug, array($post_type['slug'], 'revision', 'view', 'view-template', 'nav_menu_item', 'attachment', 'mediapage')) || !$temp_post_type->show_ui) { continue; } // Check if it's in has if (isset($has[$temp_post_type_slug])) { continue; } $options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][belongs][' . $temp_post_type_slug . ']'; $options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name; $options[$temp_post_type_slug]['#default_value'] = isset($belongs[$temp_post_type_slug]); $options[$temp_post_type_slug]['#inline'] = true; $options[$temp_post_type_slug]['#after'] = ' '; } $form['table-pr-has-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-belongs-apply">' . __('Apply') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-belongs-cancel">' . __('Cancel') . '</a></div></div>', '#inline' => true); $form['table-pr-has'] = array('#type' => 'markup', '#markup' => '<div style="margin: 10px 0 5px 0;"><span class="wpcf-pr-has-summary">' . $txt_has . '</span> ' . '<a href="javascript:void(0);" id="wpcf-pr-has-edit" class="button-secondary wpcf-pr-edit">' . __('Edit') . '</a>'); $options = array(); foreach ($post_types as $temp_post_type_slug => $temp_post_type) { if (in_array($temp_post_type_slug, array($post_type['slug'], 'revision', 'view', 'view-template', 'nav_menu_item', 'attachment', 'mediapage')) || !$temp_post_type->show_ui) { continue; } // Check if it already belongs if (isset($belongs[$temp_post_type_slug])) { continue; } $options[$temp_post_type_slug]['#name'] = 'ct[post_relationship][has][' . $temp_post_type_slug . ']'; $options[$temp_post_type_slug]['#title'] = $temp_post_type->labels->singular_name; $options[$temp_post_type_slug]['#default_value'] = isset($has[$temp_post_type_slug]); $options[$temp_post_type_slug]['#inline'] = true; $options[$temp_post_type_slug]['#after'] = isset($has[$temp_post_type_slug]) ? '' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&wpcf_action=pt_edit_fields&child=' . $temp_post_type_slug . '&parent=' . $post_type['slug'] . '&_wpnonce=' . wp_create_nonce('pt_edit_fields') . '&KeepThis=true&TB_iframe=true') . '" class="thickbox">(' . __('Edit fields') . ')</a> ' : '' . '<a href="javascript:void(0);" style="color:Gray;" title="' . __('Please save the page first, before you can edit the child items', 'wpcf') . '">(' . __('Edit fields') . ')</a> '; } $form['table-pr-belongs-form'] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'ct[post_relationship]', '#before' => '<div style="display:none; margin: 10px 0 20px 0;">', '#after' => '<br /><br /><a href="javascript:void(0);" class="button-primary wpcf-pr-has-apply">' . __('Apply') . '</a> <a href="javascript:void(0);" class="button-secondary wpcf-pr-has-cancel">' . __('Cancel') . '</a></div></div>', '#inline' => true); $form['table-pr-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table>'); $form['table-pr-explanation'] = array('#type' => 'markup', '#markup' => '<div>' . __("You can choose which fields will show when editing parent pages.", 'wpcf') . '<br />' . __("Click on the 'edit' button to select them for each parent.", 'wpcf') . '<br />' . sprintf(__('Learn about %sPost Type Relationships%s', 'wpcf'), '<a href="http://wp-types.com/documentation/user-guides/creating-post-type-relationships/" target="_blank">', '</a>') . '</div>'); return $form; }
/** * Generates form data. */ function wpcf_admin_fields_form() { wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); $default = array(); // If it's update, get data $update = false; if (isset($_REQUEST['group_id'])) { $update = wpcf_admin_fields_get_group(intval($_REQUEST['group_id'])); if (empty($update)) { $update = false; wpcf_admin_message(sprintf(__("Group with ID %d do not exist", 'wpcf'), intval($_REQUEST['group_id']))); } else { $update['fields'] = wpcf_admin_fields_get_fields_by_group($_REQUEST['group_id']); $update['post_types'] = wpcf_admin_get_post_types_by_group($_REQUEST['group_id']); $update['taxonomies'] = wpcf_admin_get_taxonomies_by_group($_REQUEST['group_id']); $update['templates'] = wpcf_admin_get_templates_by_group($_REQUEST['group_id']); } } $form = array(); $form['#form']['callback'] = array('wpcf_admin_save_fields_groups_submit'); // Form sidebars $form['open-sidebar'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-fields-align-right">'); $form['submit2'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary')); $form['fields'] = array('#type' => 'fieldset', '#title' => __('Available fields', 'wpcf')); // Get field types $fields_registered = wpcf_admin_fields_get_available_types(); // foreach (glob(WPCF_EMBEDDED_INC_ABSPATH . '/fields/*.php') as $filename) { foreach ($fields_registered as $filename => $data) { // require_once $filename; // if (function_exists('wpcf_fields_' . basename($filename, '.php'))) { // $data = call_user_func('wpcf_fields_' . basename($filename, '.php')); // if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'], // '<')) { // continue; // } $form['fields'][basename($filename, '.php')] = array('#type' => 'markup', '#markup' => '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax&wpcf_action=fields_insert' . '&field=' . basename($filename, '.php')) . '&_wpnonce=' . wp_create_nonce('fields_insert') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary">' . $data['title'] . '</a> '); // Process JS if (!empty($data['group_form_js'])) { foreach ($data['group_form_js'] as $handle => $script) { if (isset($script['inline'])) { add_action('admin_footer', $script['inline']); continue; } $deps = !empty($script['deps']) ? $script['deps'] : array(); $in_footer = !empty($script['in_footer']) ? $script['in_footer'] : false; wp_register_script($handle, $script['src'], $deps, WPCF_VERSION, $in_footer); wp_enqueue_script($handle); } } // Process CSS if (!empty($data['group_form_css'])) { foreach ($data['group_form_css'] as $handle => $script) { if (isset($script['src'])) { $deps = !empty($script['deps']) ? $script['deps'] : array(); wp_enqueue_style($handle, $script['src'], $deps, WPCF_VERSION); } else { if (isset($script['inline'])) { add_action('admin_head', $script['inline']); } } } } // } } // Get fields created by user $fields = wpcf_admin_fields_get_fields(true, true); if (!empty($fields)) { $form['fields-existing'] = array('#type' => 'fieldset', '#title' => __('User created fields', 'wpcf'), '#id' => 'wpcf-form-groups-user-fields'); foreach ($fields as $key => $field) { if (isset($update['fields']) && array_key_exists($key, $update['fields'])) { continue; } if (!empty($field['data']['removed_from_history'])) { continue; } $form['fields-existing'][$key] = array('#type' => 'markup', '#markup' => '<div id="wpcf-user-created-fields-wrapper-' . $field['id'] . '" style="float:left; margin-right: 10px;"><a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=fields_insert_existing' . '&field=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('fields_insert_existing') . '" ' . 'class="wpcf-fields-add-ajax-link button-secondary" onclick="jQuery(this).parent().fadeOut();">' . htmlspecialchars(stripslashes($field['name'])) . '</a>' . '<a href="' . admin_url('admin-ajax.php' . '?action=wpcf_ajax' . '&wpcf_action=remove_from_history' . '&field_id=' . $field['id']) . '&_wpnonce=' . wp_create_nonce('remove_from_history') . '&wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&wpcf_ajax_update=wpcf-user-created-fields-wrapper-' . $field['id'] . '" title="' . sprintf(__('Remove field %s', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '" class="wpcf-ajax-link"><img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" style="postion:absolute;margin-top:5px;margin-left:-4px;" /></a></div>'); } } $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); // Group data $form['open-main'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-form-fields-main">'); $form['title'] = array('#type' => 'textfield', '#name' => 'wpcf[group][name]', '#id' => 'wpcf-group-name', '#value' => $update ? $update['name'] : __('Enter group title', 'wpcf'), '#inline' => true, '#attributes' => array('style' => 'width:100%;margin-bottom:10px;'), '#validate' => array('required' => array('value' => true))); if (!$update) { $form['title']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Enter group title', 'wpcf') . '\') { jQuery(this).val(\'\'); }'; $form['title']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter group title', 'wpcf') . '\') }'; } $form['description'] = array('#type' => 'textarea', '#id' => 'wpcf-group-description', '#name' => 'wpcf[group][description]', '#value' => $update ? $update['description'] : __('Enter a description for this group', 'wpcf')); if (!$update) { $form['description']['#attributes']['onfocus'] = 'if (jQuery(this).val() == \'' . __('Enter a description for this group', 'wpcf') . '\') { jQuery(this).val(\'\'); }'; $form['description']['#attributes']['onblur'] = 'if (jQuery(this).val() == \'\') { jQuery(this).val(\'' . __('Enter a description for this group', 'wpcf') . '\') }'; } // Support post types and taxonomies $post_types = get_post_types('', 'objects'); $options = array(); $post_types_currently_supported = array(); $form_types = array(); foreach ($post_types as $post_type_slug => $post_type) { if (in_array($post_type_slug, array('attachment', 'revision', 'nav_menu_item', 'view', 'view-template')) || !$post_type->show_ui) { continue; } $options[$post_type_slug]['#name'] = 'wpcf[group][supports][' . $post_type_slug . ']'; $options[$post_type_slug]['#title'] = $post_type->label; $options[$post_type_slug]['#default_value'] = $update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types']) ? 1 : 0; $options[$post_type_slug]['#value'] = $post_type_slug; $options[$post_type_slug]['#inline'] = TRUE; $options[$post_type_slug]['#suffix'] = '<br />'; $options[$post_type_slug]['#id'] = 'wpcf-form-groups-support-post-type-' . $post_type_slug; $options[$post_type_slug]['#attributes'] = array('class' => 'wpcf-form-groups-support-post-type'); if ($update && !empty($update['post_types']) && in_array($post_type_slug, $update['post_types'])) { $post_types_currently_supported[] = $post_type->label; } } if (empty($post_types_currently_supported)) { $post_types_currently_supported[] = __('Displayed on all content types', 'wpcf'); } $post_types_no_currently_supported_txt = __('Post Types:', 'wpcf') . ' ' . __('Displayed on all content types', 'wpcf'); $form_types = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][supports]', '#inline' => true, '#before' => '<span id="wpcf-group-form-update-types-ajax-response"' . ' style="font-style:italic;font-weight:bold;display:inline-block;">' . __('Post Types:', 'wpcf') . ' ' . implode(', ', $post_types_currently_supported) . '</span>' . ' <a href="javascript:void(0);" style="line-height: 30px;"' . ' class="button-secondary" onclick="' . 'window.wpcfPostTypesText = new Array(); window.wpcfFormGroupsSupportPostTypesState = new Array(); ' . 'jQuery(this).next().slideToggle()' . '.find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfPostTypesText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportPostTypesState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . ' jQuery(this).css(\'visibility\', \'hidden\');">' . __('Edit', 'wpcf') . '</a>' . '<div class="hidden" id="wpcf-form-fields-post_types">', '#after' => '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-primary wpcf-groups-form-ajax-update-post-types-ok"' . ' onclick="window.wpcfPostTypesText = new Array(); window.wpcfFormGroupsSupportPostTypesState = new Array(); ' . 'jQuery(this).parent().slideUp().find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfPostTypesText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportPostTypesState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . 'if (window.wpcfPostTypesText.length < 1) { ' . 'jQuery(\'#wpcf-group-form-update-types-ajax-response\').html(\'' . $post_types_no_currently_supported_txt . '\'); ' . '} else { jQuery(\'#wpcf-group-form-update-types-ajax-response\').html(\'' . __('Post Types:', 'wpcf') . ' \'+wpcfPostTypesText.join(\', \'));}' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('OK', 'wpcf') . '</a> ' . '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-secondary wpcf-groups-form-ajax-update-post-types-cancel"' . ' onclick="jQuery(this).parent().slideUp().find(\'input\').removeAttr(\'checked\');' . 'if (window.wpcfFormGroupsSupportPostTypesState.length > 0) { ' . 'for (var element in window.wpcfFormGroupsSupportPostTypesState) { ' . 'jQuery(\'#\'+window.wpcfFormGroupsSupportPostTypesState[element]).attr(\'checked\', \'checked\'); }}' . 'jQuery(\'#wpcf-group-form-update-types-ajax-response\').html(\'' . __('Post Types:', 'wpcf') . ' \'+window.wpcfPostTypesText.join(\', \'));' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('Cancel', 'wpcf') . '</a>' . '</div></div><br />'); $taxonomies = get_taxonomies('', 'objects'); $options = array(); $tax_currently_supported = array(); $form_tax = array(); $form_tax_single = array(); foreach ($taxonomies as $category_slug => $category) { if ($category_slug == 'nav_menu' || $category_slug == 'link_category' || $category_slug == 'post_format') { continue; } $terms = get_terms($category_slug, array('hide_empty' => false)); if (!empty($terms)) { $options = array(); $add_title = '<div class="taxonomy-title">' . $category->labels->name . '</div>'; $title = ''; foreach ($terms as $term) { $checked = 0; if ($update && !empty($update['taxonomies']) && array_key_exists($category_slug, $update['taxonomies'])) { if (array_key_exists($term->term_id, $update['taxonomies'][$category_slug])) { $checked = 1; $tax_currently_supported[$term->term_id] = $title . $term->name; $title = ''; } } $options[$term->term_id]['#name'] = 'wpcf[group][taxonomies][' . $category_slug . '][' . $term->term_id . ']'; $options[$term->term_id]['#title'] = $term->name; $options[$term->term_id]['#default_value'] = $checked; $options[$term->term_id]['#value'] = $term->term_id; $options[$term->term_id]['#inline'] = true; $options[$term->term_id]['#prefix'] = $add_title; $options[$term->term_id]['#suffix'] = '<br />'; $options[$term->term_id]['#id'] = 'wpcf-form-groups-support-tax-' . $term->term_id; $options[$term->term_id]['#attributes'] = array('class' => 'wpcf-form-groups-support-tax'); $add_title = ''; } $form_tax_single['taxonomies-' . $category_slug] = array('#type' => 'checkboxes', '#options' => $options, '#name' => 'wpcf[group][taxonomies][' . $category_slug . ']', '#suffix' => '<br />', '#inline' => true); } } if (empty($tax_currently_supported)) { $tax_currently_supported[] = __('Not Selected', 'wpcf'); } $tax_no_currently_supported_txt = __('Terms:', 'wpcf') . ' ' . __('Not Selected', 'wpcf'); $form_tax['taxonomies-open'] = array('#type' => 'markup', '#markup' => '<span id="wpcf-group-form-update-tax-ajax-response" ' . 'style="font-style:italic;font-weight:bold;display:inline-block;">' . __('Terms:', 'wpcf') . ' ' . implode(', ', $tax_currently_supported) . '</span>' . ' <a href="javascript:void(0);" style="line-height: 30px;" ' . 'class="button-secondary" onclick="' . 'window.wpcfTaxText = new Array(); window.wpcfFormGroupsSupportTaxState = new Array(); ' . 'jQuery(this).next().slideToggle()' . '.find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfTaxText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportTaxState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . ' jQuery(this).css(\'visibility\', \'hidden\');">' . __('Edit', 'wpcf') . '</a>' . '<div class="hidden" id="wpcf-form-fields-taxonomies">'); $form_tax = $form_tax + $form_tax_single; $form_tax['taxonomies-close'] = array('#type' => 'markup', '#markup' => '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-primary wpcf-groups-form-ajax-update-tax-ok"' . ' onclick="window.wpcfTaxText = new Array(); window.wpcfFormGroupsSupportTaxState = new Array(); ' . 'jQuery(this).parent().slideUp().find(\'.checkbox\').each(function(index){' . 'if (jQuery(this).is(\':checked\')) { ' . 'window.wpcfTaxText.push(jQuery(this).next().html()); ' . 'window.wpcfFormGroupsSupportTaxState.push(jQuery(this).attr(\'id\'));' . '}' . '});' . 'if (window.wpcfTaxText.length < 1) { ' . 'jQuery(\'#wpcf-group-form-update-tax-ajax-response\').html(\'' . $tax_no_currently_supported_txt . '\'); ' . '} else { jQuery(\'#wpcf-group-form-update-tax-ajax-response\').html(\'' . __('Terms:', 'wpcf') . ' \'+wpcfTaxText.join(\', \'));' . '}' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('OK', 'wpcf') . '</a> ' . '<a href="javascript:void(0);" style="line-height: 35px;" ' . 'class="button-secondary wpcf-groups-form-ajax-update-tax-cancel"' . ' onclick="jQuery(this).parent().slideUp().find(\'input\').removeAttr(\'checked\');' . 'if (window.wpcfFormGroupsSupportTaxState.length > 0) { ' . 'for (var element in window.wpcfFormGroupsSupportTaxState) { ' . 'jQuery(\'#\'+window.wpcfFormGroupsSupportTaxState[element]).attr(\'checked\', \'checked\'); }}' . 'jQuery(\'#wpcf-group-form-update-tax-ajax-response\').html(\'' . __('Terms:', 'wpcf') . ' \'+window.wpcfTaxText.join(\', \'));' . ' jQuery(this).parent().parent().children(\'a\').css(\'visibility\', \'visible\');' . '">' . __('Cancel', 'wpcf') . '</a>' . '</div><br />'); $form['supports-table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat"><thead><tr><th>' . __('Where to display this group', 'wpcf') . '</th></tr></thead><tbody><tr><td>' . __('Each custom fields group can display on different content types or different taxonomy.', 'wpcf') . '<br />'); $form['types'] = $form_types; $form = $form + $form_tax; // Choose templates $templates = get_page_templates(); $templates_views = get_posts('post_type=view-template&numberposts=-1&status=publish'); $options = array(); $options['default-template'] = array('#title' => __('Default Template'), '#default_value' => !empty($update['templates']) && in_array('default', $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => 'default', '#inline' => true, '#after' => '<br />'); foreach ($templates as $template_name => $template_filename) { $options[$template_filename] = array('#title' => $template_name, '#default_value' => !empty($update['templates']) && in_array($template_filename, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_filename, '#inline' => true, '#after' => '<br />'); } foreach ($templates_views as $template_view) { $options[$template_view->post_name] = array('#title' => 'View Template ' . $template_view->post_title, '#default_value' => !empty($update['templates']) && in_array($template_view->ID, $update['templates']), '#name' => 'wpcf[group][templates][]', '#value' => $template_view->ID, '#inline' => true, '#after' => '<br />'); $templates_view_list_text[$template_view->ID] = $template_view->post_title; } $text = ''; $empty_txt = __('Not Selected', 'wpcf'); if (!empty($update['templates'])) { $text = array(); $templates = array_flip($templates); foreach ($update['templates'] as $template) { if ($template == 'default') { $template = __('Default Template'); } else { if (strpos($template, '.php') !== false) { $template = $templates[$template]; } else { $template = 'View Template ' . $templates_view_list_text[$template]; } } $text[] = $template; } $text = implode(', ', $text); } else { $text = __('Not Selected', 'wpcf'); } $form['templates'] = array('#type' => 'checkboxes', '#name' => 'wpcf[group][templates]', '#options' => $options, '#inline' => true); $form['templates'] = wpcf_admin_fields_form_nested_elements('templates', $form['templates'], __('Content templates:', 'wpcf'), $text, $empty_txt); $count = 0; $count += !empty($update['post_types']) ? 1 : 0; $count += !empty($update['taxonomies']) ? 1 : 0; $count += !empty($update['templates']) ? 1 : 0; $display = $count > 1 ? '' : ' style="display:none;"'; $form['filters_association'] = array('#type' => 'radios', '#name' => 'wpcf[group][filters_association]', '#id' => 'wpcf-fields-form-filters-association', '#options' => array(__('Display this group when ANY of the above conditions is met', 'wpcf') => 'any', __('Display this group when ALL the above conditions is met', 'wpcf') => 'all'), '#default_value' => !empty($update['filters_association']) ? $update['filters_association'] : 'any', '#inline' => true, '#before' => '<div id="wpcf-fields-form-filters-association-form"' . $display . '>', '#after' => '<div id="wpcf-fields-form-filters-association-summary" style="margin-top:10px;font-style:italic;"></div></div>'); wpcf_admin_add_js_settings('wpcf_filters_association_or', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% or View Template is: %vt%', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_and', '\'' . __('This group will appear on %pt% edit pages where content belongs to taxonomy: %tx% and View Template is: %vt%', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_pages', '\'' . __('all', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_taxonomies', '\'' . __('any', 'wpcf') . '\''); wpcf_admin_add_js_settings('wpcf_filters_association_all_templates', '\'' . __('any', 'wpcf') . '\''); $form['supports-table-close'] = array('#type' => 'markup', '#markup' => '</td></tr></tbody></table><br />'); // Group fields $form['fields_title'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Fields', 'wpcf') . '</h2>'); $show_under_title = true; $form['ajax-response-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-fields-sortable" class="ui-sortable">'); // If it's update, display existing fields $existing_fields = array(); if ($update && isset($update['fields'])) { foreach ($update['fields'] as $slug => $field) { $field['submitted_key'] = $slug; $field['group_id'] = $update['id']; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } $existing_fields[] = $slug; $show_under_title = false; } } // Any new fields submitted but failed? (Don't double it) if (!empty($_POST['wpcf']['fields'])) { foreach ($_POST['wpcf']['fields'] as $key => $field) { if (in_array($key, $existing_fields)) { continue; } $field['submitted_key'] = $key; $form_field = wpcf_fields_get_field_form_data($field['type'], $field); if (is_array($form_field)) { $form['draggable-open-' . rand()] = array('#type' => 'markup', '#markup' => '<div class="ui-draggable">'); $form = $form + $form_field; $form['draggable-close-' . rand()] = array('#type' => 'markup', '#markup' => '</div>'); } } $show_under_title = false; } $form['ajax-response-close'] = array('#type' => 'markup', '#markup' => '</div>' . '<div id="wpcf-ajax-response"></div>'); if ($show_under_title) { $form['fields_title']['#markup'] = $form['fields_title']['#markup'] . '<div id="wpcf-fields-under-title">' . __('There are no fields in this group. To add a field, click on the field buttons at the right.', 'wpcf') . '</div>'; } // If update, create ID field if ($update) { $form['group_id'] = array('#type' => 'hidden', '#name' => 'group_id', '#value' => $update['id'], '#forced_value' => true); } $form['submit'] = array('#type' => 'submit', '#name' => 'save', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary')); // Close main div $form['close-sidebar'] = array('#type' => 'markup', '#markup' => '</div>'); $form = apply_filters('wpcf_form_fields', $form); // Add JS settings wpcf_admin_add_js_settings('wpcfFormUniqueValuesCheckText', '\'' . __('Warning: same values selected', 'wpcf') . '\''); return $form; }
/** * Enqueues scripts. */ function add_js() { wp_enqueue_script('types-conditional'); wpcf_admin_add_js_settings('wpcfConditionalVerify_nonce', wp_create_nonce('cd_verify')); }