示例#1
0
 /**
  * Create CSS styles from a background type.
  *
  * @since 1.0.0
  * @access public
  * @param array $background background values as an array
  * @param string $idtag
  * @param bool|string $important
  * @return mixed empty if sanitization failed, else array of sanitized properties arrays
  */
 function backgroundarray($background, $idtag = '', $important = false)
 {
     if (empty($idtag) || !is_string($idtag)) {
         $idtag = '';
     }
     /** Variables **/
     $output = array();
     $properties = array('color', 'type', 'pattern', 'image', 'repeat', 'position', 'attachment');
     $background_defaults = array('color' => '', 'type' => 'predefined', 'pattern' => 0, 'image' => '', 'repeat' => '', 'position' => '', 'attachment' => '');
     $background = wp_parse_args($background, $background_defaults);
     extract($background, EXTR_SKIP);
     /** Load Sanitization functions if not loaded already (for frontend) **/
     if (!function_exists('hoot_sanitize_enum')) {
         require_once trailingslashit(HOOT_INCLUDES) . 'sanitization.php';
     }
     /** Create CSS Rules **/
     if (!empty($color)) {
         $output['color'] = $this->css_rule_sanitized_array('background-color', $color, $idtag . '-color', $important);
     }
     if ('custom' == $type) {
         if (!empty($image)) {
             $output['image'] = $this->css_rule_sanitized_array('background-image', $image, $idtag . '-image', $important);
             if (!empty($repeat)) {
                 $output['repeat'] = $this->css_rule_sanitized_array('background-repeat', $repeat, $idtag . '-repeat', $important);
             }
             if (!empty($position)) {
                 $output['position'] = $this->css_rule_sanitized_array('background-position', $position, $idtag . '-position', $important);
             }
             if (!empty($attachment)) {
                 $output['attachment'] = $this->css_rule_sanitized_array('background-attachment', $attachment, $idtag . '-attachment', $important);
             }
         }
     } else {
         // 'predefined' == $type
         if (!empty($pattern)) {
             // skip if pattern = 0 (i.e. user has selected 'No Pattern')
             $recognized = hoot_enum_background_pattern();
             if (array_key_exists($pattern, $recognized)) {
                 $background_image = trailingslashit(THEME_URI) . $pattern;
                 $output['image'] = $this->css_rule_sanitized_array('background-image', $background_image, $idtag . '-pattern', $important);
                 $output['repeat'] = $this->css_rule_sanitized_array('background-repeat', 'repeat', '', $important);
             }
         }
     }
     $output = apply_filters('hoot_style_builder_background', $output, $idtag);
     /** Return **/
     if (is_array($output) && !empty($output)) {
         $return = array();
         foreach ($output as $rule) {
             if (!empty($rule) && is_array($rule)) {
                 $return = array_merge($return, $rule);
             }
         }
         return $return;
     }
     return '';
     // if $output is empty => failed sanitization checks
 }
示例#2
0
 function hoot_sanitize_background_pattern($value)
 {
     $recognized = hoot_enum_background_pattern();
     if (array_key_exists($value, $recognized)) {
         return $value;
     }
     return apply_filters('hoot_sanitize_default_background_pattern', current($recognized));
 }
示例#3
0
/**
 * Modify the settings array and prepare betterbackground settings for Customizer Library Interface functions
 *
 * @since 2.0.0
 * @param array $value
 * @param string $key
 * @param array $setting
 * @param int $count
 * @return void
 */
function hoot_customizer_prepare_betterbackground_settings($value, $key, $setting, $count)
{
    if ($setting['type'] == 'betterbackground') {
        $setting = wp_parse_args($setting, array('label' => '', 'section' => '', 'priority' => '', 'choices' => hoot_enum_background_pattern(), 'default' => array(), 'description' => '', 'options' => array('image', 'color', 'repeat', 'position', 'attachment', 'pattern')));
        $setting['default'] = wp_parse_args($setting['default'], array('type' => 'predefined', 'color' => '', 'image' => '', 'repeat' => 'repeat', 'position' => 'top center', 'attachment' => 'scroll', 'pattern' => '0'));
        if (is_array($setting['options']) && !empty($setting['options'])) {
            $color = in_array('color', $setting['options']);
            $image = in_array('image', $setting['options']);
            $repeat = in_array('repeat', $setting['options']);
            $position = in_array('position', $setting['options']);
            $attachment = in_array('attachment', $setting['options']);
            $pattern = in_array('pattern', $setting['options']) && !empty($setting['choices']);
            if ($color || $image || $pattern) {
                // Betterbackground Start
                $value["betterbackground-{$count}"] = array('label' => $setting['label'], 'section' => $setting['section'], 'type' => 'betterbackground', 'priority' => $setting['priority'], 'description' => $setting['description'], 'background' => 'start');
                // Background Color :: (priority & section same as betterbackground)
                if ($color) {
                    $value["{$key}-color"] = array('section' => $setting['section'], 'type' => 'color', 'priority' => $setting['priority'], 'default' => $setting['default']['color']);
                }
                // Background Type Button
                if ($image && $pattern) {
                    $value["{$key}-type"] = array('section' => $setting['section'], 'type' => 'betterbackground', 'priority' => $setting['priority'], 'default' => $setting['default']['type'], 'background' => 'button');
                }
                // Background Image :: (priority & section same as betterbackground)
                if ($image) {
                    $value["{$key}-image"] = array('section' => $setting['section'], 'type' => 'image', 'priority' => $setting['priority'], 'default' => $setting['default']['image']);
                    if ($repeat) {
                        $value["{$key}-repeat"] = array('section' => $setting['section'], 'type' => 'select', 'priority' => $setting['priority'], 'choices' => hoot_enum_background_repeat(), 'default' => $setting['default']['repeat']);
                    }
                    if ($position) {
                        $value["{$key}-position"] = array('section' => $setting['section'], 'type' => 'select', 'priority' => $setting['priority'], 'choices' => hoot_enum_background_position(), 'default' => $setting['default']['position']);
                    }
                    if ($attachment) {
                        $value["{$key}-attachment"] = array('section' => $setting['section'], 'type' => 'select', 'priority' => $setting['priority'], 'choices' => hoot_enum_background_attachment(), 'default' => $setting['default']['attachment']);
                    }
                }
                // Background Patterns :: (priority & section same as betterbackground)
                if ($pattern) {
                    // Group Start
                    $value["group-{$count}-p"] = array('section' => $setting['section'], 'type' => 'group', 'priority' => $setting['priority'], 'button' => '<span class="hoot-betterbackground-button-pattern"></span>' . __('Select Pattern', 'responsive-brix'), 'group' => 'start');
                    // Pattern Images
                    $value["{$key}-pattern"] = array('section' => $setting['section'], 'type' => 'radioimage', 'priority' => $setting['priority'], 'choices' => $setting['choices'], 'default' => $setting['default']['pattern']);
                    // Group End
                    $value["group-{$count}-p-end"] = array('section' => $setting['section'], 'type' => 'group', 'priority' => $setting['priority'], 'group' => 'end');
                }
                // Betterbackground End
                $value["betterbackground-{$count}-end"] = array('section' => $setting['section'], 'type' => 'betterbackground', 'priority' => $setting['priority'], 'background' => 'end');
            }
        }
    }
    return $value;
}