コード例 #1
0
ファイル: skype.php プロジェクト: SpencerNeitzke/types
/**
 * Form data for post edit page.
 *
 * @param type $field
 */
function wpcf_fields_skype_meta_box_form($field)
{
    add_thickbox();
    if (isset($field['value'])) {
        $field['value'] = maybe_unserialize($field['value']);
    }
    $form = array();
    add_filter('wpcf_fields_shortcode_slug_' . $field['slug'], 'wpcf_fields_skype_shortcode_filter', 10, 2);
    $rand = wpcf_unique_id(serialize($field));
    $form['skypename'] = array('#type' => 'textfield', '#value' => isset($field['value']['skypename']) ? $field['value']['skypename'] : '', '#name' => 'wpcf[' . $field['slug'] . '][skypename]', '#id' => 'wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '-skypename', '#inline' => true, '#suffix' => '&nbsp;' . __('Skype name', 'wpcf'), '#description' => '', '#prefix' => !empty($field['description']) ? wpcf_translate('field ' . $field['id'] . ' description', $field['description']) . '<br /><br />' : '', '#attributes' => array('style' => 'width:60%;'), '#_validate_this' => true, '#before' => '<div class="wpcf-skype">');
    $form['style'] = array('#type' => 'hidden', '#value' => isset($field['value']['style']) ? $field['value']['style'] : 'btn2', '#name' => 'wpcf[' . $field['slug'] . '][style]', '#id' => 'wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '-style');
    $preview_skypename = !empty($field['value']['skypename']) ? $field['value']['skypename'] : '--not--';
    $preview_style = !empty($field['value']['style']) ? $field['value']['style'] : 'btn2';
    $preview = wpcf_fields_skype_get_button_image($preview_skypename, $preview_style);
    // Set button
    // TODO WPML move
    if (isset($field['disable']) || wpcf_wpml_field_is_copied($field)) {
        $edit_button = '';
    } else {
        $edit_button = '' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=insert_skype_button&amp;_wpnonce=' . wp_create_nonce('insert_skype_button') . '&amp;update=wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '&amp;skypename=' . $preview_skypename . '&amp;button_style=' . $preview_style . '&amp;keepThis=true&amp;TB_iframe=true&amp;width=500&amp;height=500') . '"' . ' class="thickbox wpcf-fields-skype button-secondary"' . ' title="' . __('Edit Skype button', 'wpcf') . '"' . '>' . __('Edit Skype button', 'wpcf') . '</a>';
    }
    $form['markup'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-item">' . '<div id="wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '-preview">' . $preview . '</div>' . $edit_button . '</div>');
    $form['markup-close'] = array('#type' => 'markup', '#markup' => '</div>');
    return $form;
}
コード例 #2
0
ファイル: checkboxes.php プロジェクト: dewavi/occupysandy.net
/**
 * Form data for post edit page.
 * 
 * @param type $field 
 */
function wpcf_fields_checkboxes_meta_box_form($field, $data)
{
    $options = array();
    if (!empty($field['data']['options'])) {
        global $pagenow;
        foreach ($field['data']['options'] as $option_key => $option) {
            // Set value
            $options[$option_key] = array('#value' => $option['set_value'], '#title' => wpcf_translate('field ' . $field['id'] . ' option ' . $option_key . ' title', $option['title']), '#default_value' => !empty($data['#value'][$option_key]) || $pagenow == 'post-new.php' && !empty($option['checked']) ? 1 : 0, '#name' => 'wpcf[' . $field['id'] . '][' . $option_key . ']', '#id' => $option_key . '_' . wpcf_unique_id(serialize($field) . serialize($data)));
        }
    }
    return array('#type' => 'checkboxes', '#options' => $options);
}
コード例 #3
0
ファイル: select.php プロジェクト: phuocdungit/fundy
function wpcf_fields_select_get_option($parent_name = '', $form_data = array())
{
    $id = isset($form_data['key']) ? $form_data['key'] : 'wpcf-fields-select-option-' . wpcf_unique_id(serialize($form_data));
    $form = array();
    $value = isset($_GET['count']) ? __('Option title', 'wpcf') . ' ' . intval($_GET['count']) : __('Option title', 'wpcf') . ' 1';
    $value = isset($form_data['title']) ? $form_data['title'] : $value;
    $form[$id . '-title'] = array('#type' => 'textfield', '#id' => $id . '-title', '#name' => $parent_name . '[options][' . $id . '][title]', '#value' => $value, '#inline' => true, '#attributes' => array('placeholder' => __('Title', 'wpcf')), '#before' => sprintf('<span class="js-types-sortable hndle"><i title="%s" class="js-types-sort-button fa fa-arrows-v"></i></span>', esc_attr__('Move this option', 'wpcf')), '#pattern' => '<tr><td class="num"><BEFORE></td><td><ELEMENT><AFTER></td>');
    $value = isset($_GET['count']) ? intval($_GET['count']) : 1;
    $value = isset($form_data['value']) ? $form_data['value'] : $value;
    $form[$id . '-value'] = array('#type' => 'textfield', '#id' => $id . '-value', '#name' => $parent_name . '[options][' . $id . '][value]', '#value' => $value, '#inline' => true, '#attributes' => array('class' => 'wpcf-compare-unique-value', 'placeholder' => __('Value', 'wpcf')), '#pattern' => '<td><BEFORE><ELEMENT><AFTER></td>');
    $form[$id . '-default'] = array('#type' => 'radio', '#id' => $id . '-default', '#inline' => true, '#title' => __('Default', 'wpcf'), '#after' => '</div>', '#name' => $parent_name . '[options][default]', '#value' => $id, '#default_value' => isset($form_data['default']) ? $form_data['default'] : false, '#pattern' => '<td class="num"><BEFORE><ELEMENT></td><td class="num"><AFTER></td></tr>', '#after' => sprintf('<span><a href="#" class="js-wpcf-button-delete" data-message-delete-confirm="%s" data-id="%s"><i title="%s" class="fa fa-trash"></i></span>', esc_attr__('Are you sure?', 'wpcf'), esc_attr(sprintf('%s-title-display-value-wrapper', $id)), esc_attr__('Delete this option', 'wpcf')));
    return $form;
}
コード例 #4
0
ファイル: select.php プロジェクト: olechka1505/hungrylemur
function wpcf_fields_select_get_option($parent_name = '', $form_data = array())
{
    $id = isset($form_data['key']) ? $form_data['key'] : 'wpcf-fields-select-option-' . wpcf_unique_id(serialize($form_data));
    $form = array();
    $value = isset($_GET['count']) ? __('Option title', 'wpcf') . ' ' . intval($_GET['count']) : __('Option title', 'wpcf') . ' 1';
    $value = isset($form_data['title']) ? $form_data['title'] : $value;
    $form[$id . '-title'] = array('#type' => 'textfield', '#id' => $id . '-title', '#name' => $parent_name . '[options][' . $id . '][title]', '#value' => $value, '#inline' => true, '#attributes' => array('style' => 'width:80px;', 'placeholder' => __('Title', 'wpcf')), '#before' => '<div class="js-types-sortable"><img src="' . WPCF_RES_RELPATH . '/images/move.png" class="js-types-sort-button" alt="' . __('Move this option', 'wpcf') . '" /><img src="' . WPCF_RES_RELPATH . '/images/delete.png"' . ' class="wpcf-fields-select-delete-option wpcf-pointer"' . ' onclick="if (confirm(\'' . __('Are you sure?', 'wpcf') . '\')) { jQuery(this).parent().fadeOut(function(){jQuery(this).remove();}); }"' . 'alt="' . __('Delete this option', 'wpcf') . '" />');
    $value = isset($_GET['count']) ? intval($_GET['count']) : 1;
    $value = isset($form_data['value']) ? $form_data['value'] : $value;
    $form[$id . '-value'] = array('#type' => 'textfield', '#id' => $id . '-value', '#name' => $parent_name . '[options][' . $id . '][value]', '#value' => $value, '#inline' => true, '#attributes' => array('style' => 'width:80px;', 'class' => 'wpcf-compare-unique-value', 'placeholder' => __('Value', 'wpcf')));
    $form[$id . '-default'] = array('#type' => 'radio', '#id' => $id . '-default', '#inline' => true, '#title' => __('Default', 'wpcf'), '#after' => '</div>', '#name' => $parent_name . '[options][default]', '#value' => $id, '#default_value' => isset($form_data['default']) ? $form_data['default'] : false);
    return $form;
}
コード例 #5
0
ファイル: radio.php プロジェクト: dewavi/occupysandy.net
/**
 * Returns form data for radio.
 * 
 * @param type $parent_name Used for AJAX adding options
 * @param type $form_data
 * @return type 
 */
function wpcf_fields_radio_get_option($parent_name = '', $form_data = array())
{
    $id = isset($form_data['key']) ? $form_data['key'] : 'wpcf-fields-radio-option-' . wpcf_unique_id(serialize($form_data));
    $form = array();
    $value = isset($_GET['count']) ? __('Option title', 'wpcf') . ' ' . $_GET['count'] : __('Option title', 'wpcf') . ' 1';
    $value = isset($form_data['title']) ? $form_data['title'] : $value;
    $form[$id . '-id'] = $id;
    $form[$id . '-title'] = array('#type' => 'textfield', '#id' => $id . '-title', '#name' => $parent_name . '[options][' . $id . '][title]', '#value' => $value, '#inline' => true, '#attributes' => array('style' => 'width:80px;', 'class' => 'wpcf-form-groups-radio-update-title-display-value'), '#before' => '<div class="wpcf-fields-radio-draggable"><img src="' . WPCF_RES_RELPATH . '/images/move.png" class="wpcf-fields-form-radio-move-field" alt="' . __('Move this option', 'wpcf') . '" /><img src="' . WPCF_RES_RELPATH . '/images/delete.png"' . ' class="wpcf-fields-radio-delete-option wpcf-pointer"' . ' onclick="if (confirm(\'' . __('Are you sure?', 'wpcf') . '\')) { jQuery(this).parent().fadeOut(function(){jQuery(this).remove(); ' . '}); ' . 'jQuery(\'#\'+jQuery(this).parent().find(\'input\').attr(\'id\')+\'' . '-display-value-wrapper\').fadeOut(function(){jQuery(this).remove();}); }"' . 'alt="' . __('Delete this option', 'wpcf') . '" />');
    $value = isset($_GET['count']) ? $_GET['count'] : 1;
    $value = isset($form_data['value']) ? $form_data['value'] : $value;
    $form[$id . '-value'] = array('#type' => 'textfield', '#id' => $id . '-value', '#name' => $parent_name . '[options][' . $id . '][value]', '#value' => $value, '#inline' => true, '#attributes' => array('style' => 'width:80px;', 'class' => 'wpcf-compare-unique-value'));
    $form[$id . '-default'] = array('#type' => 'radio', '#id' => $id . '-default', '#inline' => true, '#title' => __('Default', 'wpcf'), '#after' => '</div>', '#name' => $parent_name . '[options][default]', '#value' => $id, '#default_value' => isset($form_data['default']) ? $form_data['default'] : '');
    return $form;
}
コード例 #6
0
ファイル: file.php プロジェクト: olechka1505/hungrylemur
/**
 * Form data for post edit page.
 *
 * @global object $wpdb
 *
 * @param type $field
 */
function wpcf_fields_file_meta_box_form($field)
{
    add_thickbox();
    $button_text = sprintf(__('Select %s', 'wpcf'), $field['type']);
    // Set ID
    $element_id = 'wpcf-fields-' . wpcf_unique_id(serialize(func_get_args()));
    $attachment_id = false;
    // Get attachment by guid
    global $wpdb;
    if (!empty($field['value'])) {
        $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND guid=%s", $field['value']));
    }
    // Set preview
    $preview = '';
    // TODO WPML move
    if (!wpcf_wpml_field_is_copied($field)) {
        if (!empty($attachment_id)) {
            $preview = wp_get_attachment_image($attachment_id, 'thumbnail');
        } else {
            // If external image set preview
            $file_path = parse_url($field['value']);
            if ($file_path && isset($file_path['path'])) {
                $file = pathinfo($file_path['path']);
            } else {
                $file = pathinfo($field['value']);
            }
            if (isset($file['extension']) && in_array(strtolower($file['extension']), array('jpg', 'jpeg', 'gif', 'png'))) {
                $preview = '<img alt="" src="' . $field['value'] . '" />';
            }
        }
    }
    // Set button
    // TODO WPML move
    if (!wpcf_wpml_field_is_copied($field)) {
        if (!empty($field['#attributes']['readonly']) || !empty($field['#attributes']['disabled'])) {
            $button = '';
        } else {
            $button = '<a href="javascript:void(0);"' . ' class="wpcf-fields-' . ($field['type'] == 'image' ? 'image' : 'file') . '-upload-link button-secondary"' . ' id="' . $element_id . '-upload" ' . "data-types='{\"type\":\"{$field['type']}\",\"id\":\"{$field['id']}\"}'>" . $button_text . '</a>';
        }
    } else {
        $button = '';
    }
    // Set form
    $form = array('#type' => 'textfield', '#id' => $element_id . '-upload-holder', '#name' => 'wpcf[' . $field['slug'] . ']', '#suffix' => '&nbsp;' . $button, '#after' => '<div id="' . $element_id . '-upload-holder-preview"' . ' class="wpcf-fields-file-preview">' . $preview . '</div>', '#attributes' => array('class' => 'wpcf-fields-file-textfield'));
    return $form;
}
コード例 #7
0
 /**
  * Set current post and field.
  * 
  * @param type $post
  * @param type $cf 
  */
 function set($user_id, $cf)
 {
     global $wpcf;
     /*
      * 
      * Check if $cf is string
      */
     if (is_string($cf)) {
         WPCF_Loader::loadInclude('fields');
         $cf = wpcf_admin_fields_get_field($this->__get_slug_no_prefix($cf));
         if (empty($cf)) {
             $this->_reset();
             return false;
         }
     }
     $this->currentUID = $user_id;
     $this->ID = $cf['id'];
     $this->cf = $cf;
     $this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug'];
     $this->meta = $this->_get_meta();
     $this->config = $this->_get_config();
     $this->unique_id = wpcf_unique_id(serialize((array) $this));
     $this->cf['value'] = $this->meta;
     // Debug
     $wpcf->debug->fieds[$this->unique_id] = $this->cf;
     $wpcf->debug->meta[$this->slug][] = $this->meta;
     // Load files
     if (isset($this->cf['type'])) {
         $file = WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php';
         if (file_exists($file)) {
             include_once $file;
         }
         if (defined('WPCF_INC_ABSPATH')) {
             $file = WPCF_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php';
             if (file_exists($file)) {
                 include_once $file;
             }
         }
     }
 }
コード例 #8
0
/**
 * 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;" />&nbsp;<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&amp;wpcf_action=fields_insert' . '&amp;field=' . basename($filename, '.php') . '&amp;page=wpcf-edit-usermeta') . '&amp;_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' . '&amp;page=wpcf-edit' . '&amp;wpcf_action=usermeta_insert_existing' . '&amp;field=' . $field['id']) . '&amp;_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' . '&amp;wpcf_action=remove_from_history2' . '&amp;field_id=' . $field['id']) . '&amp;_wpnonce=' . wp_create_nonce('remove_from_history2') . '&amp;wpcf_warning=' . sprintf(__('Are you sure that you want to remove field %s from history?', 'wpcf'), htmlspecialchars(stripslashes($field['name']))) . '&amp;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;
}
コード例 #9
0
function wpcf_admin_render_fields($group, $user_id, $echo = '')
{
    global $wpcf;
    $output = '<div class="wpcf-group-area wpcf-group-area_' . $group['slug'] . '">' . "\n\n";
    $output .= '<h3>' . wpcf_translate('group ' . $group['id'] . ' name', $group['name']) . '</h3>' . "\n\n";
    if (!empty($group['fields'])) {
        // Display description
        if (!empty($group['description'])) {
            $output .= '<span>' . wpautop(wpcf_translate('group ' . $group['id'] . ' description', $group['description'])) . '</span>' . "\n\n";
        }
        $output .= '<div class="wpcf-profile-field-line">' . "\n\n";
        foreach ($group['fields'] as $field_slug => $field) {
            if (empty($field) || !is_array($field)) {
                continue;
            }
            $field = $wpcf->usermeta_field->_parse_cf_form_element($field);
            if (!isset($field['#id'])) {
                $field['#id'] = wpcf_unique_id(serialize($field));
            }
            if (isset($field['wpcf-type'])) {
                // May be ignored
                $field = apply_filters('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form_value_display', $field);
            }
            // Render form elements
            if (wpcf_compare_wp_version() && $field['#type'] == 'wysiwyg') {
                $field['#editor_settings']['media_buttons'] = '';
                if (!empty($echo)) {
                    $field['#editor_settings']['wpautop'] = true;
                }
                // Especially for WYSIWYG
                $output .= "\n" . '<div class="wpcf-profile-field-line">' . "\n\n";
                $output .= '<div class="wpcf-wysiwyg">' . "\n\n";
                $output .= '<div id="wpcf-textarea-textarea-wrapper" class="form-item form-item-textarea wpcf-form-item wpcf-form-item-textarea">' . "\n\n";
                $output .= isset($field['#before']) ? $field['#before'] : '';
                $output .= '<label class="wpcf-form-label wpcf-form-textarea-label">' . $field['#title'] . '</label>' . "\n\n";
                $output .= '<div class="description wpcf-form-description wpcf-form-description-textarea description-textarea">' . "\n\n" . wpautop($field['#description']) . '</div>' . "\n\n";
                ob_start();
                wp_editor($field['#value'], $field['#id'], $field['#editor_settings']);
                $output .= ob_get_clean() . "\n\n";
                $field['slug'] = str_replace(WPCF_META_PREFIX . 'wysiwyg-', '', $field_slug);
                $field['type'] = 'wysiwyg';
                $output .= '</div>' . "\n\n";
                $output .= isset($field['#after']) ? $field['#after'] : '';
                $output .= '</div>' . "\n\n";
                $output .= '</div>' . "\n\n";
            } else {
                if ($field['#type'] == 'wysiwyg') {
                    $field['#type'] = 'textarea';
                }
                $field['#pattern'] = "\n" . '<div class="wpcf-profile-field-line">
	<div class="wpcf-profile-line-left">
		<LABEL><DESCRIPTION>
	</div>
	<div class="wpcf-profile-line-right"><BEFORE><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER></div>
</div>' . "\n\n";
                if (isset($field['#name']) && (strpos($field['#name'], '[hour]') !== false || strpos($field['#name'], '[minute]') !== false)) {
                    if (isset($field['#attributes']) && $field['#attributes']['class'] == 'wpcf-repetitive') {
                        $field['#pattern'] = strpos($field['#name'], '[hour]') !== false ? __('Hour', 'wpcf') : __('Minute', 'wpcf');
                        $field['#pattern'] .= '<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER>' . "\n\n";
                    } else {
                        if (strpos($field['#name'], '[hour]') !== false) {
                            $field['#pattern'] = "\n" . '<div class="wpcf-profile-field-line">
	<div class="wpcf-profile-line-left">&nbsp;&nbsp;&nbsp;&nbsp;' . __('Time', 'wpcf') . '</div>
	<div class="wpcf-profile-line-right">
	<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER>' . "\n";
                        } else {
                            $field['#pattern'] = "\n" . '
	<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER></div>
</div>' . "\n\n";
                        }
                    }
                }
                if (!empty($echo)) {
                    $field['#validate'] = '';
                }
                $output .= wpcf_form_simple(array($field['#id'] => $field));
            }
        }
        $output .= '</div>';
    }
    /*
     * TODO Move to Conditional code
     *
     * This is already checked. Use hook to add wrapper DIVS and apply CSS.
     */
    if (!empty($group['_conditional_display'])) {
        $output .= '</div>';
    }
    $output .= "\n\n" . '</div>';
    if (!empty($echo)) {
        return $output;
    } else {
        echo $output;
    }
}
コード例 #10
0
ファイル: checkboxes.php プロジェクト: CrankMaster336/FFW-TR
/**
 * This marks child posts checkboxes.
 * 
 * Because if all unchecked, on submit there won't be any data.
 * 
 * @param string $form
 * @param type $cf
 * @return string
 */
