Ejemplo n.º 1
0
 /**
  * Updates Post Section settings from the database.
  * @since 2.0
  */
 public function flush_settings($override = array())
 {
     global $ar2_options;
     $_defaults = array('enabled' => true, 'label' => sprintf(__('Post Section ID: %s', 'ar2'), $this->id), 'terms' => array(), 'count' => get_option('posts_per_page'), 'taxonomy' => 'category', 'post_type' => 'post', 'priority' => 10, 'container' => true, 'persistent' => array('enabled', 'terms', 'count', 'taxonomy', 'post_type', 'type', 'title'), 'display_types' => array('node', 'quick', 'line', 'traditional'), 'use_main_query' => false, '_preview' => false);
     $args = wp_parse_args($override, $_defaults);
     if (is_array($args['persistent']) && !is_array($ar2_options)) {
         ar2_flush_theme_options();
     }
     if (is_array($args['persistent']) && isset($ar2_options['sections'][$this->id])) {
         $this->settings = wp_parse_args($ar2_options['sections'][$this->id], $args);
     } else {
         $this->settings = $args;
     }
     $this->priority =& $this->settings['priority'];
     /*if ( is_array( $this->settings[ 'persistent' ] ) && !isset( $ar2_options[ 'sections' ][ $this->id ] ) ) {
     		
     			foreach( $this->settings[ 'persistent' ] as $id ) {
     				if ( isset( $this->settings[ $id ] ) )
     					$ar2_options[ 'sections' ][ $this->id ][ $id ] = $this->settings[ $id ];
     			}
     			
     			update_option( 'ar2_theme_options', $ar2_options );
     			
     		}*/
 }
Ejemplo n.º 2
0
 /**
  * Updates settings from the database.
  * @since 2.0
  */
 public function flush_settings($override = array())
 {
     global $ar2_options;
     $_defaults = array('label' => sprintf(__('ID: %s', 'ar2'), $this->id), 'description' => '', 'priority' => 10, 'show_in_theme_options' => false, 'show_in_customize' => false, '_builtin' => false, 'hide_duplicates' => false, 'ignore_sticky' => false, 'persistent' => array('hide_duplicates', 'ignore_sticky'));
     $args = wp_parse_args($override, $_defaults);
     if (is_array($args['persistent']) && !is_array($ar2_options)) {
         ar2_flush_theme_options();
     }
     if (is_array($args['persistent']) && isset($ar2_options['zones'][$this->id])) {
         $this->settings = wp_parse_args($ar2_options['zones'][$this->id], $args);
     } else {
         $this->settings = $args;
     }
     if (is_array($this->settings['persistent'])) {
         foreach ($this->settings['persistent'] as $id) {
             if (isset($this->settings[$id])) {
                 $ar2_options['zones'][$this->id][$id] = $this->settings[$id];
             }
         }
         update_option('ar2_theme_options', $ar2_options);
     }
 }
Ejemplo n.º 3
0
/**
 * Renders individual field in theme options.
 * @since 1.6
 */
function ar2_theme_options_render_field($args = array())
{
    global $ar2_options;
    extract($args, EXTR_SKIP);
    if (!isset($value)) {
        if (!is_array($ar2_options)) {
            ar2_flush_theme_options();
        }
        $value = ar2_multidimensional_get($ar2_options, $_id_data['keys']);
    }
    switch ($type) {
        case 'thumbnail-size':
            ?>
			<div class="thumbnail-size-fields">
				<label for="'ar2_theme_options[<?php 
            echo $id;
            ?>
][w]"><?php 
            _e('Width', 'ar2');
            ?>
</label>
				<?php 
            echo ar2_form_input('ar2_theme_options[' . $id . '][w]', $width, 'class="thumb-width" style="width: 50px" maxlength="3"');
            ?>
				<span class="thumbnail_default_width" style="display: none"><?php 
            echo $d_width;
            ?>
</span>
				
				<label for="'ar2_theme_options[<?php 
            echo $id;
            ?>
][h]"><?php 
            _e('Height', 'ar2');
            ?>
</label>
				<?php 
            echo ar2_form_input('ar2_theme_options[' . $id . '][h]', $height, 'class="thumb-height" style="width: 50px" maxlength="3"');
            ?>
				<span class="thumbnail_default_height" style="display: none"><?php 
            echo $d_height;
            ?>
</span>
				
				<a class="reset-thumbnail-sizes button-secondary"><?php 
            _e('Reset to Defaults', 'ar2');
            ?>
