<?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', '>')) {
<?php

UF_Field::add_field('checkbox', __('Checkbox', 'uf'));
class UF_Field_Checkbox extends UF_Field
{
    public $multilingual_support = true;
    protected $text;
    public function set_text($text)
    {
        $this->text = $text;
        return $this;
    }
    public function display_input()
    {
        # Revert to "Yes" if no other text set
        if (!$this->text) {
            $this->text = __('Yes', 'uf');
        }
        $checked = $this->value ? ' checked="checked"' : '';
        echo '<input type="checkbox" name="' . $this->input_id . '" id="' . $this->input_id . '" ' . $checked . ' />';
        echo '<label for="' . $this->input_id . '" class="text">' . $this->text . '</label>';
    }
    public function save($data)
    {
        if ($this->is_multilingual) {
            $languages = UF_ML::get();
            $this->value = array();
            foreach ($languages as $l) {
                $this->value[$l['code']] = isset($data[$this->id][$l['code']]);
            }
            $this->value = UF_ML::join($this->value);
<?php

UF_Field::add_field('textarea', __('Textarea', 'uf'));
class UF_Field_Textarea extends UF_Field
{
    protected $rows = 5, $multilingual_support = true;
    public function display_input()
    {
        echo '<textarea name="' . $this->input_id . '" id="' . $this->input_id . '" rows="' . $this->rows . '">' . htmlspecialchars(stripslashes($this->value)) . '</textarea>';
    }
    public function set_rows($rows)
    {
        $this->rows = $rows;
        return $this;
    }
    /**
     * Returns a description for the field, will be used in the settings
     * 
     * @return string The description
     */
    public static function settings_description()
    {
        return __('Displays a basic text area with adjustable number of rows.', 'uf');
    }
    /**
     * Adds additional fields to the settings pages
     * 
     * @return UF_Field[]
     */
    public static function additional_settings()
    {
Exemple #4
0
<?php

UF_Field::add_field('select', __('Select', 'uf'));
class UF_Field_Select extends UF_Field
{
    protected $options = array(), $no_options_message, $multilingual_support = true;
    protected function check_options($default_message)
    {
        if (empty($this->options)) {
            if (!$this->no_options_message) {
                $this->no_options_message = $default_message;
            }
            echo '<p class="only-child">' . $this->no_options_message . '</p>';
            return false;
        }
        return true;
    }
    protected function select($input_id, $options, $active = '')
    {
        $output = '<select name="' . esc_attr($input_id) . '" id="' . esc_attr($input_id) . '">';
        foreach ($options as $key => $option) {
            $selected = $active == $key ? ' selected="selected"' : '';
            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . $option . '</option>';
        }
        $output .= '</select>';
        return $output;
    }
    public function display_input()
    {
        if (!$this->check_options(__('This select has no options.', 'uf'))) {
            return;
Exemple #5
0
<?php

/**
 * Displays a list of checkboxes
 */
UF_Field::add_field('set', __('Set', 'uf'));
class UF_Field_Set extends UF_Field_Select
{
    protected $is_sortable = false, $order = array(), $separator = '_^_', $multilingual_support = true, $html_attributes = array('data-sortable' => '0', 'data-separator' => '_^_');
    function sortable($sortable = true)
    {
        $this->is_sortable = $sortable;
        $this->html_attributes['data-sortable'] = $this->is_sortable ? '1' : '0';
        wp_enqueue_script('jquery-ui-sortable');
        return $this;
    }
    function prepare_order()
    {
        if ($this->is_sortable) {
            $order = $this->datastore->get_value('order_' . $this->id);
            if ($this->is_multilingual && $this->language) {
                $order = UF_ML::split($order, $this->language);
            }
            if ($order) {
                $order_val = $order;
                $order = explode($this->separator, $order);
                $this->options = $this->sort_array_by_array($this->options, $order);
            } else {
                $order_val = implode($this->separator, array_keys($this->options));
            }
            $this->order = $order_val;
Exemple #6
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;
            ?>
/>
<?php

UF_Field::add_field('select_page', __('Select Page', 'uf'));
class UF_Field_Select_Page extends UF_Field
{
    public $multilingual_support = true;
    private $post_type = 'page';
    public function display_input()
    {
        wp_dropdown_pages(array('selected' => $this->value, 'name' => $this->input_id, 'post_type' => $this->post_type));
    }
    /**
     * Set a specific post type for the dropdown
     * 
     * WARNING: If the provided post type is not hierarchical, it will be silently reverted to page
     *
     * @param string $post_type The post type for the dropdown
     * @return UF_Field The instance of the field
     */
    public function set_post_type($post_type)
    {
        $this->post_type = apply_filters('uf_field_select_page_pt', $post_type, $this);
        return $this;
    }
    /**
     * Returns a description for the field, will be used in the settings
     * 
     * @return string The description
     */
    public static function settings_description()
    {
Exemple #8
0
<?php

/**
 * Displays a field, which lets the user upload files.
 *
 * The field is using the media uploader that is used by WordPress 3.5, but has
 * a fallback to the media gallery, that was used in the verions before that.
 *
 * @since 1.3
 * @package ultimatefields
 */
UF_Field::add_field('file', __('File', 'uf'));
class UF_Field_File extends UF_Field
{
    /** @type boolean Indicates if the field supports multilingual values */
    protected $multilingual_support = true;
    /**
     * Prepares strings & classes + enqueueing media
     */
    protected function after_constructor()
    {
        # All of the settings above apply only in the admin
        if (!is_admin()) {
            return;
        }
        # Prepare texts
        $this->strings = apply_filters('uf_file_field_texts', array('btn_text' => __('Select', 'uf'), 'delete_text' => __('Remove', 'uf'), 'confirm_text' => __('Are you sure you want to remove this file?', 'uf'), 'use_text' => __('Save & Use', 'uf')), $this);
        # Add some data to the HTML elements
        $this->html_attributes = array('data-confirm-deletion' => $this->strings['confirm_text']);
        # Enqueue media scripts on admin_init
        remove_action('admin_enqueue_scripts', array('UF_Field_File', 'enqueue_media'));
<?php

/**
 * Displays a simple text separator
 */
UF_Field::add_field('separator', __('Heading', 'uf'));
class UF_Field_Separator extends UF_Field
{
    function display($location = null)
    {
        global $ultimatefields;
        include $ultimatefields->themes->path('field/separator', $location);
    }
    /**
     * 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);
    }
    /**
     * Returns a description for the field, will be used in the settings
     * 
     * @return string The description
     */
    public static function settings_description()