function wpcf_filds_checkboxes_relationship_form_filter($form, $cf)
{
    if ($cf->cf['type'] == 'checkboxes') {
        $form[wpcf_unique_id(serialize($cf) . 'rel_child')] = array('#type' => 'hidden', '#name' => '_wpcf_check_checkboxes[' . $cf->post->ID . '][' . $cf->slug . ']', '#value' => '1');
    }
    return $form;
}
コード例 #11
0
ファイル: field.php プロジェクト: olechka1505/hungrylemur
 /**
  * Set current post and field.
  *
  * @param type $post
  * @param type $cf
  */
 function set($post, $cf)
 {
     global $wpcf;
     /*
      *
      * Check if $cf is string
      */
     if (is_string($cf)) {
         WPCF_Loader::loadInclude('fields');
         $_cf = wpcf_admin_fields_get_field($this->__get_slug_no_prefix($cf));
         // Check if found without prefix
         if (empty($_cf)) {
             $_cf = wpcf_admin_fields_get_field($cf);
         }
         if (empty($_cf)) {
             /*
              * TODO Check what happens if field is not found
              */
             $this->_reset();
             return false;
         }
         $cf = $_cf;
     }
     $this->post = is_integer($post) ? get_post($post) : $post;
     // If empty post it is new
     if (empty($this->post->ID)) {
         $this->post = new stdClass();
         $this->post->ID = 0;
     }
     $this->ID = $cf['id'];
     $this->cf = $cf;
     $this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug'];
     $this->meta = $this->_get_meta();
     $this->config = $this->_get_config();
     $this->unique_id = wpcf_unique_id(serialize((array) $this));
     $this->cf['value'] = $this->meta;
     // Debug
     $wpcf->debug->fields[$this->unique_id] = $this->cf;
     $wpcf->debug->meta[$this->slug][] = $this->meta;
     // Load files
     $this->_include_file_by_field_type($this->cf['type']);
     if (defined('WPCF_INC_ABSPATH')) {
         $file = WPCF_INC_ABSPATH . '/fields/' . preg_replace('/[^\\w]+/', '', $this->cf['type']) . '.php';
         if (file_exists($file)) {
             include_once $file;
         }
     }
 }
