@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return void|string |
30 | 30 | */ |
31 | - public function build(array $args = []) |
|
31 | + public function build( array $args = [] ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
35 | - if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
34 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args ); |
|
35 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
38 | + $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
|
39 | 39 | $this->generateSchema(); |
40 | - return glsr(Template::class)->build('templates/reviews-summary', [ |
|
40 | + return glsr( Template::class )->build( 'templates/reviews-summary', [ |
|
41 | 41 | 'context' => [ |
42 | 42 | 'assigned_to' => $this->args['assigned_to'], |
43 | 43 | 'category' => $this->args['category'], |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'stars' => $this->buildStars(), |
49 | 49 | 'text' => $this->buildText(), |
50 | 50 | ], |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -56,40 +56,40 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected function buildPercentage() |
58 | 58 | { |
59 | - if ($this->isHidden('bars')) { |
|
59 | + if( $this->isHidden( 'bars' ) ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | - $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
63 | - $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
64 | - $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
65 | - $background = $this->buildPercentageBackground($percentages[$level]); |
|
66 | - $count = apply_filters('site-reviews/summary/counts', |
|
62 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) ); |
|
63 | + $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use ($percentages) { |
|
64 | + $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
|
65 | + $background = $this->buildPercentageBackground( $percentages[$level] ); |
|
66 | + $count = apply_filters( 'site-reviews/summary/counts', |
|
67 | 67 | $percentages[$level], |
68 | 68 | $this->ratingCounts[$level] |
69 | 69 | ); |
70 | - $percent = $this->buildPercentageCount($count); |
|
70 | + $percent = $this->buildPercentageCount( $count ); |
|
71 | 71 | $value = $label.$background.$percent; |
72 | - $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
73 | - 'percent' => wp_strip_all_tags($count, true), |
|
72 | + $value = apply_filters( 'site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
73 | + 'percent' => wp_strip_all_tags( $count, true ), |
|
74 | 74 | 'rating' => $level, |
75 | - ]); |
|
76 | - return $carry.glsr(Builder::class)->div($value, [ |
|
75 | + ] ); |
|
76 | + return $carry.glsr( Builder::class )->div( $value, [ |
|
77 | 77 | 'class' => 'glsr-bar', |
78 | - ]); |
|
78 | + ] ); |
|
79 | 79 | }); |
80 | - return $this->wrap('percentage', $bars); |
|
80 | + return $this->wrap( 'percentage', $bars ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * @param string $percent |
85 | 85 | * @return string |
86 | 86 | */ |
87 | - protected function buildPercentageBackground($percent) |
|
87 | + protected function buildPercentageBackground( $percent ) |
|
88 | 88 | { |
89 | - $backgroundPercent = glsr(Builder::class)->span([ |
|
89 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
90 | 90 | 'class' => 'glsr-bar-background-percent', |
91 | 91 | 'style' => 'width:'.$percent, |
92 | - ]); |
|
92 | + ] ); |
|
93 | 93 | return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
94 | 94 | } |
95 | 95 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string $count |
98 | 98 | * @return string |
99 | 99 | */ |
100 | - protected function buildPercentageCount($count) |
|
100 | + protected function buildPercentageCount( $count ) |
|
101 | 101 | { |
102 | 102 | return '<span class="glsr-bar-percent">'.$count.'</span>'; |
103 | 103 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param string $label |
107 | 107 | * @return string |
108 | 108 | */ |
109 | - protected function buildPercentageLabel($label) |
|
109 | + protected function buildPercentageLabel( $label ) |
|
110 | 110 | { |
111 | 111 | return '<span class="glsr-bar-label">'.$label.'</span>'; |
112 | 112 | } |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function buildRating() |
118 | 118 | { |
119 | - if ($this->isHidden('rating')) { |
|
119 | + if( $this->isHidden( 'rating' ) ) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | - return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
122 | + return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildStars() |
129 | 129 | { |
130 | - if ($this->isHidden('stars')) { |
|
130 | + if( $this->isHidden( 'stars' ) ) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | - $stars = glsr_star_rating($this->averageRating); |
|
134 | - return $this->wrap('stars', $stars); |
|
133 | + $stars = glsr_star_rating( $this->averageRating ); |
|
134 | + return $this->wrap( 'stars', $stars ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function buildText() |
141 | 141 | { |
142 | - if ($this->isHidden('summary')) { |
|
142 | + if( $this->isHidden( 'summary' ) ) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | - $count = intval(array_sum($this->ratingCounts)); |
|
146 | - if (empty($this->args['text'])) { |
|
145 | + $count = intval( array_sum( $this->ratingCounts ) ); |
|
146 | + if( empty($this->args['text']) ) { |
|
147 | 147 | // @todo document this change |
148 | 148 | $this->args['text'] = _nx( |
149 | 149 | '{rating} out of {max} stars (based on {num} review)', |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | } |
156 | 156 | $summary = str_replace( |
157 | 157 | ['{rating}', '{max}', '{num}'], |
158 | - [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
158 | + [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count], |
|
159 | 159 | $this->args['text'] |
160 | 160 | ); |
161 | - return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
161 | + return $this->wrap( 'text', '<span>'.$summary.'</span>' ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | */ |
167 | 167 | protected function generateSchema() |
168 | 168 | { |
169 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
169 | + if( !wp_validate_boolean( $this->args['schema'] ) ) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | - glsr(Schema::class)->store( |
|
173 | - glsr(Schema::class)->buildSummary($this->args) |
|
172 | + glsr( Schema::class )->store( |
|
173 | + glsr( Schema::class )->buildSummary( $this->args ) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function getClass() |
181 | 181 | { |
182 | - return trim('glsr-summary glsr-default '.$this->args['class']); |
|
182 | + return trim( 'glsr-summary glsr-default '.$this->args['class'] ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | 186 | * @param string $key |
187 | 187 | * @return bool |
188 | 188 | */ |
189 | - protected function isHidden($key) |
|
189 | + protected function isHidden( $key ) |
|
190 | 190 | { |
191 | - return in_array($key, $this->args['hide']); |
|
191 | + return in_array( $key, $this->args['hide'] ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | * @param string $value |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - protected function wrap($key, $value) |
|
199 | + protected function wrap( $key, $value ) |
|
200 | 200 | { |
201 | - $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args); |
|
202 | - return glsr(Builder::class)->div($value, [ |
|
201 | + $value = apply_filters( 'site-reviews/summary/wrap/'.$key, $value, $this->args ); |
|
202 | + return glsr( Builder::class )->div( $value, [ |
|
203 | 203 | 'class' => 'glsr-summary-'.$key, |
204 | - ]); |
|
204 | + ] ); |
|
205 | 205 | } |
206 | 206 | } |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | * @param string $templatePath |
12 | 12 | * @return void|string |
13 | 13 | */ |
14 | - public function build($templatePath, array $data = []) |
|
14 | + public function build( $templatePath, array $data = [] ) |
|
15 | 15 | { |
16 | - $data = $this->normalize($data); |
|
17 | - $path = Str::removePrefix('templates/', $templatePath); |
|
18 | - $template = glsr()->build($templatePath, $data); |
|
19 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
20 | - $template = $this->interpolate($template, $data, $path); |
|
21 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
22 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
16 | + $data = $this->normalize( $data ); |
|
17 | + $path = Str::removePrefix( 'templates/', $templatePath ); |
|
18 | + $template = glsr()->build( $templatePath, $data ); |
|
19 | + $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data ); |
|
20 | + $template = $this->interpolate( $template, $data, $path ); |
|
21 | + $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data ); |
|
22 | + $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data ); |
|
23 | 23 | return $template; |
24 | 24 | } |
25 | 25 | |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | * @param string $templatePath |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function interpolate($template, array $data = [], $templatePath) |
|
32 | + public function interpolate( $template, array $data = [], $templatePath ) |
|
33 | 33 | { |
34 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
35 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
36 | - return $this->interpolateContext($template, $context); |
|
34 | + $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) ); |
|
35 | + $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data ); |
|
36 | + return $this->interpolateContext( $template, $context ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,35 +41,35 @@ discard block |
||
41 | 41 | * @param string $text |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - public function interpolateContext($text, array $context = []) |
|
44 | + public function interpolateContext( $text, array $context = [] ) |
|
45 | 45 | { |
46 | - foreach ($context as $key => $value) { |
|
46 | + foreach( $context as $key => $value ) { |
|
47 | 47 | $text = strtr( |
48 | 48 | $text, |
49 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
49 | + array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value ) |
|
50 | 50 | ); |
51 | 51 | } |
52 | - return trim($text); |
|
52 | + return trim( $text ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @param string $templatePath |
57 | 57 | * @return void|string |
58 | 58 | */ |
59 | - public function render($templatePath, array $data = []) |
|
59 | + public function render( $templatePath, array $data = [] ) |
|
60 | 60 | { |
61 | - echo $this->build($templatePath, $data); |
|
61 | + echo $this->build( $templatePath, $data ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - protected function normalize(array $data) |
|
67 | + protected function normalize( array $data ) |
|
68 | 68 | { |
69 | 69 | $arrayKeys = ['context', 'globals']; |
70 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
71 | - foreach ($arrayKeys as $key) { |
|
72 | - if (is_array($data[$key])) { |
|
70 | + $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) ); |
|
71 | + foreach( $arrayKeys as $key ) { |
|
72 | + if( is_array( $data[$key] ) ) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | $data[$key] = []; |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * @return array |
82 | 82 | */ |
83 | - protected function normalizeContext(array $context) |
|
83 | + protected function normalizeContext( array $context ) |
|
84 | 84 | { |
85 | - $context = array_filter($context, function ($value) { |
|
86 | - return !is_array($value) && !is_object($value); |
|
85 | + $context = array_filter( $context, function( $value ) { |
|
86 | + return !is_array( $value ) && !is_object( $value ); |
|
87 | 87 | }); |
88 | - return array_map(function ($value) { |
|
89 | - return (string) $value; |
|
90 | - }, $context); |
|
88 | + return array_map( function( $value ) { |
|
89 | + return (string)$value; |
|
90 | + }, $context ); |
|
91 | 91 | } |
92 | 92 | } |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * @return bool |
9 | 9 | */ |
10 | - public static function compareArrays(array $arr1, array $arr2) |
|
10 | + public static function compareArrays( 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 consolidateArray($array) |
|
21 | + public static function consolidateArray( $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 convertDotNotationArray(array $array) |
|
31 | + public static function convertDotNotationArray( 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 convertStringToArray($string, $callback = null) |
|
45 | + public static function convertStringToArray( $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 flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
58 | + public static function flattenArray( array $array, $flattenValue = false, $prefix = '' ) |
|
59 | 59 | { |
60 | 60 | $result = []; |
61 | - foreach ($array as $key => $value) { |
|
62 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
63 | - if (static::isIndexedFlatArray($value)) { |
|
64 | - if ($flattenValue) { |
|
65 | - $value = '['.implode(', ', $value).']'; |
|
61 | + foreach( $array as $key => $value ) { |
|
62 | + $newKey = ltrim( $prefix.'.'.$key, '.' ); |
|
63 | + if( static::isIndexedFlatArray( $value ) ) { |
|
64 | + if( $flattenValue ) { |
|
65 | + $value = '['.implode( ', ', $value ).']'; |
|
66 | 66 | } |
67 | - } elseif (is_array($value)) { |
|
68 | - $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey)); |
|
67 | + } elseif( is_array( $value ) ) { |
|
68 | + $result = array_merge( $result, static::flattenArray( $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::consolidateArray($data); |
|
86 | - $keys = explode('.', $path); |
|
87 | - foreach ($keys as $key) { |
|
88 | - if (!isset($data[$key])) { |
|
85 | + $data = static::consolidateArray( $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::insertInArray($array, $insert, $key, 'after'); |
|
102 | + return static::insertInArray( $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::insertInArray($array, $insert, $key, 'before'); |
|
111 | + return static::insertInArray( $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 insertInArray(array $array, array $insert, $key, $position = 'before') |
|
119 | + public static function insertInArray( 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 isIndexedFlatArray($array) |
|
137 | + public static function isIndexedFlatArray( $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 prefixArrayKeys(array $values, $prefixed = true) |
|
149 | + public static function prefixArrayKeys( 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 removeEmptyArrayValues(array $array) |
|
169 | + public static function removeEmptyArrayValues( 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::removeEmptyArrayValues($value) |
|
176 | + $result[$key] = is_array( $value ) |
|
177 | + ? static::removeEmptyArrayValues( $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::consolidateArray($ref); |
|
194 | + while( false !== $token ) { |
|
195 | + $ref = static::consolidateArray( $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 unprefixArrayKeys(array $values) |
|
214 | + public static function unprefixArrayKeys( array $values ) |
|
215 | 215 | { |
216 | - return static::prefixArrayKeys($values, false); |
|
216 | + return static::prefixArrayKeys( $values, false ); |
|
217 | 217 | } |
218 | 218 | } |
@@ -1,42 +1,42 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | -<?php if (glsr()->hasPermission('settings')) : ?> |
|
3 | +<?php if( glsr()->hasPermission( 'settings' ) ) : ?> |
|
4 | 4 | <div class="glsr-card card"> |
5 | 5 | <h3>Export Settings</h3> |
6 | 6 | <p>Export the Site Reviews settings for this site to a <code>*.json</code> file. This allows you to easily import the plugin settings into another site.</p> |
7 | - <p>To export your Site Reviews' reviews and categories, please use the WordPress <a href="<?= admin_url('export.php'); ?>">Export</a> tool.</p> |
|
7 | + <p>To export your Site Reviews' reviews and categories, please use the WordPress <a href="<?= admin_url( 'export.php' ); ?>">Export</a> tool.</p> |
|
8 | 8 | <form method="post"> |
9 | 9 | <input type="hidden" name="{{ id }}[_action]" value="export-settings"> |
10 | - <?php wp_nonce_field('export-settings'); ?> |
|
11 | - <?php submit_button(__('Export Settings', 'site-reviews'), 'secondary'); ?> |
|
10 | + <?php wp_nonce_field( 'export-settings' ); ?> |
|
11 | + <?php submit_button( __( 'Export Settings', 'site-reviews' ), 'secondary' ); ?> |
|
12 | 12 | </form> |
13 | 13 | </div> |
14 | 14 | <?php endif; ?> |
15 | 15 | |
16 | -<?php if (glsr()->hasPermission('settings')) : ?> |
|
16 | +<?php if( glsr()->hasPermission( 'settings' ) ) : ?> |
|
17 | 17 | <div class="glsr-card card"> |
18 | 18 | <h3>Import Settings</h3> |
19 | 19 | <p>Import the Site Reviews settings from a <code>*.json</code> file. This file can be obtained by exporting the settings on another site using the export tool below.</p> |
20 | - <p>To import your Site Reviews' reviews and categories from another website, please use the WordPress <a href="<?= admin_url('import.php'); ?>">Import</a> tool.</p> |
|
20 | + <p>To import your Site Reviews' reviews and categories from another website, please use the WordPress <a href="<?= admin_url( 'import.php' ); ?>">Import</a> tool.</p> |
|
21 | 21 | <form method="post" enctype="multipart/form-data"> |
22 | 22 | <input type="file" name="import-file"> |
23 | 23 | <input type="hidden" name="{{ id }}[_action]" value="import-settings"> |
24 | - <?php wp_nonce_field('import-settings'); ?> |
|
25 | - <?php submit_button(__('Import Settings', 'site-reviews'), 'secondary'); ?> |
|
24 | + <?php wp_nonce_field( 'import-settings' ); ?> |
|
25 | + <?php submit_button( __( 'Import Settings', 'site-reviews' ), 'secondary' ); ?> |
|
26 | 26 | </form> |
27 | 27 | </div> |
28 | 28 | <?php endif; ?> |
29 | 29 | |
30 | -<?php if (glsr()->hasPermission('settings')) : ?> |
|
30 | +<?php if( glsr()->hasPermission( 'settings' ) ) : ?> |
|
31 | 31 | <div class="glsr-card card"> |
32 | 32 | <h3>Migrate Plugin</h3> |
33 | 33 | <p>Run this tool if your reviews stopped working correctly after upgrading the plugin to the latest version (i.e. read-only reviews, zero-star ratings, missing role capabilities, etc.).</p> |
34 | 34 | <form method="post"> |
35 | 35 | <input type="hidden" name="{{ id }}[_action]" value="migrate-reviews"> |
36 | - <?php wp_nonce_field('migrate-reviews'); ?> |
|
36 | + <?php wp_nonce_field( 'migrate-reviews' ); ?> |
|
37 | 37 | <p class="submit"> |
38 | 38 | <button type="submit" class="glsr-button button" name="migrate-reviews" id="migrate-reviews"> |
39 | - <span data-loading="<?= __('Migrating Reviews, please wait...', 'site-reviews'); ?>"><?= __('Run Migration', 'site-reviews'); ?></span> |
|
39 | + <span data-loading="<?= __( 'Migrating Reviews, please wait...', 'site-reviews' ); ?>"><?= __( 'Run Migration', 'site-reviews' ); ?></span> |
|
40 | 40 | </button> |
41 | 41 | </p> |
42 | 42 | </form> |
@@ -49,26 +49,26 @@ discard block |
||
49 | 49 | <p>If you suspect that the rating counts are incorrect (perhaps you have cloned a page that had reviews assigned to it, or edited/deleted reviews directly from your database), you can recalculate them here.</p> |
50 | 50 | <form method="post"> |
51 | 51 | <input type="hidden" name="{{ id }}[_action]" value="count-reviews"> |
52 | - <?php wp_nonce_field('count-reviews'); ?> |
|
52 | + <?php wp_nonce_field( 'count-reviews' ); ?> |
|
53 | 53 | <p class="submit"> |
54 | 54 | <button type="submit" class="glsr-button button" name="count-reviews" id="count-reviews"> |
55 | - <span data-loading="<?= __('Recalculating Counts, please wait...', 'site-reviews'); ?>"><?= __('Recalculate Counts', 'site-reviews'); ?></span> |
|
55 | + <span data-loading="<?= __( 'Recalculating Counts, please wait...', 'site-reviews' ); ?>"><?= __( 'Recalculate Counts', 'site-reviews' ); ?></span> |
|
56 | 56 | </button> |
57 | 57 | </p> |
58 | 58 | </form> |
59 | 59 | </div> |
60 | 60 | |
61 | -<?php if (glsr()->hasPermission('settings')) : ?> |
|
61 | +<?php if( glsr()->hasPermission( 'settings' ) ) : ?> |
|
62 | 62 | <div class="glsr-card card"> |
63 | 63 | <h3>Reset Permissions</h3> |
64 | 64 | <p>Site Reviews provides custom post_type capabilities that mirror the capabilities of your posts by default. For example, if a user role has permission to edit others posts, then that role will also have permission to edit other users reviews.</p> |
65 | 65 | <p>If you have changed the capabilities of your user roles and you suspect that Site Reviews is not working correctly due to your changes, you may use this tool to reset the Site Reviews capabilities for your user roles.</p> |
66 | 66 | <form method="post"> |
67 | 67 | <input type="hidden" name="{{ id }}[_action]" value="reset-permissions"> |
68 | - <?php wp_nonce_field('reset-permissions'); ?> |
|
68 | + <?php wp_nonce_field( 'reset-permissions' ); ?> |
|
69 | 69 | <p class="submit"> |
70 | 70 | <button type="submit" class="glsr-button button" name="reset-permissions" id="reset-permissions"> |
71 | - <span data-loading="<?= __('Resetting Permissions, please wait...', 'site-reviews'); ?>"><?= __('Reset Permissions', 'site-reviews'); ?></span> |
|
71 | + <span data-loading="<?= __( 'Resetting Permissions, please wait...', 'site-reviews' ); ?>"><?= __( 'Reset Permissions', 'site-reviews' ); ?></span> |
|
72 | 72 | </button> |
73 | 73 | </p> |
74 | 74 | </form> |