</a>
			</div>
			<?php 
            break;
        case 'cat-dropdown':
            $_taxonomy_keys = array_slice($_id_data['keys'], 0, count($_id_data['keys']) - 1);
            $_taxonomy_keys[] = 'taxonomy';
            ?>
			<div class="cat-dropdown-container">
				<p class="cat-dropdown-multiselect">
					<?php 
            echo ar2_form_terms_dropdown($id, $setting, ar2_multidimensional_get($ar2_options, $_taxonomy_keys), $value);
            ?>
					<?php 
            $taxonomy = ar2_multidimensional_get($ar2_options, $_taxonomy_keys);
            echo ar2_form_dropdown('ar2_theme_options[' . $id . '][]', ar2_get_terms_list($taxonomy), $value, 'multiple="multiple" class="terms-multiselect"');
            ?>
				</p>
				<span style="display: none" class="choosetax"><?php 
            _e('Please choose your taxonomy before proceeding.', 'ar2');
            ?>
</span>
			</div>
			<?php 
            break;
        case 'taxonomies-dropdown':
            $_posttype_keys = array_slice($_id_data['keys'], 0, count($_id_data['keys']) - 1);
            $_posttype_keys[] = 'post_type';
            $_post_type = ar2_multidimensional_get($ar2_options, $_posttype_keys) == '' ? 'post' : ar2_multidimensional_get($ar2_options, $_posttype_keys);
            $taxonomy = get_taxonomy($value);
            echo '<span class="no-js-label">' . $taxonomy->labels->name . '</span>';
            ?>
			<div class="tax-dropdown-container">
				<?php 
            echo ar2_form_taxonomies_dropdown('ar2_theme_options[' . $id . ']', $_post_type, $value, $extras);
            ?>
 
				<img class="ajax-feedback" src="<?php 
            echo get_template_directory_uri();
            ?>
/images/admin/wpspin_light.gif" alt="<?php 
            _e('Loading', 'ar2');
            ?>
" />
			</div>
			<?php 
            break;
        case 'posttype-dropdown':
            $post_type = get_post_type_object($value);
            echo '<span class="no-js-label">' . $post_type->labels->name . '</span>';
            echo ar2_form_posttype_dropdown('ar2_theme_options[' . $id . ']', $value, $extras);
            break;
        case 'switch':
            echo '<input type="hidden" value="0" name="ar2_theme_options[' . $id . ']" />';
            echo '<div class="switch">';
            echo ar2_form_checkbox('ar2_theme_options[' . $id . ']', true, $value, 'id="ar2_theme_options[' . $id . ']"');
            echo '<label for="ar2_theme_options[' . $id . ']"><div class="switch-inner">';
            echo '<span class="switch-active">' . __('On', 'ar2') . '</span>';
            echo '<span class="switch-inactive">' . __('Off', 'ar2') . '</span>';
            echo '</div><div class="switch-node"></div></label></div>';
            break;
        case 'color-switcher':
            echo '<div class="color-switch">';
            foreach ($options as $color_id => $color) {
                if ($color_id == 'default') {
                    echo ar2_form_radio('ar2_theme_options[' . $id . ']', 'default', $value, 'id="' . $id . '-' . $color_id . '"');
                    echo '<label title="' . $color['label'] . '" class="default" for="' . $id . '-' . $color_id . '"><span>' . $color['label'] . '</span></label>';
                } else {
                    echo ar2_form_radio('ar2_theme_options[' . $id . ']', $color['hex'], $value, 'id="' . $id . '-' . $color_id . '"');
                    echo '<label title="' . $color['label'] . '" for="' . $id . '-' . $color_id . '"><span style="background: ' . $color['hex'] . '">' . $color['label'] . '</span></label>';
                }
            }
            echo '</div>';
            break;
        case 'media-upload':
            echo '<div class="media-upload">';
            echo '<p><img id="media-upload-img-' . $id . '" src="' . $value . '" alt="" /></p>';
            echo ar2_form_input('ar2_theme_options[' . $id . ']', $value, 'id="media-upload-' . $id . '"');
            echo '<input type="button" data-upload-field="' . $id . '" class="button media-upload-add" value="' . __('Add Image', 'ar2') . '" />';
            echo '<a href="#" data-upload-field="' . $id . '" class="media-upload-remove">' . __('Remove', 'ar2') . '</a>';
            echo '</div>';
            break;
        case 'input':
            echo ar2_form_input('ar2_theme_options[' . $id . ']', $value, $extras);
            break;
        case 'textarea':
            echo ar2_form_textarea('ar2_theme_options[' . $id . ']', $value, $extras);
            break;
        case 'textarea_html':
            echo ar2_form_textarea('ar2_theme_options[' . $id . ']', $value, $extras);
            break;
        case 'dropdown':
            echo ar2_form_dropdown('ar2_theme_options[' . $id . ']', $options, $value, $extras);
            break;
        case 'checkbox':
            echo '<input type="hidden" value="0" name="ar2_theme_options[' . $id . ']" />';
            echo ar2_form_checkbox('ar2_theme_options[' . $id . ']', true, $value, $extras);
            break;
        case 'custom':
            if ((string) $callback != '') {
                call_user_func($callback, array_merge($args, array('value' => $value)));
            }
            break;
        default:
            // default is static
            echo false != $content ? $content : '';
    }
    if (isset($description)) {
        if ($type == 'checkbox') {
            echo '&nbsp;';
        } else {
            echo '<br />';
        }
        echo '<span class="description">' . $description . '</span>';
    }
}
Ejemplo n.º 4
0
/**
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
 * @todo: Needs cleaning up.
 * @since 1.6
 */