コード例 #12
0
<?php

/*
 * Child table taxonomy non-hierarchical form.
 */
$defaults = array('taxonomy' => 'category');
extract(wp_parse_args($data, $defaults), EXTR_SKIP);
$tax = get_taxonomy($taxonomy);
$html_id = "wpcf-reltax-{$taxonomy}-" . wpcf_unique_id($taxonomy);
?>

	<div id="<?php 
echo $html_id;
?>
" class="js-types-child-categorydiv types-child-categorydiv" data-types-reltax="<?php 
echo $taxonomy;
?>
">
		<!--<ul id="<?php 
echo $html_id;
?>
-tabs" class="category-tabs">
			<li class="tabs"><a href="#<?php 
echo $taxonomy;
?>
-all"><?php 
echo $tax->labels->all_items;
?>
</a></li>
			<li class="hide-if-no-js"><a href="#<?php 
echo $taxonomy;
コード例 #13
0
    /**
     * deprecated
     */
    private function add_admin_style($form)
    {
        $admin_styles_value = $preview_profile = $edit_profile = '';
        if (isset($this->update['admin_styles'])) {
            $admin_styles_value = $this->update['admin_styles'];
        }
        $temp = '';
        if ($this->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, $this->update, 1);
            $group = $this->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', 'wpcf') . '</h3>
                <div id="wpcf-update-preview-div">Preview here</div>
                <script type="text/javascript">
var wpcfReadOnly = ' . json_encode(base64_encode($preview_profile)) . ';
var wpcfEditMode = ' . json_encode(base64_encode($edit_profile)) . ';
var wpcfDefaultCss = ' . json_encode(base64_encode($admin_styles_value)) . ';
        </script>
        ', '#before' => sprintf('<h3>%s</h3>', __('Your CSS', 'wpcf')));
        $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 />');
        return $form;
    }
コード例 #14
0
ファイル: form-child.php プロジェクト: phuocdungit/fundy
 /**
  * Pagination
  */
 function pagination()
 {
     global $wpcf;
     // Pagination
     $total_items = count($this->children);
     $per_page = $wpcf->relationship->get_items_per_page($this->parent_post_type, $this->child_post_type);
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     $offset = $page == 1 ? 0 : ($page - 1) * $per_page;
     $next = $total_items > $offset + $per_page;
     $prev = $page == 1 ? false : true;
     if ($total_items > $per_page) {
         $this->children = array_splice($this->children, $offset, $per_page);
     }
     $this->pagination_top = wpcf_pr_admin_has_pagination($this->parent, $this->child_post_type, $page, $prev, $next, $per_page, $total_items);
     /*
      *
      *
      * Add pagination bottom
      */
     $options = array(__('All', 'wpcf') => 'all', 5 => 5, 10 => 10, 15 => 15);
     // Add sorting
     $add_data = isset($_GET['sort']) && isset($_GET['field']) ? '&sort=' . sanitize_text_field($_GET['sort']) . '&field=' . sanitize_text_field($_GET['field']) : '';
     if (isset($_GET['post_type_sort_parent'])) {
         $add_data .= '&post_type_sort_parent=' . sanitize_text_field($_GET['post_type_sort_parent']);
     }
     $this->pagination_bottom = wpcf_form_simple(array('pagination' => array('#type' => 'select', '#before' => __('Show', 'wpcf'), '#after' => $this->child_post_type_object->labels->name, '#id' => 'wpcf_relationship_num_' . wpcf_unique_id(serialize($this->children)), '#name' => $wpcf->relationship->items_per_page_option_name, '#options' => $options, '#default_value' => $per_page, '#attributes' => array('class' => 'wpcf-relationship-items-per-page', 'data-action' => 'action=wpcf_ajax&wpcf_action=pr_pagination' . '&post_id=' . $this->parent->ID . '&post_type=' . $this->child_post_type . '&_wpnonce=' . wp_create_nonce('pr_pagination') . $add_data))));
 }
コード例 #15
0
/**
 * Group coditional display filter.
 *
 * @param type $filters
 * @param type $update
 * @return type
 */
function wpcf_cd_fields_form_additional_filters($filters, $update)
{
    $data = array();
    $data['id'] = !empty($update) && isset($update['name']) ? $update['name'] : wpcf_unique_id(serialize($filters));
    $data['group_id'] = $update['id'];
    if ($update) {
        $data['data']['conditional_display'] = maybe_unserialize(get_post_meta($update['id'], '_wpcf_conditional_display', true));
    } else {
        $data['data']['conditional_display'] = array();
    }
    $data['meta_type'] = isset($update['meta_type']) ? $update['meta_type'] : 'unknown';
    $filters = $filters + wpcf_cd_admin_form_filter(array(), $data, true);
    return $filters;
}
コード例 #16
0
ファイル: checkboxes.php プロジェクト: adisonc/MaineLearning
/**
 * Returns form data for radio.
 * 
 * @param type $parent_name Used for AJAX adding options
 * @param type $form_data
 * @return type 
 */
