@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return array |
20 | 20 | */ |
21 | - public function normalize(array $attributes) |
|
21 | + public function normalize( array $attributes ) |
|
22 | 22 | { |
23 | - $hide = array_flip(explode(',', $attributes['hide'])); |
|
23 | + $hide = array_flip( explode( ',', $attributes['hide'] ) ); |
|
24 | 24 | unset($hide['if_empty']); |
25 | - $attributes['hide'] = implode(',', array_keys($hide)); |
|
26 | - if ('post_id' === Arr::get($attributes, 'assigned_to')) { |
|
25 | + $attributes['hide'] = implode( ',', array_keys( $hide ) ); |
|
26 | + if( 'post_id' === Arr::get( $attributes, 'assigned_to' ) ) { |
|
27 | 27 | $attributes['assigned_to'] = $attributes['post_id']; |
28 | - } elseif ('parent_id' === Arr::get($attributes, 'assigned_to')) { |
|
29 | - $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
|
28 | + } elseif( 'parent_id' === Arr::get( $attributes, 'assigned_to' ) ) { |
|
29 | + $attributes['assigned_to'] = wp_get_post_parent_id( $attributes['post_id'] ); |
|
30 | 30 | } |
31 | 31 | return $attributes; |
32 | 32 | } |
@@ -34,31 +34,31 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @return void |
36 | 36 | */ |
37 | - public function register($block) |
|
37 | + public function register( $block ) |
|
38 | 38 | { |
39 | - if (!function_exists('register_block_type')) { |
|
39 | + if( !function_exists( 'register_block_type' ) ) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | - register_block_type(Application::ID.'/'.$block, [ |
|
42 | + register_block_type( Application::ID.'/'.$block, [ |
|
43 | 43 | 'attributes' => $this->attributes(), |
44 | 44 | 'editor_script' => Application::ID.'/blocks', |
45 | 45 | 'editor_style' => Application::ID.'/blocks', |
46 | 46 | 'render_callback' => [$this, 'render'], |
47 | 47 | 'style' => Application::ID, |
48 | - ]); |
|
48 | + ] ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return void |
53 | 53 | */ |
54 | - abstract public function render(array $attributes); |
|
54 | + abstract public function render( array $attributes ); |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @return void |
58 | 58 | */ |
59 | 59 | protected function filterBlockClass() |
60 | 60 | { |
61 | - add_filter('site-reviews/style', function () { |
|
61 | + add_filter( 'site-reviews/style', function() { |
|
62 | 62 | return 'default'; |
63 | 63 | }); |
64 | 64 | } |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | * @param mixed $shortcode |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - protected function hasVisibleFields($shortcode, array $attributes) |
|
70 | + protected function hasVisibleFields( $shortcode, array $attributes ) |
|
71 | 71 | { |
72 | - $args = $shortcode->normalizeAtts($attributes); |
|
72 | + $args = $shortcode->normalizeAtts( $attributes ); |
|
73 | 73 | $defaults = $shortcode->getHideOptions(); |
74 | - $hide = array_flip($args['hide']); |
|
74 | + $hide = array_flip( $args['hide'] ); |
|
75 | 75 | unset($defaults['if_empty'], $hide['if_empty']); |
76 | - return !empty(array_diff_key($defaults, $hide)); |
|
76 | + return !empty(array_diff_key( $defaults, $hide )); |
|
77 | 77 | } |
78 | 78 | } |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * @param string $search |
10 | 10 | * @return string |
11 | 11 | */ |
12 | - public static function afterLast($subject, $search) |
|
12 | + public static function afterLast( $subject, $search ) |
|
13 | 13 | { |
14 | 14 | return '' === $search |
15 | 15 | ? $subject |
16 | - : array_reverse(explode($search, $subject))[0]; |
|
16 | + : array_reverse( explode( $search, $subject ) )[0]; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,19 +21,19 @@ discard block |
||
21 | 21 | * @param string $search |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - public static function before($subject, $search) |
|
24 | + public static function before( $subject, $search ) |
|
25 | 25 | { |
26 | - return $search === '' ? $subject : explode($search, $subject)[0]; |
|
26 | + return $search === '' ? $subject : explode( $search, $subject )[0]; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @param string $string |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public static function camelCase($string) |
|
33 | + public static function camelCase( $string ) |
|
34 | 34 | { |
35 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
36 | - return str_replace(' ', '', $string); |
|
35 | + $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) ); |
|
36 | + return str_replace( ' ', '', $string ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * @param string $needle |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public static function contains($haystack, $needle) |
|
44 | + public static function contains( $haystack, $needle ) |
|
45 | 45 | { |
46 | - return false !== strpos($haystack, $needle); |
|
46 | + return false !== strpos( $haystack, $needle ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,27 +52,27 @@ discard block |
||
52 | 52 | * @param string $initialType period|period_space|space |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
55 | + public static function convertName( $name, $nameType = '', $initialType = '' ) |
|
56 | 56 | { |
57 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
58 | - $firstName = array_shift($names); |
|
59 | - $lastName = array_pop($names); |
|
57 | + $names = preg_split( '/\W/', $name, 0, PREG_SPLIT_NO_EMPTY ); |
|
58 | + $firstName = array_shift( $names ); |
|
59 | + $lastName = array_pop( $names ); |
|
60 | 60 | $initialTypes = [ |
61 | 61 | 'period' => '.', |
62 | 62 | 'period_space' => '. ', |
63 | 63 | 'space' => ' ', |
64 | 64 | ]; |
65 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
66 | - if ('initials' == $nameType) { |
|
67 | - return static::convertToInitials($name, $initialPunctuation); |
|
65 | + $initialPunctuation = (string)Arr::get( $initialTypes, $initialType, ' ' ); |
|
66 | + if( 'initials' == $nameType ) { |
|
67 | + return static::convertToInitials( $name, $initialPunctuation ); |
|
68 | 68 | } |
69 | 69 | $nameTypes = [ |
70 | 70 | 'first' => $firstName, |
71 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
71 | + 'first_initial' => substr( $firstName, 0, 1 ).$initialPunctuation.$lastName, |
|
72 | 72 | 'last' => $lastName, |
73 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
73 | + 'last_initial' => $firstName.' '.substr( $lastName, 0, 1 ).$initialPunctuation, |
|
74 | 74 | ]; |
75 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
75 | + return trim( (string)Arr::get( $nameTypes, $nameType, $name ) ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @param string $prefix |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public static function convertPathToId($path, $prefix = '') |
|
83 | + public static function convertPathToId( $path, $prefix = '' ) |
|
84 | 84 | { |
85 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
85 | + return str_replace( ['[', ']'], ['-', ''], static::convertPathToName( $path, $prefix ) ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * @param string $prefix |
91 | 91 | * @return string |
92 | 92 | */ |
93 | - public static function convertPathToName($path, $prefix = '') |
|
93 | + public static function convertPathToName( $path, $prefix = '' ) |
|
94 | 94 | { |
95 | - $levels = explode('.', $path); |
|
96 | - return array_reduce($levels, function ($result, $value) { |
|
95 | + $levels = explode( '.', $path ); |
|
96 | + return array_reduce( $levels, function( $result, $value ) { |
|
97 | 97 | return $result .= '['.$value.']'; |
98 | - }, $prefix); |
|
98 | + }, $prefix ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | * @param string $initialPunctuation |
104 | 104 | * @return string |
105 | 105 | */ |
106 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
106 | + public static function convertToInitials( $name, $initialPunctuation = '' ) |
|
107 | 107 | { |
108 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
109 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
110 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
108 | + preg_match_all( '/(?<=\s|\b)\pL/u', $name, $matches ); |
|
109 | + return array_reduce( $matches[0], function( $carry, $word ) use ($initialPunctuation) { |
|
110 | + return $carry.strtoupper( substr( $word, 0, 1 ) ).$initialPunctuation; |
|
111 | 111 | }); |
112 | 112 | } |
113 | 113 | |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * @param string $string |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public static function dashCase($string) |
|
118 | + public static function dashCase( $string ) |
|
119 | 119 | { |
120 | - return str_replace('_', '-', static::snakeCase($string)); |
|
120 | + return str_replace( '_', '-', static::snakeCase( $string ) ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * @param string $haystack |
126 | 126 | * @return bool |
127 | 127 | */ |
128 | - public static function endsWith($needle, $haystack) |
|
128 | + public static function endsWith( $needle, $haystack ) |
|
129 | 129 | { |
130 | - $length = strlen($needle); |
|
130 | + $length = strlen( $needle ); |
|
131 | 131 | return 0 != $length |
132 | - ? substr($haystack, -$length) === $needle |
|
132 | + ? substr( $haystack, -$length ) === $needle |
|
133 | 133 | : true; |
134 | 134 | } |
135 | 135 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | * @param string|null $trim |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public static function prefix($prefix, $string, $trim = null) |
|
142 | + public static function prefix( $prefix, $string, $trim = null ) |
|
143 | 143 | { |
144 | - if (empty($string)) { |
|
144 | + if( empty($string) ) { |
|
145 | 145 | return $string; |
146 | 146 | } |
147 | - if (null === $trim) { |
|
147 | + if( null === $trim ) { |
|
148 | 148 | $trim = $prefix; |
149 | 149 | } |
150 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
150 | + return $prefix.trim( static::removePrefix( $trim, $string ) ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | * @param string $string |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public static function removePrefix($prefix, $string) |
|
158 | + public static function removePrefix( $prefix, $string ) |
|
159 | 159 | { |
160 | - return static::startsWith($prefix, $string) |
|
161 | - ? substr($string, strlen($prefix)) |
|
160 | + return static::startsWith( $prefix, $string ) |
|
161 | + ? substr( $string, strlen( $prefix ) ) |
|
162 | 162 | : $string; |
163 | 163 | } |
164 | 164 | |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | * @param string $subject |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - public static function replaceFirst($search, $replace, $subject) |
|
171 | + public static function replaceFirst( $search, $replace, $subject ) |
|
172 | 172 | { |
173 | - if ($search == '') { |
|
173 | + if( $search == '' ) { |
|
174 | 174 | return $subject; |
175 | 175 | } |
176 | - $position = strpos($subject, $search); |
|
177 | - if ($position !== false) { |
|
178 | - return substr_replace($subject, $replace, $position, strlen($search)); |
|
176 | + $position = strpos( $subject, $search ); |
|
177 | + if( $position !== false ) { |
|
178 | + return substr_replace( $subject, $replace, $position, strlen( $search ) ); |
|
179 | 179 | } |
180 | 180 | return $subject; |
181 | 181 | } |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | * @param string $subject |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public static function replaceLast($search, $replace, $subject) |
|
189 | + public static function replaceLast( $search, $replace, $subject ) |
|
190 | 190 | { |
191 | - $position = strrpos($subject, $search); |
|
192 | - if ($position !== false) { |
|
193 | - return substr_replace($subject, $replace, $position, strlen($search)); |
|
191 | + $position = strrpos( $subject, $search ); |
|
192 | + if( $position !== false ) { |
|
193 | + return substr_replace( $subject, $replace, $position, strlen( $search ) ); |
|
194 | 194 | } |
195 | 195 | return $subject; |
196 | 196 | } |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | * @param string $string |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public static function snakeCase($string) |
|
202 | + public static function snakeCase( $string ) |
|
203 | 203 | { |
204 | - if (!ctype_lower($string)) { |
|
205 | - $string = preg_replace('/\s+/u', '', $string); |
|
206 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
207 | - $string = function_exists('mb_strtolower') |
|
208 | - ? mb_strtolower($string, 'UTF-8') |
|
209 | - : strtolower($string); |
|
204 | + if( !ctype_lower( $string ) ) { |
|
205 | + $string = preg_replace( '/\s+/u', '', $string ); |
|
206 | + $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
207 | + $string = function_exists( 'mb_strtolower' ) |
|
208 | + ? mb_strtolower( $string, 'UTF-8' ) |
|
209 | + : strtolower( $string ); |
|
210 | 210 | } |
211 | - return str_replace('-', '_', $string); |
|
211 | + return str_replace( '-', '_', $string ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * @param string $haystack |
217 | 217 | * @return bool |
218 | 218 | */ |
219 | - public static function startsWith($needle, $haystack) |
|
219 | + public static function startsWith( $needle, $haystack ) |
|
220 | 220 | { |
221 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
221 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | * @param int $length |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public static function truncate($string, $length) |
|
229 | + public static function truncate( $string, $length ) |
|
230 | 230 | { |
231 | - return strlen($string) > $length |
|
232 | - ? substr($string, 0, $length) |
|
231 | + return strlen( $string ) > $length |
|
232 | + ? substr( $string, 0, $length ) |
|
233 | 233 | : $string; |
234 | 234 | } |
235 | 235 | } |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * @return bool |
9 | 9 | */ |
10 | - public static function compare(array $arr1, array $arr2) |
|
10 | + public static function compare( array $arr1, array $arr2 ) |
|
11 | 11 | { |
12 | - sort($arr1); |
|
13 | - sort($arr2); |
|
12 | + sort( $arr1 ); |
|
13 | + sort( $arr2 ); |
|
14 | 14 | return $arr1 == $arr2; |
15 | 15 | } |
16 | 16 | |
@@ -18,21 +18,21 @@ discard block |
||
18 | 18 | * @param mixed $array |
19 | 19 | * @return array |
20 | 20 | */ |
21 | - public static function consolidate($array) |
|
21 | + public static function consolidate( $array ) |
|
22 | 22 | { |
23 | - return is_array($array) || is_object($array) |
|
24 | - ? (array) $array |
|
23 | + return is_array( $array ) || is_object( $array ) |
|
24 | + ? (array)$array |
|
25 | 25 | : []; |
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @return array |
30 | 30 | */ |
31 | - public static function convertFromDotNotation(array $array) |
|
31 | + public static function convertFromDotNotation( array $array ) |
|
32 | 32 | { |
33 | 33 | $results = []; |
34 | - foreach ($array as $path => $value) { |
|
35 | - $results = static::set($results, $path, $value); |
|
34 | + foreach( $array as $path => $value ) { |
|
35 | + $results = static::set( $results, $path, $value ); |
|
36 | 36 | } |
37 | 37 | return $results; |
38 | 38 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | * @param mixed $callback |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public static function convertFromString($string, $callback = null) |
|
45 | + public static function convertFromString( $string, $callback = null ) |
|
46 | 46 | { |
47 | - $array = array_map('trim', explode(',', $string)); |
|
47 | + $array = array_map( 'trim', explode( ',', $string ) ); |
|
48 | 48 | return $callback |
49 | - ? array_filter($array, $callback) |
|
50 | - : array_filter($array); |
|
49 | + ? array_filter( $array, $callback ) |
|
50 | + : array_filter( $array ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | * @param string $prefix |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - public static function flatten(array $array, $flattenValue = false, $prefix = '') |
|
58 | + public static function flatten( array $array, $flattenValue = false, $prefix = '' ) |
|
59 | 59 | { |
60 | 60 | $result = []; |
61 | - foreach ($array as $key => $value) { |
|
62 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
63 | - if (static::isIndexedAndFlat($value)) { |
|
64 | - if ($flattenValue) { |
|
65 | - $value = '['.implode(', ', $value).']'; |
|
61 | + foreach( $array as $key => $value ) { |
|
62 | + $newKey = ltrim( $prefix.'.'.$key, '.' ); |
|
63 | + if( static::isIndexedAndFlat( $value ) ) { |
|
64 | + if( $flattenValue ) { |
|
65 | + $value = '['.implode( ', ', $value ).']'; |
|
66 | 66 | } |
67 | - } elseif (is_array($value)) { |
|
68 | - $result = array_merge($result, static::flatten($value, $flattenValue, $newKey)); |
|
67 | + } elseif( is_array( $value ) ) { |
|
68 | + $result = array_merge( $result, static::flatten( $value, $flattenValue, $newKey ) ); |
|
69 | 69 | continue; |
70 | 70 | } |
71 | 71 | $result[$newKey] = $value; |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | * @param mixed $fallback |
81 | 81 | * @return mixed |
82 | 82 | */ |
83 | - public static function get($data, $path = '', $fallback = '') |
|
83 | + public static function get( $data, $path = '', $fallback = '' ) |
|
84 | 84 | { |
85 | - $data = static::consolidate($data); |
|
86 | - $keys = explode('.', $path); |
|
87 | - foreach ($keys as $key) { |
|
88 | - if (!isset($data[$key])) { |
|
85 | + $data = static::consolidate( $data ); |
|
86 | + $keys = explode( '.', $path ); |
|
87 | + foreach( $keys as $key ) { |
|
88 | + if( !isset($data[$key]) ) { |
|
89 | 89 | return $fallback; |
90 | 90 | } |
91 | 91 | $data = $data[$key]; |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | * @param string $key |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public static function insertAfter($key, array $array, array $insert) |
|
100 | + public static function insertAfter( $key, array $array, array $insert ) |
|
101 | 101 | { |
102 | - return static::insert($array, $insert, $key, 'after'); |
|
102 | + return static::insert( $array, $insert, $key, 'after' ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | 106 | * @param string $key |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public static function insertBefore($key, array $array, array $insert) |
|
109 | + public static function insertBefore( $key, array $array, array $insert ) |
|
110 | 110 | { |
111 | - return static::insert($array, $insert, $key, 'before'); |
|
111 | + return static::insert( $array, $insert, $key, 'before' ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,47 +116,47 @@ discard block |
||
116 | 116 | * @param string $position |
117 | 117 | * @return array |
118 | 118 | */ |
119 | - public static function insert(array $array, array $insert, $key, $position = 'before') |
|
119 | + public static function insert( array $array, array $insert, $key, $position = 'before' ) |
|
120 | 120 | { |
121 | - $keyPosition = intval(array_search($key, array_keys($array))); |
|
122 | - if ('after' == $position) { |
|
121 | + $keyPosition = intval( array_search( $key, array_keys( $array ) ) ); |
|
122 | + if( 'after' == $position ) { |
|
123 | 123 | ++$keyPosition; |
124 | 124 | } |
125 | - if (false !== $keyPosition) { |
|
126 | - $result = array_slice($array, 0, $keyPosition); |
|
127 | - $result = array_merge($result, $insert); |
|
128 | - return array_merge($result, array_slice($array, $keyPosition)); |
|
125 | + if( false !== $keyPosition ) { |
|
126 | + $result = array_slice( $array, 0, $keyPosition ); |
|
127 | + $result = array_merge( $result, $insert ); |
|
128 | + return array_merge( $result, array_slice( $array, $keyPosition ) ); |
|
129 | 129 | } |
130 | - return array_merge($array, $insert); |
|
130 | + return array_merge( $array, $insert ); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @param mixed $array |
135 | 135 | * @return bool |
136 | 136 | */ |
137 | - public static function isIndexedAndFlat($array) |
|
137 | + public static function isIndexedAndFlat( $array ) |
|
138 | 138 | { |
139 | - if (!is_array($array) || array_filter($array, 'is_array')) { |
|
139 | + if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | - return wp_is_numeric_array($array); |
|
142 | + return wp_is_numeric_array( $array ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @param bool $prefixed |
147 | 147 | * @return array |
148 | 148 | */ |
149 | - public static function prefixKeys(array $values, $prefixed = true) |
|
149 | + public static function prefixKeys( array $values, $prefixed = true ) |
|
150 | 150 | { |
151 | 151 | $trim = '_'; |
152 | 152 | $prefix = $prefixed |
153 | 153 | ? $trim |
154 | 154 | : ''; |
155 | 155 | $prefixed = []; |
156 | - foreach ($values as $key => $value) { |
|
157 | - $key = trim($key); |
|
158 | - if (0 === strpos($key, $trim)) { |
|
159 | - $key = substr($key, strlen($trim)); |
|
156 | + foreach( $values as $key => $value ) { |
|
157 | + $key = trim( $key ); |
|
158 | + if( 0 === strpos( $key, $trim ) ) { |
|
159 | + $key = substr( $key, strlen( $trim ) ); |
|
160 | 160 | } |
161 | 161 | $prefixed[$prefix.$key] = $value; |
162 | 162 | } |
@@ -166,15 +166,15 @@ discard block |
||
166 | 166 | /** |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - public static function removeEmptyValues(array $array) |
|
169 | + public static function removeEmptyValues( array $array ) |
|
170 | 170 | { |
171 | 171 | $result = []; |
172 | - foreach ($array as $key => $value) { |
|
173 | - if (!$value) { |
|
172 | + foreach( $array as $key => $value ) { |
|
173 | + if( !$value ) { |
|
174 | 174 | continue; |
175 | 175 | } |
176 | - $result[$key] = is_array($value) |
|
177 | - ? static::removeEmptyValues($value) |
|
176 | + $result[$key] = is_array( $value ) |
|
177 | + ? static::removeEmptyValues( $value ) |
|
178 | 178 | : $value; |
179 | 179 | } |
180 | 180 | return $result; |
@@ -187,14 +187,14 @@ discard block |
||
187 | 187 | * @param mixed $value |
188 | 188 | * @return array |
189 | 189 | */ |
190 | - public static function set(array $data, $path, $value) |
|
190 | + public static function set( array $data, $path, $value ) |
|
191 | 191 | { |
192 | - $token = strtok($path, '.'); |
|
192 | + $token = strtok( $path, '.' ); |
|
193 | 193 | $ref = &$data; |
194 | - while (false !== $token) { |
|
195 | - $ref = static::consolidate($ref); |
|
194 | + while( false !== $token ) { |
|
195 | + $ref = static::consolidate( $ref ); |
|
196 | 196 | $ref = &$ref[$token]; |
197 | - $token = strtok('.'); |
|
197 | + $token = strtok( '.' ); |
|
198 | 198 | } |
199 | 199 | $ref = $value; |
200 | 200 | return $data; |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | /** |
204 | 204 | * @return array |
205 | 205 | */ |
206 | - public static function unique(array $values) |
|
206 | + public static function unique( array $values ) |
|
207 | 207 | { |
208 | - return array_filter(array_unique($values)); |
|
208 | + return array_filter( array_unique( $values ) ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | 212 | * @return array |
213 | 213 | */ |
214 | - public static function unprefixKeys(array $values) |
|
214 | + public static function unprefixKeys( array $values ) |
|
215 | 215 | { |
216 | - return static::prefixKeys($values, false); |
|
216 | + return static::prefixKeys( $values, false ); |
|
217 | 217 | } |
218 | 218 | } |
@@ -11,47 +11,47 @@ discard block |
||
11 | 11 | * @param array $instance |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function form($instance) |
|
14 | + public function form( $instance ) |
|
15 | 15 | { |
16 | - $this->widgetArgs = $this->shortcode()->normalizeAtts($instance); |
|
17 | - $terms = glsr(Database::class)->getTerms(); |
|
18 | - $this->renderField('text', [ |
|
16 | + $this->widgetArgs = $this->shortcode()->normalizeAtts( $instance ); |
|
17 | + $terms = glsr( Database::class )->getTerms(); |
|
18 | + $this->renderField( 'text', [ |
|
19 | 19 | 'class' => 'widefat', |
20 | - 'label' => __('Title', 'site-reviews'), |
|
20 | + 'label' => __( 'Title', 'site-reviews' ), |
|
21 | 21 | 'name' => 'title', |
22 | - ]); |
|
23 | - if (count(glsr()->reviewTypes) > 1) { |
|
24 | - $this->renderField('select', [ |
|
22 | + ] ); |
|
23 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
24 | + $this->renderField( 'select', [ |
|
25 | 25 | 'class' => 'widefat', |
26 | - 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
26 | + 'label' => __( 'Which type of review would you like to use?', 'site-reviews' ), |
|
27 | 27 | 'name' => 'type', |
28 | - 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
29 | - ]); |
|
28 | + 'options' => ['' => __( 'All review types', 'site-reviews' )] + glsr()->reviewTypes, |
|
29 | + ] ); |
|
30 | 30 | } |
31 | - if (!empty($terms)) { |
|
32 | - $this->renderField('select', [ |
|
31 | + if( !empty($terms) ) { |
|
32 | + $this->renderField( 'select', [ |
|
33 | 33 | 'class' => 'widefat', |
34 | - 'label' => __('Limit summary to this category', 'site-reviews'), |
|
34 | + 'label' => __( 'Limit summary to this category', 'site-reviews' ), |
|
35 | 35 | 'name' => 'category', |
36 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
37 | - ]); |
|
36 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
37 | + ] ); |
|
38 | 38 | } |
39 | - $this->renderField('text', [ |
|
39 | + $this->renderField( 'text', [ |
|
40 | 40 | 'class' => 'widefat', |
41 | 41 | 'default' => '', |
42 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
43 | - 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
42 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
43 | + 'label' => __( 'Limit summary to reviews assigned to a page/post ID', 'site-reviews' ), |
|
44 | 44 | 'name' => 'assigned_to', |
45 | - ]); |
|
46 | - $this->renderField('text', [ |
|
45 | + ] ); |
|
46 | + $this->renderField( 'text', [ |
|
47 | 47 | 'class' => 'widefat', |
48 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
48 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
49 | 49 | 'name' => 'class', |
50 | - ]); |
|
51 | - $this->renderField('checkbox', [ |
|
50 | + ] ); |
|
51 | + $this->renderField( 'checkbox', [ |
|
52 | 52 | 'name' => 'hide', |
53 | 53 | 'options' => $this->shortcode()->getHideOptions(), |
54 | - ]); |
|
54 | + ] ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,6 +59,6 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function shortcode() |
61 | 61 | { |
62 | - return glsr(SiteReviewsSummaryShortcode::class); |
|
62 | + return glsr( SiteReviewsSummaryShortcode::class ); |
|
63 | 63 | } |
64 | 64 | } |
@@ -11,66 +11,66 @@ discard block |
||
11 | 11 | * @param array $instance |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function form($instance) |
|
14 | + public function form( $instance ) |
|
15 | 15 | { |
16 | - $this->widgetArgs = $this->shortcode()->normalizeAtts($instance); |
|
17 | - $terms = glsr(Database::class)->getTerms(); |
|
18 | - $this->renderField('text', [ |
|
16 | + $this->widgetArgs = $this->shortcode()->normalizeAtts( $instance ); |
|
17 | + $terms = glsr( Database::class )->getTerms(); |
|
18 | + $this->renderField( 'text', [ |
|
19 | 19 | 'class' => 'widefat', |
20 | - 'label' => __('Title', 'site-reviews'), |
|
20 | + 'label' => __( 'Title', 'site-reviews' ), |
|
21 | 21 | 'name' => 'title', |
22 | - ]); |
|
23 | - $this->renderField('number', [ |
|
22 | + ] ); |
|
23 | + $this->renderField( 'number', [ |
|
24 | 24 | 'class' => 'small-text', |
25 | 25 | 'default' => 10, |
26 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
26 | + 'label' => __( 'How many reviews would you like to display?', 'site-reviews' ), |
|
27 | 27 | 'max' => 100, |
28 | 28 | 'name' => 'display', |
29 | - ]); |
|
30 | - $this->renderField('select', [ |
|
31 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
29 | + ] ); |
|
30 | + $this->renderField( 'select', [ |
|
31 | + 'label' => __( 'What is the minimum rating to display?', 'site-reviews' ), |
|
32 | 32 | 'name' => 'rating', |
33 | 33 | 'options' => [ |
34 | - '0' => sprintf(_n('%s star', '%s stars', 0, 'site-reviews'), 0), |
|
35 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
36 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
37 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
38 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
39 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
34 | + '0' => sprintf( _n( '%s star', '%s stars', 0, 'site-reviews' ), 0 ), |
|
35 | + '1' => sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ), |
|
36 | + '2' => sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ), |
|
37 | + '3' => sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ), |
|
38 | + '4' => sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ), |
|
39 | + '5' => sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ), |
|
40 | 40 | ], |
41 | - ]); |
|
42 | - if (count(glsr()->reviewTypes) > 1) { |
|
43 | - $this->renderField('select', [ |
|
41 | + ] ); |
|
42 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
43 | + $this->renderField( 'select', [ |
|
44 | 44 | 'class' => 'widefat', |
45 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
45 | + 'label' => __( 'Which type of review would you like to display?', 'site-reviews' ), |
|
46 | 46 | 'name' => 'type', |
47 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
48 | - ]); |
|
47 | + 'options' => ['' => __( 'All Reviews', 'site-reviews' )] + glsr()->reviewTypes, |
|
48 | + ] ); |
|
49 | 49 | } |
50 | - if (!empty($terms)) { |
|
51 | - $this->renderField('select', [ |
|
50 | + if( !empty($terms) ) { |
|
51 | + $this->renderField( 'select', [ |
|
52 | 52 | 'class' => 'widefat', |
53 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
53 | + 'label' => __( 'Limit reviews to this category', 'site-reviews' ), |
|
54 | 54 | 'name' => 'category', |
55 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
56 | - ]); |
|
55 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
56 | + ] ); |
|
57 | 57 | } |
58 | - $this->renderField('text', [ |
|
58 | + $this->renderField( 'text', [ |
|
59 | 59 | 'class' => 'widefat', |
60 | 60 | 'default' => '', |
61 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
62 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
61 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
62 | + 'label' => __( 'Limit reviews to those assigned to this page/post ID', 'site-reviews' ), |
|
63 | 63 | 'name' => 'assigned_to', |
64 | - ]); |
|
65 | - $this->renderField('text', [ |
|
64 | + ] ); |
|
65 | + $this->renderField( 'text', [ |
|
66 | 66 | 'class' => 'widefat', |
67 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
67 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
68 | 68 | 'name' => 'class', |
69 | - ]); |
|
70 | - $this->renderField('checkbox', [ |
|
69 | + ] ); |
|
70 | + $this->renderField( 'checkbox', [ |
|
71 | 71 | 'name' => 'hide', |
72 | 72 | 'options' => $this->shortcode()->getHideOptions(), |
73 | - ]); |
|
73 | + ] ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | * @param array $oldInstance |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - public function update($newInstance, $oldInstance) |
|
81 | + public function update( $newInstance, $oldInstance ) |
|
82 | 82 | { |
83 | - if (!is_numeric($newInstance['display'])) { |
|
83 | + if( !is_numeric( $newInstance['display'] ) ) { |
|
84 | 84 | $newInstance['display'] = 10; |
85 | 85 | } |
86 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
87 | - return parent::update($newInstance, $oldInstance); |
|
86 | + $newInstance['display'] = min( 50, max( 0, intval( $newInstance['display'] ) ) ); |
|
87 | + return parent::update( $newInstance, $oldInstance ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,6 +92,6 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function shortcode() |
94 | 94 | { |
95 | - return glsr(SiteReviewsShortcode::class); |
|
95 | + return glsr( SiteReviewsShortcode::class ); |
|
96 | 96 | } |
97 | 97 | } |
@@ -11,42 +11,42 @@ discard block |
||
11 | 11 | * @param array $instance |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function form($instance) |
|
14 | + public function form( $instance ) |
|
15 | 15 | { |
16 | - $this->widgetArgs = $this->shortcode()->normalizeAtts($instance); |
|
17 | - $terms = glsr(Database::class)->getTerms(); |
|
18 | - $this->renderField('text', [ |
|
16 | + $this->widgetArgs = $this->shortcode()->normalizeAtts( $instance ); |
|
17 | + $terms = glsr( Database::class )->getTerms(); |
|
18 | + $this->renderField( 'text', [ |
|
19 | 19 | 'class' => 'widefat', |
20 | - 'label' => __('Title', 'site-reviews'), |
|
20 | + 'label' => __( 'Title', 'site-reviews' ), |
|
21 | 21 | 'name' => 'title', |
22 | - ]); |
|
23 | - $this->renderField('textarea', [ |
|
22 | + ] ); |
|
23 | + $this->renderField( 'textarea', [ |
|
24 | 24 | 'class' => 'widefat', |
25 | - 'label' => __('Description', 'site-reviews'), |
|
25 | + 'label' => __( 'Description', 'site-reviews' ), |
|
26 | 26 | 'name' => 'description', |
27 | - ]); |
|
28 | - $this->renderField('select', [ |
|
27 | + ] ); |
|
28 | + $this->renderField( 'select', [ |
|
29 | 29 | 'class' => 'widefat', |
30 | - 'label' => __('Automatically assign a category', 'site-reviews'), |
|
30 | + 'label' => __( 'Automatically assign a category', 'site-reviews' ), |
|
31 | 31 | 'name' => 'category', |
32 | - 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
33 | - ]); |
|
34 | - $this->renderField('text', [ |
|
32 | + 'options' => ['' => __( 'Do not assign a category', 'site-reviews' )] + $terms, |
|
33 | + ] ); |
|
34 | + $this->renderField( 'text', [ |
|
35 | 35 | 'class' => 'widefat', |
36 | 36 | 'default' => '', |
37 | - 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
38 | - 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
37 | + 'description' => sprintf( __( 'You may also enter %s to assign to the current post.', 'site-reviews' ), '<code>post_id</code>' ), |
|
38 | + 'label' => __( 'Assign reviews to a custom page/post ID', 'site-reviews' ), |
|
39 | 39 | 'name' => 'assign_to', |
40 | - ]); |
|
41 | - $this->renderField('text', [ |
|
40 | + ] ); |
|
41 | + $this->renderField( 'text', [ |
|
42 | 42 | 'class' => 'widefat', |
43 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
43 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
44 | 44 | 'name' => 'class', |
45 | - ]); |
|
46 | - $this->renderField('checkbox', [ |
|
45 | + ] ); |
|
46 | + $this->renderField( 'checkbox', [ |
|
47 | 47 | 'name' => 'hide', |
48 | 48 | 'options' => $this->shortcode()->getHideOptions(), |
49 | - ]); |
|
49 | + ] ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,6 +54,6 @@ discard block |
||
54 | 54 | */ |
55 | 55 | protected function shortcode() |
56 | 56 | { |
57 | - return glsr(SiteReviewsFormShortcode::class); |
|
57 | + return glsr( SiteReviewsFormShortcode::class ); |
|
58 | 58 | } |
59 | 59 | } |
@@ -17,25 +17,25 @@ discard block |
||
17 | 17 | * @param array $instance |
18 | 18 | * @return void |
19 | 19 | */ |
20 | - public function widget($args, $instance) |
|
20 | + public function widget( $args, $instance ) |
|
21 | 21 | { |
22 | - echo $this->shortcode()->build($instance, $args, 'widget'); |
|
22 | + echo $this->shortcode()->build( $instance, $args, 'widget' ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @param string $tag |
27 | 27 | * @return array |
28 | 28 | */ |
29 | - protected function normalizeFieldAttributes($tag, array $args) |
|
29 | + protected function normalizeFieldAttributes( $tag, array $args ) |
|
30 | 30 | { |
31 | - if (empty($args['value'])) { |
|
31 | + if( empty($args['value']) ) { |
|
32 | 32 | $args['value'] = $this->widgetArgs[$args['name']]; |
33 | 33 | } |
34 | - if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
35 | - $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
34 | + if( empty($this->widgetArgs['options']) && in_array( $tag, ['checkbox', 'radio'] ) ) { |
|
35 | + $args['checked'] = in_array( $args['value'], (array)$this->widgetArgs[$args['name']] ); |
|
36 | 36 | } |
37 | - $args['id'] = $this->get_field_id($args['name']); |
|
38 | - $args['name'] = $this->get_field_name($args['name']); |
|
37 | + $args['id'] = $this->get_field_id( $args['name'] ); |
|
38 | + $args['name'] = $this->get_field_name( $args['name'] ); |
|
39 | 39 | $args['is_widget'] = true; |
40 | 40 | return $args; |
41 | 41 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @param string $tag |
45 | 45 | * @return void |
46 | 46 | */ |
47 | - protected function renderField($tag, array $args = []) |
|
47 | + protected function renderField( $tag, array $args = [] ) |
|
48 | 48 | { |
49 | - $args = $this->normalizeFieldAttributes($tag, $args); |
|
50 | - $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
51 | - echo glsr(Builder::class)->div($field, [ |
|
49 | + $args = $this->normalizeFieldAttributes( $tag, $args ); |
|
50 | + $field = glsr( Builder::class )->$tag( $args['name'], $args ); |
|
51 | + echo glsr( Builder::class )->div( $field, [ |
|
52 | 52 | 'class' => 'glsr-field', |
53 | - ]); |
|
53 | + ] ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -8,11 +8,11 @@ |
||
8 | 8 | * @params string|array $atts |
9 | 9 | * @return string |
10 | 10 | */ |
11 | - public function buildBlock($atts = []); |
|
11 | + public function buildBlock( $atts = [] ); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param string|array $atts |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function buildShortcode($atts = []); |
|
17 | + public function buildShortcode( $atts = [] ); |
|
18 | 18 | } |
@@ -35,45 +35,45 @@ discard block |
||
35 | 35 | * @param string $type |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
38 | + public function build( $atts, array $args = [], $type = 'shortcode' ) |
|
39 | 39 | { |
40 | - $args = $this->normalizeArgs($args, $type); |
|
41 | - $atts = $this->normalizeAtts($atts, $type); |
|
42 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
43 | - if (!empty($atts['title'])) { |
|
44 | - $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']); |
|
40 | + $args = $this->normalizeArgs( $args, $type ); |
|
41 | + $atts = $this->normalizeAtts( $atts, $type ); |
|
42 | + $partial = glsr( Partial::class )->build( $this->partialName, $atts ); |
|
43 | + if( !empty($atts['title']) ) { |
|
44 | + $atts = Arr::set( $atts, 'title', $args['before_title'].$atts['title'].$args['after_title'] ); |
|
45 | 45 | } |
46 | - $html = glsr(Builder::class)->div((string) $partial, [ |
|
47 | - 'class' => 'glsr glsr-'.glsr(Style::class)->get(), |
|
48 | - 'data-shortcode' => Str::snakeCase($this->partialName), |
|
46 | + $html = glsr( Builder::class )->div( (string)$partial, [ |
|
47 | + 'class' => 'glsr glsr-'.glsr( Style::class )->get(), |
|
48 | + 'data-shortcode' => Str::snakeCase( $this->partialName ), |
|
49 | 49 | 'data-type' => $type, |
50 | 50 | 'data-atts' => $atts['json'], // I prefer to have this attribute displayed last |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | return $args['before_widget'].$atts['title'].$html.$args['after_widget']; |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * {@inheritdoc} |
57 | 57 | */ |
58 | - public function buildBlock($atts = []) |
|
58 | + public function buildBlock( $atts = [] ) |
|
59 | 59 | { |
60 | - return $this->build($atts, [], 'block'); |
|
60 | + return $this->build( $atts, [], 'block' ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * {@inheritdoc} |
65 | 65 | */ |
66 | - public function buildShortcode($atts = []) |
|
66 | + public function buildShortcode( $atts = [] ) |
|
67 | 67 | { |
68 | - return $this->build($atts, [], 'shortcode'); |
|
68 | + return $this->build( $atts, [], 'shortcode' ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - public function getDefaults($atts) |
|
74 | + public function getDefaults( $atts ) |
|
75 | 75 | { |
76 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
76 | + return glsr( $this->getShortcodeDefaultsClassName() )->restrict( wp_parse_args( $atts ) ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | public function getHideOptions() |
83 | 83 | { |
84 | 84 | $options = $this->hideOptions(); |
85 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
85 | + return apply_filters( 'site-reviews/shortcode/hide-options', $options, $this->shortcodeName ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - public function getShortClassName($replace = '', $search = 'Shortcode') |
|
91 | + public function getShortClassName( $replace = '', $search = 'Shortcode' ) |
|
92 | 92 | { |
93 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
93 | + return str_replace( $search, $replace, (new ReflectionClass( $this ))->getShortName() ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function getShortcodeDefaultsClassName() |
100 | 100 | { |
101 | - $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this)); |
|
102 | - return str_replace('Shortcodes', 'Defaults', $className); |
|
101 | + $className = Str::replaceLast( 'Shortcode', 'Defaults', get_class( $this ) ); |
|
102 | + return str_replace( 'Shortcodes', 'Defaults', $className ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getShortcodeName() |
109 | 109 | { |
110 | - return Str::snakeCase($this->getShortClassName()); |
|
110 | + return Str::snakeCase( $this->getShortClassName() ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function getShortcodePartialName() |
117 | 117 | { |
118 | - return Str::dashCase($this->getShortClassName()); |
|
118 | + return Str::dashCase( $this->getShortClassName() ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @param string $type |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - public function normalizeArgs($args, $type = 'shortcode') |
|
126 | + public function normalizeArgs( $args, $type = 'shortcode' ) |
|
127 | 127 | { |
128 | - $args = wp_parse_args($args, [ |
|
128 | + $args = wp_parse_args( $args, [ |
|
129 | 129 | 'before_widget' => '', |
130 | 130 | 'after_widget' => '', |
131 | 131 | 'before_title' => '<h2 class="glsr-title">', |
132 | 132 | 'after_title' => '</h2>', |
133 | - ]); |
|
134 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
133 | + ] ); |
|
134 | + return apply_filters( 'site-reviews/shortcode/args', $args, $type, $this->partialName ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,18 +139,18 @@ discard block |
||
139 | 139 | * @param string $type |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
142 | + public function normalizeAtts( $atts, $type = 'shortcode' ) |
|
143 | 143 | { |
144 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
145 | - $atts = $this->getDefaults($atts); |
|
146 | - array_walk($atts, function (&$value, $key) { |
|
147 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
148 | - if (!method_exists($this, $methodName)) { |
|
144 | + $atts = apply_filters( 'site-reviews/shortcode/atts', $atts, $type, $this->partialName ); |
|
145 | + $atts = $this->getDefaults( $atts ); |
|
146 | + array_walk( $atts, function( &$value, $key ) { |
|
147 | + $methodName = Helper::buildMethodName( $key, 'normalize' ); |
|
148 | + if( !method_exists( $this, $methodName ) ) { |
|
149 | 149 | return; |
150 | 150 | } |
151 | - $value = $this->$methodName($value); |
|
151 | + $value = $this->$methodName( $value ); |
|
152 | 152 | }); |
153 | - $this->setId($atts); |
|
153 | + $this->setId( $atts ); |
|
154 | 154 | return $atts; |
155 | 155 | } |
156 | 156 | |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @param string $postId |
164 | 164 | * @return int|string |
165 | 165 | */ |
166 | - protected function normalizeAssignedTo($postId) |
|
166 | + protected function normalizeAssignedTo( $postId ) |
|
167 | 167 | { |
168 | - if ('parent_id' == $postId) { |
|
169 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
170 | - } elseif ('post_id' == $postId) { |
|
171 | - $postId = intval(get_the_ID()); |
|
168 | + if( 'parent_id' == $postId ) { |
|
169 | + $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) ); |
|
170 | + } elseif( 'post_id' == $postId ) { |
|
171 | + $postId = intval( get_the_ID() ); |
|
172 | 172 | } |
173 | 173 | return $postId; |
174 | 174 | } |
@@ -177,23 +177,23 @@ discard block |
||
177 | 177 | * @param string $postId |
178 | 178 | * @return int|string |
179 | 179 | */ |
180 | - protected function normalizeAssignTo($postId) |
|
180 | + protected function normalizeAssignTo( $postId ) |
|
181 | 181 | { |
182 | - return $this->normalizeAssignedTo($postId); |
|
182 | + return $this->normalizeAssignedTo( $postId ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | 186 | * @param string|array $hide |
187 | 187 | * @return array |
188 | 188 | */ |
189 | - protected function normalizeHide($hide) |
|
189 | + protected function normalizeHide( $hide ) |
|
190 | 190 | { |
191 | - if (is_string($hide)) { |
|
192 | - $hide = explode(',', $hide); |
|
191 | + if( is_string( $hide ) ) { |
|
192 | + $hide = explode( ',', $hide ); |
|
193 | 193 | } |
194 | - $hideKeys = array_keys($this->getHideOptions()); |
|
195 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
196 | - return in_array($value, $hideKeys); |
|
194 | + $hideKeys = array_keys( $this->getHideOptions() ); |
|
195 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use ($hideKeys) { |
|
196 | + return in_array( $value, $hideKeys ); |
|
197 | 197 | }); |
198 | 198 | } |
199 | 199 | |
@@ -201,61 +201,61 @@ discard block |
||
201 | 201 | * @param string $id |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - protected function normalizeId($id) |
|
204 | + protected function normalizeId( $id ) |
|
205 | 205 | { |
206 | - return sanitize_title($id); |
|
206 | + return sanitize_title( $id ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | 210 | * @param string $labels |
211 | 211 | * @return array |
212 | 212 | */ |
213 | - protected function normalizeLabels($labels) |
|
213 | + protected function normalizeLabels( $labels ) |
|
214 | 214 | { |
215 | 215 | $defaults = [ |
216 | - __('Excellent', 'site-reviews'), |
|
217 | - __('Very good', 'site-reviews'), |
|
218 | - __('Average', 'site-reviews'), |
|
219 | - __('Poor', 'site-reviews'), |
|
220 | - __('Terrible', 'site-reviews'), |
|
216 | + __( 'Excellent', 'site-reviews' ), |
|
217 | + __( 'Very good', 'site-reviews' ), |
|
218 | + __( 'Average', 'site-reviews' ), |
|
219 | + __( 'Poor', 'site-reviews' ), |
|
220 | + __( 'Terrible', 'site-reviews' ), |
|
221 | 221 | ]; |
222 | - $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
223 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
224 | - $labels = array_map('trim', explode(',', $labels)); |
|
225 | - foreach ($defaults as $i => $label) { |
|
226 | - if (empty($labels[$i])) { |
|
222 | + $maxRating = (int)glsr()->constant( 'MAX_RATING', Rating::class ); |
|
223 | + $defaults = array_pad( array_slice( $defaults, 0, $maxRating ), $maxRating, '' ); |
|
224 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
225 | + foreach( $defaults as $i => $label ) { |
|
226 | + if( empty($labels[$i]) ) { |
|
227 | 227 | continue; |
228 | 228 | } |
229 | 229 | $defaults[$i] = $labels[$i]; |
230 | 230 | } |
231 | - return array_combine(range($maxRating, 1), $defaults); |
|
231 | + return array_combine( range( $maxRating, 1 ), $defaults ); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @param string $schema |
236 | 236 | * @return bool |
237 | 237 | */ |
238 | - protected function normalizeSchema($schema) |
|
238 | + protected function normalizeSchema( $schema ) |
|
239 | 239 | { |
240 | - return wp_validate_boolean($schema); |
|
240 | + return wp_validate_boolean( $schema ); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | 244 | * @param string $text |
245 | 245 | * @return string |
246 | 246 | */ |
247 | - protected function normalizeText($text) |
|
247 | + protected function normalizeText( $text ) |
|
248 | 248 | { |
249 | - return trim($text); |
|
249 | + return trim( $text ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * @return void |
254 | 254 | */ |
255 | - protected function setId(array &$atts) |
|
255 | + protected function setId( array &$atts ) |
|
256 | 256 | { |
257 | - if (empty($atts['id'])) { |
|
258 | - $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
257 | + if( empty($atts['id']) ) { |
|
258 | + $atts['id'] = Application::PREFIX.substr( md5( serialize( $atts ) ), 0, 8 ); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |