Ejemplo n.º 1
0
/**
 * Retrieve a repeater with all available fields + a nested repeater
 * 
 * @return UF_Repeater The filled repeater
 */
function uf_get_available_fields($repeater_id = 'fields')
{
    # The top
    $repeater = UF_Field::factory('repeater', $repeater_id, __('Fields', 'uf'));
    UF_Field::get_fields($repeater);
    # The inner repeater
    $inner_repeater = UF_Field::factory('repeater', 'group_fields', __('Fields', 'uf'));
    UF_Field::get_fields($inner_repeater);
    $inner_settings = array('title' => __('Repeater', 'uf'), 'description' => __('Enables repeateable field groups. Check the docs for more info.', 'uf'));
    $default_fields = UF_Field::settings_fields('repeater');
    unset($default_fields['default_value']);
    unset($default_fields['default_value_ml']);
    unset($default_fields['multilingual']);
    $repeater_settings = array_merge($default_fields, array(UF_Field::factory('repeater', 'repeater_fields', __('Repeater Fields', 'uf'))->add_fields('group', __('Group', 'uf'), array(UF_Field::factory('text', 'title')->multilingual()->make_required(), UF_Field::factory('text', 'key')->make_required('/[a-z0-9_]+/'), $inner_repeater))));
    $repeater->add_fields('repeater', $inner_settings, $repeater_settings);
    /**
     * Tab starts & ends
     */
    $details = array('title' => __('Tab Start', 'uf'), 'description' => __('Adds a tab to the container. Not available in widgets.', 'uf'));
    $repeater->add_fields('tab_start', $details, array(UF_Field::factory('text', 'title', __('Title', 'uf'))->multilingual(), UF_Field::factory('radio', 'icon_type', __('Icon Type', 'uf'))->add_options(array('image' => __('Image', 'uf'), 'font' => __('Font Icon', 'uf'))), UF_Field::factory('file', 'icon_image', __('Icon', 'uf'))->set_dependency('icon_type', 'image'), UF_Field::factory('text', 'icon_class', __('CSS Class', 'uf'))->set_dependency('icon_type', 'font')->set_description(__('You can enter the CSS class of the icon here. You could use a <a href="http://fontawesome.io/icons/">FontAwesome</a>, <a href="https://github.com/melchoyce/dashicons">Dashicons</a> or a custom font CSS class. <strong>Example:</strong> dashicons dashicons-align-none', 'uf'))));
    return $repeater;
}
Ejemplo n.º 2
0
<?php