function wpcf_fields_checkboxes_get_option($parent_name = '', $form_data = array())
{
    $id = isset($form_data['key']) ? $form_data['key'] : 'wpcf-fields-checkboxes-option-' . wpcf_unique_id(serialize($form_data) . $parent_name);
    $form = array();
    $count = isset($_GET['count']) ? $_GET['count'] : 1;
    $title = isset($_GET['count']) ? __('Checkbox title', 'wpcf') . ' ' . $_GET['count'] : __('Checkbox title', 'wpcf') . ' 1';
    $title = isset($form_data['title']) ? $form_data['title'] : $title;
    $form[$id . '-id'] = $id;
    $form[$id . '-drag'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-fields-checkboxes-draggable"><div class="wpcf-checkboxes-drag"><img src="' . WPCF_RES_RELPATH . '/images/move.png" class="wpcf-fields-form-checkboxes-move-field" alt="' . __('Move this option', 'wpcf') . '" /><img src="' . WPCF_RES_RELPATH . '/images/delete.png"' . ' class="wpcf-fields-checkboxes-delete-option wpcf-pointer"' . ' onclick="if (confirm(\'' . __('Are you sure?', 'wpcf') . '\')) { jQuery(this).parent().fadeOut().next().fadeOut(function(){jQuery(this).remove(); ' . '}); }"' . 'alt="' . __('Delete this checkbox', 'wpcf') . '" /></div>');
    $form[$id] = array('#type' => 'fieldset', '#title' => $title, '#collapsed' => isset($form_data['key']) ? true : false, '#collapsible' => true);
    $form[$id]['title'] = array('#type' => 'textfield', '#title' => __('Title', 'wpcf'), '#id' => $id . '-title', '#name' => $parent_name . '[options][' . $id . '][title]', '#value' => $title, '#inline' => true, '#attributes' => array('class' => 'wpcf-form-groups-check-update-title-display-value'), '#before' => '<br />');
    $form[$id]['value'] = array('#type' => 'textfield', '#title' => __('Value to store', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][set_value]', '#value' => isset($form_data['set_value']) ? $form_data['set_value'] : 1);
    $form[$id]['checked'] = array('#id' => 'checkboxes-' . wpcf_unique_id(serialize($form_data) . $parent_name), '#type' => 'checkbox', '#title' => __('Set checked by default (on new post)?', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][checked]', '#default_value' => !empty($form_data['checked']) ? 1 : 0);
    $form[$id]['display'] = array('#type' => 'radios', '#default_value' => !empty($form_data['display']) ? $form_data['display'] : 'db', '#name' => $parent_name . '[options][' . $id . '][display]', '#options' => array('display_from_db' => array('#title' => __('Display the value of this field from the database', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display]', '#value' => 'db', '#inline' => true, '#after' => '<br />'), 'display_values' => array('#title' => __('Show one of these two values:', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display]', '#value' => 'value')), '#inline' => true);
    $form[$id]['display-value'] = array('#type' => 'textfield', '#title' => __('Not selected:', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display_value_not_selected]', '#value' => isset($form_data['display_value_not_selected']) ? $form_data['display_value_not_selected'] : '', '#inline' => true);
    $form[$id]['display-value-2'] = array('#type' => 'textfield', '#title' => __('Selected:', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display_value_selected]', '#value' => isset($form_data['display_value_selected']) ? $form_data['display_value_selected'] : '');
    $form[$id . 'drag-close'] = array('#type' => 'markup', '#markup' => '</div>');
    return $form;
}
コード例 #17
0
ファイル: checkboxes.php プロジェクト: lytranuit/wordpress
/**
 * Returns form data for radio.
 * 
 * @param type $parent_name Used for AJAX adding options
 * @param type $form_data
 * @return type 
 */
function wpcf_fields_checkboxes_get_option($parent_name = '', $form_data = array(), $field = array())
{
    $id = isset($form_data['key']) ? $form_data['key'] : 'wpcf-fields-checkboxes-option-' . wpcf_unique_id(serialize($form_data) . $parent_name);
    $form = array();
    $count = isset($_GET['count']) ? intval($_GET['count']) : 1;
    $title = isset($_GET['count']) ? __('Checkbox title', 'wpcf') . ' ' . intval($_GET['count']) : __('Checkbox title', 'wpcf') . ' 1';
    $title = isset($form_data['title']) ? $form_data['title'] : $title;
    $form[$id . '-id'] = $id;
    $form[$id . '-drag'] = array('#type' => 'markup', '#markup' => '<div class="js-types-sortable wpcf-fields-checkboxes-draggable"><div class="wpcf-checkboxes-drag"><img src="' . WPCF_RES_RELPATH . '/images/move.png" class="js-types-sort-button wpcf-fields-form-checkboxes-move-field" alt="' . __('Move this option', 'wpcf') . '" /><img src="' . WPCF_RES_RELPATH . '/images/delete.png"' . ' class="wpcf-fields-checkboxes-delete-option wpcf-pointer"' . ' onclick="if (confirm(\'' . __('Are you sure?', 'wpcf') . '\')) { jQuery(this).parent().fadeOut().next().fadeOut(function(){jQuery(this).remove(); ' . '}); }"' . 'alt="' . __('Delete this checkbox', 'wpcf') . '" /></div>', '#pattern' => '<ELEMENT>');
    $form[$id] = array('#type' => 'fieldset', '#title' => $title, '#collapsed' => isset($form_data['key']) ? true : false, '#collapsible' => true, '#pattern' => '<ELEMENT><dl>');
    $form[$id]['title'] = array('#type' => 'textfield', '#title' => __('Title', 'wpcf'), '#id' => $id . '-title', '#name' => $parent_name . '[options][' . $id . '][title]', '#value' => $title, '#inline' => true, '#attributes' => array('class' => 'wpcf-form-groups-check-update-title-display-value'), '#pattern' => '<dt><LABEL></dt><dd><ERROR><BEFORE><ELEMENT><AFTER></dd>');
    $form[$id]['value'] = array('#type' => 'textfield', '#title' => __('Value to store', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][set_value]', '#value' => isset($form_data['set_value']) ? $form_data['set_value'] : 1, '#attributes' => array('data-wpcf-type' => 'checkbox', 'data-required-message-0' => __("This value can't be zero", 'wpcf'), 'data-required-message' => __("Please enter a value", 'wpcf')), '#pattern' => '<dt><LABEL></dt><dd><ERROR><BEFORE><ELEMENT><AFTER></dd>');
    if (isset($_GET['page']) && $_GET['page'] == 'wpcf-edit') {
        $form[$id]['checked'] = array('#id' => 'checkboxes-' . wpcf_unique_id(serialize($form_data) . $parent_name), '#type' => 'checkbox', '#title' => __('Set checked by default (on new post)?', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][checked]', '#default_value' => !empty($form_data['checked']) ? 1 : 0, '#inline' => true, '#pattern' => '</dl><p><ELEMENT><LABEL></p>');
    }
    $form[$id]['display'] = array('#type' => 'radios', '#default_value' => !empty($form_data['display']) ? $form_data['display'] : 'db', '#name' => $parent_name . '[options][' . $id . '][display]', '#options' => array('display_from_db' => array('#title' => __('Display the value of this field from the database', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display]', '#value' => 'db', '#inline' => true, '#before' => '<li>', '#after' => '</li>'), 'display_values' => array('#title' => __('Show one of these two values:', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display]', '#value' => 'value', '#inline' => true, '#before' => '<li>', '#after' => '</li>')), '#inline' => true, '#pattern' => '<LABEL><ul><ELEMENT></ul><dl>');
    $form[$id]['display-value'] = array('#type' => 'textfield', '#title' => __('Not selected:', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display_value_not_selected]', '#value' => isset($form_data['display_value_not_selected']) ? $form_data['display_value_not_selected'] : '', '#inline' => true, '#attributes' => array('placeholder' => __('Enter not selected value', 'wpcf')), '#pattern' => '<dt><LABEL></dt><dd><ERROR><BEFORE><ELEMENT><AFTER></dd>');
    $form[$id]['display-value-2'] = array('#type' => 'textfield', '#title' => __('Selected:', 'wpcf'), '#name' => $parent_name . '[options][' . $id . '][display_value_selected]', '#value' => isset($form_data['display_value_selected']) ? $form_data['display_value_selected'] : '', '#attributes' => array('placeholder' => __('Enter selected value', 'wpcf')), '#pattern' => '<dt><LABEL></dt><dd><ERROR><BEFORE><ELEMENT><AFTER></dd>');
    $form[$id . 'drag-close'] = array('#type' => 'markup', '#markup' => '</dl></div>', '#pattern' => '<ELEMENT>');
    return $form;
}
コード例 #18
0
/**
 *
 * Use this to show filter item
 *
 * @since Types 1.2
 * @global type $wpcf_button_style
 * @global type $wpcf_button_style30
 * @param type $id
 * @param type $txt
 * @param type $txt_empty
 * @param type $e
 * @return string
 */
function _wpcf_filter_wrap($id, $title, $txt, $txt_empty, $e, $edit_button = '')
{
    global $wpcf_button_style;
    global $wpcf_button_style30;
    $form = array();
    $unique_id = wpcf_unique_id(serialize(func_get_args()));
    $query = 'jQuery(this), \'' . esc_html($id) . '\', \'' . esc_html($title) . '\', \'' . esc_html($txt) . '\', \'' . esc_html($txt_empty) . '\'';
    if (empty($edit_button)) {
        $edit = __('Edit', 'wpcf');
    } else {
        $edit = $edit_button;
    }
    /*
     *
     * Title and Edit button
     */
    $form['filter_' . $unique_id . '_wrapper'] = array('#type' => 'markup', '#markup' => '<span class="wpcf-filter-ajax-response"' . ' style="font-style:italic;font-weight:bold;display:inline-block;">' . $title . ' ' . $txt . '</span>' . '&nbsp;&nbsp;<a href="javascript:void(0);" ' . $wpcf_button_style30 . ' ' . ' class="button-secondary wpcf-form-filter-edit" onclick="wpcfFilterEditClick(' . $query . ');">' . $edit . '</a><div class="hidden" id="wpcf-form-fields-' . $id . '">');
    /**
     * Form element as param
     * It may be single element or array of elements
     * Simply check if array has #type - indicates it is a form item
     */
    if (isset($e['#type'])) {
        $form['filter_' . $unique_id . '_items'] = $e;
    } else {
        /*
         * If array of elements just join
         */
        $form = $form + (array) $e;
    }
    /**
     * OK button
     */
    $form['filter_' . $unique_id . '_ok'] = array('#type' => 'markup', '#markup' => '<a href="javascript:void(0);" ' . $wpcf_button_style . ' ' . 'class="button-primary  wpcf-form-filter-ok wpcf-groups-form-ajax-update-' . $id . '-ok"' . ' onclick="wpcfFilterOkClick(' . $query . ');">' . __('OK', 'wpcf') . '</a>&nbsp;');
    /**
     * Cancel button
     */
    $form['filter_' . $unique_id . '_cancel'] = array('#type' => 'markup', '#markup' => '<a href="javascript:void(0);" ' . $wpcf_button_style . ' ' . 'class="button-secondary wpcf-form-filter-cancel wpcf-groups-form-ajax-update-' . $id . '-cancel"' . ' onclick="wpcfFilterCancelClick(' . $query . ');">' . __('Cancel', 'wpcf') . '</a>');
    /**
     * Close wrapper
     */
    $form['filter_' . $unique_id . 'wrapper_close'] = array('#type' => 'markup', '#markup' => '</div></div>');
    return $form;
}
コード例 #19
0
/**
 * Adds validation box.
 * 
 * @param type $name
 * @param string $field
 * @param type $form_data
 * @return type 
 */
function wpcf_admin_fields_form_validation($name, $field, $form_data = array())
{
    $form = array();
    if (isset($field['validate'])) {
        $form['validate-table-open'] = array('#type' => 'markup', '#markup' => '<table class="wpcf-fields-form-validate-table" ' . 'cellspacing="0" cellpadding="0"><thead><tr><td>' . __('Validation', 'wpcf') . '</td><td>' . __('Error message', 'wpcf') . '</td></tr></thead><tbody>');
        // Process methods
        foreach ($field['validate'] as $k => $method) {
            // Set additional method data
            if (is_array($method)) {
                $form_data['data']['validate'][$k]['method_data'] = $method;
                $method = $k;
            }
            if (!Wpcf_Validate::canValidate($method) || !Wpcf_Validate::hasForm($method)) {
                continue;
            }
            $form['validate-tr-' . $method] = array('#type' => 'markup', '#markup' => '<tr><td>');
            // Get method form data
            if (Wpcf_Validate::canValidate($method) && Wpcf_Validate::hasForm($method)) {
                $field['#name'] = $name . '[' . $method . ']';
                $form_validate = call_user_func_array(array('Wpcf_Validate', $method . '_form'), array($field, isset($form_data['data']['validate'][$method]) ? $form_data['data']['validate'][$method] : array()));
                // Set unique IDs
                foreach ($form_validate as $key => $element) {
                    if (isset($element['#type'])) {
                        $form_validate[$key]['#id'] = $element['#type'] . '-' . wpcf_unique_id(serialize($element));
                    }
                    if (isset($element['#name']) && strpos($element['#name'], '[message]') !== FALSE) {
                        $before = '</td><td>';
                        $after = '</td></tr>';
                        $form_validate[$key]['#before'] = isset($element['#before']) ? $element['#before'] . $before : $before;
                        $form_validate[$key]['#after'] = isset($element['#after']) ? $element['#after'] . $after : $after;
                    }
                }
                // Join
                $form = $form + $form_validate;
            }
        }
        $form['validate-table-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>');
    }
    return $form;
}
コード例 #20
0
 /**
  * Generate wrapper around form setup data.
  *
  * @param string $type
  * @param array $data
  * @param bool $render_closing_hr If true, render a hr tag at the end of the form section.
  *
  * @return array
  */
 protected function filter_wrap($type, $data = array(), $button_only = false, $render_closing_hr = true)
 {
     $data = wp_parse_args($data, array('nonce' => '', 'title' => '', 'value' => '', 'value_default' => ''));
     $form = array();
     $unique_id = wpcf_unique_id(serialize(func_get_args()));
     /**
      * form open
      */
     $form[$unique_id . '-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="%s" class="wpcf-filter-container js-wpcf-filter-container">', esc_attr($unique_id)));
     /**
      * header
      */
     if (!$button_only) {
         $form[$unique_id . '-header'] = array('#type' => 'markup', '#markup' => sprintf('<h3>%s</h3>', $data['title']));
     }
     /**
      * Description
      */
     if (!$button_only && isset($data['description'])) {
         $form[$unique_id . '-description'] = array('#type' => 'markup', '#markup' => wpautop($data['description']));
     }
     /**
      * content
      */
     if (!$button_only) {
         $form[$unique_id . '-content'] = array('#type' => 'markup', '#markup' => sprintf('<span class="js-wpcf-filter-ajax-response">%s</span>', empty($data['value']) ? $data['value_default'] : $data['value']), '#inline' => true);
     }
     /**
      * button
      */
     if ($this->current_user_can_edit) {
         $form[$unique_id . '-button'] = array('#type' => 'button', '#name' => esc_attr($unique_id . '-button'), '#value' => __('Edit', 'wpcf'), '#attributes' => array('class' => 'js-wpcf-filter-button-edit wpcf-filter-button-edit', 'data-wpcf-type' => esc_attr($type), 'data-wpcf-page' => esc_attr(wpcf_getget('page')), 'data-wpcf-nonce' => wp_create_nonce($type)), '#inline' => true, '#before' => '<div class="wpcf-filter-button-edit-container">', '#after' => '</div>');
         foreach ($data as $key => $value) {
             if (preg_match('/^data\\-wpcf\\-/', $key)) {
                 $form[$unique_id . '-button']['#attributes'][$key] = esc_attr($value);
             }
         }
     }
     /**
      * form close
      */
     $close_clear = $button_only || !$render_closing_hr ? '' : '<hr class="clear" />';
     $form[$unique_id . '-close'] = array('#type' => 'markup', '#markup' => $close_clear . '</div>');
     return $form;
 }
コード例 #21
0
ファイル: date.php プロジェクト: adisonc/MaineLearning
/**
 * From data for post edit page.
 * 
 * @param type $field 
 * @param type $data
 * @param type $field_object Field instance 
 */
function wpcf_fields_date_meta_box_form($field, $field_object = null)
{
    /*
     * 
     * @since Types 1.2
     * 
     * Added extra fields 'hour' and 'minute'.
     * 
     * If value is not array it is assumed that DB entry is timestamp()
     * and data is converted to array.
     */
    $value = $field['value'] = wpcf_fields_date_value_get_filter($field['value'], $field_object);
    // TODO WPML
    if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
        $attributes = array('style' => 'width:150px;');
    } else {
        $attributes = array('class' => 'wpcf-datepicker', 'style' => 'width:150px;');
    }
    /*
     * 
     * Do not forget to trigger datepicker script
     * 
     * Only trigger on AJAX call (inserting new)
     */
    $js_trigger = defined('DOING_AJAX') ? '<script type="text/javascript">wpcfFieldsDateInit(\'\');</script>' : '';
    /*
     * 
     * 
     * Set Form
     */
    $unique_id = wpcf_unique_id(serialize($field));
    $form = array();
    $form[$unique_id . '-datepicker'] = array('#type' => 'textfield', '#title' => '&nbsp;' . $field['name'], '#attributes' => $attributes, '#name' => 'wpcf[' . $field['slug'] . '][datepicker]', '#id' => 'wpcf-date-' . $field['slug'] . '-datepicker-' . $unique_id, '#value' => $value['datepicker'], '#inline' => true, '#after' => '' . $js_trigger, '#_validate_this' => true);
    /*
     * 
     * If set 'date_and_time' add time
     */
    if (!empty($field['data']['date_and_time']) && $field['data']['date_and_time'] == 'and_time') {
        $hours = 24;
        $minutes = 60;
        $options = array();
        // Hour
        for ($index = 0; $index < $hours; $index++) {
            $prefix = $index < 10 ? '0' : '';
            $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
        }
        $form[$unique_id . 'time_hour'] = array('#type' => 'select', '#title' => __('Hour', 'wpcf'), '#inline' => true, '#before' => '<br />', '#after' => '&nbsp;&nbsp;', '#options' => $options, '#default_value' => $value['hour'], '#name' => 'wpcf[' . $field['slug'] . '][hour]', '#id' => 'wpcf-date-' . $field['slug'] . '-select-hour-' . $unique_id, '#inline' => true);
        // Minutes
        for ($index = 1; $index < $minutes; $index++) {
            $prefix = $index < 10 ? '0' : '';
            $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
        }
        $form[$unique_id . 'time_minute'] = array('#type' => 'select', '#title' => __('Minute', 'wpcf'), '#after' => '<br /><br />', '#inline' => true, '#options' => $options, '#default_value' => $value['minute'], '#name' => 'wpcf[' . $field['slug'] . '][minute]', '#id' => 'wpcf-date-' . $field['slug'] . '-minute-' . $unique_id);
    }
    return $form;
}
コード例 #22
0
ファイル: repeater.php プロジェクト: KryvunRoman/yobko
 /**
  * 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;
 }
コード例 #23
0
ファイル: fields-post.php プロジェクト: SpencerNeitzke/types
/**
 * 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;
}
コード例 #24
0
ファイル: field.php プロジェクト: adisonc/MaineLearning
 /**
  * Set current post and field.
  * 
  * @param type $post
  * @param type $cf 
  */
 function set($post, $cf)
 {
     global $wpcf;
     /*
      * 
      * Check if $cf is string
      */
     if (is_string($cf)) {
         if (isset($this->fields[$this->__get_slug_no_prefix($cf)])) {
             $cf = $this->fields[$this->__get_slug_no_prefix($cf)];
         } else {
             /*
              * TODO Check what happens if field is not found
              */
             $this->_reset();
             return false;
         }
     }
     $this->post = is_integer($post) ? get_post($post) : $post;
     // If empty post it is new
     if (empty($this->post->ID)) {
         $this->post = new stdClass();
         $this->post->ID = 0;
     }
     $this->ID = $cf['id'];
     $this->cf = $cf;
     $this->slug = wpcf_types_get_meta_prefix($this->cf) . $this->cf['slug'];
     $this->meta = $this->_get_meta();
     $this->config = $this->_get_config();
     $this->unique_id = wpcf_unique_id(serialize((array) $this));
     $this->cf['value'] = $this->meta;
     // Debug
     $wpcf->debug->fieds[$this->unique_id] = $this->cf;
     $wpcf->debug->meta[$this->slug][] = $this->meta;
     // Load files
     $file = WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php';
     if (file_exists($file)) {
         include_once $file;
     }
     if (defined('WPCF_INC_ABSPATH')) {
         $file = WPCF_INC_ABSPATH . '/fields/' . $this->cf['type'] . '.php';
         if (file_exists($file)) {
             include_once $file;
         }
     }
 }
コード例 #25
0
/**
 * Has form table row.
 * 
 * @param type $post
 * @param type $post_type
 * @param type $data
 * @param type $parent_post_type
 * @param stdClass $item
 * @return string 
 */
function wpcf_pr_admin_post_meta_box_has_row($post, $post_type, $data, $parent_post_type, $item, $headers)
{
    if (empty($headers)) {
        return false;
    }
    $row_data = array_combine(array_keys($headers), array_fill(0, count($headers), ''));
    $new_item = false;
    $date_trigger = false;
    // Set item
    if (empty($item)) {
        $item = new stdClass();
        $item->ID = 'new_' . wpcf_unique_id(serialize($post));
        $item->post_title = '';
        $item->post_content = '';
        $item->post_type = $post_type;
        $new_item = true;
    }
    // Cleanup data
    if (empty($data['fields_setting'])) {
        $data['fields_setting'] = 'all_cf';
    }
    $item_parents = isset($data['fields']['_wpcf_pr_parents']) ? $data['fields']['_wpcf_pr_parents'] : array();
    unset($data['fields']['_wpcf_pr_parents']);
    $wpcf_fields = wpcf_admin_fields_get_fields();
    if ($data['fields_setting'] == 'specific' && !empty($data['fields'])) {
        foreach ($data['fields'] as $field_key => $true) {
            // Only add if exists in header
            if (!array_key_exists($field_key, $row_data)) {
                continue;
            }
            if ($field_key == '_wp_title') {
                $element = wpcf_form_simple(array('field' => array('#type' => 'textfield', '#id' => 'wpcf_post_relationship_' . $item->ID . '_wp_title', '#name' => 'wpcf_post_relationship[' . $item->ID . '][_wp_title]', '#value' => $item->post_title, '#inline' => true)));
            } else {
                if ($field_key == '_wp_body') {
                    $value = wp_trim_words($item->post_content, 10, null);
                    $element = wpcf_form_simple(array('field' => array('#type' => 'textarea', '#id' => 'wpcf_post_relationship_' . $item->ID . '_' . $field_key, '#name' => 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . ']', '#value' => $item->post_content, '#attributes' => array('style' => 'width:300px;height:100px;'), '#inline' => true)));
                } else {
                    $wpcf_key = str_replace(WPCF_META_PREFIX, '', $field_key);
                    if (strpos($field_key, WPCF_META_PREFIX) === 0 && isset($wpcf_fields[$wpcf_key])) {
                        // Date trigger
                        if ($wpcf_fields[$wpcf_key]['type'] == 'date') {
                            $date_trigger = true;
                        }
                        // Get WPCF form
                        $element = wpcf_admin_post_process_fields($item, array('field' => $wpcf_fields[$wpcf_key]), false, false, 'post_relationship');
                        $element = array_shift($element);
                        if (!in_array($wpcf_fields[$wpcf_key]['type'], array('image', 'file'))) {
                            $element['#id'] = 'wpcf_post_relationship_' . $item->ID . '_' . $wpcf_key;
                        }
                        $element['#name'] = 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . ']';
                        $element['#inline'] = true;
                        unset($element['#title'], $element['#description']);
                        if ($wpcf_fields[$wpcf_key]['type'] == 'skype') {
                            unset($element['#prefix']);
                        }
                        if (in_array($wpcf_fields[$wpcf_key]['type'], array('wysiwyg'))) {
                            $element['#type'] = 'textarea';
                            $element['#attributes'] = array('style' => 'width:300px;height:100px;');
                        }
                        if (in_array($wpcf_fields[$wpcf_key]['type'], array('checkbox', 'checkboxes'))) {
                            if ($wpcf_fields[$wpcf_key]['type'] == 'checkbox') {
                                $element['#suffix'] = '<input type="hidden" name="wpcf_post_relationship_checkbox[' . $item->ID . '][' . $wpcf_key . ']" value="1" />';
                            } else {
                                if ($wpcf_fields[$wpcf_key]['type'] == 'checkboxes' && !empty($element['#options'])) {
                                    foreach ($element['#options'] as $temp_key => $temp_value) {
                                        $element['#options'][$temp_key]['#name'] = 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . '][' . $temp_key . ']';
                                        $element['#options'][$temp_key]['#inline'] = true;
                                        $element['#options'][$temp_key]['#after'] = '<br />';
                                    }
                                    $element['#suffix'] = '<input type="hidden" name="wpcf_post_relationship_checkboxes[' . $item->ID . '][' . $field_key . ']" value="1" />';
                                }
                            }
                        }
                        $value = get_post_meta($item->ID, $field_key, true);
                        $element = wpcf_form_simple(array('field' => $element));
                    } else {
                        // Just render textfield
                        $value = get_post_meta($item->ID, $field_key, true);
                        $element = wpcf_form_simple(array('field' => array('#type' => 'textfield', '#id' => 'wpcf_post_relationship_' . $item->ID . '_' . $field_key, '#name' => 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . ']', '#value' => $value, '#inline' => true)));
                    }
                }
            }
            $row_data[$field_key] = $element;
        }
        // Get other parents
        foreach ($item_parents as $parent => $temp_data) {
            if ($parent == $parent_post_type) {
                continue;
            }
            $meta = get_post_meta($item->ID, '_wpcf_belongs_' . $parent . '_id', true);
            $meta = empty($meta) ? 0 : $meta;
            $belongs_data = array('belongs' => array($parent => $meta));
            $temp_form = wpcf_pr_admin_post_meta_box_belongs_form($item, $parent, $belongs_data);
            unset($temp_form[$parent]['#suffix'], $temp_form[$parent]['#prefix'], $temp_form[$parent]['#title']);
            $temp_form[$parent]['#name'] = 'wpcf_post_relationship[' . $item->ID . '][parents][' . $parent . ']';
            // Only add if exists in header
            if (array_key_exists('_wpcf_pr_parent_' . $parent, $row_data)) {
                $row_data['_wpcf_pr_parent_' . $parent] = wpcf_form_simple($temp_form);
            }
        }
    } else {
        $groups = wpcf_admin_post_get_post_groups_fields($item, 'post_relationships');
        if (array_key_exists('_wp_title', $row_data)) {
            $element = wpcf_form_simple(array('field' => array('#type' => 'textfield', '#id' => 'wpcf_post_relationship_' . $item->ID . '_wp_title', '#name' => 'wpcf_post_relationship[' . $item->ID . '][_wp_title]', '#value' => $item->post_title, '#inline' => true)));
            $row_data['_wp_title'] = $element;
        }
        if ($data['fields_setting'] == 'all_cf_standard' && array_key_exists('_wp_body', $row_data)) {
            $element = wpcf_form_simple(array('field' => array('#type' => 'textarea', '#id' => 'wpcf_post_relationship_' . $item->ID . '_wp_body', '#name' => 'wpcf_post_relationship[' . $item->ID . '][_wp_body]', '#value' => $item->post_content, '#attributes' => array('style' => 'width:300px;height:100px;'), '#inline' => true)));
            $row_data['_wp_body'] = $element;
        }
        foreach ($groups as $group) {
            foreach ($group['fields'] as $field) {
                // Only add if exists in header
                if (!array_key_exists(wpcf_types_get_meta_prefix($field) . $field['slug'], $row_data)) {
                    continue;
                }
                // Date trigger
                if ($field['type'] == 'date') {
                    $date_trigger = true;
                }
                // Get WPCF form
                $element_org = wpcf_admin_post_process_fields($item, array('field' => $field), false, false, 'post_relationship');
                $element = array_shift($element_org);
                if (!in_array($field['type'], array('image', 'file'))) {
                    $element['#id'] = 'wpcf_post_relationship_' . $item->ID . '_' . $field['id'];
                }
                $element['#name'] = 'wpcf_post_relationship[' . $item->ID . '][' . wpcf_types_get_meta_prefix($field) . $field['slug'] . ']';
                $element['#inline'] = true;
                unset($element['#title'], $element['#description']);
                if ($field['type'] == 'skype') {
                    unset($element['#prefix']);
                }
                if (in_array($field['type'], array('wysiwyg'))) {
                    $element['#type'] = 'textarea';
                    $element['#attributes'] = array('style' => 'width:300px;height:100px;');
                }
                if (in_array($field['type'], array('checkbox', 'checkboxes'))) {
                    if ($field['type'] == 'checkbox') {
                        $element['#suffix'] = '<input type="hidden" name="wpcf_post_relationship_checkbox[' . $item->ID . '][' . wpcf_types_get_meta_prefix($field) . $field['slug'] . ']" value="1" />';
                    } else {
                        if ($field['type'] == 'checkboxes' && !empty($element['#options'])) {
                            foreach ($element['#options'] as $temp_key => $temp_value) {
                                $element['#options'][$temp_key]['#name'] = 'wpcf_post_relationship[' . $item->ID . '][' . wpcf_types_get_meta_prefix($field) . $field['slug'] . '][' . $temp_key . ']';
                                $element['#options'][$temp_key]['#inline'] = true;
                                $element['#options'][$temp_key]['#after'] = '<br />';
                            }
                            $element['#suffix'] = '<input type="hidden" name="wpcf_post_relationship_checkboxes[' . $item->ID . '][' . wpcf_types_get_meta_prefix($field) . $field['slug'] . ']" value="1" />';
                        }
                    }
                }
                $value = get_post_meta($item->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                $element = array('field' => $element);
                $element = wpcf_form_simple($element);
                $row_data[wpcf_types_get_meta_prefix($field) . $field['slug']] = $element;
            }
        }
        // Get all parents
        $item_parents = wpcf_pr_admin_get_belongs($post_type);
        if ($item_parents) {
            foreach ($item_parents as $parent => $temp_data) {
                if ($parent == $parent_post_type) {
                    continue;
                }
                $meta = get_post_meta($item->ID, '_wpcf_belongs_' . $parent . '_id', true);
                $meta = empty($meta) ? 0 : $meta;
                $belongs_data = array('belongs' => array($parent => $meta));
                $temp_form = wpcf_pr_admin_post_meta_box_belongs_form($item, $parent, $belongs_data);
                unset($temp_form[$parent]['#suffix'], $temp_form[$parent]['#prefix'], $temp_form[$parent]['#title']);
                $temp_form[$parent]['#name'] = 'wpcf_post_relationship[' . $item->ID . '][parents][' . $parent . ']';
                // Only add if exists in header
                if (array_key_exists('_wpcf_pr_parent_' . $parent, $row_data)) {
                    $row_data['_wpcf_pr_parent_' . $parent] = wpcf_form_simple($temp_form);
                }
            }
        }
    }
    if (!empty($row_data)) {
        $output = '';
        $output .= '<tr><td>' . implode('</td><td>', $row_data) . '<input type="hidden" name="wpcf_post_relationship[' . $item->ID . '][post_type]" value="' . $post_type . '" /></td><td class="actions">' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=pr_save_child_post&amp;post_type_parent=' . $parent_post_type . '&amp;post_id=' . $post->ID . '&amp;post_type_child=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_save_child_post')) . '" class="wpcf-pr-save-ajax button-secondary">' . __('Save', 'wpcf') . '</a>';
        $output .= strpos($item->ID, 'new_') === false ? ' <a href="' . get_edit_post_link($item->ID) . '" class="button-secondary">' . __('Edit', 'wpcf') . '</a>' : '';
        $output .= strpos($item->ID, 'new_') === false ? ' <a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=pr_delete_child_post' . '&amp;post_id=' . $item->ID . '&_wpnonce=' . wp_create_nonce('pr_delete_child_post')) . '" class="wpcf-pr-delete-ajax button-secondary">' . __('Delete', 'wpcf') . '</a>' : '';
        if ($date_trigger) {
            $output .= '<script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function(){
            wpcfFieldsDateInit("#wpcf-post-relationship");
        });
        //]]>
    </script>';
        }
        if (defined('DOING_AJAX')) {
            $output .= '<script type="text/javascript">wpcfPrVerifyInit();</script>';
        }
        $output .= wpcf_form_render_js_validation('#post', false) . '</td></tr>';
        return $output;
    }
    return $output = '<tr><td><span style="color:Red;">' . __('Error occured', 'wpcf') . '</span></td></tr>';
}
コード例 #26
0
/**
 * Group coditional display filter.
 *
 * @param type $filters
 * @param type $update
 * @return type
 */
function wpcf_cd_fields_form_additional_filters($filters, $update)
{
    $data = array();
    $data['id'] = !empty($update) ? $update['name'] : wpcf_unique_id(serialize($filters));
    if ($update) {
        $data['data']['conditional_display'] = maybe_unserialize(get_post_meta($update['id'], '_wpcf_conditional_display', true));
    } else {
        $data['data']['conditional_display'] = array();
    }
    $filters = $filters + wpcf_cd_admin_form_filter($data, true);
    return $filters;
}
コード例 #27
0
ファイル: date.php プロジェクト: CrankMaster336/FFW-TR
/**
 * From data for post edit page.
 * 
 * @param type $field 
 * @param type $data
 * @param type $field_object Field instance 
 */
function wpcf_fields_date_meta_box_form($field, $field_object = null)
{
    /*
     * Added extra fields 'hour' and 'minute'.
     * 
     * If value is not array it is assumed that DB entry is timestamp()
     * and data is converted to array.
     */
    $value = $field['value'] = wpcf_fields_date_value_get_filter($field['value'], $field_object);
    // TODO WPML Set disable_in_form or similar to true, use hook for WPML
    if (wpcf_wpml_field_is_copied($field)) {
        $attributes = array('style' => 'width:150px;');
    } else {
        $attributes = array('class' => 'wpcf-datepicker', 'style' => 'width:150px;');
    }
    /*
     * 
     * Do not forget to trigger datepicker script
     * Only trigger on AJAX call (inserting new)
     */
    $js_trigger = defined('DOING_AJAX') ? '<script type="text/javascript">wpcfFieldsDateInit(\'\');</script>' : '';
    /*
     * 
     * 
     * Set Form
     */
    $unique_id = wpcf_unique_id(serialize($field));
    $form = array();
    $form[$unique_id . '-datepicker'] = array('#type' => 'textfield', '#title' => '&nbsp;' . $field['name'], '#attributes' => $attributes, '#name' => 'wpcf[' . $field['slug'] . '][datepicker]', '#id' => 'wpcf-date-' . $field['slug'] . '-datepicker-' . $unique_id, '#value' => $value['datepicker'], '#after' => '' . $js_trigger, '#_validate_this' => true);
    // Add warning about supported timestamp
    if (!fields_date_timestamp_neg_supported()) {
        $_visible = !empty($value['datepicker']) && intval($value['timestamp']) < 0 ? '' : ' style="display:none;"';
        $form[$unique_id . '-warning'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-error"' . $_visible . '><p>' . __('Please enter a date after 1 January 1970', 'wpcf') . '</p></div>');
    }
    /*
     * 
     * If set 'date_and_time' add time
     */
    if (!empty($field['data']['date_and_time']) && $field['data']['date_and_time'] == 'and_time') {
        // Set parent CSS inline
        $form[$unique_id . '-datepicker']['#inline'] = true;
        $hours = 24;
        $minutes = 60;
        $options = array();
        // Hour
        for ($index = 0; $index < $hours; $index++) {
            $prefix = $index < 10 ? '0' : '';
            $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
        }
        $form[$unique_id . 'time_hour'] = array('#type' => 'select', '#title' => __('Hour', 'wpcf'), '#inline' => true, '#before' => '<br />', '#after' => '&nbsp;&nbsp;', '#options' => $options, '#default_value' => $value['hour'], '#name' => 'wpcf[' . $field['slug'] . '][hour]', '#id' => 'wpcf-date-' . $field['slug'] . '-select-hour-' . $unique_id, '#inline' => true);
        // Minutes
        for ($index = 1; $index < $minutes; $index++) {
            $prefix = $index < 10 ? '0' : '';
            $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
        }
        $form[$unique_id . 'time_minute'] = array('#type' => 'select', '#title' => __('Minute', 'wpcf'), '#after' => '<br /><br />', '#inline' => true, '#options' => $options, '#default_value' => $value['minute'], '#name' => 'wpcf[' . $field['slug'] . '][minute]', '#id' => 'wpcf-date-' . $field['slug'] . '-minute-' . $unique_id);
    }
    return $form;
}
コード例 #28
0
<?php

/*
 * Child table Taxonomy non-hierarchical form.
 */
$defaults = array('taxonomy' => 'post_tag');
extract(wp_parse_args($data, $defaults), EXTR_SKIP);
$tax_name = esc_attr($taxonomy);
$taxonomy = get_taxonomy($taxonomy);
$user_can_assign_terms = current_user_can($taxonomy->cap->assign_terms);
$comma = _x(',', 'tag delimiter');
$html_id = esc_attr(wpcf_unique_id($tax_name));
?>
<div class="js-types-child-tagsdiv" id="<?php 
echo $html_id;
?>
">
	<div class="jaxtag">
	<div class="nojs-tags hide-if-js">
	<p><?php 
echo $taxonomy->labels->add_or_remove_items;
?>
</p>
	<textarea name="<?php 
echo esc_attr($_wpcf_name);
?>
" rows="3" cols="20" class="the-tags" id="tax-input-<?php 
echo $html_id;
?>
" <?php 
disabled(!$user_can_assign_terms);
コード例 #29
0
 /**
  * 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 form_validation($name, $field, $form_data = array())
 {
     if (!isset($field['validate'])) {
         return array();
     }
     $form = array();
     // Process methods
     foreach ($field['validate'] as $k => $method) {
         // Set additional method data
         if (is_array($method)) {
             $form_data['data']['validate'][$k]['method_data'] = $method;
             $method = $k;
         }
         if (!Wpcf_Validate::canValidate($method) || !Wpcf_Validate::hasForm($method)) {
             continue;
         }
         // Get method form data
         if (Wpcf_Validate::canValidate($method) && Wpcf_Validate::hasForm($method)) {
             $field['#name'] = $name . '[' . $method . ']';
             $form_validate = call_user_func_array(array('Wpcf_Validate', $method . '_form'), array($field, isset($form_data['data']['validate'][$method]) ? $form_data['data']['validate'][$method] : array()));
             // Set unique IDs
             $is_first = true;
             foreach ($form_validate as $key => $element) {
                 if (isset($element['#type'])) {
                     $form_validate[$key]['#id'] = $element['#type'] . '-' . wpcf_unique_id(serialize($element));
                 }
                 if ($is_first && isset($element['#pattern'])) {
                     $is_first = false;
                     $form_validate[$key]['#pattern'] = preg_replace('/<tr>/', '<tr class="wpcf-border-top">', $element['#pattern']);
                 }
             }
             // Join
             $form = $form + $form_validate;
         }
     }
     return $form;
 }
コード例 #30
0
/**
 * Processes single field.
 * 
 * @staticvar array $repetitive_started
 * @param type $post
 * @param type $field
 * @param type $use_cache
 * @param type $add_to_editor
 * @param type $context
 * @param type $original_cf
 * @param type $invalid_fields
 * @return mixed boolean|array
 */
function wpcf_admin_post_process_field($post = false, $field_unedited = array(), $use_cache = true, $add_to_editor = true, $context = 'group', $original_cf = array(), $invalid_fields = array())
{
    $field = wpcf_admin_fields_get_field($field_unedited['id']);
    if (!empty($field)) {
        // Set values
        $field['value'] = isset($field_unedited['value']) ? maybe_unserialize($field_unedited['value']) : '';
        $field['wpml_action'] = isset($field_unedited['wpml_action']) ? $field_unedited['wpml_action'] : '';
        $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . wpcf_unique_id(serialize($field));
        $field_init_data = wpcf_fields_type_action($field['type']);
        // Get inherited field
        $inherited_field_data = false;
        if (isset($field_init_data['inherited_field_type'])) {
            $inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
        }
        // Apply filters
        $field['value'] = apply_filters('wpcf_fields_value_get', $field['value'], $field, $field_init_data);
        $field['value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_get', $field['value'], $field, $field_init_data);
        $field['value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_get', $field['value'], $field, $field_init_data);
        wpcf_admin_post_field_load_js_css($field_init_data);
        $element = array();
        // Set generic values
        $element = array('#type' => isset($field_init_data['inherited_field_type']) ? $field_init_data['inherited_field_type'] : $field['type'], '#id' => $field_id, '#title' => wpcf_translate('field ' . $field['id'] . ' name', $field['name']), '#description' => wpautop(wpcf_translate('field ' . $field['id'] . ' description', $field['description'])), '#name' => 'wpcf[' . $field['slug'] . ']', '#value' => isset($field['value']) ? $field['value'] : '', 'wpcf-id' => $field['id'], 'wpcf-slug' => $field['slug'], 'wpcf-type' => $field['type']);
        // Set inherited values
        $element_inherited = array();
        if ($inherited_field_data) {
            if (function_exists('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form')) {
                $element_inherited = call_user_func_array('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form', array($field, $element));
            }
        }
        $element = array_merge($element, $element_inherited);
        if (isset($field['description_extra'])) {
            $element['#description'] .= wpautop($field['description_extra']);
        }
        // Set atributes #1
        if (isset($field['disable'])) {
            $field['#disable'] = $field['disable'];
        }
        if (!empty($field['disable'])) {
            $field['#attributes']['disabled'] = 'disabled';
        }
        if (!empty($field['readonly'])) {
            $field['#attributes']['readonly'] = 'readonly';
        }
        // Set specific values
        if (defined('WPCF_INC_ABSPATH') && file_exists(WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php')) {
            require_once WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php';
        }
        // Load field
        if (function_exists('wpcf_fields_' . $field['type'] . '_meta_box_form')) {
            $element_specific = call_user_func_array('wpcf_fields_' . $field['type'] . '_meta_box_form', array($field, $element));
            // Check if it's single
            if (isset($element_specific['#type'])) {
                // Format description
                if (!empty($element_specific['#description'])) {
                    $element_specific['#description'] = wpautop($element_specific['#description']);
                }
                $element = array_merge($element, $element_specific);
                // Set validation element
                if (isset($field['data']['validate'])) {
                    $element['#validate'] = $field['data']['validate'];
                }
                // Repetitive fields
                if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship') {
                    $element = wpcf_admin_post_process_repetitive_field($post, $field, $element);
                }
            } else {
                // More fields, loop all
                // Only Skype for now have multiple fields, so process only that
                if ($field['type'] == 'skype') {
                    $skype_element = array();
                    foreach ($element_specific as $element_specific_fields_key => $element_specific_fields_value) {
                        $element_specific_fields_value['__element_key'] = $element_specific_fields_key;
                        // Format description
                        if (!empty($element_specific_fields_value['#description'])) {
                            $element_specific_fields_value['#description'] = wpautop($element_specific_fields_value['#description']);
                        }
                        // If no ID
                        if (!isset($element_specific_fields_value['#id'])) {
                            $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . wpcf_unique_id(serialize($field));
                        }
                        // Set validation element
                        if (!empty($element_specific_fields_value['#_validate_this']) && isset($field['data']['validate'])) {
                            $element_specific_fields_value['#validate'] = $field['data']['validate'];
                        }
                        if ($element_specific_fields_key != 'skypename') {
                            if (!isset($element_specific_fields_value['#name'])) {
                                $element_specific_fields_value['#name'] = 'wpcf[ignore][' . wpcf_unique_id(serialize($element_specific_fields_value)) . ']';
                            }
                            $skype_element[$element_specific_fields_value['#id']] = $element_specific_fields_value;
                            continue;
                        }
                        // This one is actually value and keep it (#name is required)
                        $element = array_merge($element, $element_specific_fields_value);
                        // Add it here to keep order
                        $skype_element[$element['#id']] = $element;
                    }
                    // Repetitive fields
                    if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship') {
                        list($element, $skype_element) = wpcf_admin_post_process_repetitive_field_skype($post, $field, $skype_element);
                    }
                }
            }
        } else {
            // Repetitive fields
            if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship') {
                $element = wpcf_admin_post_process_repetitive_field($post, $field, $element);
            }
        }
        // Set atributes #2 (override)
        if (isset($field['disable'])) {
            $element['#disable'] = $field['disable'];
        }
        if (!empty($field['disable'])) {
            $element['#attributes']['disabled'] = 'disabled';
        }
        if (!empty($field['readonly'])) {
            $element['#attributes']['readonly'] = 'readonly';
            if (!empty($element['#options'])) {
                foreach ($element['#options'] as $key => $option) {
                    if (!is_array($option)) {
                        $element['#options'][$key] = array('#title' => $key, '#value' => $option);
                    }
                    $element['#options'][$key]['#attributes']['readonly'] = 'readonly';
                    if ($element['#type'] == 'select') {
                        $element['#options'][$key]['#attributes']['disabled'] = 'disabled';
                    }
                }
            }
            if ($element['#type'] == 'select') {
                $element['#attributes']['disabled'] = 'disabled';
            }
        }
        // Set validation element
        if ($field['type'] != 'skype' && empty($element['#validate']) && isset($field['data']['validate'])) {
            $element['#validate'] = $field['data']['validate'];
        }
        // Check if it was invalid on submit and add error message
        if ($post && !empty($invalid_fields)) {
            if (isset($invalid_fields[$element['#id']]['#error'])) {
                $element['#error'] = $invalid_fields[$element['#id']]['#error'];
            }
        }
        // Set WPML locked icon
        if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
            $element['#title'] .= '<img src="' . WPCF_EMBEDDED_RES_RELPATH . '/images/locked.png" alt="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" title="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" style="position:relative;left:2px;top:2px;" />';
        }
        // Add to editor
        if ($add_to_editor) {
            wpcf_admin_post_add_to_editor($field);
        }
        // Add repetitive class
        // @TODO Why not add repetitive class if copied?
        if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) {
            if (!empty($element['#options']) && $element['#type'] != 'select') {
                foreach ($element['#options'] as $temp_key => $temp_value) {
                    $element['#options'][$temp_key]['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive';
                }
            } else {
                $element['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive';
            }
            wpcf_admin_add_js_settings('wpcfFormRepetitiveUniqueValuesCheckText', '\'' . __('Warning: same values set', 'wpcf') . '\'');
        }
        // Set read-only if copied by WPML
        if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
            if (isset($element['#options'])) {
                foreach ($element['#options'] as $temp_key => $temp_value) {
                    if (isset($temp_value['#attributes'])) {
                        $element['#options'][$temp_key]['#attributes']['readonly'] = 'readonly';
                    } else {
                        $element['#options'][$temp_key]['#attributes'] = array('readonly' => 'readonly');
                    }
                }
            }
            if ($field['type'] == 'select') {
                if (isset($element['#attributes'])) {
                    $element['#attributes']['disabled'] = 'disabled';
                } else {
                    $element['#attributes'] = array('disabled' => 'disabled');
                }
            } else {
                if (isset($element['#attributes'])) {
                    $element['#attributes']['readonly'] = 'readonly';
                } else {
                    $element['#attributes'] = array('readonly' => 'readonly');
                }
            }
        }
        // Specific for Skype
        if ($field['type'] == 'skype') {
            $skype_element[$element['#id']] = $element;
            $element = $skype_element;
        }
        return array('field' => $field, 'element' => $element);
    }
    return false;
}