PluginProbe
WP Ultimate Post Grid / 3.8.0
WP Ultimate Post Grid v3.8.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / includes / public / class-wpupg-filter.php

class-wpupg-filter.php in WP Ultimate Post Grid 3.8.0, at includes/public/class-wpupg-filter.php

141 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Responsible for grid filters.
4 *
5 * @link https://bootstrapped.ventures
6 * @since 3.0.0
7 *
8 * @package WP_Ultimate_Post_Grid
9 * @subpackage WP_Ultimate_Post_Grid/includes/public
10 */
11
12 /**
13 * Responsible for grid filters.
14 *
15 * @since 3.0.0
16 * @package WP_Ultimate_Post_Grid
17 * @subpackage WP_Ultimate_Post_Grid/includes/public
18 * @author Brecht Vandersmissen <brecht@bootstrapped.ventures>
19 */
20 class WPUPG_Filter {
21
22 /**
23 * Register actions and filters.
24 *
25 * @since 3.8.0
26 */
27 public static function init() {
28 add_filter( 'wpupg_filter_defaults', array( __CLASS__, 'responsive_defaults' ), 99 );
29 add_filter( 'wpupg_filter_sanitize_options', array( __CLASS__, 'responsive_sanitize' ), 99, 2 );
30 }
31
32 /**
33 * Get filter defaults.
34 *
35 * @since 3.0.0
36 * @param mixed $type Optional filter type to get the defaults for.
37 */
38 public static function get_defaults( $type = false ) {
39 $defaults = apply_filters( 'wpupg_filter_defaults', array() );
40
41 if ( false === $type ) {
42 return $defaults;
43 } else {
44 if ( isset( $defaults[ $type ] ) ) {
45 return $defaults[ $type ];
46 } else {
47 return false;
48 }
49 }
50 }
51
52 /**
53 * Default resposive options for all filters.
54 *
55 * @since 3.8.0
56 * @param mixed $defaults Current defaults to filter.
57 */
58 public static function responsive_defaults( $defaults ) {
59 foreach ( $defaults as $filter => $options ) {
60 $defaults[ $filter ]['responsive'] = array(
61 'desktop' => 'show',
62 'tablet' => 'show',
63 'mobile' => 'show',
64 );
65 }
66
67 return $defaults;
68 }
69
70 /**
71 * Sanitize resposive options for all filters when saving.
72 *
73 * @since 3.8.0
74 * @param mixed $sanitized_options Current sanitized options.
75 * @param mixed $filter Filter to sanitize.
76 */
77 public static function responsive_sanitize( $sanitized_options, $filter ) {
78 if ( isset( $filter['options']['responsive'] ) ) {
79 $sanitized_responsive = array();
80
81 // Limited options fields.
82 $field_options = array( 'show', 'hide', 'toggle_open', 'toggle_closed' );
83
84 foreach ( array( 'desktop', 'tablet', 'mobile' ) as $size ) {
85 if ( isset( $filter['options']['responsive'][ $size ] ) && in_array( $filter['options']['responsive'][ $size ], $field_options, true ) ) {
86 $sanitized_responsive[ $size ] = $filter['options']['responsive'][ $size ];
87 }
88 }
89
90 $sanitized_options['responsive'] = $sanitized_responsive;
91 }
92
93 return $sanitized_options;
94 }
95
96 /**
97 * Get filter with defaults.
98 *
99 * @since 3.0.0
100 * @param mixed $filter Filter to get the defaults for.
101 */
102 public static function filter_with_defaults( $filter ) {
103 if ( $filter && isset( $filter['type'] ) ) {
104 // Set default options.
105 $defaults = self::get_defaults( $filter['type'] );
106 if ( $defaults ) {
107 $filter['options'] = array_replace_recursive( $defaults, $filter['options'] );
108 }
109
110 // Set default label.
111 if ( ! isset( $filter['label'] ) ) {
112 $filter['label'] = '';
113 }
114 }
115
116 return $filter;
117 }
118
119 /**
120 * Get general filter style defaults.
121 *
122 * @since 3.1.0
123 */
124 public static function get_general_style_defaults() {
125 $defaults = apply_filters( 'wpupg_filter_general_style_defaults', array(
126 'display' => 'block',
127 'alignment' => 'left',
128 'spacing_vertical' => 10,
129 'spacing_horizontal' => 10,
130 'width' => 250,
131 'label_display' => 'block',
132 'label_alignment' => 'left',
133 'label_font_size' => 14,
134 'label_style' => 'bold',
135 ) );
136
137 return $defaults;
138 }
139 }
140
141 WPUPG_Filter::init();