@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | * @return void |
29 | 29 | * @action set_object_terms |
30 | 30 | */ |
31 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
31 | + public function onAfterChangeCategory( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds ) |
|
32 | 32 | { |
33 | - sort($newTTIds); |
|
34 | - sort($oldTTIds); |
|
35 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
33 | + sort( $newTTIds ); |
|
34 | + sort( $oldTTIds ); |
|
35 | + if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - $review = glsr_get_review($postId); |
|
39 | - if ('publish' !== $review->status) { |
|
38 | + $review = glsr_get_review( $postId ); |
|
39 | + if( 'publish' !== $review->status ) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
42 | + $ignoredIds = array_intersect( $oldTTIds, $newTTIds ); |
|
43 | + $decreasedIds = array_diff( $oldTTIds, $ignoredIds ); |
|
44 | + $increasedIds = array_diff( $newTTIds, $ignoredIds ); |
|
45 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $decreasedIds, 'term_taxonomy_id' ) ) { |
|
46 | + glsr( TermCountsManager::class )->decrease( $review ); |
|
47 | 47 | } |
48 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | - glsr(TermCountsManager::class)->increase($review); |
|
48 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $increasedIds, 'term_taxonomy_id' ) ) { |
|
49 | + glsr( TermCountsManager::class )->increase( $review ); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @return void |
60 | 60 | * @action transition_post_status |
61 | 61 | */ |
62 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
62 | + public function onAfterChangeStatus( $newStatus, $oldStatus, $post ) |
|
63 | 63 | { |
64 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | - || in_array($oldStatus, ['new', $newStatus])) { |
|
64 | + if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) |
|
65 | + || in_array( $oldStatus, ['new', $newStatus] ) ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | - $review = glsr_get_review($post); |
|
69 | - if ('publish' == $post->post_status) { |
|
70 | - glsr(CountsManager::class)->increaseAll($review); |
|
68 | + $review = glsr_get_review( $post ); |
|
69 | + if( 'publish' == $post->post_status ) { |
|
70 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
71 | 71 | } else { |
72 | - glsr(CountsManager::class)->decreaseAll($review); |
|
72 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | * @action site-reviews/review/created |
81 | 81 | */ |
82 | - public function onAfterCreate(Review $review) |
|
82 | + public function onAfterCreate( Review $review ) |
|
83 | 83 | { |
84 | - if ('publish' !== $review->status) { |
|
84 | + if( 'publish' !== $review->status ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - glsr(GlobalCountsManager::class)->increase($review); |
|
88 | - glsr(PostCountsManager::class)->increase($review); |
|
87 | + glsr( GlobalCountsManager::class )->increase( $review ); |
|
88 | + glsr( PostCountsManager::class )->increase( $review ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | * @action before_delete_post |
97 | 97 | */ |
98 | - public function onBeforeDelete($postId) |
|
98 | + public function onBeforeDelete( $postId ) |
|
99 | 99 | { |
100 | - if (!$this->isReviewPostId($postId)) { |
|
100 | + if( !$this->isReviewPostId( $postId ) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $review = glsr_get_review($postId); |
|
104 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | - glsr(CountsManager::class)->decreaseAll($review); |
|
103 | + $review = glsr_get_review( $postId ); |
|
104 | + if( 'trash' !== $review->status ) { // do not run for trashed posts |
|
105 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -116,21 +116,21 @@ discard block |
||
116 | 116 | * @return void |
117 | 117 | * @action update_postmeta |
118 | 118 | */ |
119 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
119 | + public function onBeforeUpdate( $metaId, $postId, $metaKey, $metaValue ) |
|
120 | 120 | { |
121 | - if (!$this->isReviewPostId($postId)) { |
|
121 | + if( !$this->isReviewPostId( $postId ) ) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
124 | + $metaKey = Str::removePrefix( '_', $metaKey ); |
|
125 | + if( !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) ) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | - $review = glsr_get_review($postId); |
|
129 | - if ($review->$metaKey == $metaValue) { |
|
128 | + $review = glsr_get_review( $postId ); |
|
129 | + if( $review->$metaKey == $metaValue ) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | - call_user_func([$this, $method], $review, $metaValue); |
|
132 | + $method = Helper::buildMethodName( $metaKey, 'onBeforeChange' ); |
|
133 | + call_user_func( [$this, $method], $review, $metaValue ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * @param string|int $assignedTo |
140 | 140 | * @return void |
141 | 141 | */ |
142 | - protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
142 | + protected function onBeforeChangeAssignedTo( Review $review, $assignedTo ) |
|
143 | 143 | { |
144 | - glsr(PostCountsManager::class)->decrease($review); |
|
144 | + glsr( PostCountsManager::class )->decrease( $review ); |
|
145 | 145 | $review->assigned_to = $assignedTo; |
146 | - glsr(PostCountsManager::class)->increase($review); |
|
146 | + glsr( PostCountsManager::class )->increase( $review ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | * @param string|int $rating |
153 | 153 | * @return void |
154 | 154 | */ |
155 | - protected function onBeforeChangeRating(Review $review, $rating) |
|
155 | + protected function onBeforeChangeRating( Review $review, $rating ) |
|
156 | 156 | { |
157 | - glsr(CountsManager::class)->decreaseAll($review); |
|
157 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
158 | 158 | $review->rating = $rating; |
159 | - glsr(CountsManager::class)->increaseAll($review); |
|
159 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | * @param string $reviewType |
166 | 166 | * @return void |
167 | 167 | */ |
168 | - protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
168 | + protected function onBeforeChangeReviewType( Review $review, $reviewType ) |
|
169 | 169 | { |
170 | - glsr(CountsManager::class)->decreaseAll($review); |
|
170 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
171 | 171 | $review->review_type = $reviewType; |
172 | - glsr(CountsManager::class)->increaseAll($review); |
|
172 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
173 | 173 | } |
174 | 174 | } |
@@ -9,21 +9,21 @@ 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 | /** |
20 | 20 | * @param string $string |
21 | 21 | * @return string |
22 | 22 | */ |
23 | - public static function camelCase($string) |
|
23 | + public static function camelCase( $string ) |
|
24 | 24 | { |
25 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | - return str_replace(' ', '', $string); |
|
25 | + $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) ); |
|
26 | + return str_replace( ' ', '', $string ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @param string $needle |
32 | 32 | * @return bool |
33 | 33 | */ |
34 | - public static function contains($haystack, $needle) |
|
34 | + public static function contains( $haystack, $needle ) |
|
35 | 35 | { |
36 | - return false !== strpos($haystack, $needle); |
|
36 | + return false !== strpos( $haystack, $needle ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,27 +42,27 @@ discard block |
||
42 | 42 | * @param string $initialType period|period_space|space |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
45 | + public static function convertName( $name, $nameType = '', $initialType = '' ) |
|
46 | 46 | { |
47 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | - $firstName = array_shift($names); |
|
49 | - $lastName = array_pop($names); |
|
47 | + $names = preg_split( '/\W/', $name, 0, PREG_SPLIT_NO_EMPTY ); |
|
48 | + $firstName = array_shift( $names ); |
|
49 | + $lastName = array_pop( $names ); |
|
50 | 50 | $initialTypes = [ |
51 | 51 | 'period' => '.', |
52 | 52 | 'period_space' => '. ', |
53 | 53 | 'space' => ' ', |
54 | 54 | ]; |
55 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | - if ('initials' == $nameType) { |
|
57 | - return static::convertToInitials($name, $initialPunctuation); |
|
55 | + $initialPunctuation = (string)Arr::get( $initialTypes, $initialType, ' ' ); |
|
56 | + if( 'initials' == $nameType ) { |
|
57 | + return static::convertToInitials( $name, $initialPunctuation ); |
|
58 | 58 | } |
59 | 59 | $nameTypes = [ |
60 | 60 | 'first' => $firstName, |
61 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
61 | + 'first_initial' => substr( $firstName, 0, 1 ).$initialPunctuation.$lastName, |
|
62 | 62 | 'last' => $lastName, |
63 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
63 | + 'last_initial' => $firstName.' '.substr( $lastName, 0, 1 ).$initialPunctuation, |
|
64 | 64 | ]; |
65 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
65 | + return trim( (string)Arr::get( $nameTypes, $nameType, $name ) ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * @param string $prefix |
71 | 71 | * @return string |
72 | 72 | */ |
73 | - public static function convertPathToId($path, $prefix = '') |
|
73 | + public static function convertPathToId( $path, $prefix = '' ) |
|
74 | 74 | { |
75 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
75 | + return str_replace( ['[', ']'], ['-', ''], static::convertPathToName( $path, $prefix ) ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | * @param string $prefix |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public static function convertPathToName($path, $prefix = '') |
|
83 | + public static function convertPathToName( $path, $prefix = '' ) |
|
84 | 84 | { |
85 | - $levels = explode('.', $path); |
|
86 | - return array_reduce($levels, function ($result, $value) { |
|
85 | + $levels = explode( '.', $path ); |
|
86 | + return array_reduce( $levels, function( $result, $value ) { |
|
87 | 87 | return $result .= '['.$value.']'; |
88 | - }, $prefix); |
|
88 | + }, $prefix ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string $initialPunctuation |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
96 | + public static function convertToInitials( $name, $initialPunctuation = '' ) |
|
97 | 97 | { |
98 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
98 | + preg_match_all( '/(?<=\s|\b)\pL/u', $name, $matches ); |
|
99 | + return array_reduce( $matches[0], function( $carry, $word ) use ($initialPunctuation) { |
|
100 | + return $carry.strtoupper( substr( $word, 0, 1 ) ).$initialPunctuation; |
|
101 | 101 | }); |
102 | 102 | } |
103 | 103 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param string $string |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public static function dashCase($string) |
|
108 | + public static function dashCase( $string ) |
|
109 | 109 | { |
110 | - return str_replace('_', '-', static::snakeCase($string)); |
|
110 | + return str_replace( '_', '-', static::snakeCase( $string ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | * @param string $haystack |
116 | 116 | * @return bool |
117 | 117 | */ |
118 | - public static function endsWith($needle, $haystack) |
|
118 | + public static function endsWith( $needle, $haystack ) |
|
119 | 119 | { |
120 | - $length = strlen($needle); |
|
120 | + $length = strlen( $needle ); |
|
121 | 121 | return 0 != $length |
122 | - ? substr($haystack, -$length) === $needle |
|
122 | + ? substr( $haystack, -$length ) === $needle |
|
123 | 123 | : true; |
124 | 124 | } |
125 | 125 | |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | * @param string|null $trim |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function prefix($prefix, $string, $trim = null) |
|
132 | + public static function prefix( $prefix, $string, $trim = null ) |
|
133 | 133 | { |
134 | - if (null === $trim) { |
|
134 | + if( null === $trim ) { |
|
135 | 135 | $trim = $prefix; |
136 | 136 | } |
137 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
137 | + return $prefix.trim( static::removePrefix( $trim, $string ) ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | * @param string $string |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public static function removePrefix($prefix, $string) |
|
145 | + public static function removePrefix( $prefix, $string ) |
|
146 | 146 | { |
147 | - return static::startsWith($prefix, $string) |
|
148 | - ? substr($string, strlen($prefix)) |
|
147 | + return static::startsWith( $prefix, $string ) |
|
148 | + ? substr( $string, strlen( $prefix ) ) |
|
149 | 149 | : $string; |
150 | 150 | } |
151 | 151 | |
@@ -153,16 +153,16 @@ discard block |
||
153 | 153 | * @param string $string |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function snakeCase($string) |
|
156 | + public static function snakeCase( $string ) |
|
157 | 157 | { |
158 | - if (!ctype_lower($string)) { |
|
159 | - $string = preg_replace('/\s+/u', '', $string); |
|
160 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | - $string = function_exists('mb_strtolower') |
|
162 | - ? mb_strtolower($string, 'UTF-8') |
|
163 | - : strtolower($string); |
|
158 | + if( !ctype_lower( $string ) ) { |
|
159 | + $string = preg_replace( '/\s+/u', '', $string ); |
|
160 | + $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
161 | + $string = function_exists( 'mb_strtolower' ) |
|
162 | + ? mb_strtolower( $string, 'UTF-8' ) |
|
163 | + : strtolower( $string ); |
|
164 | 164 | } |
165 | - return str_replace('-', '_', $string); |
|
165 | + return str_replace( '-', '_', $string ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @param string $haystack |
171 | 171 | * @return bool |
172 | 172 | */ |
173 | - public static function startsWith($needle, $haystack) |
|
173 | + public static function startsWith( $needle, $haystack ) |
|
174 | 174 | { |
175 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
175 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | * @param int $length |
181 | 181 | * @return string |
182 | 182 | */ |
183 | - public static function truncate($string, $length) |
|
183 | + public static function truncate( $string, $length ) |
|
184 | 184 | { |
185 | - return strlen($string) > $length |
|
186 | - ? substr($string, 0, $length) |
|
185 | + return strlen( $string ) > $length |
|
186 | + ? substr( $string, 0, $length ) |
|
187 | 187 | : $string; |
188 | 188 | } |
189 | 189 | } |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function validate(array $request) |
|
61 | + public function validate( array $request ) |
|
62 | 62 | { |
63 | 63 | $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
64 | 64 | $this->form_id = $request['form_id']; |
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
65 | + $this->options = glsr( OptionManager::class )->all(); |
|
66 | + $this->request = $this->validateRequest( $request ); |
|
67 | 67 | $this->validateCustom(); |
68 | 68 | $this->validatePermission(); |
69 | 69 | $this->validateHoneyPot(); |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | $this->validateBlacklist(); |
72 | 72 | $this->validateAkismet(); |
73 | 73 | $this->validateRecaptcha(); |
74 | - if (!empty($this->error)) { |
|
75 | - $this->setSessionValues('message', $this->error); |
|
74 | + if( !empty($this->error) ) { |
|
75 | + $this->setSessionValues( 'message', $this->error ); |
|
76 | 76 | } |
77 | 77 | return $this; |
78 | 78 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param mixed $fallback |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - protected function getOption($path, $fallback = '') |
|
85 | + protected function getOption( $path, $fallback = '' ) |
|
86 | 86 | { |
87 | - return Arr::get($this->options, $path, $fallback); |
|
87 | + return Arr::get( $this->options, $path, $fallback ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function getRecaptchaStatus() |
94 | 94 | { |
95 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
95 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
96 | 96 | return static::RECAPTCHA_DISABLED; |
97 | 97 | } |
98 | - if (empty($this->request['_recaptcha-token'])) { |
|
99 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
98 | + if( empty($this->request['_recaptcha-token']) ) { |
|
99 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
100 | 100 | ? static::RECAPTCHA_EMPTY |
101 | 101 | : static::RECAPTCHA_FAILED; |
102 | 102 | } |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function getRecaptchaTokenStatus() |
110 | 110 | { |
111 | - $endpoint = add_query_arg([ |
|
111 | + $endpoint = add_query_arg( [ |
|
112 | 112 | 'remoteip' => Helper::getIpAddress(), |
113 | 113 | 'response' => $this->request['_recaptcha-token'], |
114 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | - ], static::RECAPTCHA_ENDPOINT); |
|
116 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | - glsr_log()->error($response->get_error_message()); |
|
114 | + 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
|
115 | + ], static::RECAPTCHA_ENDPOINT ); |
|
116 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
117 | + glsr_log()->error( $response->get_error_message() ); |
|
118 | 118 | return static::RECAPTCHA_FAILED; |
119 | 119 | } |
120 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | - if (!empty($response->success)) { |
|
122 | - return boolval($response->success) |
|
120 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
121 | + if( !empty($response->success) ) { |
|
122 | + return boolval( $response->success ) |
|
123 | 123 | ? static::RECAPTCHA_VALID |
124 | 124 | : static::RECAPTCHA_INVALID; |
125 | 125 | } |
126 | - foreach ($response->{'error-codes'} as $error) { |
|
127 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
126 | + foreach( $response->{'error-codes'} as $error ) { |
|
127 | + glsr_log()->error( 'reCAPTCHA error: '.$error ); |
|
128 | 128 | } |
129 | 129 | return static::RECAPTCHA_INVALID; |
130 | 130 | } |
@@ -132,35 +132,35 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * @return array |
134 | 134 | */ |
135 | - protected function getValidationRules(array $request) |
|
135 | + protected function getValidationRules( array $request ) |
|
136 | 136 | { |
137 | 137 | $rules = array_intersect_key( |
138 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
138 | + apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
|
139 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
140 | 140 | ); |
141 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | - return array_diff_key($rules, array_flip($excluded)); |
|
141 | + $excluded = explode( ',', Arr::get( $request, 'excluded' ) ); |
|
142 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - protected function isRequestValid(array $request) |
|
148 | + protected function isRequestValid( array $request ) |
|
149 | 149 | { |
150 | - $rules = $this->getValidationRules($request); |
|
151 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | - if (empty($errors)) { |
|
150 | + $rules = $this->getValidationRules( $request ); |
|
151 | + $errors = glsr( Validator::class )->validate( $request, $rules ); |
|
152 | + if( empty($errors) ) { |
|
153 | 153 | return true; |
154 | 154 | } |
155 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | - $this->setSessionValues('errors', $errors); |
|
157 | - $this->setSessionValues('values', $request); |
|
155 | + $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
|
156 | + $this->setSessionValues( 'errors', $errors ); |
|
157 | + $this->setSessionValues( 'values', $request ); |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | - protected function setError($message, $loggedMessage = '') |
|
161 | + protected function setError( $message, $loggedMessage = '' ) |
|
162 | 162 | { |
163 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
163 | + $this->setSessionValues( 'errors', [], $loggedMessage ); |
|
164 | 164 | $this->error = $message; |
165 | 165 | } |
166 | 166 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * @param string $loggedMessage |
171 | 171 | * @return void |
172 | 172 | */ |
173 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
173 | + protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
|
174 | 174 | { |
175 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | - if (!empty($loggedMessage)) { |
|
177 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
175 | + glsr()->sessionSet( $this->form_id.$type, $value ); |
|
176 | + if( !empty($loggedMessage) ) { |
|
177 | + glsr_log()->warning( $loggedMessage )->debug( $this->request ); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function validateAkismet() |
185 | 185 | { |
186 | - if (!empty($this->error)) { |
|
186 | + if( !empty($this->error) ) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
189 | + if( glsr( Akismet::class )->isSpam( $this->request ) ) { |
|
190 | + $this->setError( __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ), |
|
191 | 191 | 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
192 | 192 | ); |
193 | 193 | } |
@@ -198,18 +198,18 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function validateBlacklist() |
200 | 200 | { |
201 | - if (!empty($this->error)) { |
|
201 | + if( !empty($this->error) ) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
204 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | - if ('reject' != $blacklistAction) { |
|
207 | + $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
|
208 | + if( 'reject' != $blacklistAction ) { |
|
209 | 209 | $this->request['blacklisted'] = true; |
210 | 210 | return; |
211 | 211 | } |
212 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
212 | + $this->setError( __( 'Your review cannot be submitted at this time.', 'site-reviews' ), |
|
213 | 213 | 'Blacklisted submission detected:' |
214 | 214 | ); |
215 | 215 | } |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | */ |
220 | 220 | protected function validateCustom() |
221 | 221 | { |
222 | - if (!empty($this->error)) { |
|
222 | + if( !empty($this->error) ) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | - if (true === $validated) { |
|
225 | + $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
|
226 | + if( true === $validated ) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - $errorMessage = is_string($validated) |
|
229 | + $errorMessage = is_string( $validated ) |
|
230 | 230 | ? $validated |
231 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | - $this->setError($errorMessage); |
|
233 | - $this->setSessionValues('values', $this->request); |
|
231 | + : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
232 | + $this->setError( $errorMessage ); |
|
233 | + $this->setSessionValues( 'values', $this->request ); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function validateHoneyPot() |
240 | 240 | { |
241 | - if (!empty($this->error)) { |
|
241 | + if( !empty($this->error) ) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | - if (!empty($this->request['gotcha'])) { |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
244 | + if( !empty($this->request['gotcha']) ) { |
|
245 | + $this->setError( __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ), |
|
246 | 246 | 'The Honeypot caught a bad submission:' |
247 | 247 | ); |
248 | 248 | } |
@@ -253,11 +253,11 @@ discard block |
||
253 | 253 | */ |
254 | 254 | protected function validatePermission() |
255 | 255 | { |
256 | - if (!empty($this->error)) { |
|
256 | + if( !empty($this->error) ) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | - $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
259 | + if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
260 | + $this->setError( __( 'You must be logged in to submit a review.', 'site-reviews' ) ); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function validateReviewLimits() |
268 | 268 | { |
269 | - if (!empty($this->error)) { |
|
269 | + if( !empty($this->error) ) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
272 | + if( glsr( ReviewLimits::class )->hasReachedLimit( $this->request ) ) { |
|
273 | + $this->setError( __( 'You have already submitted a review.', 'site-reviews' ) ); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -279,33 +279,33 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function validateRecaptcha() |
281 | 281 | { |
282 | - if (!empty($this->error)) { |
|
282 | + if( !empty($this->error) ) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | $status = $this->getRecaptchaStatus(); |
286 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
286 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) { |
|
287 | 287 | return; |
288 | 288 | } |
289 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | - $this->setSessionValues('recaptcha', 'unset'); |
|
289 | + if( static::RECAPTCHA_EMPTY === $status ) { |
|
290 | + $this->setSessionValues( 'recaptcha', 'unset' ); |
|
291 | 291 | $this->recaptchaIsUnset = true; |
292 | 292 | return; |
293 | 293 | } |
294 | - $this->setSessionValues('recaptcha', 'reset'); |
|
294 | + $this->setSessionValues( 'recaptcha', 'reset' ); |
|
295 | 295 | $errors = [ |
296 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
296 | + static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ), |
|
297 | + static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ), |
|
298 | 298 | ]; |
299 | - $this->setError($errors[$status]); |
|
299 | + $this->setError( $errors[$status] ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | 303 | * @return array |
304 | 304 | */ |
305 | - protected function validateRequest(array $request) |
|
305 | + protected function validateRequest( array $request ) |
|
306 | 306 | { |
307 | - return $this->isRequestValid($request) |
|
308 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
307 | + return $this->isRequestValid( $request ) |
|
308 | + ? array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ) |
|
309 | 309 | : $request; |
310 | 310 | } |
311 | 311 | } |
@@ -30,18 +30,18 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - public function build(array $args = []) |
|
33 | + public function build( array $args = [] ) |
|
34 | 34 | { |
35 | 35 | $this->args = $args; |
36 | - $schema = $this->buildSummary($args); |
|
37 | - if (!empty($schema)) { |
|
36 | + $schema = $this->buildSummary( $args ); |
|
37 | + if( !empty($schema) ) { |
|
38 | 38 | $reviews = $this->buildReviews(); |
39 | - foreach ($reviews as &$review) { |
|
39 | + foreach( $reviews as &$review ) { |
|
40 | 40 | unset($review['@context']); |
41 | 41 | unset($review['itemReviewed']); |
42 | 42 | } |
43 | 43 | } |
44 | - if (!empty($reviews)) { |
|
44 | + if( !empty($reviews) ) { |
|
45 | 45 | $schema['review'] = $reviews; |
46 | 46 | } |
47 | 47 | return $schema; |
@@ -51,25 +51,25 @@ discard block |
||
51 | 51 | * @param array|null $args |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function buildSummary($args = null) |
|
54 | + public function buildSummary( $args = null ) |
|
55 | 55 | { |
56 | - if (is_array($args)) { |
|
56 | + if( is_array( $args ) ) { |
|
57 | 57 | $this->args = $args; |
58 | 58 | } |
59 | - $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
60 | - if ($count = array_sum($this->getRatingCounts())) { |
|
61 | - $schema = method_exists($this, $buildSummary) |
|
59 | + $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
|
60 | + if( $count = array_sum( $this->getRatingCounts() ) ) { |
|
61 | + $schema = method_exists( $this, $buildSummary ) |
|
62 | 62 | ? $this->$buildSummary() |
63 | 63 | : $this->buildSummaryForCustom(); |
64 | 64 | $schema->aggregateRating( |
65 | - $this->getSchemaType('AggregateRating') |
|
66 | - ->ratingValue($this->getRatingValue()) |
|
67 | - ->reviewCount($count) |
|
68 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
69 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
65 | + $this->getSchemaType( 'AggregateRating' ) |
|
66 | + ->ratingValue( $this->getRatingValue() ) |
|
67 | + ->reviewCount( $count ) |
|
68 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
69 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
70 | 70 | ); |
71 | 71 | $schema = $schema->toArray(); |
72 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
72 | + return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args ); |
|
73 | 73 | } |
74 | 74 | return []; |
75 | 75 | } |
@@ -79,53 +79,53 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function render() |
81 | 81 | { |
82 | - if (empty(glsr()->schemas)) { |
|
82 | + if( empty(glsr()->schemas) ) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
86 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
85 | + printf( '<script type="application/ld+json">%s</script>', json_encode( |
|
86 | + apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
|
87 | 87 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
88 | - )); |
|
88 | + ) ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * @return void |
93 | 93 | */ |
94 | - public function store(array $schema) |
|
94 | + public function store( array $schema ) |
|
95 | 95 | { |
96 | - if (empty($schema)) { |
|
96 | + if( empty($schema) ) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | $schemas = glsr()->schemas; |
100 | 100 | $schemas[] = $schema; |
101 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
101 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @param Review $review |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - protected function buildReview($review) |
|
108 | + protected function buildReview( $review ) |
|
109 | 109 | { |
110 | - $schema = $this->getSchemaType('Review') |
|
111 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
112 | - $schema->name($review->title); |
|
110 | + $schema = $this->getSchemaType( 'Review' ) |
|
111 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) { |
|
112 | + $schema->name( $review->title ); |
|
113 | 113 | }) |
114 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
115 | - $schema->reviewBody($review->content); |
|
114 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) { |
|
115 | + $schema->reviewBody( $review->content ); |
|
116 | 116 | }) |
117 | - ->datePublished((new DateTime($review->date))) |
|
118 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
119 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
120 | - if (!empty($review->rating)) { |
|
117 | + ->datePublished( (new DateTime( $review->date )) ) |
|
118 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
119 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
120 | + if( !empty($review->rating) ) { |
|
121 | 121 | $schema->reviewRating( |
122 | - $this->getSchemaType('Rating') |
|
123 | - ->ratingValue($review->rating) |
|
124 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
125 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
122 | + $this->getSchemaType( 'Rating' ) |
|
123 | + ->ratingValue( $review->rating ) |
|
124 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
125 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
126 | 126 | ); |
127 | 127 | } |
128 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
128 | + return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | protected function buildReviews() |
135 | 135 | { |
136 | 136 | $reviews = []; |
137 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
137 | + foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) { |
|
138 | 138 | // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
139 | 139 | // @see https://developers.google.com/search/docs/data-types/review |
140 | - if ('local' === $review->review_type) { |
|
141 | - $reviews[] = $this->buildReview($review); |
|
140 | + if( 'local' === $review->review_type ) { |
|
141 | + $reviews[] = $this->buildReview( $review ); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | return $reviews; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param mixed $schema |
149 | 149 | * @return mixed |
150 | 150 | */ |
151 | - protected function buildSchemaValues($schema, array $values = []) |
|
151 | + protected function buildSchemaValues( $schema, array $values = [] ) |
|
152 | 152 | { |
153 | - foreach ($values as $value) { |
|
154 | - $option = $this->getSchemaOptionValue($value); |
|
155 | - if (empty($option)) { |
|
153 | + foreach( $values as $value ) { |
|
154 | + $option = $this->getSchemaOptionValue( $value ); |
|
155 | + if( empty($option) ) { |
|
156 | 156 | continue; |
157 | 157 | } |
158 | - $schema->$value($option); |
|
158 | + $schema->$value( $option ); |
|
159 | 159 | } |
160 | 160 | return $schema; |
161 | 161 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected function buildSummaryForCustom() |
167 | 167 | { |
168 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
168 | + return $this->buildSchemaValues( $this->getSchemaType(), [ |
|
169 | 169 | 'description', 'image', 'name', 'url', |
170 | - ]); |
|
170 | + ] ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | */ |
176 | 176 | protected function buildSummaryForLocalBusiness() |
177 | 177 | { |
178 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
178 | + return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
|
179 | 179 | 'address', 'priceRange', 'telephone', |
180 | - ]); |
|
180 | + ] ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function buildSummaryForProduct() |
187 | 187 | { |
188 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
189 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
188 | + $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
|
189 | + $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
|
190 | 190 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
191 | - ]); |
|
191 | + ] ); |
|
192 | 192 | return $this->buildSummaryForCustom() |
193 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
194 | - $schema->offers($offers); |
|
193 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) { |
|
194 | + $schema->offers( $offers ); |
|
195 | 195 | }) |
196 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
196 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | */ |
202 | 202 | protected function getRatingCounts() |
203 | 203 | { |
204 | - if (!isset($this->ratingCounts)) { |
|
205 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
204 | + if( !isset($this->ratingCounts) ) { |
|
205 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
|
206 | 206 | } |
207 | 207 | return $this->ratingCounts; |
208 | 208 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function getRatingValue() |
214 | 214 | { |
215 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
215 | + return glsr( Rating::class )->getAverage( $this->getRatingCounts() ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,15 +220,15 @@ discard block |
||
220 | 220 | * @param string $fallback |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - protected function getSchemaOption($option, $fallback) |
|
223 | + protected function getSchemaOption( $option, $fallback ) |
|
224 | 224 | { |
225 | - $option = strtolower($option); |
|
226 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
225 | + $option = strtolower( $option ); |
|
226 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
227 | 227 | return $schemaOption; |
228 | 228 | } |
229 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
230 | - if (is_array($setting)) { |
|
231 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
229 | + $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
|
230 | + if( is_array( $setting ) ) { |
|
231 | + return $this->getSchemaOptionDefault( $setting, $fallback ); |
|
232 | 232 | } |
233 | 233 | return !empty($setting) |
234 | 234 | ? $setting |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | * @param string $fallback |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
242 | + protected function getSchemaOptionDefault( array $setting, $fallback ) |
|
243 | 243 | { |
244 | - $setting = wp_parse_args($setting, [ |
|
244 | + $setting = wp_parse_args( $setting, [ |
|
245 | 245 | 'custom' => '', |
246 | 246 | 'default' => $fallback, |
247 | - ]); |
|
247 | + ] ); |
|
248 | 248 | return 'custom' != $setting['default'] |
249 | 249 | ? $setting['default'] |
250 | 250 | : $setting['custom']; |
@@ -255,21 +255,21 @@ discard block |
||
255 | 255 | * @param string $fallback |
256 | 256 | * @return void|string |
257 | 257 | */ |
258 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
258 | + protected function getSchemaOptionValue( $option, $fallback = 'post' ) |
|
259 | 259 | { |
260 | - if (array_key_exists($option, $this->keyValues)) { |
|
260 | + if( array_key_exists( $option, $this->keyValues ) ) { |
|
261 | 261 | return $this->keyValues[$option]; |
262 | 262 | } |
263 | - $value = $this->getSchemaOption($option, $fallback); |
|
264 | - if ($value != $fallback) { |
|
265 | - return $this->setAndGetKeyValue($option, $value); |
|
263 | + $value = $this->getSchemaOption( $option, $fallback ); |
|
264 | + if( $value != $fallback ) { |
|
265 | + return $this->setAndGetKeyValue( $option, $value ); |
|
266 | 266 | } |
267 | - if (!is_single() && !is_page()) { |
|
267 | + if( !is_single() && !is_page() ) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | - $method = Helper::buildMethodName($option, 'getThing'); |
|
271 | - if (method_exists($this, $method)) { |
|
272 | - return $this->setAndGetKeyValue($option, $this->$method()); |
|
270 | + $method = Helper::buildMethodName( $option, 'getThing' ); |
|
271 | + if( method_exists( $this, $method ) ) { |
|
272 | + return $this->setAndGetKeyValue( $option, $this->$method() ); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | * @param string|null $type |
278 | 278 | * @return mixed |
279 | 279 | */ |
280 | - protected function getSchemaType($type = null) |
|
280 | + protected function getSchemaType( $type = null ) |
|
281 | 281 | { |
282 | - if (!is_string($type)) { |
|
283 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
282 | + if( !is_string( $type ) ) { |
|
283 | + $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
|
284 | 284 | } |
285 | - $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
286 | - return class_exists($className) |
|
285 | + $className = Helper::buildClassName( $type, 'Modules\Schema' ); |
|
286 | + return class_exists( $className ) |
|
287 | 287 | ? new $className() |
288 | - : new UnknownType($type); |
|
288 | + : new UnknownType( $type ); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,19 +294,19 @@ discard block |
||
294 | 294 | protected function getThingDescription() |
295 | 295 | { |
296 | 296 | $post = get_post(); |
297 | - $text = Arr::get($post, 'post_excerpt'); |
|
298 | - if (empty($text)) { |
|
299 | - $text = Arr::get($post, 'post_content'); |
|
297 | + $text = Arr::get( $post, 'post_excerpt' ); |
|
298 | + if( empty($text) ) { |
|
299 | + $text = Arr::get( $post, 'post_content' ); |
|
300 | 300 | } |
301 | - if (function_exists('excerpt_remove_blocks')) { |
|
302 | - $text = excerpt_remove_blocks($text); |
|
301 | + if( function_exists( 'excerpt_remove_blocks' ) ) { |
|
302 | + $text = excerpt_remove_blocks( $text ); |
|
303 | 303 | } |
304 | - $text = strip_shortcodes($text); |
|
305 | - $text = wpautop($text); |
|
306 | - $text = wptexturize($text); |
|
307 | - $text = wp_strip_all_tags($text); |
|
308 | - $text = str_replace(']]>', ']]>', $text); |
|
309 | - return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
304 | + $text = strip_shortcodes( $text ); |
|
305 | + $text = wpautop( $text ); |
|
306 | + $text = wptexturize( $text ); |
|
307 | + $text = wp_strip_all_tags( $text ); |
|
308 | + $text = str_replace( ']]>', ']]>', $text ); |
|
309 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | protected function getThingImage() |
316 | 316 | { |
317 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
317 | + return (string)get_the_post_thumbnail_url( null, 'large' ); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | protected function getThingUrl() |
332 | 332 | { |
333 | - return (string) get_the_permalink(); |
|
333 | + return (string)get_the_permalink(); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @param string $value |
339 | 339 | * @return string |
340 | 340 | */ |
341 | - protected function setAndGetKeyValue($option, $value) |
|
341 | + protected function setAndGetKeyValue( $option, $value ) |
|
342 | 342 | { |
343 | 343 | $this->keyValues[$option] = $value; |
344 | 344 | return $value; |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | * @param string $format |
32 | 32 | * @return bool |
33 | 33 | */ |
34 | - public function isDate($date, $format = 'Y-m-d H:i:s') |
|
34 | + public function isDate( $date, $format = 'Y-m-d H:i:s' ) |
|
35 | 35 | { |
36 | - $datetime = DateTime::createFromFormat($format, $date); |
|
37 | - return $datetime && $date == $datetime->format($format); |
|
36 | + $datetime = DateTime::createFromFormat( $format, $date ); |
|
37 | + return $datetime && $date == $datetime->format( $format ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @param mixed $date |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public function isTimestamp($date) |
|
44 | + public function isTimestamp( $date ) |
|
45 | 45 | { |
46 | - return ctype_digit($date) |
|
46 | + return ctype_digit( $date ) |
|
47 | 47 | ? true |
48 | 48 | : false; |
49 | 49 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * @param string $fallback |
54 | 54 | * @return string |
55 | 55 | */ |
56 | - public function localized($date, $fallback = '') |
|
56 | + public function localized( $date, $fallback = '' ) |
|
57 | 57 | { |
58 | - return $this->isDate($date) || $this->isTimestamp($date) |
|
59 | - ? date_i18n('Y-m-d H:i', $date) |
|
58 | + return $this->isDate( $date ) || $this->isTimestamp( $date ) |
|
59 | + ? date_i18n( 'Y-m-d H:i', $date ) |
|
60 | 60 | : $fallback; |
61 | 61 | } |
62 | 62 | |
@@ -64,29 +64,29 @@ discard block |
||
64 | 64 | * @param mixed $date |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - public function relative($date) |
|
67 | + public function relative( $date ) |
|
68 | 68 | { |
69 | - if (!$this->isDate($date)) { |
|
69 | + if( !$this->isDate( $date ) ) { |
|
70 | 70 | return ''; |
71 | 71 | } |
72 | - $diff = time() - strtotime($date); |
|
73 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
74 | - if ($diff > $timePeriod[0]) { |
|
72 | + $diff = time() - strtotime( $date ); |
|
73 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
74 | + if( $diff > $timePeriod[0] ) { |
|
75 | 75 | continue; |
76 | 76 | } |
77 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
77 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
78 | 78 | $relativeDates = [ |
79 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
80 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
81 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
82 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
83 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
84 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
85 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
79 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
80 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
81 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
82 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
83 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
84 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
85 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
86 | 86 | ]; |
87 | 87 | $relativeDate = $relativeDates[$i]; |
88 | - return Str::contains($relativeDate, '%s') |
|
89 | - ? sprintf($relativeDate, $unit) |
|
88 | + return Str::contains( $relativeDate, '%s' ) |
|
89 | + ? sprintf( $relativeDate, $unit ) |
|
90 | 90 | : $relativeDate; |
91 | 91 | } |
92 | 92 | } |
@@ -29,33 +29,33 @@ discard block |
||
29 | 29 | * @param string $apiUrl |
30 | 30 | * @param string $file |
31 | 31 | */ |
32 | - public function __construct($apiUrl, $file, array $data = []) |
|
32 | + public function __construct( $apiUrl, $file, array $data = [] ) |
|
33 | 33 | { |
34 | - if (!function_exists('get_plugin_data')) { |
|
34 | + if( !function_exists( 'get_plugin_data' ) ) { |
|
35 | 35 | require_once ABSPATH.WPINC.'/plugin.php'; |
36 | 36 | } |
37 | - $this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl)); |
|
38 | - $this->data = wp_parse_args($data, get_plugin_data($file)); |
|
39 | - $this->plugin = plugin_basename($file); |
|
40 | - $this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain')); |
|
37 | + $this->apiUrl = trailingslashit( apply_filters( 'site-reviews/addon/api-url', $apiUrl ) ); |
|
38 | + $this->data = wp_parse_args( $data, get_plugin_data( $file ) ); |
|
39 | + $this->plugin = plugin_basename( $file ); |
|
40 | + $this->transientName = Application::PREFIX.md5( Arr::get( $data, 'TextDomain' ) ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @return object |
45 | 45 | */ |
46 | - public function activateLicense(array $data = []) |
|
46 | + public function activateLicense( array $data = [] ) |
|
47 | 47 | { |
48 | - return $this->request('activate_license', $data); |
|
48 | + return $this->request( 'activate_license', $data ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return object |
53 | 53 | */ |
54 | - public function checkLicense(array $data = []) |
|
54 | + public function checkLicense( array $data = [] ) |
|
55 | 55 | { |
56 | - $response = $this->request('check_license', $data); |
|
57 | - if ('valid' === Arr::get($response, 'license')) { |
|
58 | - $this->getPluginUpdate(true); |
|
56 | + $response = $this->request( 'check_license', $data ); |
|
57 | + if( 'valid' === Arr::get( $response, 'license' ) ) { |
|
58 | + $this->getPluginUpdate( true ); |
|
59 | 59 | } |
60 | 60 | return $response; |
61 | 61 | } |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @return object |
65 | 65 | */ |
66 | - public function deactivateLicense(array $data = []) |
|
66 | + public function deactivateLicense( array $data = [] ) |
|
67 | 67 | { |
68 | - return $this->request('deactivate_license', $data); |
|
68 | + return $this->request( 'deactivate_license', $data ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param object $args |
75 | 75 | * @return mixed |
76 | 76 | */ |
77 | - public function filterPluginUpdateDetails($result, $action, $args) |
|
77 | + public function filterPluginUpdateDetails( $result, $action, $args ) |
|
78 | 78 | { |
79 | - if ('plugin_information' != $action |
|
80 | - || Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) { |
|
79 | + if( 'plugin_information' != $action |
|
80 | + || Arr::get( $this->data, 'TextDomain' ) != Arr::get( $args, 'slug' ) ) { |
|
81 | 81 | return $result; |
82 | 82 | } |
83 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
84 | - return $this->modifyUpdateDetails($updateInfo); |
|
83 | + if( $updateInfo = $this->getPluginUpdate() ) { |
|
84 | + return $this->modifyUpdateDetails( $updateInfo ); |
|
85 | 85 | } |
86 | 86 | return $result; |
87 | 87 | } |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @param object $transient |
91 | 91 | * @return object |
92 | 92 | */ |
93 | - public function filterPluginUpdates($transient) |
|
93 | + public function filterPluginUpdates( $transient ) |
|
94 | 94 | { |
95 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
96 | - return $this->modifyPluginUpdates($transient, $updateInfo); |
|
95 | + if( $updateInfo = $this->getPluginUpdate() ) { |
|
96 | + return $this->modifyPluginUpdates( $transient, $updateInfo ); |
|
97 | 97 | } |
98 | 98 | return $transient; |
99 | 99 | } |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * @return object |
103 | 103 | */ |
104 | - public function getVersion(array $data = []) |
|
104 | + public function getVersion( array $data = [] ) |
|
105 | 105 | { |
106 | - return $this->request('get_version', $data); |
|
106 | + return $this->request( 'get_version', $data ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function init() |
113 | 113 | { |
114 | - if ($this->apiUrl === trailingslashit(home_url())) { |
|
114 | + if( $this->apiUrl === trailingslashit( home_url() ) ) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | - add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3); |
|
118 | - add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999); |
|
119 | - add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9); |
|
120 | - add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']); |
|
117 | + add_filter( 'plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3 ); |
|
118 | + add_filter( 'pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999 ); |
|
119 | + add_action( 'load-update-core.php', [$this, 'onForceUpdateCheck'], 9 ); |
|
120 | + add_action( 'in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink'] ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function isLicenseValid() |
127 | 127 | { |
128 | 128 | $result = $this->checkLicense(); |
129 | - return 'valid' === Arr::get($result, 'license'); |
|
129 | + return 'valid' === Arr::get( $result, 'license' ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function onForceUpdateCheck() |
136 | 136 | { |
137 | - if (!filter_input(INPUT_GET, 'force-check')) { |
|
137 | + if( !filter_input( INPUT_GET, 'force-check' ) ) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | - foreach (glsr()->addons as $addon) { |
|
140 | + foreach( glsr()->addons as $addon ) { |
|
141 | 141 | try { |
142 | - glsr($addon)->updater->getPluginUpdate(true); |
|
143 | - } catch (\Exception $e) { |
|
144 | - glsr_log()->error($e->getMessage()); |
|
142 | + glsr( $addon )->updater->getPluginUpdate( true ); |
|
143 | + } catch( \Exception $e ) { |
|
144 | + glsr_log()->error( $e->getMessage() ); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function renderLicenseMissingLink() |
153 | 153 | { |
154 | - if (!$this->isLicenseValid()) { |
|
155 | - glsr()->render('partials/addons/license-missing'); |
|
154 | + if( !$this->isLicenseValid() ) { |
|
155 | + glsr()->render( 'partials/addons/license-missing' ); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -161,22 +161,22 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function getCachedVersion() |
163 | 163 | { |
164 | - return get_transient($this->transientName); |
|
164 | + return get_transient( $this->transientName ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | 168 | * @param bool $force |
169 | 169 | * @return false|object |
170 | 170 | */ |
171 | - protected function getPluginUpdate($force = false) |
|
171 | + protected function getPluginUpdate( $force = false ) |
|
172 | 172 | { |
173 | 173 | $version = $this->getCachedVersion(); |
174 | - if (false === $version || $force) { |
|
174 | + if( false === $version || $force ) { |
|
175 | 175 | $version = $this->getVersion(); |
176 | - $this->setCachedVersion($version); |
|
176 | + $this->setCachedVersion( $version ); |
|
177 | 177 | } |
178 | - if (isset($version->error)) { |
|
179 | - glsr_log()->error($version->error); |
|
178 | + if( isset($version->error) ) { |
|
179 | + glsr_log()->error( $version->error ); |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | return $version; |
@@ -187,15 +187,15 @@ discard block |
||
187 | 187 | * @param object $updateInfo |
188 | 188 | * @return object |
189 | 189 | */ |
190 | - protected function modifyPluginUpdates($transient, $updateInfo) |
|
190 | + protected function modifyPluginUpdates( $transient, $updateInfo ) |
|
191 | 191 | { |
192 | - $updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain'); |
|
192 | + $updateInfo->id = Application::ID.'/'.Arr::get( $this->data, 'TextDomain' ); |
|
193 | 193 | $updateInfo->plugin = $this->plugin; |
194 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
195 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
196 | - $transient->checked[$this->plugin] = Arr::get($this->data, 'Version'); |
|
194 | + $updateInfo->requires_php = Arr::get( $this->data, 'RequiresPHP' ); |
|
195 | + $updateInfo->tested = Arr::get( $this->data, 'testedTo' ); |
|
196 | + $transient->checked[$this->plugin] = Arr::get( $this->data, 'Version' ); |
|
197 | 197 | $transient->last_checked = time(); |
198 | - if (Helper::isGreaterThan($updateInfo->new_version, Arr::get($this->data, 'Version'))) { |
|
198 | + if( Helper::isGreaterThan( $updateInfo->new_version, Arr::get( $this->data, 'Version' ) ) ) { |
|
199 | 199 | unset($transient->no_update[$this->plugin]); |
200 | 200 | $updateInfo->update = true; |
201 | 201 | $transient->response[$this->plugin] = $updateInfo; |
@@ -210,13 +210,13 @@ discard block |
||
210 | 210 | * @param object $updateInfo |
211 | 211 | * @return object |
212 | 212 | */ |
213 | - protected function modifyUpdateDetails($updateInfo) |
|
213 | + protected function modifyUpdateDetails( $updateInfo ) |
|
214 | 214 | { |
215 | - $updateInfo->author = Arr::get($this->data, 'Author'); |
|
216 | - $updateInfo->author_profile = Arr::get($this->data, 'AuthorURI'); |
|
217 | - $updateInfo->requires = Arr::get($this->data, 'RequiresWP'); |
|
218 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
219 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
215 | + $updateInfo->author = Arr::get( $this->data, 'Author' ); |
|
216 | + $updateInfo->author_profile = Arr::get( $this->data, 'AuthorURI' ); |
|
217 | + $updateInfo->requires = Arr::get( $this->data, 'RequiresWP' ); |
|
218 | + $updateInfo->requires_php = Arr::get( $this->data, 'RequiresPHP' ); |
|
219 | + $updateInfo->tested = Arr::get( $this->data, 'testedTo' ); |
|
220 | 220 | $updateInfo->version = $updateInfo->new_version; |
221 | 221 | return $updateInfo; |
222 | 222 | } |
@@ -225,49 +225,49 @@ discard block |
||
225 | 225 | * @param \WP_Error|array $response |
226 | 226 | * @return object |
227 | 227 | */ |
228 | - protected function normalizeResponse($response) |
|
228 | + protected function normalizeResponse( $response ) |
|
229 | 229 | { |
230 | - $body = wp_remote_retrieve_body($response); |
|
231 | - if ($data = json_decode($body)) { |
|
232 | - $data = array_map('maybe_unserialize', (array) $data); |
|
233 | - return (object) $data; |
|
230 | + $body = wp_remote_retrieve_body( $response ); |
|
231 | + if( $data = json_decode( $body ) ) { |
|
232 | + $data = array_map( 'maybe_unserialize', (array)$data ); |
|
233 | + return (object)$data; |
|
234 | 234 | } |
235 | - $error = is_wp_error($response) |
|
235 | + $error = is_wp_error( $response ) |
|
236 | 236 | ? $response->get_error_message() |
237 | - : 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')'; |
|
238 | - return (object) ['error' => $error]; |
|
237 | + : 'Update server not responding ('.Arr::get( $this->data, 'TextDomain' ).')'; |
|
238 | + return (object)['error' => $error]; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * @param string $action activate_license|check_license|deactivate_license|get_version |
243 | 243 | * @return object |
244 | 244 | */ |
245 | - protected function request($action, array $data = []) |
|
245 | + protected function request( $action, array $data = [] ) |
|
246 | 246 | { |
247 | - $data = wp_parse_args($data, $this->data); |
|
248 | - $response = wp_remote_post($this->apiUrl, [ |
|
247 | + $data = wp_parse_args( $data, $this->data ); |
|
248 | + $response = wp_remote_post( $this->apiUrl, [ |
|
249 | 249 | 'body' => [ |
250 | 250 | 'edd_action' => $action, |
251 | - 'item_id' => Arr::get($data, 'item_id'), |
|
252 | - 'item_name' => Arr::get($data, 'Name'), |
|
253 | - 'license' => Arr::get($data, 'license'), |
|
254 | - 'slug' => Arr::get($data, 'TextDomain'), |
|
251 | + 'item_id' => Arr::get( $data, 'item_id' ), |
|
252 | + 'item_name' => Arr::get( $data, 'Name' ), |
|
253 | + 'license' => Arr::get( $data, 'license' ), |
|
254 | + 'slug' => Arr::get( $data, 'TextDomain' ), |
|
255 | 255 | 'url' => home_url(), |
256 | 256 | ], |
257 | - 'sslverify' => apply_filters('site-reviews/sslverify/post', false), |
|
257 | + 'sslverify' => apply_filters( 'site-reviews/sslverify/post', false ), |
|
258 | 258 | 'timeout' => 15, |
259 | - ]); |
|
260 | - return $this->normalizeResponse($response); |
|
259 | + ] ); |
|
260 | + return $this->normalizeResponse( $response ); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
264 | 264 | * @param object $version |
265 | 265 | * @return void |
266 | 266 | */ |
267 | - protected function setCachedVersion($version) |
|
267 | + protected function setCachedVersion( $version ) |
|
268 | 268 | { |
269 | - if (!isset($version->error)) { |
|
270 | - set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS); |
|
269 | + if( !isset($version->error) ) { |
|
270 | + set_transient( $this->transientName, $version, 3 * HOUR_IN_SECONDS ); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | public function deleteSessions() |
16 | 16 | { |
17 | 17 | global $wpdb; |
18 | - $wpdb->query(" |
|
18 | + $wpdb->query( " |
|
19 | 19 | DELETE |
20 | 20 | FROM {$wpdb->options} |
21 | 21 | WHERE option_name LIKE '_glsr_session%' |
22 | - "); |
|
22 | + " ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function migrateSettings() |
29 | 29 | { |
30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
30 | + if( $settings = get_option( OptionManager::databaseKey( 3 ) ) ) { |
|
31 | + $multilingual = 'yes' == Arr::get( $settings, 'settings.general.support.polylang' ) |
|
32 | 32 | ? 'polylang' |
33 | 33 | : ''; |
34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
34 | + $settings = Arr::set( $settings, 'settings.general.multilingual', $multilingual ); |
|
35 | + $settings = Arr::set( $settings, 'settings.general.rebusify', 'no' ); |
|
36 | + $settings = Arr::set( $settings, 'settings.general.rebusify_email', '' ); |
|
37 | + $settings = Arr::set( $settings, 'settings.general.rebusify_serial', '' ); |
|
38 | + $settings = Arr::set( $settings, 'settings.reviews.name.format', '' ); |
|
39 | + $settings = Arr::set( $settings, 'settings.reviews.name.initial', '' ); |
|
40 | + $settings = Arr::set( $settings, 'settings.submissions.blacklist.integration', '' ); |
|
41 | + $settings = Arr::set( $settings, 'settings.submissions.limit', '' ); |
|
42 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.email', '' ); |
|
43 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.ip_address', '' ); |
|
44 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.username', '' ); |
|
45 | 45 | unset($settings['settings']['general']['support']); |
46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
46 | + update_option( OptionManager::databaseKey( 4 ), $settings ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | public function protectMetaKeys() |
54 | 54 | { |
55 | 55 | global $wpdb; |
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
56 | + $keys = array_keys( glsr( CreateReviewDefaults::class )->defaults() ); |
|
57 | + $keys = implode( "','", $keys ); |
|
58 | 58 | $postType = Application::POST_TYPE; |
59 | - $wpdb->query(" |
|
59 | + $wpdb->query( " |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | - "); |
|
65 | + " ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -73,6 +73,6 @@ discard block |
||
73 | 73 | $this->migrateSettings(); |
74 | 74 | $this->protectMetaKeys(); |
75 | 75 | $this->deleteSessions(); |
76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
76 | + delete_transient( Application::ID.'_cloudflare_ips' ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | { |
66 | 66 | $this->newSettings = $this->getNewSettings(); |
67 | 67 | $this->oldSettings = $this->getOldSettings(); |
68 | - if (empty($this->oldSettings) || empty($this->newSettings)) { |
|
68 | + if( empty($this->oldSettings) || empty($this->newSettings) ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
72 | - if (empty($this->oldSettings[$old])) { |
|
71 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
72 | + if( empty($this->oldSettings[$old]) ) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | $this->migrateNotificationSettings(); |
78 | 78 | $this->migrateRecaptchaSettings(); |
79 | 79 | $this->migrateRequiredSettings(); |
80 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
81 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
82 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
80 | + $oldSettings = Arr::convertDotNotationArray( $this->oldSettings ); |
|
81 | + $newSettings = Arr::convertDotNotationArray( $this->newSettings ); |
|
82 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
83 | 83 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
84 | 84 | } |
85 | - update_option(OptionManager::databaseKey(3), $newSettings); |
|
85 | + update_option( OptionManager::databaseKey( 3 ), $newSettings ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function getNewSettings() |
100 | 100 | { |
101 | - return Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3))); |
|
101 | + return Arr::flattenArray( Arr::consolidateArray( OptionManager::databaseKey( 3 ) ) ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function getOldSettings() |
108 | 108 | { |
109 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
110 | - $settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2))); |
|
111 | - $settings = Arr::flattenArray($settings); |
|
109 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
110 | + $settings = Arr::consolidateArray( get_option( OptionManager::databaseKey( 2 ) ) ); |
|
111 | + $settings = Arr::flattenArray( $settings ); |
|
112 | 112 | return !empty($settings) |
113 | - ? wp_parse_args($settings, $defaults) |
|
113 | + ? wp_parse_args( $settings, $defaults ) |
|
114 | 114 | : []; |
115 | 115 | } |
116 | 116 | |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | 'webhook' => 'slack', |
126 | 126 | ]; |
127 | 127 | $this->newSettings['settings.general.notifications'] = []; |
128 | - foreach ($notifications as $old => $new) { |
|
129 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
128 | + foreach( $notifications as $old => $new ) { |
|
129 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
144 | 144 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
145 | 145 | ]; |
146 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
146 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
147 | 147 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
148 | 148 | } |
149 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
150 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
149 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
150 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
151 | 151 | } |
152 | 152 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | protected function migrateRequiredSettings() |
161 | 161 | { |
162 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
162 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
163 | 163 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
165 | 165 | } |
@@ -15,44 +15,44 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | - public function getPostId($postId) |
|
18 | + public function getPostId( $postId ) |
|
19 | 19 | { |
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
20 | + $postId = trim( $postId ); |
|
21 | + if( !is_numeric( $postId ) ) { |
|
22 | 22 | return 0; |
23 | 23 | } |
24 | - if ($this->isEnabled()) { |
|
25 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + if( $this->isEnabled() ) { |
|
25 | + $postId = apply_filters( 'wpml_object_id', $postId, 'any', true ); |
|
26 | 26 | } |
27 | - return intval($postId); |
|
27 | + return intval( $postId ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * {@inheritdoc} |
32 | 32 | */ |
33 | - public function getPostIds(array $postIds) |
|
33 | + public function getPostIds( array $postIds ) |
|
34 | 34 | { |
35 | - if (!$this->isEnabled()) { |
|
35 | + if( !$this->isEnabled() ) { |
|
36 | 36 | return $postIds; |
37 | 37 | } |
38 | 38 | $newPostIds = []; |
39 | - foreach (Arr::unique($postIds) as $postId) { |
|
40 | - $postType = get_post_type($postId); |
|
41 | - if (!$postType) { |
|
39 | + foreach( Arr::unique( $postIds ) as $postId ) { |
|
40 | + $postType = get_post_type( $postId ); |
|
41 | + if( !$postType ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | $elementType = 'post_'.$postType; |
45 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | - if (!is_array($translations)) { |
|
45 | + $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType ); |
|
46 | + $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType ); |
|
47 | + if( !is_array( $translations ) ) { |
|
48 | 48 | $translations = []; |
49 | 49 | } |
50 | 50 | $newPostIds = array_merge( |
51 | 51 | $newPostIds, |
52 | - array_column($translations, 'element_id') |
|
52 | + array_column( $translations, 'element_id' ) |
|
53 | 53 | ); |
54 | 54 | } |
55 | - return Arr::unique($newPostIds); |
|
55 | + return Arr::unique( $newPostIds ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function isActive() |
62 | 62 | { |
63 | - return defined('ICL_SITEPRESS_VERSION'); |
|
63 | + return defined( 'ICL_SITEPRESS_VERSION' ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function isEnabled() |
70 | 70 | { |
71 | 71 | return $this->isActive() |
72 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
72 | + && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,6 +78,6 @@ discard block |
||
78 | 78 | public function isSupported() |
79 | 79 | { |
80 | 80 | return $this->isActive() |
81 | - && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
81 | + && Helper::isGreaterThanOrEqual( ICL_SITEPRESS_VERSION, $this->supportedVersion ); |
|
82 | 82 | } |
83 | 83 | } |