@@ -39,20 +39,20 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - public function render(array $attributes) |
|
42 | + public function render( array $attributes ) |
|
43 | 43 | { |
44 | 44 | $attributes['class'] = $attributes['className']; |
45 | - $shortcode = glsr(Shortcode::class); |
|
46 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
45 | + $shortcode = glsr( Shortcode::class ); |
|
46 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
47 | 47 | $this->filterFormFields(); |
48 | 48 | $this->filterRatingField(); |
49 | 49 | $this->filterShortcodeClass(); |
50 | 50 | $this->filterSubmitButton(); |
51 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
51 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
52 | 52 | $this->filterInterpolation(); |
53 | 53 | } |
54 | 54 | } |
55 | - return $shortcode->buildShortcode($attributes); |
|
55 | + return $shortcode->buildShortcode( $attributes ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected function filterFormFields() |
62 | 62 | { |
63 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | - array_walk($config, function (&$field) { |
|
63 | + add_filter( 'site-reviews/config/forms/submission-form', function( array $config ) { |
|
64 | + array_walk( $config, function( &$field ) { |
|
65 | 65 | $field['disabled'] = true; |
66 | 66 | $field['tabindex'] = '-1'; |
67 | 67 | }); |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function filterInterpolation() |
76 | 76 | { |
77 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
77 | + add_filter( 'site-reviews/interpolate/reviews-form', function( $context ) { |
|
78 | 78 | $context['class'] = 'glsr-default glsr-block-disabled'; |
79 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
79 | + $context['fields'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
80 | 80 | $context['response'] = ''; |
81 | 81 | $context['submit_button'] = ''; |
82 | 82 | return $context; |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function filterRatingField() |
90 | 90 | { |
91 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | - if ('rating' == $args['path']) { |
|
91 | + add_filter( 'site-reviews/rendered/field', function( $html, $type, $args ) { |
|
92 | + if( 'rating' == $args['path'] ) { |
|
93 | 93 | $stars = '<span class="glsr-stars">'; |
94 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | - $stars.= '</span>'; |
|
96 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
94 | + $stars .= str_repeat( '<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int)glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
95 | + $stars .= '</span>'; |
|
96 | + $html = preg_replace( '/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html ); |
|
97 | 97 | } |
98 | 98 | return $html; |
99 | - }, 10, 3); |
|
99 | + }, 10, 3 ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function filterShortcodeClass() |
106 | 106 | { |
107 | - add_filter('site-reviews/style', function () { |
|
107 | + add_filter( 'site-reviews/style', function() { |
|
108 | 108 | return 'default'; |
109 | 109 | }); |
110 | 110 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function filterSubmitButton() |
116 | 116 | { |
117 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
117 | + add_filter( 'site-reviews/rendered/template/form/submit-button', function( $template ) { |
|
118 | + return str_replace( 'type="submit"', 'tabindex="-1"', $template ); |
|
119 | 119 | }); |
120 | 120 | } |
121 | 121 | } |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | * @param int $postId |
15 | 15 | * @return void|string |
16 | 16 | */ |
17 | - public function buildColumnAssignedTo($postId) |
|
17 | + public function buildColumnAssignedTo( $postId ) |
|
18 | 18 | { |
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | - return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | - ]); |
|
19 | + $assignedPost = glsr( Database::class )->getAssignedToPost( $postId ); |
|
20 | + if( $assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status ) { |
|
21 | + return glsr( Builder::class )->a( get_the_title( $assignedPost->ID ), [ |
|
22 | + 'href' => (string)get_the_permalink( $assignedPost->ID ), |
|
23 | + ] ); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * @param int $postId |
29 | 29 | * @return void|string |
30 | 30 | */ |
31 | - public function buildColumnEmail($postId) |
|
31 | + public function buildColumnEmail( $postId ) |
|
32 | 32 | { |
33 | - if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
33 | + if( $email = glsr( Database::class )->get( $postId, 'email' ) ) { |
|
34 | 34 | return $email; |
35 | 35 | } |
36 | 36 | } |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | * @param int $postId |
40 | 40 | * @return void|string |
41 | 41 | */ |
42 | - public function buildColumnIpAddress($postId) |
|
42 | + public function buildColumnIpAddress( $postId ) |
|
43 | 43 | { |
44 | - if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
44 | + if( $ipAddress = glsr( Database::class )->get( $postId, 'ip_address' ) ) { |
|
45 | 45 | return $ipAddress; |
46 | 46 | } |
47 | 47 | } |
@@ -50,35 +50,35 @@ discard block |
||
50 | 50 | * @param int $postId |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - public function buildColumnPinned($postId) |
|
53 | + public function buildColumnPinned( $postId ) |
|
54 | 54 | { |
55 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
55 | + $pinned = glsr( Database::class )->get( $postId, 'pinned' ) |
|
56 | 56 | ? 'pinned ' |
57 | 57 | : ''; |
58 | - return glsr(Builder::class)->i([ |
|
58 | + return glsr( Builder::class )->i( [ |
|
59 | 59 | 'class' => $pinned.'dashicons dashicons-sticky', |
60 | 60 | 'data-id' => $postId, |
61 | - ]); |
|
61 | + ] ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @param int $postId |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function buildColumnResponse($postId) |
|
68 | + public function buildColumnResponse( $postId ) |
|
69 | 69 | { |
70 | - return glsr(Database::class)->get($postId, 'response') |
|
71 | - ? __('Yes', 'site-reviews') |
|
72 | - : __('No', 'site-reviews'); |
|
70 | + return glsr( Database::class )->get( $postId, 'response' ) |
|
71 | + ? __( 'Yes', 'site-reviews' ) |
|
72 | + : __( 'No', 'site-reviews' ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @param int $postId |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function buildColumnReviewer($postId) |
|
79 | + public function buildColumnReviewer( $postId ) |
|
80 | 80 | { |
81 | - return strval(glsr(Database::class)->get($postId, 'author')); |
|
81 | + return strval( glsr( Database::class )->get( $postId, 'author' ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,39 +86,39 @@ discard block |
||
86 | 86 | * @param int|null $rating |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function buildColumnRating($postId) |
|
89 | + public function buildColumnRating( $postId ) |
|
90 | 90 | { |
91 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
91 | + return glsr_star_rating( intval( glsr( Database::class )->get( $postId, 'rating' ) ) ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | 95 | * @param int $postId |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - public function buildColumnReviewType($postId) |
|
98 | + public function buildColumnReviewType( $postId ) |
|
99 | 99 | { |
100 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
101 | - return array_key_exists($type, glsr()->reviewTypes) |
|
100 | + $type = glsr( Database::class )->get( $postId, 'review_type' ); |
|
101 | + return array_key_exists( $type, glsr()->reviewTypes ) |
|
102 | 102 | ? glsr()->reviewTypes[$type] |
103 | - : __('Unsupported Type', 'site-reviews'); |
|
103 | + : __( 'Unsupported Type', 'site-reviews' ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @param string $postType |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - public function renderFilters($postType) |
|
110 | + public function renderFilters( $postType ) |
|
111 | 111 | { |
112 | - if (Application::POST_TYPE !== $postType) { |
|
112 | + if( Application::POST_TYPE !== $postType ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
115 | + if( !($status = filter_input( INPUT_GET, 'post_status' )) ) { |
|
116 | 116 | $status = 'publish'; |
117 | 117 | } |
118 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
119 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
120 | - $this->renderFilterRatings($ratings); |
|
121 | - $this->renderFilterTypes($types); |
|
118 | + $ratings = glsr( Database::class )->getReviewsMeta( 'rating', $status ); |
|
119 | + $types = glsr( Database::class )->getReviewsMeta( 'review_type', $status ); |
|
120 | + $this->renderFilterRatings( $ratings ); |
|
121 | + $this->renderFilterTypes( $types ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | * @param int $postId |
127 | 127 | * @return void |
128 | 128 | */ |
129 | - public function renderValues($column, $postId) |
|
129 | + public function renderValues( $column, $postId ) |
|
130 | 130 | { |
131 | - $method = Helper::buildMethodName($column, 'buildColumn'); |
|
132 | - $value = method_exists($this, $method) |
|
133 | - ? call_user_func([$this, $method], $postId) |
|
131 | + $method = Helper::buildMethodName( $column, 'buildColumn' ); |
|
132 | + $value = method_exists( $this, $method ) |
|
133 | + ? call_user_func( [$this, $method], $postId ) |
|
134 | 134 | : ''; |
135 | - $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
136 | - if (0 !== $value && empty($value)) { |
|
135 | + $value = apply_filters( 'site-reviews/columns/'.$column, $value, $postId ); |
|
136 | + if( 0 !== $value && empty($value) ) { |
|
137 | 137 | $value = '—'; |
138 | 138 | } |
139 | 139 | echo $value; |
@@ -143,44 +143,44 @@ discard block |
||
143 | 143 | * @param array $ratings |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - protected function renderFilterRatings($ratings) |
|
146 | + protected function renderFilterRatings( $ratings ) |
|
147 | 147 | { |
148 | - if (empty($ratings)) { |
|
148 | + if( empty($ratings) ) { |
|
149 | 149 | return; |
150 | 150 | } |
151 | - $ratings = array_flip(array_reverse($ratings)); |
|
152 | - array_walk($ratings, function (&$value, $key) { |
|
153 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
154 | - $value = sprintf($label, $key); |
|
151 | + $ratings = array_flip( array_reverse( $ratings ) ); |
|
152 | + array_walk( $ratings, function( &$value, $key ) { |
|
153 | + $label = _n( '%s star', '%s stars', $key, 'site-reviews' ); |
|
154 | + $value = sprintf( $label, $key ); |
|
155 | 155 | }); |
156 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
156 | + echo glsr( Builder::class )->label( __( 'Filter by rating', 'site-reviews' ), [ |
|
157 | 157 | 'class' => 'screen-reader-text', |
158 | 158 | 'for' => 'rating', |
159 | - ]); |
|
160 | - echo glsr(Builder::class)->select([ |
|
159 | + ] ); |
|
160 | + echo glsr( Builder::class )->select( [ |
|
161 | 161 | 'name' => 'rating', |
162 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
163 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
164 | - ]); |
|
162 | + 'options' => ['' => __( 'All ratings', 'site-reviews' )] + $ratings, |
|
163 | + 'value' => filter_input( INPUT_GET, 'rating' ), |
|
164 | + ] ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | 168 | * @param array $types |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - protected function renderFilterTypes($types) |
|
171 | + protected function renderFilterTypes( $types ) |
|
172 | 172 | { |
173 | - if (count(glsr()->reviewTypes) < 2) { |
|
173 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
176 | + echo glsr( Builder::class )->label( __( 'Filter by type', 'site-reviews' ), [ |
|
177 | 177 | 'class' => 'screen-reader-text', |
178 | 178 | 'for' => 'review_type', |
179 | - ]); |
|
180 | - echo glsr(Builder::class)->select([ |
|
179 | + ] ); |
|
180 | + echo glsr( Builder::class )->select( [ |
|
181 | 181 | 'name' => 'review_type', |
182 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
183 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
184 | - ]); |
|
182 | + 'options' => ['' => __( 'All types', 'site-reviews' )] + glsr()->reviewTypes, |
|
183 | + 'value' => filter_input( INPUT_GET, 'review_type' ), |
|
184 | + ] ); |
|
185 | 185 | } |
186 | 186 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p class="about-description">We hope you love the changes in this new release!</p> |
4 | 4 | <div class="is-fullwidth"> |
@@ -28,33 +28,33 @@ discard block |
||
28 | 28 | * @param string $apiUrl |
29 | 29 | * @param string $file |
30 | 30 | */ |
31 | - public function __construct($apiUrl, $file, array $data = []) |
|
31 | + public function __construct( $apiUrl, $file, array $data = [] ) |
|
32 | 32 | { |
33 | - if (!function_exists('get_plugin_data')) { |
|
33 | + if( !function_exists( 'get_plugin_data' ) ) { |
|
34 | 34 | require_once ABSPATH.WPINC.'/plugin.php'; |
35 | 35 | } |
36 | - $this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl)); |
|
37 | - $this->data = wp_parse_args($data, get_plugin_data($file)); |
|
38 | - $this->plugin = plugin_basename($file); |
|
39 | - $this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain')); |
|
36 | + $this->apiUrl = trailingslashit( apply_filters( 'site-reviews/addon/api-url', $apiUrl ) ); |
|
37 | + $this->data = wp_parse_args( $data, get_plugin_data( $file ) ); |
|
38 | + $this->plugin = plugin_basename( $file ); |
|
39 | + $this->transientName = Application::PREFIX.md5( Arr::get( $data, 'TextDomain' ) ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @return object |
44 | 44 | */ |
45 | - public function activateLicense(array $data = []) |
|
45 | + public function activateLicense( array $data = [] ) |
|
46 | 46 | { |
47 | - return $this->request('activate_license', $data); |
|
47 | + return $this->request( 'activate_license', $data ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @return object |
52 | 52 | */ |
53 | - public function checkLicense(array $data = []) |
|
53 | + public function checkLicense( array $data = [] ) |
|
54 | 54 | { |
55 | - $response = $this->request('check_license', $data); |
|
56 | - if ('valid' === Arr::get($response, 'license')) { |
|
57 | - $this->getPluginUpdate(true); |
|
55 | + $response = $this->request( 'check_license', $data ); |
|
56 | + if( 'valid' === Arr::get( $response, 'license' ) ) { |
|
57 | + $this->getPluginUpdate( true ); |
|
58 | 58 | } |
59 | 59 | return $response; |
60 | 60 | } |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @return object |
64 | 64 | */ |
65 | - public function deactivateLicense(array $data = []) |
|
65 | + public function deactivateLicense( array $data = [] ) |
|
66 | 66 | { |
67 | - return $this->request('deactivate_license', $data); |
|
67 | + return $this->request( 'deactivate_license', $data ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | * @param object $args |
74 | 74 | * @return mixed |
75 | 75 | */ |
76 | - public function filterPluginUpdateDetails($result, $action, $args) |
|
76 | + public function filterPluginUpdateDetails( $result, $action, $args ) |
|
77 | 77 | { |
78 | - if ('plugin_information' != $action |
|
79 | - || Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) { |
|
78 | + if( 'plugin_information' != $action |
|
79 | + || Arr::get( $this->data, 'TextDomain' ) != Arr::get( $args, 'slug' ) ) { |
|
80 | 80 | return $result; |
81 | 81 | } |
82 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
83 | - return $this->modifyUpdateDetails($updateInfo); |
|
82 | + if( $updateInfo = $this->getPluginUpdate() ) { |
|
83 | + return $this->modifyUpdateDetails( $updateInfo ); |
|
84 | 84 | } |
85 | 85 | return $result; |
86 | 86 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * @param object $transient |
90 | 90 | * @return object |
91 | 91 | */ |
92 | - public function filterPluginUpdates($transient) |
|
92 | + public function filterPluginUpdates( $transient ) |
|
93 | 93 | { |
94 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
95 | - return $this->modifyPluginUpdates($transient, $updateInfo); |
|
94 | + if( $updateInfo = $this->getPluginUpdate() ) { |
|
95 | + return $this->modifyPluginUpdates( $transient, $updateInfo ); |
|
96 | 96 | } |
97 | 97 | return $transient; |
98 | 98 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * @return object |
102 | 102 | */ |
103 | - public function getVersion(array $data = []) |
|
103 | + public function getVersion( array $data = [] ) |
|
104 | 104 | { |
105 | - return $this->request('get_version', $data); |
|
105 | + return $this->request( 'get_version', $data ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function init() |
112 | 112 | { |
113 | - if ($this->apiUrl === trailingslashit(home_url())) { |
|
113 | + if( $this->apiUrl === trailingslashit( home_url() ) ) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | - add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3); |
|
117 | - add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999); |
|
118 | - add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9); |
|
119 | - add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']); |
|
116 | + add_filter( 'plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3 ); |
|
117 | + add_filter( 'pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999 ); |
|
118 | + add_action( 'load-update-core.php', [$this, 'onForceUpdateCheck'], 9 ); |
|
119 | + add_action( 'in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink'] ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | public function isLicenseValid() |
126 | 126 | { |
127 | 127 | $result = $this->checkLicense(); |
128 | - return 'valid' === Arr::get($result, 'license'); |
|
128 | + return 'valid' === Arr::get( $result, 'license' ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function onForceUpdateCheck() |
135 | 135 | { |
136 | - if (!filter_input(INPUT_GET, 'force-check')) { |
|
136 | + if( !filter_input( INPUT_GET, 'force-check' ) ) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | - foreach (glsr()->addons as $addon) { |
|
139 | + foreach( glsr()->addons as $addon ) { |
|
140 | 140 | try { |
141 | - glsr($addon)->updater->getPluginUpdate(true); |
|
142 | - } catch (\Exception $e) { |
|
143 | - glsr_log()->error($e->getMessage()); |
|
141 | + glsr( $addon )->updater->getPluginUpdate( true ); |
|
142 | + } catch( \Exception $e ) { |
|
143 | + glsr_log()->error( $e->getMessage() ); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | } |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function renderLicenseMissingLink() |
152 | 152 | { |
153 | - if (!$this->isLicenseValid()) { |
|
154 | - glsr()->render('partials/addons/license-missing'); |
|
153 | + if( !$this->isLicenseValid() ) { |
|
154 | + glsr()->render( 'partials/addons/license-missing' ); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
@@ -160,22 +160,22 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function getCachedVersion() |
162 | 162 | { |
163 | - return get_transient($this->transientName); |
|
163 | + return get_transient( $this->transientName ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | 167 | * @param bool $force |
168 | 168 | * @return false|object |
169 | 169 | */ |
170 | - protected function getPluginUpdate($force = false) |
|
170 | + protected function getPluginUpdate( $force = false ) |
|
171 | 171 | { |
172 | 172 | $version = $this->getCachedVersion(); |
173 | - if (false === $version || $force) { |
|
173 | + if( false === $version || $force ) { |
|
174 | 174 | $version = $this->getVersion(); |
175 | - $this->setCachedVersion($version); |
|
175 | + $this->setCachedVersion( $version ); |
|
176 | 176 | } |
177 | - if (isset($version->error)) { |
|
178 | - glsr_log()->error($version->error); |
|
177 | + if( isset($version->error) ) { |
|
178 | + glsr_log()->error( $version->error ); |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | return $version; |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | * @param object $updateInfo |
187 | 187 | * @return object |
188 | 188 | */ |
189 | - protected function modifyPluginUpdates($transient, $updateInfo) |
|
189 | + protected function modifyPluginUpdates( $transient, $updateInfo ) |
|
190 | 190 | { |
191 | - $updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain'); |
|
191 | + $updateInfo->id = Application::ID.'/'.Arr::get( $this->data, 'TextDomain' ); |
|
192 | 192 | $updateInfo->plugin = $this->plugin; |
193 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
194 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
195 | - $transient->checked[$this->plugin] = Arr::get($this->data, 'Version'); |
|
193 | + $updateInfo->requires_php = Arr::get( $this->data, 'RequiresPHP' ); |
|
194 | + $updateInfo->tested = Arr::get( $this->data, 'testedTo' ); |
|
195 | + $transient->checked[$this->plugin] = Arr::get( $this->data, 'Version' ); |
|
196 | 196 | $transient->last_checked = time(); |
197 | - if (version_compare($updateInfo->new_version, Arr::get($this->data, 'Version'), '>')) { |
|
197 | + if( version_compare( $updateInfo->new_version, Arr::get( $this->data, 'Version' ), '>' ) ) { |
|
198 | 198 | unset($transient->no_update[$this->plugin]); |
199 | 199 | $updateInfo->update = true; |
200 | 200 | $transient->response[$this->plugin] = $updateInfo; |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | * @param object $updateInfo |
210 | 210 | * @return object |
211 | 211 | */ |
212 | - protected function modifyUpdateDetails($updateInfo) |
|
212 | + protected function modifyUpdateDetails( $updateInfo ) |
|
213 | 213 | { |
214 | - $updateInfo->author = Arr::get($this->data, 'Author'); |
|
215 | - $updateInfo->author_profile = Arr::get($this->data, 'AuthorURI'); |
|
216 | - $updateInfo->requires = Arr::get($this->data, 'RequiresWP'); |
|
217 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
218 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
214 | + $updateInfo->author = Arr::get( $this->data, 'Author' ); |
|
215 | + $updateInfo->author_profile = Arr::get( $this->data, 'AuthorURI' ); |
|
216 | + $updateInfo->requires = Arr::get( $this->data, 'RequiresWP' ); |
|
217 | + $updateInfo->requires_php = Arr::get( $this->data, 'RequiresPHP' ); |
|
218 | + $updateInfo->tested = Arr::get( $this->data, 'testedTo' ); |
|
219 | 219 | $updateInfo->version = $updateInfo->new_version; |
220 | 220 | return $updateInfo; |
221 | 221 | } |
@@ -224,49 +224,49 @@ discard block |
||
224 | 224 | * @param \WP_Error|array $response |
225 | 225 | * @return object |
226 | 226 | */ |
227 | - protected function normalizeResponse($response) |
|
227 | + protected function normalizeResponse( $response ) |
|
228 | 228 | { |
229 | - $body = wp_remote_retrieve_body($response); |
|
230 | - if ($data = json_decode($body)) { |
|
231 | - $data = array_map('maybe_unserialize', (array) $data); |
|
232 | - return (object) $data; |
|
229 | + $body = wp_remote_retrieve_body( $response ); |
|
230 | + if( $data = json_decode( $body ) ) { |
|
231 | + $data = array_map( 'maybe_unserialize', (array)$data ); |
|
232 | + return (object)$data; |
|
233 | 233 | } |
234 | - $error = is_wp_error($response) |
|
234 | + $error = is_wp_error( $response ) |
|
235 | 235 | ? $response->get_error_message() |
236 | - : 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')'; |
|
237 | - return (object) ['error' => $error]; |
|
236 | + : 'Update server not responding ('.Arr::get( $this->data, 'TextDomain' ).')'; |
|
237 | + return (object)['error' => $error]; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | 241 | * @param string $action activate_license|check_license|deactivate_license|get_version |
242 | 242 | * @return object |
243 | 243 | */ |
244 | - protected function request($action, array $data = []) |
|
244 | + protected function request( $action, array $data = [] ) |
|
245 | 245 | { |
246 | - $data = wp_parse_args($data, $this->data); |
|
247 | - $response = wp_remote_post($this->apiUrl, [ |
|
246 | + $data = wp_parse_args( $data, $this->data ); |
|
247 | + $response = wp_remote_post( $this->apiUrl, [ |
|
248 | 248 | 'body' => [ |
249 | 249 | 'edd_action' => $action, |
250 | - 'item_id' => Arr::get($data, 'item_id'), |
|
251 | - 'item_name' => Arr::get($data, 'Name'), |
|
252 | - 'license' => Arr::get($data, 'license'), |
|
253 | - 'slug' => Arr::get($data, 'TextDomain'), |
|
250 | + 'item_id' => Arr::get( $data, 'item_id' ), |
|
251 | + 'item_name' => Arr::get( $data, 'Name' ), |
|
252 | + 'license' => Arr::get( $data, 'license' ), |
|
253 | + 'slug' => Arr::get( $data, 'TextDomain' ), |
|
254 | 254 | 'url' => home_url(), |
255 | 255 | ], |
256 | - 'sslverify' => apply_filters('site-reviews/sslverify/post', false), |
|
256 | + 'sslverify' => apply_filters( 'site-reviews/sslverify/post', false ), |
|
257 | 257 | 'timeout' => 15, |
258 | - ]); |
|
259 | - return $this->normalizeResponse($response); |
|
258 | + ] ); |
|
259 | + return $this->normalizeResponse( $response ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * @param object $version |
264 | 264 | * @return void |
265 | 265 | */ |
266 | - protected function setCachedVersion($version) |
|
266 | + protected function setCachedVersion( $version ) |
|
267 | 267 | { |
268 | - if (!isset($version->error)) { |
|
269 | - set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS); |
|
268 | + if( !isset($version->error) ) { |
|
269 | + set_transient( $this->transientName, $version, 3 * HOUR_IN_SECONDS ); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
@@ -16,31 +16,31 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->manager = glsr(CountsManager::class); |
|
19 | + $this->manager = glsr( CountsManager::class ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param int $termTaxonomyId |
24 | 24 | * @return array |
25 | 25 | */ |
26 | - public function build($termTaxonomyId) |
|
26 | + public function build( $termTaxonomyId ) |
|
27 | 27 | { |
28 | - return $this->manager->buildCounts([ |
|
28 | + return $this->manager->buildCounts( [ |
|
29 | 29 | 'term_ids' => [$termTaxonomyId], |
30 | - ]); |
|
30 | + ] ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public function decrease(Review $review) |
|
36 | + public function decrease( Review $review ) |
|
37 | 37 | { |
38 | - foreach ($review->term_ids as $termId) { |
|
39 | - if (empty($counts = $this->get($termId))) { |
|
38 | + foreach( $review->term_ids as $termId ) { |
|
39 | + if( empty($counts = $this->get( $termId )) ) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | - $this->update($termId, |
|
43 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
42 | + $this->update( $termId, |
|
43 | + $this->manager->decreaseRating( $counts, $review->review_type, $review->rating ) |
|
44 | 44 | ); |
45 | 45 | } |
46 | 46 | } |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | * @param int $termId |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - public function get($termId) |
|
52 | + public function get( $termId ) |
|
53 | 53 | { |
54 | - return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
54 | + return array_filter( (array)get_term_meta( $termId, CountsManager::META_COUNT, true ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function increase(Review $review) |
|
60 | + public function increase( Review $review ) |
|
61 | 61 | { |
62 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | - foreach ($terms as $term) { |
|
64 | - $counts = $this->get($term['term_id']); |
|
62 | + $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
63 | + foreach( $terms as $term ) { |
|
64 | + $counts = $this->get( $term['term_id'] ); |
|
65 | 65 | $counts = empty($counts) |
66 | - ? $this->build($term['term_taxonomy_id']) |
|
67 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | - $this->update($term['term_id'], $counts); |
|
66 | + ? $this->build( $term['term_taxonomy_id'] ) |
|
67 | + : $this->manager->increaseRating( $counts, $review->review_type, $review->rating ); |
|
68 | + $this->update( $term['term_id'], $counts ); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | * @param int $termId |
74 | 74 | * @return void |
75 | 75 | */ |
76 | - public function update($termId, array $reviewCounts) |
|
76 | + public function update( $termId, array $reviewCounts ) |
|
77 | 77 | { |
78 | - $term = get_term($termId, Application::TAXONOMY); |
|
79 | - if (!isset($term->term_id)) { |
|
78 | + $term = get_term( $termId, Application::TAXONOMY ); |
|
79 | + if( !isset($term->term_id) ) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | - update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | - update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | - update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
82 | + $ratingCounts = $this->manager->flatten( $reviewCounts ); |
|
83 | + update_term_meta( $termId, CountsManager::META_COUNT, $reviewCounts ); |
|
84 | + update_term_meta( $termId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
85 | + update_term_meta( $termId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function updateAll() |
92 | 92 | { |
93 | - $terms = glsr(Database::class)->getTerms([ |
|
93 | + $terms = glsr( Database::class )->getTerms( [ |
|
94 | 94 | 'fields' => 'all', |
95 | - ]); |
|
96 | - foreach ($terms as $term) { |
|
97 | - $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
95 | + ] ); |
|
96 | + foreach( $terms as $term ) { |
|
97 | + $this->update( $term->term_id, $this->build( $term->term_taxonomy_id ) ); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->manager = glsr(CountsManager::class); |
|
17 | + $this->manager = glsr( CountsManager::class ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param int $postId |
22 | 22 | * @return array |
23 | 23 | */ |
24 | - public function build($postId) |
|
24 | + public function build( $postId ) |
|
25 | 25 | { |
26 | - return $this->manager->buildCounts([ |
|
26 | + return $this->manager->buildCounts( [ |
|
27 | 27 | 'post_ids' => [$postId], |
28 | - ]); |
|
28 | + ] ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @return void |
33 | 33 | */ |
34 | - public function decrease(Review $review) |
|
34 | + public function decrease( Review $review ) |
|
35 | 35 | { |
36 | - if (empty($counts = $this->get($review->assigned_to))) { |
|
36 | + if( empty($counts = $this->get( $review->assigned_to )) ) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | - $this->update($review->assigned_to, |
|
40 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
39 | + $this->update( $review->assigned_to, |
|
40 | + $this->manager->decreaseRating( $counts, $review->review_type, $review->rating ) |
|
41 | 41 | ); |
42 | 42 | } |
43 | 43 | |
@@ -45,36 +45,36 @@ discard block |
||
45 | 45 | * @param int $postId |
46 | 46 | * @return array |
47 | 47 | */ |
48 | - public function get($postId) |
|
48 | + public function get( $postId ) |
|
49 | 49 | { |
50 | - return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
50 | + return array_filter( (array)get_post_meta( $postId, CountsManager::META_COUNT, true ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function increase(Review $review) |
|
56 | + public function increase( Review $review ) |
|
57 | 57 | { |
58 | - if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
58 | + if( !(get_post( $review->assigned_to ) instanceof \WP_Post) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | - $counts = $this->get($review->assigned_to); |
|
61 | + $counts = $this->get( $review->assigned_to ); |
|
62 | 62 | $counts = empty($counts) |
63 | - ? $this->build($review->assigned_to) |
|
64 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | - $this->update($review->assigned_to, $counts); |
|
63 | + ? $this->build( $review->assigned_to ) |
|
64 | + : $this->manager->increaseRating( $counts, $review->review_type, $review->rating ); |
|
65 | + $this->update( $review->assigned_to, $counts ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param int $postId |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function update($postId, array $reviewCounts) |
|
72 | + public function update( $postId, array $reviewCounts ) |
|
73 | 73 | { |
74 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | - update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | - update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | - update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
74 | + $ratingCounts = $this->manager->flatten( $reviewCounts ); |
|
75 | + update_post_meta( $postId, CountsManager::META_COUNT, $reviewCounts ); |
|
76 | + update_post_meta( $postId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
77 | + update_post_meta( $postId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function updateAll() |
84 | 84 | { |
85 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
86 | - foreach ($postIds as $postId) { |
|
87 | - $this->update($postId, $this->build($postId)); |
|
85 | + $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
|
86 | + foreach( $postIds as $postId ) { |
|
87 | + $this->update( $postId, $this->build( $postId ) ); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @return false|Review |
21 | 21 | */ |
22 | - public function create(CreateReview $command) |
|
22 | + public function create( CreateReview $command ) |
|
23 | 23 | { |
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
24 | + $reviewValues = glsr( CreateReviewDefaults::class )->restrict( (array)$command ); |
|
25 | + $reviewValues = apply_filters( 'site-reviews/create/review-values', $reviewValues, $command ); |
|
26 | + $reviewValues = Arr::prefixArrayKeys( $reviewValues ); |
|
27 | 27 | unset($reviewValues['json']); // @todo remove the need for this |
28 | 28 | $postValues = [ |
29 | 29 | 'comment_status' => 'closed', |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | 'ping_status' => 'closed', |
32 | 32 | 'post_content' => $reviewValues['_content'], |
33 | 33 | 'post_date' => $reviewValues['_date'], |
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
34 | + 'post_date_gmt' => get_gmt_from_date( $reviewValues['_date'] ), |
|
35 | 35 | 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
36 | + 'post_status' => $this->getNewPostStatus( $reviewValues, $command->blacklisted ), |
|
37 | 37 | 'post_title' => $reviewValues['_title'], |
38 | 38 | 'post_type' => Application::POST_TYPE, |
39 | 39 | ]; |
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
40 | + $postId = wp_insert_post( $postValues, true ); |
|
41 | + if( is_wp_error( $postId ) ) { |
|
42 | + glsr_log()->error( $postId->get_error_message() )->debug( $postValues ); |
|
43 | 43 | return false; |
44 | 44 | } |
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
45 | + $this->setTerms( $postId, $command->category ); |
|
46 | + $review = $this->single( get_post( $postId ) ); |
|
47 | + do_action( 'site-reviews/review/created', $review, $command ); |
|
48 | 48 | return $review; |
49 | 49 | } |
50 | 50 | |
@@ -52,29 +52,29 @@ discard block |
||
52 | 52 | * @param string $metaReviewId |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function delete($metaReviewId) |
|
55 | + public function delete( $metaReviewId ) |
|
56 | 56 | { |
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
57 | + if( $postId = $this->getPostId( $metaReviewId ) ) { |
|
58 | + wp_delete_post( $postId, true ); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return object |
64 | 64 | */ |
65 | - public function get(array $args = []) |
|
65 | + public function get( array $args = [] ) |
|
66 | 66 | { |
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
67 | + $args = glsr( ReviewsDefaults::class )->merge( $args ); |
|
68 | + $metaQuery = glsr( QueryBuilder::class )->buildQuery( |
|
69 | 69 | ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
70 | 70 | $args |
71 | 71 | ); |
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
72 | + $taxQuery = glsr( QueryBuilder::class )->buildQuery( |
|
73 | 73 | ['category'], |
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
74 | + ['category' => $this->normalizeTermIds( $args['category'] )] |
|
75 | 75 | ); |
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
76 | + $paged = glsr( QueryBuilder::class )->getPaged( |
|
77 | + wp_validate_boolean( $args['pagination'] ) |
|
78 | 78 | ); |
79 | 79 | $parameters = [ |
80 | 80 | 'meta_key' => '_pinned', |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | 'offset' => $args['offset'], |
83 | 83 | 'order' => $args['order'], |
84 | 84 | 'orderby' => 'meta_value '.$args['orderby'], |
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
85 | + 'paged' => Arr::get( $args, 'paged', $paged ), |
|
86 | 86 | 'post__in' => $args['post__in'], |
87 | 87 | 'post__not_in' => $args['post__not_in'], |
88 | 88 | 'post_status' => 'publish', |
@@ -90,62 +90,62 @@ discard block |
||
90 | 90 | 'posts_per_page' => $args['per_page'], |
91 | 91 | 'tax_query' => $taxQuery, |
92 | 92 | ]; |
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
93 | + $parameters = apply_filters( 'site-reviews/get/reviews/query', $parameters, $args ); |
|
94 | + $query = new WP_Query( $parameters ); |
|
95 | + $results = array_map( [$this, 'single'], $query->posts ); |
|
96 | + $reviews = new Reviews( $results, $query->max_num_pages, $args ); |
|
97 | + return apply_filters( 'site-reviews/get/reviews', $reviews, $query ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param string $metaReviewId |
102 | 102 | * @return int |
103 | 103 | */ |
104 | - public function getPostId($metaReviewId) |
|
104 | + public function getPostId( $metaReviewId ) |
|
105 | 105 | { |
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
106 | + return glsr( SqlQueries::class )->getPostIdFromReviewId( $metaReviewId ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public function getRatingCounts(array $args = []) |
|
112 | + public function getRatingCounts( array $args = [] ) |
|
113 | 113 | { |
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
114 | + $args = glsr( SiteReviewsSummaryDefaults::class )->filter( $args ); |
|
115 | + $counts = glsr( CountsManager::class )->getCounts( [ |
|
116 | + 'post_ids' => Arr::convertStringToArray( $args['assigned_to'] ), |
|
117 | + 'term_ids' => $this->normalizeTermIds( $args['category'] ), |
|
118 | 118 | 'type' => $args['type'], |
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
119 | + ] ); |
|
120 | + return glsr( CountsManager::class )->flatten( $counts, [ |
|
121 | 121 | 'min' => $args['rating'], |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @param string $commaSeparatedTermIds |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
129 | + public function normalizeTermIds( $commaSeparatedTermIds ) |
|
130 | 130 | { |
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
131 | + $termIds = glsr_array_column( $this->normalizeTerms( $commaSeparatedTermIds ), 'term_id' ); |
|
132 | + return array_unique( array_map( 'intval', $termIds ) ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | 136 | * @param string $commaSeparatedTermIds |
137 | 137 | * @return array |
138 | 138 | */ |
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
139 | + public function normalizeTerms( $commaSeparatedTermIds ) |
|
140 | 140 | { |
141 | 141 | $terms = []; |
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
142 | + $termIds = Arr::convertStringToArray( $commaSeparatedTermIds ); |
|
143 | + foreach( $termIds as $termId ) { |
|
144 | + if( is_numeric( $termId ) ) { |
|
145 | + $termId = intval( $termId ); |
|
146 | 146 | } |
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
147 | + $term = term_exists( $termId, Application::TAXONOMY ); |
|
148 | + if( !isset($term['term_id']) ) { |
|
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | $terms[] = $term; |
@@ -157,44 +157,44 @@ discard block |
||
157 | 157 | * @param int $postId |
158 | 158 | * @return void |
159 | 159 | */ |
160 | - public function revert($postId) |
|
160 | + public function revert( $postId ) |
|
161 | 161 | { |
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
162 | + if( Application::POST_TYPE != get_post_field( 'post_type', $postId ) ) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
165 | + delete_post_meta( $postId, '_edit_last' ); |
|
166 | + $result = wp_update_post( [ |
|
167 | 167 | 'ID' => $postId, |
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
168 | + 'post_content' => glsr( Database::class )->get( $postId, 'content' ), |
|
169 | + 'post_date' => glsr( Database::class )->get( $postId, 'date' ), |
|
170 | + 'post_title' => glsr( Database::class )->get( $postId, 'title' ), |
|
171 | + ] ); |
|
172 | + if( is_wp_error( $result ) ) { |
|
173 | + glsr_log()->error( $result->get_error_message() ); |
|
174 | 174 | return; |
175 | 175 | } |
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
176 | + do_action( 'site-reviews/review/reverted', glsr_get_review( $postId ) ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @return Review |
181 | 181 | */ |
182 | - public function single(WP_Post $post) |
|
182 | + public function single( WP_Post $post ) |
|
183 | 183 | { |
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
184 | + if( Application::POST_TYPE != $post->post_type ) { |
|
185 | + $post = new WP_Post( (object)[] ); |
|
186 | 186 | } |
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
187 | + $review = new Review( $post ); |
|
188 | + return apply_filters( 'site-reviews/get/review', $review, $post ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param bool $isBlacklisted |
193 | 193 | * @return string |
194 | 194 | */ |
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
195 | + protected function getNewPostStatus( array $reviewValues, $isBlacklisted ) |
|
196 | 196 | { |
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
197 | + $requireApproval = glsr( OptionManager::class )->getBool( 'settings.general.require.approval' ); |
|
198 | 198 | return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
199 | 199 | ? 'pending' |
200 | 200 | : 'publish'; |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | * @param string $termIds |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - protected function setTerms($postId, $termIds) |
|
208 | + protected function setTerms( $postId, $termIds ) |
|
209 | 209 | { |
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
210 | + $termIds = $this->normalizeTermIds( $termIds ); |
|
211 | + if( empty($termIds) ) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
214 | + $termTaxonomyIds = wp_set_object_terms( $postId, $termIds, Application::TAXONOMY ); |
|
215 | + if( is_wp_error( $termTaxonomyIds ) ) { |
|
216 | + glsr_log()->error( $termTaxonomyIds->get_error_message() ); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->manager = glsr(CountsManager::class); |
|
17 | + $this->manager = glsr( CountsManager::class ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public function decrease(Review $review) |
|
31 | + public function decrease( Review $review ) |
|
32 | 32 | { |
33 | - $this->update($this->manager->decreaseRating( |
|
33 | + $this->update( $this->manager->decreaseRating( |
|
34 | 34 | $this->get(), |
35 | 35 | $review->review_type, |
36 | 36 | $review->rating |
37 | - )); |
|
37 | + ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function get() |
44 | 44 | { |
45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | - if (!is_array($counts)) { |
|
47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
45 | + $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
|
46 | + if( !is_array( $counts ) ) { |
|
47 | + glsr_log()->error( 'Review counts is not an array; possibly due to incorrectly imported reviews.' )->debug( $counts ); |
|
48 | 48 | return []; |
49 | 49 | } |
50 | 50 | return $counts; |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function increase(Review $review) |
|
56 | + public function increase( Review $review ) |
|
57 | 57 | { |
58 | - if (empty($counts = $this->get())) { |
|
58 | + if( empty($counts = $this->get()) ) { |
|
59 | 59 | $counts = $this->build(); |
60 | 60 | } |
61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
61 | + $this->update( $this->manager->increaseRating( $counts, $review->review_type, $review->rating ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function update(array $reviewCounts) |
|
67 | + public function update( array $reviewCounts ) |
|
68 | 68 | { |
69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
69 | + glsr( OptionManager::class )->set( 'counts', $reviewCounts ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function updateAll() |
76 | 76 | { |
77 | - $this->update($this->build()); |
|
77 | + $this->update( $this->build() ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -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 | } |