function ar2_theme_options_validate($input)
{
    $output = ar2_flush_theme_options();
    $defaults = ar2_get_default_theme_options();
    if (isset($input['reset'])) {
        // Reset theme options to default settings.
        ar2_reset_theme_options();
        add_settings_error('reset', 'ar2-theme-options-reset', __('Your settings have been reverted to the defaults.', 'ar2'), 'updated');
        return $defaults;
    } else {
        if (isset($input['import_theme_options']) && $input['import_theme_options'] != '') {
            // Import theme options from user input.
            $output = json_decode($input['import_theme_options'], true);
            add_settings_error('import_theme_options', 'ar2-theme-options-import', __('Your settings have been successfully imported.', 'ar2'), 'updated');
            return $output;
        } else {
            if (isset($input['submit'])) {
                /* Validation for theme options page. Refer to WordPress Codex on Data Validation: 
                 * http://codex.wordpress.org/Data_Validation */
                $setting_fields = ar2_theme_options_default_fields();
                unset($input['export_theme_options']);
                unset($input['import_theme_options']);
                foreach ($input as $id => $value) {
                    if (isset($setting_fields[$id])) {
                        switch ($setting_fields[$id]['type']) {
                            case 'thumbnail-size':
                                $sanitized_val = array('w' => is_numeric($value['w']) ? absint($value['w']) : 0, 'h' => is_numeric($value['h']) ? absint($value['h']) : 0);
                                break;
                            case 'cat-dropdown':
                                $sanitized_val = ar2_theme_options_validate_terms_input($value);
                                break;
                            case 'taxonomies-dropdown':
                                if (taxonomy_exists($value)) {
                                    $sanitized_val = $value;
                                }
                                break;
                            case 'posttype-dropdown':
                                if (post_type_exists($value)) {
                                    $sanitized_val = $value;
                                }
                                break;
                            case 'color-switcher':
                                $sanitized_val = $value;
                                // do nothing
                                break;
                            case 'textarea_html':
                                $sanitized_val = esc_html($value);
                                break;
                            case 'wp_editor':
                                $sanitized_val = esc_html($value);
                                break;
                            case 'dropdown':
                                if (in_array($value, array_keys($setting_fields[$id]['options']))) {
                                    $sanitized_val = $value;
                                }
                                break;
                            case 'checkbox':
                                $sanitized_val = 1 == $value ? true : false;
                                break;
                            case 'switch':
                                $sanitized_val = 1 == $value ? true : false;
                                break;
                            case 'custom':
                                $sanitized_val = $value;
                                // do nothing
                                break;
                            default:
                                $sanitized_val = esc_attr($value);
                        }
                        $sanitized_val = apply_filters('ar2_theme_options_validate_setting-' . $id, $sanitized_val, $value, $output);
                        $output = ar2_multidimensional_replace($output, $setting_fields[$id]['_id_data']['keys'], $sanitized_val);
                    }
                }
                add_settings_error('submit', 'ar2-theme-options-submit', __('Your settings have been successfully saved.', 'ar2'), 'updated');
            } else {
                // Input from WP Customize
                $output = apply_filters('ar2_theme_customize_validate', $output, $input, $defaults);
            }
        }
    }
    // Leave for debugging purposes.
    /*
    echo '<pre><code>';
    print_r( $input );
    echo '</code></pre>';
    
    echo '<pre><code>';
    print_r( $output );
    echo '</code></pre>';
    */
    return apply_filters('ar2_theme_options_validate', $output, $input, $defaults);
}