UF_Field::add_field('richtext', __('Rich Text Editor', 'uf'));
class UF_Field_Richtext extends UF_Field_Textarea
{
    public $multilingual_support = true;
    public static function dummy_editor()
    {
        # Avoid creating more than one editor
        remove_action('uf_after_container', array('UF_Field_Richtext', 'dummy_editor'));
        echo '<div style="display:none;">';
        wp_editor('', 'uf_dummy_editor_id', array('textarea_name' => 'uf_dummy_editor_name'));
        echo '</div>';
    }
    function after_constructor()
    {
        if (!is_admin()) {
            return;
        }
        add_action('uf_after_container', array('UF_Field_Richtext', 'dummy_editor'));
    }
    function display_input()
    {
        $this->mce_id = md5(microtime());
        ob_start();
        do_action('media_buttons', $this->mce_id);
        $media_buttons = ob_get_clean();
        $content = stripslashes($this->value);
        $content = wpautop($content);
        global $wp_version;
        if (version_compare($wp_version, '3.8.2', '>')) {
Ejemplo n.º 3
0
<?php

/**
 * Add a settings page
 */
global $ultimatefields;
$fields = array();
# This will control the multilingual functionality
$fields[] = UF_Field::factory('checkbox', 'uf_multilingual', __('Multilingual Fields', 'uf'))->set_text(__('Enable', 'uf'))->set_description(__('This plugin is compatible with qTranslate, which is a WordPress multilingual plugin. If you enable the multilingual fields and you use qTranslate, we will automatically get the available languages and display two field versions for each language. Please remember that each field will have it&apos;s own setting and you will need to use it in order to make it multilingual.', 'uf'));
# Add a theme chooser field
$themes = $ultimatefields->themes->get();
if (true || $themes) {
    # Start with the default theme
    $themes = array_merge(array(array('id' => 'default', 'title' => __('Default Theme', 'uf'), 'dir' => UF_DIR . 'templates', 'url' => UF_URL . 'templates', 'image' => UF_URL . 'settings/images/screenshot.png')), $themes);
    foreach ($themes as $theme) {
        $options[$theme['id']] = $theme['title'];
    }
    # Add the field
    $fields[] = UF_Field::factory('select', 'uf_theme', __('Theme', 'uf'))->add_options($options);
}
# Create the page
$page = UF_Options::page('Settings', array('parent' => 'edit.php?post_type=ultimatefields', 'title' => __('Settings', 'uf')))->tab('general', $fields, 'dashicons dashicons-admin-generic', __('General', 'uf'));
/**
 * Allows adding of additional fields to the container for specific fields.
 * 
 * @param UF_Options $page The page which works with the options.
 * 
 * @since 2.0
 */
do_action('uf_settings', $page);
Ejemplo n.º 4
0
/**
 * Create field objects by a plain array
 * 
 * @param mixed[] $fields - The plain array, containing raw data
 * @param string $container_type The type of the container those fields will be in. Class name
 * @param UF_Field_Repeater $parent If there is a parent set, all processing callbacks will be sent there.
 * @return UF_Field[] $prepared - The fields, ready to be added to a container
 */
function uf_setup_fields($fields, $container_type, $parent = '')
{
    if (is_a($parent, 'UF_Field_Repeater')) {
        $uf_processors = array();
    } else {
        $uf_processors =& $GLOBALS['uf_datastore_getter']->processors;
    }
    $prepared = array();
    if (!is_array($fields)) {
        return;
    }
    foreach ($fields as $field) {
        if ($field['type'] == 'tab_start' || $field['type'] == 'tab_end') {
            # Add the icon as a path
            if ($field['type'] == 'tab_start') {
                if ($type = $field['icon_type']) {
                    if ($type == 'image' && $field['icon_image']) {
                        $field['icon'] = wp_get_attachment_url($field['icon']);
                    } elseif ($type == 'font' && $field['icon_class']) {
                        $field['icon'] = $field['icon_class'];
                    }
                }
            }
            $prepared[] = $field;
        } else {
            $obj = null;
            switch ($field['type']) {
                case 'separator':
                    $obj = UF_Field::factory('separator', 'separator_' . md5(microtime()));
                    break;
                case 'text':
                    $obj = UF_Field::factory($field['type'], $field['field_id']);
                    if (isset($field['autocomplete_suggestions'])) {
                        $obj->add_suggestions(explode("\n", $field['autocomplete_suggestions']));
                    }
                    break;
                case 'select':
                case 'set':
                case 'radio':
                    $obj = UF_Field::factory($field['type'], $field['field_id']);
                    if ($field['values_source'] == 'textarea') {
                        $values = array();
                        if (isset($field['options'])) {
                            foreach ($field['options'] as $option) {
                                $values[$option['key']] = $option['value'];
                            }
                        }
                        $obj->add_options($values);
                    } else {
                        $obj->add_posts(array('posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'post_title', 'post_type' => $field['post_type']));
                    }
                    if (isset($field['sortable']) && $field['sortable'] && $field['type'] == 'set') {
                        $obj->sortable(true);
                    }
                    if (isset($field['jquery_plugin']) && $field['jquery_plugin']) {
                        $obj->chosen();
                    }
                    break;
                case 'textarea':
                case 'richtext':
                    $obj = UF_Field::factory($field['type'], $field['field_id']);
                    $obj->set_rows($field['rows']);
                    break;
                case 'checkbox':
                    $obj = UF_Field::factory('checkbox', $field['field_id']);
                    if (isset($field['text'])) {
                        $obj->set_text($field['text']);
                    }
                    break;
                case 'select_term':
                    $obj = UF_Field::factory('select_term', $field['field_id']);
                    $obj->set_taxonomy($field['taxonomy']);
                    break;
                case 'repeater':
                    $obj = UF_Field::factory('repeater', $field['field_id']);
                    if (isset($field['repeater_fields'])) {
                        foreach ($field['repeater_fields'] as $group) {
                            $sub_fields_arr = uf_setup_fields($group['group_fields'], 'UF_Field_Repeater', $obj);
                            $obj->add_fields($group['key'], array('title' => UF_ML::split($group['title'])), $sub_fields_arr);
                        }
                    }
                    break;
                default:
                    $obj = UF_Field::factory($field['type'], $field['field_id']);
            }
            if ($obj) {
                foreach ($field as $key => $value) {
                    switch ($key) {
                        case 'title':
                        case 'field_title':
                            $obj->set_title(UF_ML::split($value));
                            break;
                        case 'default_value':
                            $obj->set_default_value($value);
                            break;
                        case 'help_text':
                            $obj->set_help_text(UF_ML::split($value));
                            break;
                        case 'description':
                            $obj->set_description(UF_ML::split($value));
                            break;
                        case 'multilingual':
                            if ($value) {
                                $obj->multilingual();
                            }
                            break;
                    }
                }
                # Add the field as a processor
                if (method_exists($obj, 'process_value')) {
                    if (!isset($uf_processors[$container_type])) {
                        $uf_processors[$container_type] = array();
                    }
                    if (!isset($uf_processors[$container_type][$field['field_id']])) {
                        $uf_processors[$container_type][$field['field_id']] = array(10 => array());
                    }
                    $uf_processors[$container_type][$field['field_id']][10][] = array('callback' => array($obj, 'process_value'), 'data' => $field);
                }
                /**
                 * Modifies the field.
                 * 
                 * When the field is created, additional information might need
                 * to be set up. You can do it here, as the object is passed by reference.
                 * 
                 * @since 2.0
                 * 
                 * @param UF_Field $object The generated field.
                 * @param mixed[] $field_data The all settings of the field as saved in the admin.
                 */
                do_action('uf_setup_field', $obj, $field);
                $prepared[] = $obj;
            }
        }
    }
    if (is_a($parent, 'UF_Field_Repeater')) {
        $parent->processors = $uf_processors['UF_Field_Repeater'];
    }
    return $prepared;
}
Ejemplo n.º 5
0
 /**
  * Adds additional fields to the settings pages
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     $post_types = array();
     $excluded = apply_filters('uf_excluded_post_types', array('attachment', 'ultimatefields'));
     $raw = get_post_types(array('show_ui' => true), 'objects');
     foreach ($raw as $id => $post_type) {
         if (in_array($id, $excluded)) {
             continue;
         }
         $post_types[$id] = $post_type->labels->name;
     }
     return array('values_source' => UF_Field::factory('select', 'values_source', __('Values Source', 'uf'))->add_options(array('textarea' => __('Manually Entered', 'uf'), 'posttype' => __('Automatically add pages/posts', 'uf'))), 'options' => UF_Field::factory('repeater', 'options', __('Options', 'uf'))->set_dependency('values_source', 'textarea')->add_fields('option', __('Option', 'uf'), array(UF_Field::factory('text', 'value', __('Value', 'uf')), UF_Field::factory('text', 'key', __('Key', 'uf')))), 'post_type' => UF_Field::factory('select', 'post_type', __('Post Type', 'uf'))->add_options($post_types)->set_description(__('If you&apos;ve choosen &quot;Automatically add pages/posts&quot; above, please choose the required post type.', 'uf'))->set_dependency('values_source', 'posttype'), 'jquery_plugin' => UF_Field::factory('checkbox', 'jquery_plugin', __('jQuery Enchanced', 'uf')), 'output_data_separator' => UF_Field::factory('separator', 'output_data_separator', __('Output Settings', 'uf'))->set_description(__('The following settings will affect the output of this field when using the &quot;uf&quot; function or shortcode.', 'uf')), 'output_data_type' => UF_Field::factory('select', 'output_data_type', __('Output Item', 'uf'))->add_options(array('value' => __('Output the value of the select, the way it is saved', 'uf'), 'text' => __('Output the label of the selected value', 'uf'))));
 }
Ejemplo n.º 6
0
 /**
  * Get setting fields for the settings page.
  * Calls static additional_settings() for child classes.
  * 
  * @param string $field_type The type of the field.
  * @return UF_Field[] The fields for the group in the Fields repeater
  */
 public static function settings_fields($field_type)
 {
     $default_value_description = __('This value will be automatically populated when the field is initially shown.', 'uf');
     $class_name = self::get_class($field_type);
     # Optionally, set a specific type for the default value
     $default_field_type = $field_type;
     if (method_exists($class_name, 'get_default_value_type')) {
         $default_field_type = call_user_func(array($class_name, 'get_default_value_type'));
     }
     # Generic fields, which are available for each field
     $fields = array('field_title' => UF_Field::factory('text', 'field_title', __('Field Title', 'uf'))->set_description(__('This name will appear as a label next to the field.', 'uf'))->make_required()->multilingual(), 'field_id' => UF_Field::factory('text', 'field_id', __('Field ID (key)', 'uf'))->set_description(__('You will be able to get the field\'s value using this ID', 'uf'))->make_required('/[a-z0-9_]+/'), 'description' => UF_Field::factory('text', 'description', __('Description', 'uf'))->multilingual()->set_description(__('The description would appear after the field, just like this one.', 'uf')));
     # A checkbox for enabling multilingual functionality
     if (UF_ML::check() && $field_type != 'repeater') {
         $fields['multilingual'] = UF_Field::factory('checkbox', 'multilingual', __('Multilingual', 'uf'))->set_text(__('Enable multilingual functionality', 'uf'))->set_description(__('If enabled, Ultimate Fields will automatically display fields for each language.', 'uf'));
     }
     if ($field_type != 'repeater') {
         # The default value, which is a field of the same type. This one is not multilingual
         $fields['default_value'] = UF_Field::factory($default_field_type, 'default_value', __('Default Value', 'uf'))->set_description($default_value_description);
     }
     # The site is multilingual
     if (UF_ML::check() && $field_type != 'repeater') {
         $fields['default_value']->set_dependency('multilingual', true, '!=');
         $fields['default_value_multilingual'] = UF_Field::factory($default_field_type, 'default_value_ml', __('Default Value', 'uf'))->multilingual()->set_description($default_value_description)->set_dependency('multilingual');
     }
     # Provide a way to change those fields
     $fields = apply_filters('uf_default_field_settings_fields', $fields, $field_type);
     # Get additional field settings
     if (method_exists($class_name, 'additional_settings')) {
         $fields = array_merge($fields, call_user_func(array($class_name, 'additional_settings')));
     }
     return apply_filters('uf_field_settings_fields', $fields, $field_type);
 }
Ejemplo n.º 7
0
 /**
  * Adds additional fields to the settings pages
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     return array(UF_Field::factory('text', 'rows', __('Rows', 'uf'))->set_default_value(5), UF_Field::factory('separator', 'output_data_separator', __('Output Settings', 'uf'))->set_description(__('The following settings will affect the output of this field when using the &quot;uf&quot; function or shortcode.', 'uf')), UF_Field::factory('checkbox', 'output_add_paragraphs', __('Add Paragraphs', 'uf'))->set_text(__('Automatically add paragraphs and new lines.', 'uf')), UF_Field::factory('checkbox', 'output_apply_shortcodes', __('Apply Shortcodes', 'uf'))->set_text(__('Apply', 'uf')));
 }
Ejemplo n.º 8
0
 /**
  * Adds additional fields to the settings pages
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     return array(UF_Field::factory('separator', 'output_data_separator', __('Output Settings', 'uf'))->set_description(__('The following settings will affect the output of this field when using the &quot;uf&quot; function or shortcode.', 'uf')), UF_Field::factory('select', 'output_type', __('Output Type', 'uf'))->add_options(array('link' => __('A link to the file', 'uf'), 'url' => __('The URL of the file', 'uf'), 'id' => __('The ID of the file', 'uf'))));
 }
Ejemplo n.º 9
0
 /**
  * Adds additional fields to the settings pages
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     $parent_fields = parent::additional_settings();
     # Disable the jQuery thingy
     unset($parent_fields['jquery_plugin']);
     unset($parent_fields['output_data_separator']);
     unset($parent_fields['output_data_type']);
     return array_merge($parent_fields, array(UF_Field::factory('checkbox', 'sortable', __('Sortable', 'uf'))->set_description(__('If checked, the user will be able to change the order of the options.', 'uf')), UF_Field::factory('separator', 'output_data_separator', __('Output Settings', 'uf'))->set_description(__('The following settings will affect the output of this field when using the &quot;uf&quot; function or shortcode.', 'uf')), UF_Field::factory('select', 'output_type', __('Output Type', 'uf'))->add_options(array('unordered_list' => __('Unordered List', 'uf'), 'join' => __('A single line, joined with commas.', 'uf'))), UF_Field::factory('select', 'output_item', __('Output Item', 'uf'))->add_options(array('value' => __('Output the value of the select, the way it is saved', 'uf'), 'text' => __('Output the label of the selected value', 'uf')))));
 }
 /**
  * Returns the fields for the layout tab.
  * 
  * @since 2.0
  * @return UF_Field[]
  */
 public function layout_tab_fields()
 {
     $templates = array('single' => __('Use the post template.', 'ultimate-post-types'), 'page' => __('Use the default page template.', 'ultimate-post-types'));
     foreach (wp_get_theme()->get_page_templates() as $template => $name) {
         $templates[$template] = sprintf(__('Use the &quot;%s&quot; page template.', 'ultimate-post-types'), $name);
     }
     $fields = array(UF_Field::factory('select', 'upt_pt_template_type', __('Template Type', 'ultimate-post-types'))->set_input_type('radio')->add_options($templates), UF_Field::factory('wysiwyg', 'upt_pt_before_content', __('Before Content', 'ultimate-post-types')), UF_Field::factory('wysiwyg', 'upt_pt_after_content', __('After Content', 'ultimate-post-types'))->set_description(__('This content will be displayed before/after the content of the post type, in the template that is selected above. You can use shorcodes like [value key="meta_key"] to display values that are associated with the current post type in order to create a template for it. <strong>meta_key</strong> is the key of the field as created int the <strong>Fields</strong> tab.')));
     return $fields;
 }
Ejemplo n.º 11
0
<?php

UF_Field::add_field('radio', __('Radio', 'uf'));
class UF_Field_Radio extends UF_Field_Select
{
    public function display_input()
    {
        if (!$this->check_options(__('This radio has no options.', 'uf'))) {
            return;
        }
        # Prepare checked value - 1st one
        if (!$this->value && key($this->options)) {
            $this->value = key($this->options);
        }
        ?>
		<div>
			<?php 
        foreach ($this->options as $key => $value) {
            $checked = $key == $this->value ? ' checked="checked"' : '';
            ?>
				<label>
					<input type="radio" value="<?php 
            echo esc_attr($key);
            ?>
" name="<?php 
            echo $this->input_id;
            ?>
" <?php 
            echo $checked;
            ?>
/>
Ejemplo n.º 12
0
 /**
  * Displays a prototype of a field. 
  * 
  * To do this, the input's ID is changed to include the placeholder.
  * 
  * @access protected
  * @param UF_Field $field The field that will be displayed
  * @return UF_Field
  */
 protected function display_prototype(UF_Field $field)
 {
     # Get the normal ID of the field
     $old_input_id = $field->get_id();
     # Set the custom one
     $field->set_input_id($this->input_id . '[' . $this->i_placeholder . '][' . $old_input_id . ']');
     # Reset the field
     $field->reset();
     # Display it with the repeater template
     $field->display('repeater');
 }
Ejemplo n.º 13
0
 /**
  * Adds additional fields to the settings page (editing a Ultimate Fields container)
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     return array(UF_Field::factory('separator', 'output_data_separator', __('Output Settings', 'uf'))->set_description(__('The following settings will affect the output of this field when using the &quot;uf&quot; function or shortcode.', 'uf')), UF_Field::factory('radio', 'output_type', __('Output Type', 'uf'))->add_options(array('page_id' => __('Show the page ID, which is the value of the field.', 'uf'), 'page_title' => __('Show the title of the page.', 'uf'), 'page_link' => __('Show a link to the page.', 'uf'), 'page_url' => __('Show the URL of the page.', 'uf'))));
 }
Ejemplo n.º 14
0
 /**
  * Adds additional fields to the settings pages
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     return array(UF_Field::factory('text', 'text', __('Text', 'uf'))->set_description(__('This text could appear next to the checkbox itself, ex. &quot;Enable&quot;', 'uf'))->set_default_value(__('Yes', 'uf')));
 }
Ejemplo n.º 15
0
 /**
  * Adds additional fields to the settings pages
  * 
  * @return UF_Field[]
  */
 public static function additional_settings()
 {
     return array(UF_Field::factory('textarea', 'autocomplete_suggestions', __('Autocomplete Suggestions', 'uf'))->set_description(__('You may list predefined values here. One value per row.', 'uf')), UF_Field::factory('separator', 'output_data_separator', __('Output Settings', 'uf'))->set_description(__('The following settings will affect the output of this field when using the &quot;uf&quot; function or shortcode.', 'uf')), UF_Field::factory('select', 'output_format_value', __('Format Value', 'uf'))->add_options(array('none' => __('None', 'uf'), 'html' => __('HTML Entities', 'uf'))));
 }
    /**
     * Generates the fields for the fields tab.
     * 
     * @since 2.0
     * @return UF_Field[]
     */
    public function fields_tab_fields()
    {
        $fields = array(UF_Field::factory('fields', 'upt_taxonomy_fields', __('Fields', 'ultimate-post-types'))->set_custom_template('no-label'));
        if (!defined('ULTIMATE_FIELDS_PRO')) {
            $html = <<<HTML
<p><strong>This functionality is only available for Ultimate Fields Pro users.</strong></p>
<p>To add fields to a taxonomy, you need to use the <strong>Terms Meta</strong> container, which is a premium feature. You can add fields below, but they wil not be active until you get the plugin.</p>
<p>Ultimate Fields Premium is available at <a href="http://ultimate-fields.com/premium/" target="_blank">http://ultimate-fields.com/premium/</a>.</p>
HTML;
            $fields[0]->set_description($html);
        }
        return $fields;
    }
Ejemplo n.º 17
0
 /**
  * Get setting fields for the settings page.
  * Calls static additional_settings() for child classes.
  * 
  * @param string $field_type The type of the field.
  * @return UF_Field[] The fields for the group in the Fields repeater
  */
 public static function settings_fields($field_type)
 {
     $fields = array(UF_Field::factory('text', 'title', __('Title', 'uf'))->multilingual()->set_description(__('This title will separate different kinds of content.', 'uf'))->make_required(), UF_Field::factory('text', 'description', __('Description', 'uf'))->multilingual()->set_description(__('This text will appear under the title and may be used to give users directions what to do.', 'uf')));
     return apply_filters('uf_field_settings_fields', $fields, $field_type);
 }