@@ -10,141 +10,141 @@ |
||
10 | 10 | |
11 | 11 | class Columns |
12 | 12 | { |
13 | - /** |
|
14 | - * @param int $postId |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function buildColumnAssignedTo($postId) |
|
18 | - { |
|
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - $column = '—'; |
|
21 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
22 | - $column = glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
23 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
24 | - ]); |
|
25 | - } |
|
26 | - return $column; |
|
27 | - } |
|
13 | + /** |
|
14 | + * @param int $postId |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function buildColumnAssignedTo($postId) |
|
18 | + { |
|
19 | + $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | + $column = '—'; |
|
21 | + if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
22 | + $column = glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
23 | + 'href' => (string) get_the_permalink($assignedPost->ID), |
|
24 | + ]); |
|
25 | + } |
|
26 | + return $column; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param int $postId |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function buildColumnPinned($postId) |
|
34 | - { |
|
35 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
36 | - ? 'pinned ' |
|
37 | - : ''; |
|
38 | - return glsr(Builder::class)->i([ |
|
39 | - 'class' => $pinned.'dashicons dashicons-sticky', |
|
40 | - 'data-id' => $postId, |
|
41 | - ]); |
|
42 | - } |
|
29 | + /** |
|
30 | + * @param int $postId |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function buildColumnPinned($postId) |
|
34 | + { |
|
35 | + $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
36 | + ? 'pinned ' |
|
37 | + : ''; |
|
38 | + return glsr(Builder::class)->i([ |
|
39 | + 'class' => $pinned.'dashicons dashicons-sticky', |
|
40 | + 'data-id' => $postId, |
|
41 | + ]); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int $postId |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function buildColumnReviewer($postId) |
|
49 | - { |
|
50 | - return strval(glsr(Database::class)->get($postId, 'author')); |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param int $postId |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function buildColumnReviewer($postId) |
|
49 | + { |
|
50 | + return strval(glsr(Database::class)->get($postId, 'author')); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param int $postId |
|
55 | - * @param int|null $rating |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function buildColumnRating($postId) |
|
59 | - { |
|
60 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
61 | - } |
|
53 | + /** |
|
54 | + * @param int $postId |
|
55 | + * @param int|null $rating |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function buildColumnRating($postId) |
|
59 | + { |
|
60 | + return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param int $postId |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function buildColumnReviewType($postId) |
|
68 | - { |
|
69 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
70 | - return array_key_exists($type, glsr()->reviewTypes) |
|
71 | - ? glsr()->reviewTypes[$type] |
|
72 | - : __('Unsupported Type', 'site-reviews'); |
|
73 | - } |
|
63 | + /** |
|
64 | + * @param int $postId |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function buildColumnReviewType($postId) |
|
68 | + { |
|
69 | + $type = glsr(Database::class)->get($postId, 'review_type'); |
|
70 | + return array_key_exists($type, glsr()->reviewTypes) |
|
71 | + ? glsr()->reviewTypes[$type] |
|
72 | + : __('Unsupported Type', 'site-reviews'); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param string $postType |
|
77 | - * @return void |
|
78 | - */ |
|
79 | - public function renderFilters($postType) |
|
80 | - { |
|
81 | - if (Application::POST_TYPE !== $postType) { |
|
82 | - return; |
|
83 | - } |
|
84 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
85 | - $status = 'publish'; |
|
86 | - } |
|
87 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
88 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
89 | - $this->renderFilterRatings($ratings); |
|
90 | - $this->renderFilterTypes($types); |
|
91 | - } |
|
75 | + /** |
|
76 | + * @param string $postType |
|
77 | + * @return void |
|
78 | + */ |
|
79 | + public function renderFilters($postType) |
|
80 | + { |
|
81 | + if (Application::POST_TYPE !== $postType) { |
|
82 | + return; |
|
83 | + } |
|
84 | + if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
85 | + $status = 'publish'; |
|
86 | + } |
|
87 | + $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
88 | + $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
89 | + $this->renderFilterRatings($ratings); |
|
90 | + $this->renderFilterTypes($types); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param string $column |
|
95 | - * @param int $postId |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public function renderValues($column, $postId) |
|
99 | - { |
|
100 | - $method = glsr(Helper::class)->buildMethodName($column, 'buildColumn'); |
|
101 | - echo method_exists($this, $method) |
|
102 | - ? call_user_func([$this, $method], $postId) |
|
103 | - : apply_filters('site-reviews/columns/'.$column, '', $postId); |
|
104 | - } |
|
93 | + /** |
|
94 | + * @param string $column |
|
95 | + * @param int $postId |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public function renderValues($column, $postId) |
|
99 | + { |
|
100 | + $method = glsr(Helper::class)->buildMethodName($column, 'buildColumn'); |
|
101 | + echo method_exists($this, $method) |
|
102 | + ? call_user_func([$this, $method], $postId) |
|
103 | + : apply_filters('site-reviews/columns/'.$column, '', $postId); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param array $ratings |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - protected function renderFilterRatings($ratings) |
|
111 | - { |
|
112 | - if (empty($ratings)) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $ratings = array_flip(array_reverse($ratings)); |
|
116 | - array_walk($ratings, function (&$value, $key) { |
|
117 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
118 | - $value = sprintf($label, $key); |
|
119 | - }); |
|
120 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
121 | - 'class' => 'screen-reader-text', |
|
122 | - 'for' => 'rating', |
|
123 | - ]); |
|
124 | - echo glsr(Builder::class)->select([ |
|
125 | - 'name' => 'rating', |
|
126 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
127 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
128 | - ]); |
|
129 | - } |
|
106 | + /** |
|
107 | + * @param array $ratings |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + protected function renderFilterRatings($ratings) |
|
111 | + { |
|
112 | + if (empty($ratings)) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $ratings = array_flip(array_reverse($ratings)); |
|
116 | + array_walk($ratings, function (&$value, $key) { |
|
117 | + $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
118 | + $value = sprintf($label, $key); |
|
119 | + }); |
|
120 | + echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
121 | + 'class' => 'screen-reader-text', |
|
122 | + 'for' => 'rating', |
|
123 | + ]); |
|
124 | + echo glsr(Builder::class)->select([ |
|
125 | + 'name' => 'rating', |
|
126 | + 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
127 | + 'value' => filter_input(INPUT_GET, 'rating'), |
|
128 | + ]); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param array $types |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function renderFilterTypes($types) |
|
136 | - { |
|
137 | - if (count(glsr()->reviewTypes) < 2) { |
|
138 | - return; |
|
139 | - } |
|
140 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
141 | - 'class' => 'screen-reader-text', |
|
142 | - 'for' => 'review_type', |
|
143 | - ]); |
|
144 | - echo glsr(Builder::class)->select([ |
|
145 | - 'name' => 'review_type', |
|
146 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
147 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
148 | - ]); |
|
149 | - } |
|
131 | + /** |
|
132 | + * @param array $types |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function renderFilterTypes($types) |
|
136 | + { |
|
137 | + if (count(glsr()->reviewTypes) < 2) { |
|
138 | + return; |
|
139 | + } |
|
140 | + echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
141 | + 'class' => 'screen-reader-text', |
|
142 | + 'for' => 'review_type', |
|
143 | + ]); |
|
144 | + echo glsr(Builder::class)->select([ |
|
145 | + 'name' => 'review_type', |
|
146 | + 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
147 | + 'value' => filter_input(INPUT_GET, 'review_type'), |
|
148 | + ]); |
|
149 | + } |
|
150 | 150 | } |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | * @param int $postId |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function buildColumnAssignedTo($postId) |
|
17 | + public function buildColumnAssignedTo( $postId ) |
|
18 | 18 | { |
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
19 | + $assignedPost = glsr( Database::class )->getAssignedToPost( $postId ); |
|
20 | 20 | $column = '—'; |
21 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
22 | - $column = glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
23 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
24 | - ]); |
|
21 | + if( $assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status ) { |
|
22 | + $column = glsr( Builder::class )->a( get_the_title( $assignedPost->ID ), [ |
|
23 | + 'href' => (string)get_the_permalink( $assignedPost->ID ), |
|
24 | + ] ); |
|
25 | 25 | } |
26 | 26 | return $column; |
27 | 27 | } |
@@ -30,24 +30,24 @@ discard block |
||
30 | 30 | * @param int $postId |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function buildColumnPinned($postId) |
|
33 | + public function buildColumnPinned( $postId ) |
|
34 | 34 | { |
35 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
35 | + $pinned = glsr( Database::class )->get( $postId, 'pinned' ) |
|
36 | 36 | ? 'pinned ' |
37 | 37 | : ''; |
38 | - return glsr(Builder::class)->i([ |
|
38 | + return glsr( Builder::class )->i( [ |
|
39 | 39 | 'class' => $pinned.'dashicons dashicons-sticky', |
40 | 40 | 'data-id' => $postId, |
41 | - ]); |
|
41 | + ] ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @param int $postId |
46 | 46 | * @return string |
47 | 47 | */ |
48 | - public function buildColumnReviewer($postId) |
|
48 | + public function buildColumnReviewer( $postId ) |
|
49 | 49 | { |
50 | - return strval(glsr(Database::class)->get($postId, 'author')); |
|
50 | + return strval( glsr( Database::class )->get( $postId, 'author' ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,39 +55,39 @@ discard block |
||
55 | 55 | * @param int|null $rating |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - public function buildColumnRating($postId) |
|
58 | + public function buildColumnRating( $postId ) |
|
59 | 59 | { |
60 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
60 | + return glsr_star_rating( intval( glsr( Database::class )->get( $postId, 'rating' ) ) ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @param int $postId |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - public function buildColumnReviewType($postId) |
|
67 | + public function buildColumnReviewType( $postId ) |
|
68 | 68 | { |
69 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
70 | - return array_key_exists($type, glsr()->reviewTypes) |
|
69 | + $type = glsr( Database::class )->get( $postId, 'review_type' ); |
|
70 | + return array_key_exists( $type, glsr()->reviewTypes ) |
|
71 | 71 | ? glsr()->reviewTypes[$type] |
72 | - : __('Unsupported Type', 'site-reviews'); |
|
72 | + : __( 'Unsupported Type', 'site-reviews' ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @param string $postType |
77 | 77 | * @return void |
78 | 78 | */ |
79 | - public function renderFilters($postType) |
|
79 | + public function renderFilters( $postType ) |
|
80 | 80 | { |
81 | - if (Application::POST_TYPE !== $postType) { |
|
81 | + if( Application::POST_TYPE !== $postType ) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
84 | + if( !($status = filter_input( INPUT_GET, 'post_status' )) ) { |
|
85 | 85 | $status = 'publish'; |
86 | 86 | } |
87 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
88 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
89 | - $this->renderFilterRatings($ratings); |
|
90 | - $this->renderFilterTypes($types); |
|
87 | + $ratings = glsr( Database::class )->getReviewsMeta( 'rating', $status ); |
|
88 | + $types = glsr( Database::class )->getReviewsMeta( 'review_type', $status ); |
|
89 | + $this->renderFilterRatings( $ratings ); |
|
90 | + $this->renderFilterTypes( $types ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -95,56 +95,56 @@ discard block |
||
95 | 95 | * @param int $postId |
96 | 96 | * @return void |
97 | 97 | */ |
98 | - public function renderValues($column, $postId) |
|
98 | + public function renderValues( $column, $postId ) |
|
99 | 99 | { |
100 | - $method = glsr(Helper::class)->buildMethodName($column, 'buildColumn'); |
|
101 | - echo method_exists($this, $method) |
|
102 | - ? call_user_func([$this, $method], $postId) |
|
103 | - : apply_filters('site-reviews/columns/'.$column, '', $postId); |
|
100 | + $method = glsr( Helper::class )->buildMethodName( $column, 'buildColumn' ); |
|
101 | + echo method_exists( $this, $method ) |
|
102 | + ? call_user_func( [$this, $method], $postId ) |
|
103 | + : apply_filters( 'site-reviews/columns/'.$column, '', $postId ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @param array $ratings |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - protected function renderFilterRatings($ratings) |
|
110 | + protected function renderFilterRatings( $ratings ) |
|
111 | 111 | { |
112 | - if (empty($ratings)) { |
|
112 | + if( empty($ratings) ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | - $ratings = array_flip(array_reverse($ratings)); |
|
116 | - array_walk($ratings, function (&$value, $key) { |
|
117 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
118 | - $value = sprintf($label, $key); |
|
115 | + $ratings = array_flip( array_reverse( $ratings ) ); |
|
116 | + array_walk( $ratings, function( &$value, $key ) { |
|
117 | + $label = _n( '%s star', '%s stars', $key, 'site-reviews' ); |
|
118 | + $value = sprintf( $label, $key ); |
|
119 | 119 | }); |
120 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
120 | + echo glsr( Builder::class )->label( __( 'Filter by rating', 'site-reviews' ), [ |
|
121 | 121 | 'class' => 'screen-reader-text', |
122 | 122 | 'for' => 'rating', |
123 | - ]); |
|
124 | - echo glsr(Builder::class)->select([ |
|
123 | + ] ); |
|
124 | + echo glsr( Builder::class )->select( [ |
|
125 | 125 | 'name' => 'rating', |
126 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
127 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
128 | - ]); |
|
126 | + 'options' => ['' => __( 'All ratings', 'site-reviews' )] + $ratings, |
|
127 | + 'value' => filter_input( INPUT_GET, 'rating' ), |
|
128 | + ] ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @param array $types |
133 | 133 | * @return void |
134 | 134 | */ |
135 | - protected function renderFilterTypes($types) |
|
135 | + protected function renderFilterTypes( $types ) |
|
136 | 136 | { |
137 | - if (count(glsr()->reviewTypes) < 2) { |
|
137 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
140 | + echo glsr( Builder::class )->label( __( 'Filter by type', 'site-reviews' ), [ |
|
141 | 141 | 'class' => 'screen-reader-text', |
142 | 142 | 'for' => 'review_type', |
143 | - ]); |
|
144 | - echo glsr(Builder::class)->select([ |
|
143 | + ] ); |
|
144 | + echo glsr( Builder::class )->select( [ |
|
145 | 145 | 'name' => 'review_type', |
146 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
147 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
148 | - ]); |
|
146 | + 'options' => ['' => __( 'All types', 'site-reviews' )] + glsr()->reviewTypes, |
|
147 | + 'value' => filter_input( INPUT_GET, 'review_type' ), |
|
148 | + ] ); |
|
149 | 149 | } |
150 | 150 | } |
@@ -108,7 +108,8 @@ |
||
108 | 108 | constant($integrationClass.'::PLUGIN_NAME') |
109 | 109 | )); |
110 | 110 | return false; |
111 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
111 | + } |
|
112 | + elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | 113 | glsr(Notice::class)->addError(sprintf( |
113 | 114 | __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
114 | 115 | constant($integrationClass.'::PLUGIN_NAME'), |
@@ -9,113 +9,113 @@ |
||
9 | 9 | |
10 | 10 | class SettingsController extends Controller |
11 | 11 | { |
12 | - /** |
|
13 | - * @param mixed $input |
|
14 | - * @return array |
|
15 | - * @callback register_setting |
|
16 | - */ |
|
17 | - public function callbackRegisterSettings($input) |
|
18 | - { |
|
19 | - $settings = glsr(Helper::class)->consolidateArray($input); |
|
20 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | - $options = $this->sanitizeGeneral($input, $options); |
|
23 | - $options = $this->sanitizeSubmissions($input, $options); |
|
24 | - $options = $this->sanitizeTranslations($input, $options); |
|
25 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | - } |
|
29 | - return $options; |
|
30 | - } |
|
31 | - return $input; |
|
32 | - } |
|
12 | + /** |
|
13 | + * @param mixed $input |
|
14 | + * @return array |
|
15 | + * @callback register_setting |
|
16 | + */ |
|
17 | + public function callbackRegisterSettings($input) |
|
18 | + { |
|
19 | + $settings = glsr(Helper::class)->consolidateArray($input); |
|
20 | + if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | + $options = $this->sanitizeGeneral($input, $options); |
|
23 | + $options = $this->sanitizeSubmissions($input, $options); |
|
24 | + $options = $this->sanitizeTranslations($input, $options); |
|
25 | + $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | + } |
|
29 | + return $options; |
|
30 | + } |
|
31 | + return $input; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return void |
|
36 | - * @action admin_init |
|
37 | - */ |
|
38 | - public function registerSettings() |
|
39 | - { |
|
40 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | - ]); |
|
43 | - } |
|
34 | + /** |
|
35 | + * @return void |
|
36 | + * @action admin_init |
|
37 | + */ |
|
38 | + public function registerSettings() |
|
39 | + { |
|
40 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | + ]); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - protected function sanitizeGeneral(array $input, array $options) |
|
49 | - { |
|
50 | - $inputForm = $input['settings']['general']; |
|
51 | - if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
52 | - $options['settings']['general']['support']['multilingual'] = ''; |
|
53 | - } |
|
54 | - if ('' == trim($inputForm['notification_message'])) { |
|
55 | - $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
|
56 | - } |
|
57 | - $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []); |
|
58 | - return $options; |
|
59 | - } |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + protected function sanitizeGeneral(array $input, array $options) |
|
49 | + { |
|
50 | + $inputForm = $input['settings']['general']; |
|
51 | + if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
52 | + $options['settings']['general']['support']['multilingual'] = ''; |
|
53 | + } |
|
54 | + if ('' == trim($inputForm['notification_message'])) { |
|
55 | + $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
|
56 | + } |
|
57 | + $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []); |
|
58 | + return $options; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - protected function sanitizeSubmissions(array $input, array $options) |
|
65 | - { |
|
66 | - $inputForm = $input['settings']['submissions']; |
|
67 | - $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
68 | - ? $inputForm['required'] |
|
69 | - : []; |
|
70 | - return $options; |
|
71 | - } |
|
61 | + /** |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + protected function sanitizeSubmissions(array $input, array $options) |
|
65 | + { |
|
66 | + $inputForm = $input['settings']['submissions']; |
|
67 | + $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
68 | + ? $inputForm['required'] |
|
69 | + : []; |
|
70 | + return $options; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return array |
|
75 | - */ |
|
76 | - protected function sanitizeTranslations(array $input, array $options) |
|
77 | - { |
|
78 | - if (isset($input['settings']['strings'])) { |
|
79 | - $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
80 | - $allowedTags = [ |
|
81 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
82 | - 'span' => ['class' => []], |
|
83 | - ]; |
|
84 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | - if (isset($string['s2'])) { |
|
86 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
87 | - } |
|
88 | - if (isset($string['p2'])) { |
|
89 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
90 | - } |
|
91 | - }); |
|
92 | - } |
|
93 | - return $options; |
|
94 | - } |
|
73 | + /** |
|
74 | + * @return array |
|
75 | + */ |
|
76 | + protected function sanitizeTranslations(array $input, array $options) |
|
77 | + { |
|
78 | + if (isset($input['settings']['strings'])) { |
|
79 | + $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
80 | + $allowedTags = [ |
|
81 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
82 | + 'span' => ['class' => []], |
|
83 | + ]; |
|
84 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | + if (isset($string['s2'])) { |
|
86 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
87 | + } |
|
88 | + if (isset($string['p2'])) { |
|
89 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
90 | + } |
|
91 | + }); |
|
92 | + } |
|
93 | + return $options; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - protected function hasMultilingualIntegration($integration) |
|
100 | - { |
|
101 | - if (!in_array($integration, ['polylang', 'wpml'])) { |
|
102 | - return false; |
|
103 | - } |
|
104 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | - if (!glsr($integrationClass)->isActive()) { |
|
106 | - glsr(Notice::class)->addError(sprintf( |
|
107 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | - constant($integrationClass.'::PLUGIN_NAME') |
|
109 | - )); |
|
110 | - return false; |
|
111 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | - glsr(Notice::class)->addError(sprintf( |
|
113 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | - constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | - constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | - )); |
|
117 | - return false; |
|
118 | - } |
|
119 | - return true; |
|
120 | - } |
|
96 | + /** |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + protected function hasMultilingualIntegration($integration) |
|
100 | + { |
|
101 | + if (!in_array($integration, ['polylang', 'wpml'])) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | + if (!glsr($integrationClass)->isActive()) { |
|
106 | + glsr(Notice::class)->addError(sprintf( |
|
107 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | + constant($integrationClass.'::PLUGIN_NAME') |
|
109 | + )); |
|
110 | + return false; |
|
111 | + } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | + glsr(Notice::class)->addError(sprintf( |
|
113 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | + constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | + constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | + )); |
|
117 | + return false; |
|
118 | + } |
|
119 | + return true; |
|
120 | + } |
|
121 | 121 | } |
@@ -14,17 +14,17 @@ discard block |
||
14 | 14 | * @return array |
15 | 15 | * @callback register_setting |
16 | 16 | */ |
17 | - public function callbackRegisterSettings($input) |
|
17 | + public function callbackRegisterSettings( $input ) |
|
18 | 18 | { |
19 | - $settings = glsr(Helper::class)->consolidateArray($input); |
|
20 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | - $options = $this->sanitizeGeneral($input, $options); |
|
23 | - $options = $this->sanitizeSubmissions($input, $options); |
|
24 | - $options = $this->sanitizeTranslations($input, $options); |
|
25 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
19 | + $settings = glsr( Helper::class )->consolidateArray( $input ); |
|
20 | + if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) { |
|
21 | + $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input ); |
|
22 | + $options = $this->sanitizeGeneral( $input, $options ); |
|
23 | + $options = $this->sanitizeSubmissions( $input, $options ); |
|
24 | + $options = $this->sanitizeTranslations( $input, $options ); |
|
25 | + $options = apply_filters( 'site-reviews/settings/callback', $options, $settings ); |
|
26 | + if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
|
27 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
28 | 28 | } |
29 | 29 | return $options; |
30 | 30 | } |
@@ -37,31 +37,31 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function registerSettings() |
39 | 39 | { |
40 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
40 | + register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | 41 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
42 | - ]); |
|
42 | + ] ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @return array |
47 | 47 | */ |
48 | - protected function sanitizeGeneral(array $input, array $options) |
|
48 | + protected function sanitizeGeneral( array $input, array $options ) |
|
49 | 49 | { |
50 | 50 | $inputForm = $input['settings']['general']; |
51 | - if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
51 | + if( !$this->hasMultilingualIntegration( $inputForm['support']['multilingual'] ) ) { |
|
52 | 52 | $options['settings']['general']['support']['multilingual'] = ''; |
53 | 53 | } |
54 | - if ('' == trim($inputForm['notification_message'])) { |
|
54 | + if( '' == trim( $inputForm['notification_message'] ) ) { |
|
55 | 55 | $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
56 | 56 | } |
57 | - $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []); |
|
57 | + $options['settings']['general']['notifications'] = glsr_get( $inputForm, 'notifications', [] ); |
|
58 | 58 | return $options; |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - protected function sanitizeSubmissions(array $input, array $options) |
|
64 | + protected function sanitizeSubmissions( array $input, array $options ) |
|
65 | 65 | { |
66 | 66 | $inputForm = $input['settings']['submissions']; |
67 | 67 | $options['settings']['submissions']['required'] = isset($inputForm['required']) |
@@ -73,20 +73,20 @@ discard block |
||
73 | 73 | /** |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - protected function sanitizeTranslations(array $input, array $options) |
|
76 | + protected function sanitizeTranslations( array $input, array $options ) |
|
77 | 77 | { |
78 | - if (isset($input['settings']['strings'])) { |
|
79 | - $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
78 | + if( isset($input['settings']['strings']) ) { |
|
79 | + $options['settings']['strings'] = array_values( array_filter( $input['settings']['strings'] ) ); |
|
80 | 80 | $allowedTags = [ |
81 | 81 | 'a' => ['class' => [], 'href' => [], 'target' => []], |
82 | 82 | 'span' => ['class' => []], |
83 | 83 | ]; |
84 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | - if (isset($string['s2'])) { |
|
86 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
84 | + array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) { |
|
85 | + if( isset($string['s2']) ) { |
|
86 | + $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
|
87 | 87 | } |
88 | - if (isset($string['p2'])) { |
|
89 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
88 | + if( isset($string['p2']) ) { |
|
89 | + $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
|
90 | 90 | } |
91 | 91 | }); |
92 | 92 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - protected function hasMultilingualIntegration($integration) |
|
99 | + protected function hasMultilingualIntegration( $integration ) |
|
100 | 100 | { |
101 | - if (!in_array($integration, ['polylang', 'wpml'])) { |
|
101 | + if( !in_array( $integration, ['polylang', 'wpml'] ) ) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | - if (!glsr($integrationClass)->isActive()) { |
|
106 | - glsr(Notice::class)->addError(sprintf( |
|
107 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | - constant($integrationClass.'::PLUGIN_NAME') |
|
109 | - )); |
|
104 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst( $integration ); |
|
105 | + if( !glsr( $integrationClass )->isActive() ) { |
|
106 | + glsr( Notice::class )->addError( sprintf( |
|
107 | + __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ), |
|
108 | + constant( $integrationClass.'::PLUGIN_NAME' ) |
|
109 | + ) ); |
|
110 | 110 | return false; |
111 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | - glsr(Notice::class)->addError(sprintf( |
|
113 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | - constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | - constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | - )); |
|
111 | + } elseif( !glsr( $integrationClass )->isSupported() ) { |
|
112 | + glsr( Notice::class )->addError( sprintf( |
|
113 | + __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ), |
|
114 | + constant( $integrationClass.'::PLUGIN_NAME' ), |
|
115 | + constant( $integrationClass.'::SUPPORTED_VERSION' ) |
|
116 | + ) ); |
|
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | return true; |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | interface MultilingualContract |
6 | 6 | { |
7 | - /** |
|
8 | - * @param int|string $postId |
|
9 | - * @return \WP_Post|void|null |
|
10 | - */ |
|
11 | - public function getPost($postId); |
|
7 | + /** |
|
8 | + * @param int|string $postId |
|
9 | + * @return \WP_Post|void|null |
|
10 | + */ |
|
11 | + public function getPost($postId); |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return array |
|
15 | - */ |
|
16 | - public function getPostIds(array $postIds); |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + */ |
|
16 | + public function getPostIds(array $postIds); |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActive(); |
|
18 | + /** |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActive(); |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return bool |
|
25 | - */ |
|
26 | - public function isEnabled(); |
|
23 | + /** |
|
24 | + * @return bool |
|
25 | + */ |
|
26 | + public function isEnabled(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function isSupported(); |
|
28 | + /** |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function isSupported(); |
|
32 | 32 | } |
@@ -8,12 +8,12 @@ |
||
8 | 8 | * @param int|string $postId |
9 | 9 | * @return \WP_Post|void|null |
10 | 10 | */ |
11 | - public function getPost($postId); |
|
11 | + public function getPost( $postId ); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @return array |
15 | 15 | */ |
16 | - public function getPostIds(array $postIds); |
|
16 | + public function getPostIds( array $postIds ); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @return bool |
@@ -12,291 +12,291 @@ |
||
12 | 12 | |
13 | 13 | class Schema |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $args; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $args; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $ratingCounts; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $ratingCounts; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function build(array $args = []) |
|
29 | - { |
|
30 | - $this->args = $args; |
|
31 | - $schema = $this->buildSummary($args); |
|
32 | - $reviews = []; |
|
33 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
34 | - // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
35 | - // @see https://developers.google.com/search/docs/data-types/review |
|
36 | - if ('local' != $review->review_type) { |
|
37 | - continue; |
|
38 | - } |
|
39 | - $reviews[] = $this->buildReview($review); |
|
40 | - } |
|
41 | - if (!empty($reviews)) { |
|
42 | - array_walk($reviews, function (&$review) { |
|
43 | - unset($review['@context']); |
|
44 | - unset($review['itemReviewed']); |
|
45 | - }); |
|
46 | - $schema['review'] = $reviews; |
|
47 | - } |
|
48 | - return $schema; |
|
49 | - } |
|
25 | + /** |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function build(array $args = []) |
|
29 | + { |
|
30 | + $this->args = $args; |
|
31 | + $schema = $this->buildSummary($args); |
|
32 | + $reviews = []; |
|
33 | + foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
34 | + // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
35 | + // @see https://developers.google.com/search/docs/data-types/review |
|
36 | + if ('local' != $review->review_type) { |
|
37 | + continue; |
|
38 | + } |
|
39 | + $reviews[] = $this->buildReview($review); |
|
40 | + } |
|
41 | + if (!empty($reviews)) { |
|
42 | + array_walk($reviews, function (&$review) { |
|
43 | + unset($review['@context']); |
|
44 | + unset($review['itemReviewed']); |
|
45 | + }); |
|
46 | + $schema['review'] = $reviews; |
|
47 | + } |
|
48 | + return $schema; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param array|null $args |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function buildSummary($args = null) |
|
56 | - { |
|
57 | - if (is_array($args)) { |
|
58 | - $this->args = $args; |
|
59 | - } |
|
60 | - $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
61 | - $count = array_sum($this->getRatingCounts()); |
|
62 | - $schema = method_exists($this, $buildSummary) |
|
63 | - ? $this->$buildSummary() |
|
64 | - : $this->buildSummaryForCustom(); |
|
65 | - if (!empty($count)) { |
|
66 | - $schema->aggregateRating( |
|
67 | - $this->getSchemaType('AggregateRating') |
|
68 | - ->ratingValue($this->getRatingValue()) |
|
69 | - ->reviewCount($count) |
|
70 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
71 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
72 | - ); |
|
73 | - } |
|
74 | - $schema = $schema->toArray(); |
|
75 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
76 | - } |
|
51 | + /** |
|
52 | + * @param array|null $args |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function buildSummary($args = null) |
|
56 | + { |
|
57 | + if (is_array($args)) { |
|
58 | + $this->args = $args; |
|
59 | + } |
|
60 | + $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
61 | + $count = array_sum($this->getRatingCounts()); |
|
62 | + $schema = method_exists($this, $buildSummary) |
|
63 | + ? $this->$buildSummary() |
|
64 | + : $this->buildSummaryForCustom(); |
|
65 | + if (!empty($count)) { |
|
66 | + $schema->aggregateRating( |
|
67 | + $this->getSchemaType('AggregateRating') |
|
68 | + ->ratingValue($this->getRatingValue()) |
|
69 | + ->reviewCount($count) |
|
70 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
71 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
72 | + ); |
|
73 | + } |
|
74 | + $schema = $schema->toArray(); |
|
75 | + return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function render() |
|
82 | - { |
|
83 | - if (empty(glsr()->schemas)) { |
|
84 | - return; |
|
85 | - } |
|
86 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
87 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
88 | - JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
89 | - )); |
|
90 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function render() |
|
82 | + { |
|
83 | + if (empty(glsr()->schemas)) { |
|
84 | + return; |
|
85 | + } |
|
86 | + printf('<script type="application/ld+json">%s</script>', json_encode( |
|
87 | + apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
88 | + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
89 | + )); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function store(array $schema) |
|
96 | - { |
|
97 | - $schemas = glsr()->schemas; |
|
98 | - $schemas[] = $schema; |
|
99 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
100 | - } |
|
92 | + /** |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function store(array $schema) |
|
96 | + { |
|
97 | + $schemas = glsr()->schemas; |
|
98 | + $schemas[] = $schema; |
|
99 | + glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param Review $review |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - protected function buildReview($review) |
|
107 | - { |
|
108 | - $schema = $this->getSchemaType('Review') |
|
109 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
110 | - $schema->name($review->title); |
|
111 | - }) |
|
112 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
113 | - $schema->reviewBody($review->content); |
|
114 | - }) |
|
115 | - ->datePublished((new DateTime($review->date))) |
|
116 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
117 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
118 | - if (!empty($review->rating)) { |
|
119 | - $schema->reviewRating( |
|
120 | - $this->getSchemaType('Rating') |
|
121 | - ->ratingValue($review->rating) |
|
122 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
123 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
124 | - ); |
|
125 | - } |
|
126 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
127 | - } |
|
102 | + /** |
|
103 | + * @param Review $review |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + protected function buildReview($review) |
|
107 | + { |
|
108 | + $schema = $this->getSchemaType('Review') |
|
109 | + ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
110 | + $schema->name($review->title); |
|
111 | + }) |
|
112 | + ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
113 | + $schema->reviewBody($review->content); |
|
114 | + }) |
|
115 | + ->datePublished((new DateTime($review->date))) |
|
116 | + ->author($this->getSchemaType('Person')->name($review->author)) |
|
117 | + ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
118 | + if (!empty($review->rating)) { |
|
119 | + $schema->reviewRating( |
|
120 | + $this->getSchemaType('Rating') |
|
121 | + ->ratingValue($review->rating) |
|
122 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
123 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
124 | + ); |
|
125 | + } |
|
126 | + return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @param mixed $schema |
|
131 | - * @return mixed |
|
132 | - */ |
|
133 | - protected function buildSchemaValues($schema, array $values = []) |
|
134 | - { |
|
135 | - foreach ($values as $value) { |
|
136 | - $option = $this->getSchemaOptionValue($value); |
|
137 | - if (empty($option)) { |
|
138 | - continue; |
|
139 | - } |
|
140 | - $schema->$value($option); |
|
141 | - } |
|
142 | - return $schema; |
|
143 | - } |
|
129 | + /** |
|
130 | + * @param mixed $schema |
|
131 | + * @return mixed |
|
132 | + */ |
|
133 | + protected function buildSchemaValues($schema, array $values = []) |
|
134 | + { |
|
135 | + foreach ($values as $value) { |
|
136 | + $option = $this->getSchemaOptionValue($value); |
|
137 | + if (empty($option)) { |
|
138 | + continue; |
|
139 | + } |
|
140 | + $schema->$value($option); |
|
141 | + } |
|
142 | + return $schema; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return mixed |
|
147 | - */ |
|
148 | - protected function buildSummaryForCustom() |
|
149 | - { |
|
150 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
151 | - 'description', 'image', 'name', 'url', |
|
152 | - ]); |
|
153 | - } |
|
145 | + /** |
|
146 | + * @return mixed |
|
147 | + */ |
|
148 | + protected function buildSummaryForCustom() |
|
149 | + { |
|
150 | + return $this->buildSchemaValues($this->getSchemaType(), [ |
|
151 | + 'description', 'image', 'name', 'url', |
|
152 | + ]); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @return mixed |
|
157 | - */ |
|
158 | - protected function buildSummaryForLocalBusiness() |
|
159 | - { |
|
160 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
161 | - 'address', 'priceRange', 'telephone', |
|
162 | - ]); |
|
163 | - } |
|
155 | + /** |
|
156 | + * @return mixed |
|
157 | + */ |
|
158 | + protected function buildSummaryForLocalBusiness() |
|
159 | + { |
|
160 | + return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
161 | + 'address', 'priceRange', 'telephone', |
|
162 | + ]); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @return mixed |
|
167 | - */ |
|
168 | - protected function buildSummaryForProduct() |
|
169 | - { |
|
170 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
171 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
172 | - 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
173 | - ]); |
|
174 | - return $this->buildSummaryForCustom() |
|
175 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
176 | - $schema->offers($offers); |
|
177 | - }) |
|
178 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
179 | - } |
|
165 | + /** |
|
166 | + * @return mixed |
|
167 | + */ |
|
168 | + protected function buildSummaryForProduct() |
|
169 | + { |
|
170 | + $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
171 | + $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
172 | + 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
173 | + ]); |
|
174 | + return $this->buildSummaryForCustom() |
|
175 | + ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
176 | + $schema->offers($offers); |
|
177 | + }) |
|
178 | + ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function getRatingCounts() |
|
185 | - { |
|
186 | - if (!isset($this->ratingCounts)) { |
|
187 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
188 | - } |
|
189 | - return $this->ratingCounts; |
|
190 | - } |
|
181 | + /** |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function getRatingCounts() |
|
185 | + { |
|
186 | + if (!isset($this->ratingCounts)) { |
|
187 | + $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
188 | + } |
|
189 | + return $this->ratingCounts; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * @return int|float |
|
194 | - */ |
|
195 | - protected function getRatingValue() |
|
196 | - { |
|
197 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
198 | - } |
|
192 | + /** |
|
193 | + * @return int|float |
|
194 | + */ |
|
195 | + protected function getRatingValue() |
|
196 | + { |
|
197 | + return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @param string $option |
|
202 | - * @param string $fallback |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - protected function getSchemaOption($option, $fallback) |
|
206 | - { |
|
207 | - $option = strtolower($option); |
|
208 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
209 | - return $schemaOption; |
|
210 | - } |
|
211 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
212 | - if (is_array($setting)) { |
|
213 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
214 | - } |
|
215 | - return !empty($setting) |
|
216 | - ? $setting |
|
217 | - : $fallback; |
|
218 | - } |
|
200 | + /** |
|
201 | + * @param string $option |
|
202 | + * @param string $fallback |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + protected function getSchemaOption($option, $fallback) |
|
206 | + { |
|
207 | + $option = strtolower($option); |
|
208 | + if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
209 | + return $schemaOption; |
|
210 | + } |
|
211 | + $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
212 | + if (is_array($setting)) { |
|
213 | + return $this->getSchemaOptionDefault($setting, $fallback); |
|
214 | + } |
|
215 | + return !empty($setting) |
|
216 | + ? $setting |
|
217 | + : $fallback; |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * @param string $fallback |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
225 | - { |
|
226 | - $setting = wp_parse_args($setting, [ |
|
227 | - 'custom' => '', |
|
228 | - 'default' => $fallback, |
|
229 | - ]); |
|
230 | - return 'custom' != $setting['default'] |
|
231 | - ? $setting['default'] |
|
232 | - : $setting['custom']; |
|
233 | - } |
|
220 | + /** |
|
221 | + * @param string $fallback |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + protected function getSchemaOptionDefault(array $setting, $fallback) |
|
225 | + { |
|
226 | + $setting = wp_parse_args($setting, [ |
|
227 | + 'custom' => '', |
|
228 | + 'default' => $fallback, |
|
229 | + ]); |
|
230 | + return 'custom' != $setting['default'] |
|
231 | + ? $setting['default'] |
|
232 | + : $setting['custom']; |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * @param string $option |
|
237 | - * @param string $fallback |
|
238 | - * @return void|string |
|
239 | - */ |
|
240 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
241 | - { |
|
242 | - $value = $this->getSchemaOption($option, $fallback); |
|
243 | - if ($value != $fallback) { |
|
244 | - return $value; |
|
245 | - } |
|
246 | - if (!is_single() && !is_page()) { |
|
247 | - return; |
|
248 | - } |
|
249 | - $method = glsr(Helper::class)->buildMethodName($option, 'getThing'); |
|
250 | - if (method_exists($this, $method)) { |
|
251 | - return $this->$method(); |
|
252 | - } |
|
253 | - } |
|
235 | + /** |
|
236 | + * @param string $option |
|
237 | + * @param string $fallback |
|
238 | + * @return void|string |
|
239 | + */ |
|
240 | + protected function getSchemaOptionValue($option, $fallback = 'post') |
|
241 | + { |
|
242 | + $value = $this->getSchemaOption($option, $fallback); |
|
243 | + if ($value != $fallback) { |
|
244 | + return $value; |
|
245 | + } |
|
246 | + if (!is_single() && !is_page()) { |
|
247 | + return; |
|
248 | + } |
|
249 | + $method = glsr(Helper::class)->buildMethodName($option, 'getThing'); |
|
250 | + if (method_exists($this, $method)) { |
|
251 | + return $this->$method(); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @param string|null $type |
|
257 | - * @return mixed |
|
258 | - */ |
|
259 | - protected function getSchemaType($type = null) |
|
260 | - { |
|
261 | - if (!is_string($type)) { |
|
262 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
263 | - } |
|
264 | - $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema'); |
|
265 | - return class_exists($className) |
|
266 | - ? new $className() |
|
267 | - : new UnknownType($type); |
|
268 | - } |
|
255 | + /** |
|
256 | + * @param string|null $type |
|
257 | + * @return mixed |
|
258 | + */ |
|
259 | + protected function getSchemaType($type = null) |
|
260 | + { |
|
261 | + if (!is_string($type)) { |
|
262 | + $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
263 | + } |
|
264 | + $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema'); |
|
265 | + return class_exists($className) |
|
266 | + ? new $className() |
|
267 | + : new UnknownType($type); |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - protected function getThingDescription() |
|
274 | - { |
|
275 | - $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt())); |
|
276 | - return wp_trim_words($description, apply_filters('excerpt_length', 55)); |
|
277 | - } |
|
270 | + /** |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + protected function getThingDescription() |
|
274 | + { |
|
275 | + $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt())); |
|
276 | + return wp_trim_words($description, apply_filters('excerpt_length', 55)); |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * @return string |
|
281 | - */ |
|
282 | - protected function getThingImage() |
|
283 | - { |
|
284 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
285 | - } |
|
279 | + /** |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + protected function getThingImage() |
|
283 | + { |
|
284 | + return (string) get_the_post_thumbnail_url(null, 'large'); |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * @return string |
|
289 | - */ |
|
290 | - protected function getThingName() |
|
291 | - { |
|
292 | - return get_the_title(); |
|
293 | - } |
|
287 | + /** |
|
288 | + * @return string |
|
289 | + */ |
|
290 | + protected function getThingName() |
|
291 | + { |
|
292 | + return get_the_title(); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - protected function getThingUrl() |
|
299 | - { |
|
300 | - return (string) get_the_permalink(); |
|
301 | - } |
|
295 | + /** |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + protected function getThingUrl() |
|
299 | + { |
|
300 | + return (string) get_the_permalink(); |
|
301 | + } |
|
302 | 302 | } |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @return array |
27 | 27 | */ |
28 | - public function build(array $args = []) |
|
28 | + public function build( array $args = [] ) |
|
29 | 29 | { |
30 | 30 | $this->args = $args; |
31 | - $schema = $this->buildSummary($args); |
|
31 | + $schema = $this->buildSummary( $args ); |
|
32 | 32 | $reviews = []; |
33 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
33 | + foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) { |
|
34 | 34 | // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
35 | 35 | // @see https://developers.google.com/search/docs/data-types/review |
36 | - if ('local' != $review->review_type) { |
|
36 | + if( 'local' != $review->review_type ) { |
|
37 | 37 | continue; |
38 | 38 | } |
39 | - $reviews[] = $this->buildReview($review); |
|
39 | + $reviews[] = $this->buildReview( $review ); |
|
40 | 40 | } |
41 | - if (!empty($reviews)) { |
|
42 | - array_walk($reviews, function (&$review) { |
|
41 | + if( !empty($reviews) ) { |
|
42 | + array_walk( $reviews, function( &$review ) { |
|
43 | 43 | unset($review['@context']); |
44 | 44 | unset($review['itemReviewed']); |
45 | 45 | }); |
@@ -52,27 +52,27 @@ discard block |
||
52 | 52 | * @param array|null $args |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public function buildSummary($args = null) |
|
55 | + public function buildSummary( $args = null ) |
|
56 | 56 | { |
57 | - if (is_array($args)) { |
|
57 | + if( is_array( $args ) ) { |
|
58 | 58 | $this->args = $args; |
59 | 59 | } |
60 | - $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
61 | - $count = array_sum($this->getRatingCounts()); |
|
62 | - $schema = method_exists($this, $buildSummary) |
|
60 | + $buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
|
61 | + $count = array_sum( $this->getRatingCounts() ); |
|
62 | + $schema = method_exists( $this, $buildSummary ) |
|
63 | 63 | ? $this->$buildSummary() |
64 | 64 | : $this->buildSummaryForCustom(); |
65 | - if (!empty($count)) { |
|
65 | + if( !empty($count) ) { |
|
66 | 66 | $schema->aggregateRating( |
67 | - $this->getSchemaType('AggregateRating') |
|
68 | - ->ratingValue($this->getRatingValue()) |
|
69 | - ->reviewCount($count) |
|
70 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
71 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
67 | + $this->getSchemaType( 'AggregateRating' ) |
|
68 | + ->ratingValue( $this->getRatingValue() ) |
|
69 | + ->reviewCount( $count ) |
|
70 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
71 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | $schema = $schema->toArray(); |
75 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
75 | + return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,64 +80,64 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function render() |
82 | 82 | { |
83 | - if (empty(glsr()->schemas)) { |
|
83 | + if( empty(glsr()->schemas) ) { |
|
84 | 84 | return; |
85 | 85 | } |
86 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
87 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
86 | + printf( '<script type="application/ld+json">%s</script>', json_encode( |
|
87 | + apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
|
88 | 88 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
89 | - )); |
|
89 | + ) ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * @return void |
94 | 94 | */ |
95 | - public function store(array $schema) |
|
95 | + public function store( array $schema ) |
|
96 | 96 | { |
97 | 97 | $schemas = glsr()->schemas; |
98 | 98 | $schemas[] = $schema; |
99 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
99 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param Review $review |
104 | 104 | * @return array |
105 | 105 | */ |
106 | - protected function buildReview($review) |
|
106 | + protected function buildReview( $review ) |
|
107 | 107 | { |
108 | - $schema = $this->getSchemaType('Review') |
|
109 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
110 | - $schema->name($review->title); |
|
108 | + $schema = $this->getSchemaType( 'Review' ) |
|
109 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) { |
|
110 | + $schema->name( $review->title ); |
|
111 | 111 | }) |
112 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
113 | - $schema->reviewBody($review->content); |
|
112 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) { |
|
113 | + $schema->reviewBody( $review->content ); |
|
114 | 114 | }) |
115 | - ->datePublished((new DateTime($review->date))) |
|
116 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
117 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
118 | - if (!empty($review->rating)) { |
|
115 | + ->datePublished( (new DateTime( $review->date )) ) |
|
116 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
117 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
118 | + if( !empty($review->rating) ) { |
|
119 | 119 | $schema->reviewRating( |
120 | - $this->getSchemaType('Rating') |
|
121 | - ->ratingValue($review->rating) |
|
122 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
123 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
120 | + $this->getSchemaType( 'Rating' ) |
|
121 | + ->ratingValue( $review->rating ) |
|
122 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
123 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
124 | 124 | ); |
125 | 125 | } |
126 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
126 | + return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * @param mixed $schema |
131 | 131 | * @return mixed |
132 | 132 | */ |
133 | - protected function buildSchemaValues($schema, array $values = []) |
|
133 | + protected function buildSchemaValues( $schema, array $values = [] ) |
|
134 | 134 | { |
135 | - foreach ($values as $value) { |
|
136 | - $option = $this->getSchemaOptionValue($value); |
|
137 | - if (empty($option)) { |
|
135 | + foreach( $values as $value ) { |
|
136 | + $option = $this->getSchemaOptionValue( $value ); |
|
137 | + if( empty($option) ) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | - $schema->$value($option); |
|
140 | + $schema->$value( $option ); |
|
141 | 141 | } |
142 | 142 | return $schema; |
143 | 143 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function buildSummaryForCustom() |
149 | 149 | { |
150 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
150 | + return $this->buildSchemaValues( $this->getSchemaType(), [ |
|
151 | 151 | 'description', 'image', 'name', 'url', |
152 | - ]); |
|
152 | + ] ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function buildSummaryForLocalBusiness() |
159 | 159 | { |
160 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
160 | + return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
|
161 | 161 | 'address', 'priceRange', 'telephone', |
162 | - ]); |
|
162 | + ] ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | */ |
168 | 168 | protected function buildSummaryForProduct() |
169 | 169 | { |
170 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
171 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
170 | + $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
|
171 | + $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
|
172 | 172 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
173 | - ]); |
|
173 | + ] ); |
|
174 | 174 | return $this->buildSummaryForCustom() |
175 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
176 | - $schema->offers($offers); |
|
175 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) { |
|
176 | + $schema->offers( $offers ); |
|
177 | 177 | }) |
178 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
178 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function getRatingCounts() |
185 | 185 | { |
186 | - if (!isset($this->ratingCounts)) { |
|
187 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
186 | + if( !isset($this->ratingCounts) ) { |
|
187 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
|
188 | 188 | } |
189 | 189 | return $this->ratingCounts; |
190 | 190 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | protected function getRatingValue() |
196 | 196 | { |
197 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
197 | + return glsr( Rating::class )->getAverage( $this->getRatingCounts() ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -202,15 +202,15 @@ discard block |
||
202 | 202 | * @param string $fallback |
203 | 203 | * @return string |
204 | 204 | */ |
205 | - protected function getSchemaOption($option, $fallback) |
|
205 | + protected function getSchemaOption( $option, $fallback ) |
|
206 | 206 | { |
207 | - $option = strtolower($option); |
|
208 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
207 | + $option = strtolower( $option ); |
|
208 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
209 | 209 | return $schemaOption; |
210 | 210 | } |
211 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
212 | - if (is_array($setting)) { |
|
213 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
211 | + $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
|
212 | + if( is_array( $setting ) ) { |
|
213 | + return $this->getSchemaOptionDefault( $setting, $fallback ); |
|
214 | 214 | } |
215 | 215 | return !empty($setting) |
216 | 216 | ? $setting |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | * @param string $fallback |
222 | 222 | * @return string |
223 | 223 | */ |
224 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
224 | + protected function getSchemaOptionDefault( array $setting, $fallback ) |
|
225 | 225 | { |
226 | - $setting = wp_parse_args($setting, [ |
|
226 | + $setting = wp_parse_args( $setting, [ |
|
227 | 227 | 'custom' => '', |
228 | 228 | 'default' => $fallback, |
229 | - ]); |
|
229 | + ] ); |
|
230 | 230 | return 'custom' != $setting['default'] |
231 | 231 | ? $setting['default'] |
232 | 232 | : $setting['custom']; |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | * @param string $fallback |
238 | 238 | * @return void|string |
239 | 239 | */ |
240 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
240 | + protected function getSchemaOptionValue( $option, $fallback = 'post' ) |
|
241 | 241 | { |
242 | - $value = $this->getSchemaOption($option, $fallback); |
|
243 | - if ($value != $fallback) { |
|
242 | + $value = $this->getSchemaOption( $option, $fallback ); |
|
243 | + if( $value != $fallback ) { |
|
244 | 244 | return $value; |
245 | 245 | } |
246 | - if (!is_single() && !is_page()) { |
|
246 | + if( !is_single() && !is_page() ) { |
|
247 | 247 | return; |
248 | 248 | } |
249 | - $method = glsr(Helper::class)->buildMethodName($option, 'getThing'); |
|
250 | - if (method_exists($this, $method)) { |
|
249 | + $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
|
250 | + if( method_exists( $this, $method ) ) { |
|
251 | 251 | return $this->$method(); |
252 | 252 | } |
253 | 253 | } |
@@ -256,15 +256,15 @@ discard block |
||
256 | 256 | * @param string|null $type |
257 | 257 | * @return mixed |
258 | 258 | */ |
259 | - protected function getSchemaType($type = null) |
|
259 | + protected function getSchemaType( $type = null ) |
|
260 | 260 | { |
261 | - if (!is_string($type)) { |
|
262 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
261 | + if( !is_string( $type ) ) { |
|
262 | + $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
|
263 | 263 | } |
264 | - $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema'); |
|
265 | - return class_exists($className) |
|
264 | + $className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' ); |
|
265 | + return class_exists( $className ) |
|
266 | 266 | ? new $className() |
267 | - : new UnknownType($type); |
|
267 | + : new UnknownType( $type ); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | */ |
273 | 273 | protected function getThingDescription() |
274 | 274 | { |
275 | - $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt())); |
|
276 | - return wp_trim_words($description, apply_filters('excerpt_length', 55)); |
|
275 | + $description = strip_shortcodes( wp_strip_all_tags( get_the_excerpt() ) ); |
|
276 | + return wp_trim_words( $description, apply_filters( 'excerpt_length', 55 ) ); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | */ |
282 | 282 | protected function getThingImage() |
283 | 283 | { |
284 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
284 | + return (string)get_the_post_thumbnail_url( null, 'large' ); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -297,6 +297,6 @@ discard block |
||
297 | 297 | */ |
298 | 298 | protected function getThingUrl() |
299 | 299 | { |
300 | - return (string) get_the_permalink(); |
|
300 | + return (string)get_the_permalink(); |
|
301 | 301 | } |
302 | 302 | } |
@@ -221,7 +221,8 @@ |
||
221 | 221 | if ($flattenValue) { |
222 | 222 | $value = '['.implode(', ', $value).']'; |
223 | 223 | } |
224 | - } elseif (is_array($value)) { |
|
224 | + } |
|
225 | + elseif (is_array($value)) { |
|
225 | 226 | $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
226 | 227 | continue; |
227 | 228 | } |
@@ -4,188 +4,188 @@ |
||
4 | 4 | |
5 | 5 | trait Arr |
6 | 6 | { |
7 | - /** |
|
8 | - * @return bool |
|
9 | - */ |
|
10 | - public function compareArrays(array $arr1, array $arr2) |
|
11 | - { |
|
12 | - sort($arr1); |
|
13 | - sort($arr2); |
|
14 | - return $arr1 == $arr2; |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return bool |
|
9 | + */ |
|
10 | + public function compareArrays(array $arr1, array $arr2) |
|
11 | + { |
|
12 | + sort($arr1); |
|
13 | + sort($arr2); |
|
14 | + return $arr1 == $arr2; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @param mixed $array |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function consolidateArray($array) |
|
22 | - { |
|
23 | - return is_array($array) || is_object($array) |
|
24 | - ? (array) $array |
|
25 | - : []; |
|
26 | - } |
|
17 | + /** |
|
18 | + * @param mixed $array |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function consolidateArray($array) |
|
22 | + { |
|
23 | + return is_array($array) || is_object($array) |
|
24 | + ? (array) $array |
|
25 | + : []; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public function convertDotNotationArray(array $array) |
|
32 | - { |
|
33 | - $results = []; |
|
34 | - foreach ($array as $path => $value) { |
|
35 | - $results = $this->dataSet($results, $path, $value); |
|
36 | - } |
|
37 | - return $results; |
|
38 | - } |
|
28 | + /** |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public function convertDotNotationArray(array $array) |
|
32 | + { |
|
33 | + $results = []; |
|
34 | + foreach ($array as $path => $value) { |
|
35 | + $results = $this->dataSet($results, $path, $value); |
|
36 | + } |
|
37 | + return $results; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $string |
|
42 | - * @param mixed $callback |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function convertStringToArray($string, $callback = null) |
|
46 | - { |
|
47 | - $array = array_map('trim', explode(',', $string)); |
|
48 | - return $callback |
|
49 | - ? array_filter($array, $callback) |
|
50 | - : array_filter($array); |
|
51 | - } |
|
40 | + /** |
|
41 | + * @param string $string |
|
42 | + * @param mixed $callback |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function convertStringToArray($string, $callback = null) |
|
46 | + { |
|
47 | + $array = array_map('trim', explode(',', $string)); |
|
48 | + return $callback |
|
49 | + ? array_filter($array, $callback) |
|
50 | + : array_filter($array); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get a value from an array of values using a dot-notation path as reference. |
|
55 | - * @param array $data |
|
56 | - * @param string $path |
|
57 | - * @param mixed $fallback |
|
58 | - * @return mixed |
|
59 | - */ |
|
60 | - public function dataGet($data, $path = '', $fallback = '') |
|
61 | - { |
|
62 | - $data = $this->consolidateArray($data); |
|
63 | - $keys = explode('.', $path); |
|
64 | - foreach ($keys as $key) { |
|
65 | - if (!isset($data[$key])) { |
|
66 | - return $fallback; |
|
67 | - } |
|
68 | - $data = $data[$key]; |
|
69 | - } |
|
70 | - return $data; |
|
71 | - } |
|
53 | + /** |
|
54 | + * Get a value from an array of values using a dot-notation path as reference. |
|
55 | + * @param array $data |
|
56 | + * @param string $path |
|
57 | + * @param mixed $fallback |
|
58 | + * @return mixed |
|
59 | + */ |
|
60 | + public function dataGet($data, $path = '', $fallback = '') |
|
61 | + { |
|
62 | + $data = $this->consolidateArray($data); |
|
63 | + $keys = explode('.', $path); |
|
64 | + foreach ($keys as $key) { |
|
65 | + if (!isset($data[$key])) { |
|
66 | + return $fallback; |
|
67 | + } |
|
68 | + $data = $data[$key]; |
|
69 | + } |
|
70 | + return $data; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Set a value to an array of values using a dot-notation path as reference. |
|
75 | - * @param string $path |
|
76 | - * @param mixed $value |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function dataSet(array $data, $path, $value) |
|
80 | - { |
|
81 | - $token = strtok($path, '.'); |
|
82 | - $ref = &$data; |
|
83 | - while (false !== $token) { |
|
84 | - $ref = $this->consolidateArray($ref); |
|
85 | - $ref = &$ref[$token]; |
|
86 | - $token = strtok('.'); |
|
87 | - } |
|
88 | - $ref = $value; |
|
89 | - return $data; |
|
90 | - } |
|
73 | + /** |
|
74 | + * Set a value to an array of values using a dot-notation path as reference. |
|
75 | + * @param string $path |
|
76 | + * @param mixed $value |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function dataSet(array $data, $path, $value) |
|
80 | + { |
|
81 | + $token = strtok($path, '.'); |
|
82 | + $ref = &$data; |
|
83 | + while (false !== $token) { |
|
84 | + $ref = $this->consolidateArray($ref); |
|
85 | + $ref = &$ref[$token]; |
|
86 | + $token = strtok('.'); |
|
87 | + } |
|
88 | + $ref = $value; |
|
89 | + return $data; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param bool $flattenValue |
|
94 | - * @param string $prefix |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
98 | - { |
|
99 | - $result = []; |
|
100 | - foreach ($array as $key => $value) { |
|
101 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
102 | - if ($this->isIndexedFlatArray($value)) { |
|
103 | - if ($flattenValue) { |
|
104 | - $value = '['.implode(', ', $value).']'; |
|
105 | - } |
|
106 | - } elseif (is_array($value)) { |
|
107 | - $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
|
108 | - continue; |
|
109 | - } |
|
110 | - $result[$newKey] = $value; |
|
111 | - } |
|
112 | - return $result; |
|
113 | - } |
|
92 | + /** |
|
93 | + * @param bool $flattenValue |
|
94 | + * @param string $prefix |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
98 | + { |
|
99 | + $result = []; |
|
100 | + foreach ($array as $key => $value) { |
|
101 | + $newKey = ltrim($prefix.'.'.$key, '.'); |
|
102 | + if ($this->isIndexedFlatArray($value)) { |
|
103 | + if ($flattenValue) { |
|
104 | + $value = '['.implode(', ', $value).']'; |
|
105 | + } |
|
106 | + } elseif (is_array($value)) { |
|
107 | + $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
|
108 | + continue; |
|
109 | + } |
|
110 | + $result[$newKey] = $value; |
|
111 | + } |
|
112 | + return $result; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @param string $key |
|
117 | - * @param string $position |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
121 | - { |
|
122 | - $keyPosition = intval(array_search($key, array_keys($array))); |
|
123 | - if ('after' == $position) { |
|
124 | - ++$keyPosition; |
|
125 | - } |
|
126 | - if (false !== $keyPosition) { |
|
127 | - $result = array_slice($array, 0, $keyPosition); |
|
128 | - $result = array_merge($result, $insert); |
|
129 | - return array_merge($result, array_slice($array, $keyPosition)); |
|
130 | - } |
|
131 | - return array_merge($array, $insert); |
|
132 | - } |
|
115 | + /** |
|
116 | + * @param string $key |
|
117 | + * @param string $position |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
121 | + { |
|
122 | + $keyPosition = intval(array_search($key, array_keys($array))); |
|
123 | + if ('after' == $position) { |
|
124 | + ++$keyPosition; |
|
125 | + } |
|
126 | + if (false !== $keyPosition) { |
|
127 | + $result = array_slice($array, 0, $keyPosition); |
|
128 | + $result = array_merge($result, $insert); |
|
129 | + return array_merge($result, array_slice($array, $keyPosition)); |
|
130 | + } |
|
131 | + return array_merge($array, $insert); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param mixed $array |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function isIndexedFlatArray($array) |
|
139 | - { |
|
140 | - if (!is_array($array) || array_filter($array, 'is_array')) { |
|
141 | - return false; |
|
142 | - } |
|
143 | - return wp_is_numeric_array($array); |
|
144 | - } |
|
134 | + /** |
|
135 | + * @param mixed $array |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function isIndexedFlatArray($array) |
|
139 | + { |
|
140 | + if (!is_array($array) || array_filter($array, 'is_array')) { |
|
141 | + return false; |
|
142 | + } |
|
143 | + return wp_is_numeric_array($array); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param bool $prefixed |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - public function prefixArrayKeys(array $values, $prefixed = true) |
|
151 | - { |
|
152 | - $trim = '_'; |
|
153 | - $prefix = $prefixed |
|
154 | - ? $trim |
|
155 | - : ''; |
|
156 | - $prefixed = []; |
|
157 | - foreach ($values as $key => $value) { |
|
158 | - $key = trim($key); |
|
159 | - if (0 === strpos($key, $trim)) { |
|
160 | - $key = substr($key, strlen($trim)); |
|
161 | - } |
|
162 | - $prefixed[$prefix.$key] = $value; |
|
163 | - } |
|
164 | - return $prefixed; |
|
165 | - } |
|
146 | + /** |
|
147 | + * @param bool $prefixed |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + public function prefixArrayKeys(array $values, $prefixed = true) |
|
151 | + { |
|
152 | + $trim = '_'; |
|
153 | + $prefix = $prefixed |
|
154 | + ? $trim |
|
155 | + : ''; |
|
156 | + $prefixed = []; |
|
157 | + foreach ($values as $key => $value) { |
|
158 | + $key = trim($key); |
|
159 | + if (0 === strpos($key, $trim)) { |
|
160 | + $key = substr($key, strlen($trim)); |
|
161 | + } |
|
162 | + $prefixed[$prefix.$key] = $value; |
|
163 | + } |
|
164 | + return $prefixed; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - public function removeEmptyArrayValues(array $array) |
|
171 | - { |
|
172 | - $result = []; |
|
173 | - foreach ($array as $key => $value) { |
|
174 | - if (!$value) { |
|
175 | - continue; |
|
176 | - } |
|
177 | - $result[$key] = is_array($value) |
|
178 | - ? $this->removeEmptyArrayValues($value) |
|
179 | - : $value; |
|
180 | - } |
|
181 | - return $result; |
|
182 | - } |
|
167 | + /** |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + public function removeEmptyArrayValues(array $array) |
|
171 | + { |
|
172 | + $result = []; |
|
173 | + foreach ($array as $key => $value) { |
|
174 | + if (!$value) { |
|
175 | + continue; |
|
176 | + } |
|
177 | + $result[$key] = is_array($value) |
|
178 | + ? $this->removeEmptyArrayValues($value) |
|
179 | + : $value; |
|
180 | + } |
|
181 | + return $result; |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @return array |
|
186 | - */ |
|
187 | - public function unprefixArrayKeys(array $values) |
|
188 | - { |
|
189 | - return $this->prefixArrayKeys($values, false); |
|
190 | - } |
|
184 | + /** |
|
185 | + * @return array |
|
186 | + */ |
|
187 | + public function unprefixArrayKeys(array $values) |
|
188 | + { |
|
189 | + return $this->prefixArrayKeys($values, false); |
|
190 | + } |
|
191 | 191 | } |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * @return bool |
9 | 9 | */ |
10 | - public function compareArrays(array $arr1, array $arr2) |
|
10 | + public function compareArrays( array $arr1, array $arr2 ) |
|
11 | 11 | { |
12 | - sort($arr1); |
|
13 | - sort($arr2); |
|
12 | + sort( $arr1 ); |
|
13 | + sort( $arr2 ); |
|
14 | 14 | return $arr1 == $arr2; |
15 | 15 | } |
16 | 16 | |
@@ -18,21 +18,21 @@ discard block |
||
18 | 18 | * @param mixed $array |
19 | 19 | * @return array |
20 | 20 | */ |
21 | - public function consolidateArray($array) |
|
21 | + public function consolidateArray( $array ) |
|
22 | 22 | { |
23 | - return is_array($array) || is_object($array) |
|
24 | - ? (array) $array |
|
23 | + return is_array( $array ) || is_object( $array ) |
|
24 | + ? (array)$array |
|
25 | 25 | : []; |
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @return array |
30 | 30 | */ |
31 | - public function convertDotNotationArray(array $array) |
|
31 | + public function convertDotNotationArray( array $array ) |
|
32 | 32 | { |
33 | 33 | $results = []; |
34 | - foreach ($array as $path => $value) { |
|
35 | - $results = $this->dataSet($results, $path, $value); |
|
34 | + foreach( $array as $path => $value ) { |
|
35 | + $results = $this->dataSet( $results, $path, $value ); |
|
36 | 36 | } |
37 | 37 | return $results; |
38 | 38 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | * @param mixed $callback |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public function convertStringToArray($string, $callback = null) |
|
45 | + public function convertStringToArray( $string, $callback = null ) |
|
46 | 46 | { |
47 | - $array = array_map('trim', explode(',', $string)); |
|
47 | + $array = array_map( 'trim', explode( ',', $string ) ); |
|
48 | 48 | return $callback |
49 | - ? array_filter($array, $callback) |
|
50 | - : array_filter($array); |
|
49 | + ? array_filter( $array, $callback ) |
|
50 | + : array_filter( $array ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * @param mixed $fallback |
58 | 58 | * @return mixed |
59 | 59 | */ |
60 | - public function dataGet($data, $path = '', $fallback = '') |
|
60 | + public function dataGet( $data, $path = '', $fallback = '' ) |
|
61 | 61 | { |
62 | - $data = $this->consolidateArray($data); |
|
63 | - $keys = explode('.', $path); |
|
64 | - foreach ($keys as $key) { |
|
65 | - if (!isset($data[$key])) { |
|
62 | + $data = $this->consolidateArray( $data ); |
|
63 | + $keys = explode( '.', $path ); |
|
64 | + foreach( $keys as $key ) { |
|
65 | + if( !isset($data[$key]) ) { |
|
66 | 66 | return $fallback; |
67 | 67 | } |
68 | 68 | $data = $data[$key]; |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | * @param mixed $value |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public function dataSet(array $data, $path, $value) |
|
79 | + public function dataSet( array $data, $path, $value ) |
|
80 | 80 | { |
81 | - $token = strtok($path, '.'); |
|
81 | + $token = strtok( $path, '.' ); |
|
82 | 82 | $ref = &$data; |
83 | - while (false !== $token) { |
|
84 | - $ref = $this->consolidateArray($ref); |
|
83 | + while( false !== $token ) { |
|
84 | + $ref = $this->consolidateArray( $ref ); |
|
85 | 85 | $ref = &$ref[$token]; |
86 | - $token = strtok('.'); |
|
86 | + $token = strtok( '.' ); |
|
87 | 87 | } |
88 | 88 | $ref = $value; |
89 | 89 | return $data; |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | * @param string $prefix |
95 | 95 | * @return array |
96 | 96 | */ |
97 | - public function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
97 | + public function flattenArray( array $array, $flattenValue = false, $prefix = '' ) |
|
98 | 98 | { |
99 | 99 | $result = []; |
100 | - foreach ($array as $key => $value) { |
|
101 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
102 | - if ($this->isIndexedFlatArray($value)) { |
|
103 | - if ($flattenValue) { |
|
104 | - $value = '['.implode(', ', $value).']'; |
|
100 | + foreach( $array as $key => $value ) { |
|
101 | + $newKey = ltrim( $prefix.'.'.$key, '.' ); |
|
102 | + if( $this->isIndexedFlatArray( $value ) ) { |
|
103 | + if( $flattenValue ) { |
|
104 | + $value = '['.implode( ', ', $value ).']'; |
|
105 | 105 | } |
106 | - } elseif (is_array($value)) { |
|
107 | - $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
|
106 | + } elseif( is_array( $value ) ) { |
|
107 | + $result = array_merge( $result, $this->flattenArray( $value, $flattenValue, $newKey ) ); |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | $result[$newKey] = $value; |
@@ -117,47 +117,47 @@ discard block |
||
117 | 117 | * @param string $position |
118 | 118 | * @return array |
119 | 119 | */ |
120 | - public function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
120 | + public function insertInArray( array $array, array $insert, $key, $position = 'before' ) |
|
121 | 121 | { |
122 | - $keyPosition = intval(array_search($key, array_keys($array))); |
|
123 | - if ('after' == $position) { |
|
122 | + $keyPosition = intval( array_search( $key, array_keys( $array ) ) ); |
|
123 | + if( 'after' == $position ) { |
|
124 | 124 | ++$keyPosition; |
125 | 125 | } |
126 | - if (false !== $keyPosition) { |
|
127 | - $result = array_slice($array, 0, $keyPosition); |
|
128 | - $result = array_merge($result, $insert); |
|
129 | - return array_merge($result, array_slice($array, $keyPosition)); |
|
126 | + if( false !== $keyPosition ) { |
|
127 | + $result = array_slice( $array, 0, $keyPosition ); |
|
128 | + $result = array_merge( $result, $insert ); |
|
129 | + return array_merge( $result, array_slice( $array, $keyPosition ) ); |
|
130 | 130 | } |
131 | - return array_merge($array, $insert); |
|
131 | + return array_merge( $array, $insert ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param mixed $array |
136 | 136 | * @return bool |
137 | 137 | */ |
138 | - public function isIndexedFlatArray($array) |
|
138 | + public function isIndexedFlatArray( $array ) |
|
139 | 139 | { |
140 | - if (!is_array($array) || array_filter($array, 'is_array')) { |
|
140 | + if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | - return wp_is_numeric_array($array); |
|
143 | + return wp_is_numeric_array( $array ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @param bool $prefixed |
148 | 148 | * @return array |
149 | 149 | */ |
150 | - public function prefixArrayKeys(array $values, $prefixed = true) |
|
150 | + public function prefixArrayKeys( array $values, $prefixed = true ) |
|
151 | 151 | { |
152 | 152 | $trim = '_'; |
153 | 153 | $prefix = $prefixed |
154 | 154 | ? $trim |
155 | 155 | : ''; |
156 | 156 | $prefixed = []; |
157 | - foreach ($values as $key => $value) { |
|
158 | - $key = trim($key); |
|
159 | - if (0 === strpos($key, $trim)) { |
|
160 | - $key = substr($key, strlen($trim)); |
|
157 | + foreach( $values as $key => $value ) { |
|
158 | + $key = trim( $key ); |
|
159 | + if( 0 === strpos( $key, $trim ) ) { |
|
160 | + $key = substr( $key, strlen( $trim ) ); |
|
161 | 161 | } |
162 | 162 | $prefixed[$prefix.$key] = $value; |
163 | 163 | } |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - public function removeEmptyArrayValues(array $array) |
|
170 | + public function removeEmptyArrayValues( array $array ) |
|
171 | 171 | { |
172 | 172 | $result = []; |
173 | - foreach ($array as $key => $value) { |
|
174 | - if (!$value) { |
|
173 | + foreach( $array as $key => $value ) { |
|
174 | + if( !$value ) { |
|
175 | 175 | continue; |
176 | 176 | } |
177 | - $result[$key] = is_array($value) |
|
178 | - ? $this->removeEmptyArrayValues($value) |
|
177 | + $result[$key] = is_array( $value ) |
|
178 | + ? $this->removeEmptyArrayValues( $value ) |
|
179 | 179 | : $value; |
180 | 180 | } |
181 | 181 | return $result; |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | /** |
185 | 185 | * @return array |
186 | 186 | */ |
187 | - public function unprefixArrayKeys(array $values) |
|
187 | + public function unprefixArrayKeys( array $values ) |
|
188 | 188 | { |
189 | - return $this->prefixArrayKeys($values, false); |
|
189 | + return $this->prefixArrayKeys( $values, false ); |
|
190 | 190 | } |
191 | 191 | } |
@@ -13,346 +13,346 @@ |
||
13 | 13 | |
14 | 14 | class ListTableController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * @return void |
|
18 | - * @action admin_action_approve |
|
19 | - */ |
|
20 | - public function approve() |
|
21 | - { |
|
22 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
23 | - return; |
|
24 | - } |
|
25 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
26 | - wp_update_post([ |
|
27 | - 'ID' => $postId, |
|
28 | - 'post_status' => 'publish', |
|
29 | - ]); |
|
30 | - wp_safe_redirect(wp_get_referer()); |
|
31 | - exit; |
|
32 | - } |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + * @action admin_action_approve |
|
19 | + */ |
|
20 | + public function approve() |
|
21 | + { |
|
22 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
23 | + return; |
|
24 | + } |
|
25 | + check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
26 | + wp_update_post([ |
|
27 | + 'ID' => $postId, |
|
28 | + 'post_status' => 'publish', |
|
29 | + ]); |
|
30 | + wp_safe_redirect(wp_get_referer()); |
|
31 | + exit; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param array $messages |
|
36 | - * @return array |
|
37 | - * @filter bulk_post_updated_messages |
|
38 | - */ |
|
39 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
40 | - { |
|
41 | - $messages = glsr(Helper::class)->consolidateArray($messages); |
|
42 | - $messages[Application::POST_TYPE] = [ |
|
43 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
44 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
45 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
46 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
47 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
48 | - ]; |
|
49 | - return $messages; |
|
50 | - } |
|
34 | + /** |
|
35 | + * @param array $messages |
|
36 | + * @return array |
|
37 | + * @filter bulk_post_updated_messages |
|
38 | + */ |
|
39 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
40 | + { |
|
41 | + $messages = glsr(Helper::class)->consolidateArray($messages); |
|
42 | + $messages[Application::POST_TYPE] = [ |
|
43 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
44 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
45 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
46 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
47 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
48 | + ]; |
|
49 | + return $messages; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param array $columns |
|
54 | - * @return array |
|
55 | - * @filter manage_.Application::POST_TYPE._posts_columns |
|
56 | - */ |
|
57 | - public function filterColumnsForPostType($columns) |
|
58 | - { |
|
59 | - $columns = glsr(Helper::class)->consolidateArray($columns); |
|
60 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
61 | - foreach ($postTypeColumns as $key => &$value) { |
|
62 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
63 | - continue; |
|
64 | - } |
|
65 | - $value = $columns[$key]; |
|
66 | - } |
|
67 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
68 | - unset($postTypeColumns['review_type']); |
|
69 | - } |
|
70 | - return array_filter($postTypeColumns, 'strlen'); |
|
71 | - } |
|
52 | + /** |
|
53 | + * @param array $columns |
|
54 | + * @return array |
|
55 | + * @filter manage_.Application::POST_TYPE._posts_columns |
|
56 | + */ |
|
57 | + public function filterColumnsForPostType($columns) |
|
58 | + { |
|
59 | + $columns = glsr(Helper::class)->consolidateArray($columns); |
|
60 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
61 | + foreach ($postTypeColumns as $key => &$value) { |
|
62 | + if (!array_key_exists($key, $columns) || !empty($value)) { |
|
63 | + continue; |
|
64 | + } |
|
65 | + $value = $columns[$key]; |
|
66 | + } |
|
67 | + if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
68 | + unset($postTypeColumns['review_type']); |
|
69 | + } |
|
70 | + return array_filter($postTypeColumns, 'strlen'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $status |
|
75 | - * @param WP_Post $post |
|
76 | - * @return string |
|
77 | - * @filter post_date_column_status |
|
78 | - */ |
|
79 | - public function filterDateColumnStatus($status, $post) |
|
80 | - { |
|
81 | - if (Application::POST_TYPE == glsr_get($post, 'post_type')) { |
|
82 | - $status = __('Submitted', 'site-reviews'); |
|
83 | - } |
|
84 | - return $status; |
|
85 | - } |
|
73 | + /** |
|
74 | + * @param string $status |
|
75 | + * @param WP_Post $post |
|
76 | + * @return string |
|
77 | + * @filter post_date_column_status |
|
78 | + */ |
|
79 | + public function filterDateColumnStatus($status, $post) |
|
80 | + { |
|
81 | + if (Application::POST_TYPE == glsr_get($post, 'post_type')) { |
|
82 | + $status = __('Submitted', 'site-reviews'); |
|
83 | + } |
|
84 | + return $status; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param array $hidden |
|
89 | - * @param WP_Screen $post |
|
90 | - * @return array |
|
91 | - * @filter default_hidden_columns |
|
92 | - */ |
|
93 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
94 | - { |
|
95 | - if (glsr_get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
96 | - $hidden = glsr(Helper::class)->consolidateArray($hidden); |
|
97 | - $hidden = ['reviewer']; |
|
98 | - } |
|
99 | - return $hidden; |
|
100 | - } |
|
87 | + /** |
|
88 | + * @param array $hidden |
|
89 | + * @param WP_Screen $post |
|
90 | + * @return array |
|
91 | + * @filter default_hidden_columns |
|
92 | + */ |
|
93 | + public function filterDefaultHiddenColumns($hidden, $screen) |
|
94 | + { |
|
95 | + if (glsr_get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
96 | + $hidden = glsr(Helper::class)->consolidateArray($hidden); |
|
97 | + $hidden = ['reviewer']; |
|
98 | + } |
|
99 | + return $hidden; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param array $postStates |
|
104 | - * @param WP_Post $post |
|
105 | - * @return array |
|
106 | - * @filter display_post_states |
|
107 | - */ |
|
108 | - public function filterPostStates($postStates, $post) |
|
109 | - { |
|
110 | - $postStates = glsr(Helper::class)->consolidateArray($postStates); |
|
111 | - if (Application::POST_TYPE == glsr_get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
112 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
113 | - } |
|
114 | - return $postStates; |
|
115 | - } |
|
102 | + /** |
|
103 | + * @param array $postStates |
|
104 | + * @param WP_Post $post |
|
105 | + * @return array |
|
106 | + * @filter display_post_states |
|
107 | + */ |
|
108 | + public function filterPostStates($postStates, $post) |
|
109 | + { |
|
110 | + $postStates = glsr(Helper::class)->consolidateArray($postStates); |
|
111 | + if (Application::POST_TYPE == glsr_get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
112 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
113 | + } |
|
114 | + return $postStates; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @param array $actions |
|
119 | - * @param WP_Post $post |
|
120 | - * @return array |
|
121 | - * @filter post_row_actions |
|
122 | - */ |
|
123 | - public function filterRowActions($actions, $post) |
|
124 | - { |
|
125 | - if (Application::POST_TYPE != glsr_get($post, 'post_type') || 'trash' == $post->post_status) { |
|
126 | - return $actions; |
|
127 | - } |
|
128 | - unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
129 | - $rowActions = [ |
|
130 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
131 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
132 | - ]; |
|
133 | - $newActions = []; |
|
134 | - foreach ($rowActions as $key => $text) { |
|
135 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
136 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
137 | - 'class' => 'glsr-change-status', |
|
138 | - 'href' => wp_nonce_url( |
|
139 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
140 | - $key.'-review_'.$post->ID |
|
141 | - ), |
|
142 | - ]); |
|
143 | - } |
|
144 | - return $newActions + glsr(Helper::class)->consolidateArray($actions); |
|
145 | - } |
|
117 | + /** |
|
118 | + * @param array $actions |
|
119 | + * @param WP_Post $post |
|
120 | + * @return array |
|
121 | + * @filter post_row_actions |
|
122 | + */ |
|
123 | + public function filterRowActions($actions, $post) |
|
124 | + { |
|
125 | + if (Application::POST_TYPE != glsr_get($post, 'post_type') || 'trash' == $post->post_status) { |
|
126 | + return $actions; |
|
127 | + } |
|
128 | + unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
129 | + $rowActions = [ |
|
130 | + 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
131 | + 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
132 | + ]; |
|
133 | + $newActions = []; |
|
134 | + foreach ($rowActions as $key => $text) { |
|
135 | + $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
136 | + 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
137 | + 'class' => 'glsr-change-status', |
|
138 | + 'href' => wp_nonce_url( |
|
139 | + admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
140 | + $key.'-review_'.$post->ID |
|
141 | + ), |
|
142 | + ]); |
|
143 | + } |
|
144 | + return $newActions + glsr(Helper::class)->consolidateArray($actions); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @param array $columns |
|
149 | - * @return array |
|
150 | - * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
151 | - */ |
|
152 | - public function filterSortableColumns($columns) |
|
153 | - { |
|
154 | - $columns = glsr(Helper::class)->consolidateArray($columns); |
|
155 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
156 | - unset($postTypeColumns['cb']); |
|
157 | - foreach ($postTypeColumns as $key => $value) { |
|
158 | - if (glsr(Helper::class)->startsWith('taxonomy', $key)) { |
|
159 | - continue; |
|
160 | - } |
|
161 | - $columns[$key] = $key; |
|
162 | - } |
|
163 | - return $columns; |
|
164 | - } |
|
147 | + /** |
|
148 | + * @param array $columns |
|
149 | + * @return array |
|
150 | + * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
151 | + */ |
|
152 | + public function filterSortableColumns($columns) |
|
153 | + { |
|
154 | + $columns = glsr(Helper::class)->consolidateArray($columns); |
|
155 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
156 | + unset($postTypeColumns['cb']); |
|
157 | + foreach ($postTypeColumns as $key => $value) { |
|
158 | + if (glsr(Helper::class)->startsWith('taxonomy', $key)) { |
|
159 | + continue; |
|
160 | + } |
|
161 | + $columns[$key] = $key; |
|
162 | + } |
|
163 | + return $columns; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Customize the post_type status text. |
|
168 | - * @param string $translation |
|
169 | - * @param string $single |
|
170 | - * @param string $plural |
|
171 | - * @param int $number |
|
172 | - * @param string $domain |
|
173 | - * @return string |
|
174 | - * @filter ngettext |
|
175 | - */ |
|
176 | - public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
177 | - { |
|
178 | - if ($this->canModifyTranslation($domain)) { |
|
179 | - $strings = [ |
|
180 | - 'Published' => __('Approved', 'site-reviews'), |
|
181 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
182 | - ]; |
|
183 | - foreach ($strings as $search => $replace) { |
|
184 | - if (false === strpos($single, $search)) { |
|
185 | - continue; |
|
186 | - } |
|
187 | - $translation = $this->getTranslation([ |
|
188 | - 'number' => $number, |
|
189 | - 'plural' => str_replace($search, $replace, $plural), |
|
190 | - 'single' => str_replace($search, $replace, $single), |
|
191 | - ]); |
|
192 | - } |
|
193 | - } |
|
194 | - return $translation; |
|
195 | - } |
|
166 | + /** |
|
167 | + * Customize the post_type status text. |
|
168 | + * @param string $translation |
|
169 | + * @param string $single |
|
170 | + * @param string $plural |
|
171 | + * @param int $number |
|
172 | + * @param string $domain |
|
173 | + * @return string |
|
174 | + * @filter ngettext |
|
175 | + */ |
|
176 | + public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
177 | + { |
|
178 | + if ($this->canModifyTranslation($domain)) { |
|
179 | + $strings = [ |
|
180 | + 'Published' => __('Approved', 'site-reviews'), |
|
181 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
182 | + ]; |
|
183 | + foreach ($strings as $search => $replace) { |
|
184 | + if (false === strpos($single, $search)) { |
|
185 | + continue; |
|
186 | + } |
|
187 | + $translation = $this->getTranslation([ |
|
188 | + 'number' => $number, |
|
189 | + 'plural' => str_replace($search, $replace, $plural), |
|
190 | + 'single' => str_replace($search, $replace, $single), |
|
191 | + ]); |
|
192 | + } |
|
193 | + } |
|
194 | + return $translation; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @param string $columnName |
|
199 | - * @param string $postType |
|
200 | - * @return void |
|
201 | - * @action bulk_edit_custom_box |
|
202 | - */ |
|
203 | - public function renderBulkEditFields($columnName, $postType) |
|
204 | - { |
|
205 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
206 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
207 | - } |
|
208 | - } |
|
197 | + /** |
|
198 | + * @param string $columnName |
|
199 | + * @param string $postType |
|
200 | + * @return void |
|
201 | + * @action bulk_edit_custom_box |
|
202 | + */ |
|
203 | + public function renderBulkEditFields($columnName, $postType) |
|
204 | + { |
|
205 | + if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
206 | + glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * @param string $postType |
|
212 | - * @return void |
|
213 | - * @action restrict_manage_posts |
|
214 | - */ |
|
215 | - public function renderColumnFilters($postType) |
|
216 | - { |
|
217 | - glsr(Columns::class)->renderFilters($postType); |
|
218 | - } |
|
210 | + /** |
|
211 | + * @param string $postType |
|
212 | + * @return void |
|
213 | + * @action restrict_manage_posts |
|
214 | + */ |
|
215 | + public function renderColumnFilters($postType) |
|
216 | + { |
|
217 | + glsr(Columns::class)->renderFilters($postType); |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * @param string $column |
|
222 | - * @param string $postId |
|
223 | - * @return void |
|
224 | - * @action manage_posts_custom_column |
|
225 | - */ |
|
226 | - public function renderColumnValues($column, $postId) |
|
227 | - { |
|
228 | - glsr(Columns::class)->renderValues($column, $postId); |
|
229 | - } |
|
220 | + /** |
|
221 | + * @param string $column |
|
222 | + * @param string $postId |
|
223 | + * @return void |
|
224 | + * @action manage_posts_custom_column |
|
225 | + */ |
|
226 | + public function renderColumnValues($column, $postId) |
|
227 | + { |
|
228 | + glsr(Columns::class)->renderValues($column, $postId); |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * @param int $postId |
|
233 | - * @return void |
|
234 | - * @action save_post_.Application::POST_TYPE |
|
235 | - */ |
|
236 | - public function saveBulkEditFields($postId) |
|
237 | - { |
|
238 | - if (!current_user_can('edit_posts')) { |
|
239 | - return; |
|
240 | - } |
|
241 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
242 | - if ($assignedTo && get_post($assignedTo)) { |
|
243 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
244 | - } |
|
245 | - } |
|
231 | + /** |
|
232 | + * @param int $postId |
|
233 | + * @return void |
|
234 | + * @action save_post_.Application::POST_TYPE |
|
235 | + */ |
|
236 | + public function saveBulkEditFields($postId) |
|
237 | + { |
|
238 | + if (!current_user_can('edit_posts')) { |
|
239 | + return; |
|
240 | + } |
|
241 | + $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
242 | + if ($assignedTo && get_post($assignedTo)) { |
|
243 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
244 | + } |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * @return void |
|
249 | - * @action pre_get_posts |
|
250 | - */ |
|
251 | - public function setQueryForColumn(WP_Query $query) |
|
252 | - { |
|
253 | - if (!$this->hasPermission($query)) { |
|
254 | - return; |
|
255 | - } |
|
256 | - $this->setMetaQuery($query, [ |
|
257 | - 'rating', 'review_type', |
|
258 | - ]); |
|
259 | - $this->setOrderby($query); |
|
260 | - } |
|
247 | + /** |
|
248 | + * @return void |
|
249 | + * @action pre_get_posts |
|
250 | + */ |
|
251 | + public function setQueryForColumn(WP_Query $query) |
|
252 | + { |
|
253 | + if (!$this->hasPermission($query)) { |
|
254 | + return; |
|
255 | + } |
|
256 | + $this->setMetaQuery($query, [ |
|
257 | + 'rating', 'review_type', |
|
258 | + ]); |
|
259 | + $this->setOrderby($query); |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * @return void |
|
264 | - * @action admin_action_unapprove |
|
265 | - */ |
|
266 | - public function unapprove() |
|
267 | - { |
|
268 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
269 | - return; |
|
270 | - } |
|
271 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
272 | - wp_update_post([ |
|
273 | - 'ID' => $postId, |
|
274 | - 'post_status' => 'pending', |
|
275 | - ]); |
|
276 | - wp_safe_redirect(wp_get_referer()); |
|
277 | - exit; |
|
278 | - } |
|
262 | + /** |
|
263 | + * @return void |
|
264 | + * @action admin_action_unapprove |
|
265 | + */ |
|
266 | + public function unapprove() |
|
267 | + { |
|
268 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
269 | + return; |
|
270 | + } |
|
271 | + check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
272 | + wp_update_post([ |
|
273 | + 'ID' => $postId, |
|
274 | + 'post_status' => 'pending', |
|
275 | + ]); |
|
276 | + wp_safe_redirect(wp_get_referer()); |
|
277 | + exit; |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Check if the translation string can be modified. |
|
282 | - * @param string $domain |
|
283 | - * @return bool |
|
284 | - */ |
|
285 | - protected function canModifyTranslation($domain = 'default') |
|
286 | - { |
|
287 | - $screen = glsr_current_screen(); |
|
288 | - return 'default' == $domain |
|
289 | - && 'edit' == $screen->base |
|
290 | - && Application::POST_TYPE == $screen->post_type; |
|
291 | - } |
|
280 | + /** |
|
281 | + * Check if the translation string can be modified. |
|
282 | + * @param string $domain |
|
283 | + * @return bool |
|
284 | + */ |
|
285 | + protected function canModifyTranslation($domain = 'default') |
|
286 | + { |
|
287 | + $screen = glsr_current_screen(); |
|
288 | + return 'default' == $domain |
|
289 | + && 'edit' == $screen->base |
|
290 | + && Application::POST_TYPE == $screen->post_type; |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * Get the modified translation string. |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - protected function getTranslation(array $args) |
|
298 | - { |
|
299 | - $defaults = [ |
|
300 | - 'number' => 0, |
|
301 | - 'plural' => '', |
|
302 | - 'single' => '', |
|
303 | - 'text' => '', |
|
304 | - ]; |
|
305 | - $args = (object) wp_parse_args($args, $defaults); |
|
306 | - $translations = get_translations_for_domain(Application::ID); |
|
307 | - return $args->text |
|
308 | - ? $translations->translate($args->text) |
|
309 | - : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
310 | - } |
|
293 | + /** |
|
294 | + * Get the modified translation string. |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + protected function getTranslation(array $args) |
|
298 | + { |
|
299 | + $defaults = [ |
|
300 | + 'number' => 0, |
|
301 | + 'plural' => '', |
|
302 | + 'single' => '', |
|
303 | + 'text' => '', |
|
304 | + ]; |
|
305 | + $args = (object) wp_parse_args($args, $defaults); |
|
306 | + $translations = get_translations_for_domain(Application::ID); |
|
307 | + return $args->text |
|
308 | + ? $translations->translate($args->text) |
|
309 | + : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * @return bool |
|
314 | - */ |
|
315 | - protected function hasPermission(WP_Query $query) |
|
316 | - { |
|
317 | - global $pagenow; |
|
318 | - return is_admin() |
|
319 | - && $query->is_main_query() |
|
320 | - && Application::POST_TYPE == $query->get('post_type') |
|
321 | - && 'edit.php' == $pagenow; |
|
322 | - } |
|
312 | + /** |
|
313 | + * @return bool |
|
314 | + */ |
|
315 | + protected function hasPermission(WP_Query $query) |
|
316 | + { |
|
317 | + global $pagenow; |
|
318 | + return is_admin() |
|
319 | + && $query->is_main_query() |
|
320 | + && Application::POST_TYPE == $query->get('post_type') |
|
321 | + && 'edit.php' == $pagenow; |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * @return void |
|
326 | - */ |
|
327 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
328 | - { |
|
329 | - foreach ($metaKeys as $key) { |
|
330 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
331 | - continue; |
|
332 | - } |
|
333 | - $metaQuery = (array) $query->get('meta_query'); |
|
334 | - $metaQuery[] = [ |
|
335 | - 'key' => glsr(Helper::class)->prefix('_', $key), |
|
336 | - 'value' => $value, |
|
337 | - ]; |
|
338 | - $query->set('meta_query', $metaQuery); |
|
339 | - } |
|
340 | - } |
|
324 | + /** |
|
325 | + * @return void |
|
326 | + */ |
|
327 | + protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
328 | + { |
|
329 | + foreach ($metaKeys as $key) { |
|
330 | + if (!($value = filter_input(INPUT_GET, $key))) { |
|
331 | + continue; |
|
332 | + } |
|
333 | + $metaQuery = (array) $query->get('meta_query'); |
|
334 | + $metaQuery[] = [ |
|
335 | + 'key' => glsr(Helper::class)->prefix('_', $key), |
|
336 | + 'value' => $value, |
|
337 | + ]; |
|
338 | + $query->set('meta_query', $metaQuery); |
|
339 | + } |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * @return void |
|
344 | - */ |
|
345 | - protected function setOrderby(WP_Query $query) |
|
346 | - { |
|
347 | - $orderby = $query->get('orderby'); |
|
348 | - $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
349 | - unset($columns['cb'], $columns['title'], $columns['date']); |
|
350 | - if (in_array($orderby, array_keys($columns))) { |
|
351 | - if ('reviewer' == $orderby) { |
|
352 | - $orderby = '_author'; |
|
353 | - } |
|
354 | - $query->set('meta_key', $orderby); |
|
355 | - $query->set('orderby', 'meta_value'); |
|
356 | - } |
|
357 | - } |
|
342 | + /** |
|
343 | + * @return void |
|
344 | + */ |
|
345 | + protected function setOrderby(WP_Query $query) |
|
346 | + { |
|
347 | + $orderby = $query->get('orderby'); |
|
348 | + $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
349 | + unset($columns['cb'], $columns['title'], $columns['date']); |
|
350 | + if (in_array($orderby, array_keys($columns))) { |
|
351 | + if ('reviewer' == $orderby) { |
|
352 | + $orderby = '_author'; |
|
353 | + } |
|
354 | + $query->set('meta_key', $orderby); |
|
355 | + $query->set('orderby', 'meta_value'); |
|
356 | + } |
|
357 | + } |
|
358 | 358 | } |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function approve() |
21 | 21 | { |
22 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
22 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
26 | - wp_update_post([ |
|
25 | + check_admin_referer( 'approve-review_'.($postId = $this->getPostId()) ); |
|
26 | + wp_update_post( [ |
|
27 | 27 | 'ID' => $postId, |
28 | 28 | 'post_status' => 'publish', |
29 | - ]); |
|
30 | - wp_safe_redirect(wp_get_referer()); |
|
29 | + ] ); |
|
30 | + wp_safe_redirect( wp_get_referer() ); |
|
31 | 31 | exit; |
32 | 32 | } |
33 | 33 | |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | * @return array |
37 | 37 | * @filter bulk_post_updated_messages |
38 | 38 | */ |
39 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
39 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
40 | 40 | { |
41 | - $messages = glsr(Helper::class)->consolidateArray($messages); |
|
41 | + $messages = glsr( Helper::class )->consolidateArray( $messages ); |
|
42 | 42 | $messages[Application::POST_TYPE] = [ |
43 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
44 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
45 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
46 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
47 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
43 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
44 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
45 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
46 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
47 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
48 | 48 | ]; |
49 | 49 | return $messages; |
50 | 50 | } |
@@ -54,20 +54,20 @@ discard block |
||
54 | 54 | * @return array |
55 | 55 | * @filter manage_.Application::POST_TYPE._posts_columns |
56 | 56 | */ |
57 | - public function filterColumnsForPostType($columns) |
|
57 | + public function filterColumnsForPostType( $columns ) |
|
58 | 58 | { |
59 | - $columns = glsr(Helper::class)->consolidateArray($columns); |
|
59 | + $columns = glsr( Helper::class )->consolidateArray( $columns ); |
|
60 | 60 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
61 | - foreach ($postTypeColumns as $key => &$value) { |
|
62 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
61 | + foreach( $postTypeColumns as $key => &$value ) { |
|
62 | + if( !array_key_exists( $key, $columns ) || !empty($value) ) { |
|
63 | 63 | continue; |
64 | 64 | } |
65 | 65 | $value = $columns[$key]; |
66 | 66 | } |
67 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
67 | + if( count( glsr( Database::class )->getReviewsMeta( 'review_type' ) ) < 2 ) { |
|
68 | 68 | unset($postTypeColumns['review_type']); |
69 | 69 | } |
70 | - return array_filter($postTypeColumns, 'strlen'); |
|
70 | + return array_filter( $postTypeColumns, 'strlen' ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | * @return string |
77 | 77 | * @filter post_date_column_status |
78 | 78 | */ |
79 | - public function filterDateColumnStatus($status, $post) |
|
79 | + public function filterDateColumnStatus( $status, $post ) |
|
80 | 80 | { |
81 | - if (Application::POST_TYPE == glsr_get($post, 'post_type')) { |
|
82 | - $status = __('Submitted', 'site-reviews'); |
|
81 | + if( Application::POST_TYPE == glsr_get( $post, 'post_type' ) ) { |
|
82 | + $status = __( 'Submitted', 'site-reviews' ); |
|
83 | 83 | } |
84 | 84 | return $status; |
85 | 85 | } |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @return array |
91 | 91 | * @filter default_hidden_columns |
92 | 92 | */ |
93 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
93 | + public function filterDefaultHiddenColumns( $hidden, $screen ) |
|
94 | 94 | { |
95 | - if (glsr_get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
96 | - $hidden = glsr(Helper::class)->consolidateArray($hidden); |
|
95 | + if( glsr_get( $screen, 'id' ) == 'edit-'.Application::POST_TYPE ) { |
|
96 | + $hidden = glsr( Helper::class )->consolidateArray( $hidden ); |
|
97 | 97 | $hidden = ['reviewer']; |
98 | 98 | } |
99 | 99 | return $hidden; |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | * @return array |
106 | 106 | * @filter display_post_states |
107 | 107 | */ |
108 | - public function filterPostStates($postStates, $post) |
|
108 | + public function filterPostStates( $postStates, $post ) |
|
109 | 109 | { |
110 | - $postStates = glsr(Helper::class)->consolidateArray($postStates); |
|
111 | - if (Application::POST_TYPE == glsr_get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
112 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
110 | + $postStates = glsr( Helper::class )->consolidateArray( $postStates ); |
|
111 | + if( Application::POST_TYPE == glsr_get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
112 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
113 | 113 | } |
114 | 114 | return $postStates; |
115 | 115 | } |
@@ -120,28 +120,28 @@ discard block |
||
120 | 120 | * @return array |
121 | 121 | * @filter post_row_actions |
122 | 122 | */ |
123 | - public function filterRowActions($actions, $post) |
|
123 | + public function filterRowActions( $actions, $post ) |
|
124 | 124 | { |
125 | - if (Application::POST_TYPE != glsr_get($post, 'post_type') || 'trash' == $post->post_status) { |
|
125 | + if( Application::POST_TYPE != glsr_get( $post, 'post_type' ) || 'trash' == $post->post_status ) { |
|
126 | 126 | return $actions; |
127 | 127 | } |
128 | 128 | unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
129 | 129 | $rowActions = [ |
130 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
131 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
130 | + 'approve' => esc_attr__( 'Approve', 'site-reviews' ), |
|
131 | + 'unapprove' => esc_attr__( 'Unapprove', 'site-reviews' ), |
|
132 | 132 | ]; |
133 | 133 | $newActions = []; |
134 | - foreach ($rowActions as $key => $text) { |
|
135 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
136 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
134 | + foreach( $rowActions as $key => $text ) { |
|
135 | + $newActions[$key] = glsr( Builder::class )->a( $text, [ |
|
136 | + 'aria-label' => sprintf( esc_attr_x( '%s this review', 'Approve the review', 'site-reviews' ), $text ), |
|
137 | 137 | 'class' => 'glsr-change-status', |
138 | 138 | 'href' => wp_nonce_url( |
139 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
139 | + admin_url( 'post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID ), |
|
140 | 140 | $key.'-review_'.$post->ID |
141 | 141 | ), |
142 | - ]); |
|
142 | + ] ); |
|
143 | 143 | } |
144 | - return $newActions + glsr(Helper::class)->consolidateArray($actions); |
|
144 | + return $newActions + glsr( Helper::class )->consolidateArray( $actions ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | * @return array |
150 | 150 | * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
151 | 151 | */ |
152 | - public function filterSortableColumns($columns) |
|
152 | + public function filterSortableColumns( $columns ) |
|
153 | 153 | { |
154 | - $columns = glsr(Helper::class)->consolidateArray($columns); |
|
154 | + $columns = glsr( Helper::class )->consolidateArray( $columns ); |
|
155 | 155 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
156 | 156 | unset($postTypeColumns['cb']); |
157 | - foreach ($postTypeColumns as $key => $value) { |
|
158 | - if (glsr(Helper::class)->startsWith('taxonomy', $key)) { |
|
157 | + foreach( $postTypeColumns as $key => $value ) { |
|
158 | + if( glsr( Helper::class )->startsWith( 'taxonomy', $key ) ) { |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | $columns[$key] = $key; |
@@ -173,22 +173,22 @@ discard block |
||
173 | 173 | * @return string |
174 | 174 | * @filter ngettext |
175 | 175 | */ |
176 | - public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
176 | + public function filterStatusText( $translation, $single, $plural, $number, $domain ) |
|
177 | 177 | { |
178 | - if ($this->canModifyTranslation($domain)) { |
|
178 | + if( $this->canModifyTranslation( $domain ) ) { |
|
179 | 179 | $strings = [ |
180 | - 'Published' => __('Approved', 'site-reviews'), |
|
181 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
180 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
181 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
182 | 182 | ]; |
183 | - foreach ($strings as $search => $replace) { |
|
184 | - if (false === strpos($single, $search)) { |
|
183 | + foreach( $strings as $search => $replace ) { |
|
184 | + if( false === strpos( $single, $search ) ) { |
|
185 | 185 | continue; |
186 | 186 | } |
187 | - $translation = $this->getTranslation([ |
|
187 | + $translation = $this->getTranslation( [ |
|
188 | 188 | 'number' => $number, |
189 | - 'plural' => str_replace($search, $replace, $plural), |
|
190 | - 'single' => str_replace($search, $replace, $single), |
|
191 | - ]); |
|
189 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
190 | + 'single' => str_replace( $search, $replace, $single ), |
|
191 | + ] ); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | return $translation; |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | * @return void |
201 | 201 | * @action bulk_edit_custom_box |
202 | 202 | */ |
203 | - public function renderBulkEditFields($columnName, $postType) |
|
203 | + public function renderBulkEditFields( $columnName, $postType ) |
|
204 | 204 | { |
205 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
206 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
205 | + if( 'assigned_to' == $columnName && Application::POST_TYPE == $postType ) { |
|
206 | + glsr()->render( 'partials/editor/bulk-edit-assigned-to' ); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | * @return void |
213 | 213 | * @action restrict_manage_posts |
214 | 214 | */ |
215 | - public function renderColumnFilters($postType) |
|
215 | + public function renderColumnFilters( $postType ) |
|
216 | 216 | { |
217 | - glsr(Columns::class)->renderFilters($postType); |
|
217 | + glsr( Columns::class )->renderFilters( $postType ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | * @return void |
224 | 224 | * @action manage_posts_custom_column |
225 | 225 | */ |
226 | - public function renderColumnValues($column, $postId) |
|
226 | + public function renderColumnValues( $column, $postId ) |
|
227 | 227 | { |
228 | - glsr(Columns::class)->renderValues($column, $postId); |
|
228 | + glsr( Columns::class )->renderValues( $column, $postId ); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -233,14 +233,14 @@ discard block |
||
233 | 233 | * @return void |
234 | 234 | * @action save_post_.Application::POST_TYPE |
235 | 235 | */ |
236 | - public function saveBulkEditFields($postId) |
|
236 | + public function saveBulkEditFields( $postId ) |
|
237 | 237 | { |
238 | - if (!current_user_can('edit_posts')) { |
|
238 | + if( !current_user_can( 'edit_posts' ) ) { |
|
239 | 239 | return; |
240 | 240 | } |
241 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
242 | - if ($assignedTo && get_post($assignedTo)) { |
|
243 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
241 | + $assignedTo = filter_input( INPUT_GET, 'assigned_to' ); |
|
242 | + if( $assignedTo && get_post( $assignedTo ) ) { |
|
243 | + glsr( Database::class )->update( $postId, 'assigned_to', $assignedTo ); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
@@ -248,15 +248,15 @@ discard block |
||
248 | 248 | * @return void |
249 | 249 | * @action pre_get_posts |
250 | 250 | */ |
251 | - public function setQueryForColumn(WP_Query $query) |
|
251 | + public function setQueryForColumn( WP_Query $query ) |
|
252 | 252 | { |
253 | - if (!$this->hasPermission($query)) { |
|
253 | + if( !$this->hasPermission( $query ) ) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | - $this->setMetaQuery($query, [ |
|
256 | + $this->setMetaQuery( $query, [ |
|
257 | 257 | 'rating', 'review_type', |
258 | - ]); |
|
259 | - $this->setOrderby($query); |
|
258 | + ] ); |
|
259 | + $this->setOrderby( $query ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,15 +265,15 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function unapprove() |
267 | 267 | { |
268 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
268 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
272 | - wp_update_post([ |
|
271 | + check_admin_referer( 'unapprove-review_'.($postId = $this->getPostId()) ); |
|
272 | + wp_update_post( [ |
|
273 | 273 | 'ID' => $postId, |
274 | 274 | 'post_status' => 'pending', |
275 | - ]); |
|
276 | - wp_safe_redirect(wp_get_referer()); |
|
275 | + ] ); |
|
276 | + wp_safe_redirect( wp_get_referer() ); |
|
277 | 277 | exit; |
278 | 278 | } |
279 | 279 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @param string $domain |
283 | 283 | * @return bool |
284 | 284 | */ |
285 | - protected function canModifyTranslation($domain = 'default') |
|
285 | + protected function canModifyTranslation( $domain = 'default' ) |
|
286 | 286 | { |
287 | 287 | $screen = glsr_current_screen(); |
288 | 288 | return 'default' == $domain |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * Get the modified translation string. |
295 | 295 | * @return string |
296 | 296 | */ |
297 | - protected function getTranslation(array $args) |
|
297 | + protected function getTranslation( array $args ) |
|
298 | 298 | { |
299 | 299 | $defaults = [ |
300 | 300 | 'number' => 0, |
@@ -302,57 +302,57 @@ discard block |
||
302 | 302 | 'single' => '', |
303 | 303 | 'text' => '', |
304 | 304 | ]; |
305 | - $args = (object) wp_parse_args($args, $defaults); |
|
306 | - $translations = get_translations_for_domain(Application::ID); |
|
305 | + $args = (object)wp_parse_args( $args, $defaults ); |
|
306 | + $translations = get_translations_for_domain( Application::ID ); |
|
307 | 307 | return $args->text |
308 | - ? $translations->translate($args->text) |
|
309 | - : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
308 | + ? $translations->translate( $args->text ) |
|
309 | + : $translations->translate_plural( $args->single, $args->plural, $args->number ); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
313 | 313 | * @return bool |
314 | 314 | */ |
315 | - protected function hasPermission(WP_Query $query) |
|
315 | + protected function hasPermission( WP_Query $query ) |
|
316 | 316 | { |
317 | 317 | global $pagenow; |
318 | 318 | return is_admin() |
319 | 319 | && $query->is_main_query() |
320 | - && Application::POST_TYPE == $query->get('post_type') |
|
320 | + && Application::POST_TYPE == $query->get( 'post_type' ) |
|
321 | 321 | && 'edit.php' == $pagenow; |
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
325 | 325 | * @return void |
326 | 326 | */ |
327 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
327 | + protected function setMetaQuery( WP_Query $query, array $metaKeys ) |
|
328 | 328 | { |
329 | - foreach ($metaKeys as $key) { |
|
330 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
329 | + foreach( $metaKeys as $key ) { |
|
330 | + if( !($value = filter_input( INPUT_GET, $key )) ) { |
|
331 | 331 | continue; |
332 | 332 | } |
333 | - $metaQuery = (array) $query->get('meta_query'); |
|
333 | + $metaQuery = (array)$query->get( 'meta_query' ); |
|
334 | 334 | $metaQuery[] = [ |
335 | - 'key' => glsr(Helper::class)->prefix('_', $key), |
|
335 | + 'key' => glsr( Helper::class )->prefix( '_', $key ), |
|
336 | 336 | 'value' => $value, |
337 | 337 | ]; |
338 | - $query->set('meta_query', $metaQuery); |
|
338 | + $query->set( 'meta_query', $metaQuery ); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
343 | 343 | * @return void |
344 | 344 | */ |
345 | - protected function setOrderby(WP_Query $query) |
|
345 | + protected function setOrderby( WP_Query $query ) |
|
346 | 346 | { |
347 | - $orderby = $query->get('orderby'); |
|
347 | + $orderby = $query->get( 'orderby' ); |
|
348 | 348 | $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
349 | 349 | unset($columns['cb'], $columns['title'], $columns['date']); |
350 | - if (in_array($orderby, array_keys($columns))) { |
|
351 | - if ('reviewer' == $orderby) { |
|
350 | + if( in_array( $orderby, array_keys( $columns ) ) ) { |
|
351 | + if( 'reviewer' == $orderby ) { |
|
352 | 352 | $orderby = '_author'; |
353 | 353 | } |
354 | - $query->set('meta_key', $orderby); |
|
355 | - $query->set('orderby', 'meta_value'); |
|
354 | + $query->set( 'meta_key', $orderby ); |
|
355 | + $query->set( 'orderby', 'meta_value' ); |
|
356 | 356 | } |
357 | 357 | } |
358 | 358 | } |
@@ -7,23 +7,23 @@ discard block |
||
7 | 7 | |
8 | 8 | class SqlQueries |
9 | 9 | { |
10 | - protected $db; |
|
11 | - protected $postType; |
|
10 | + protected $db; |
|
11 | + protected $postType; |
|
12 | 12 | |
13 | - public function __construct() |
|
14 | - { |
|
15 | - global $wpdb; |
|
16 | - $this->db = $wpdb; |
|
17 | - $this->postType = Application::POST_TYPE; |
|
18 | - } |
|
13 | + public function __construct() |
|
14 | + { |
|
15 | + global $wpdb; |
|
16 | + $this->db = $wpdb; |
|
17 | + $this->postType = Application::POST_TYPE; |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param string $metaReviewId |
|
22 | - * @return int |
|
23 | - */ |
|
24 | - public function getPostIdFromReviewId($metaReviewId) |
|
25 | - { |
|
26 | - $postId = $this->db->get_var(" |
|
20 | + /** |
|
21 | + * @param string $metaReviewId |
|
22 | + * @return int |
|
23 | + */ |
|
24 | + public function getPostIdFromReviewId($metaReviewId) |
|
25 | + { |
|
26 | + $postId = $this->db->get_var(" |
|
27 | 27 | SELECT p.ID |
28 | 28 | FROM {$this->db->posts} AS p |
29 | 29 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -31,17 +31,17 @@ discard block |
||
31 | 31 | AND m.meta_key = '_review_id' |
32 | 32 | AND m.meta_value = '{$metaReviewId}' |
33 | 33 | "); |
34 | - return intval($postId); |
|
35 | - } |
|
34 | + return intval($postId); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param int $lastPostId |
|
39 | - * @param int $limit |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
43 | - { |
|
44 | - return (array) $this->db->get_results(" |
|
37 | + /** |
|
38 | + * @param int $lastPostId |
|
39 | + * @param int $limit |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
43 | + { |
|
44 | + return (array) $this->db->get_results(" |
|
45 | 45 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
46 | 46 | FROM {$this->db->posts} AS p |
47 | 47 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | ORDER By p.ID ASC |
57 | 57 | LIMIT {$limit} |
58 | 58 | "); |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @todo remove this? |
|
63 | - * @param string $metaKey |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getReviewCountsFor($metaKey) |
|
67 | - { |
|
68 | - $metaKey = glsr(Helper::class)->prefix('_', $metaKey); |
|
69 | - return (array) $this->db->get_results(" |
|
61 | + /** |
|
62 | + * @todo remove this? |
|
63 | + * @param string $metaKey |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getReviewCountsFor($metaKey) |
|
67 | + { |
|
68 | + $metaKey = glsr(Helper::class)->prefix('_', $metaKey); |
|
69 | + return (array) $this->db->get_results(" |
|
70 | 70 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
71 | 71 | FROM {$this->db->posts} AS p |
72 | 72 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -74,16 +74,16 @@ discard block |
||
74 | 74 | AND m.meta_key = '{$metaKey}' |
75 | 75 | GROUP BY name |
76 | 76 | "); |
77 | - } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @todo remove this? |
|
81 | - * @param string $reviewType |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function getReviewIdsByType($reviewType) |
|
85 | - { |
|
86 | - $results = $this->db->get_col(" |
|
79 | + /** |
|
80 | + * @todo remove this? |
|
81 | + * @param string $reviewType |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function getReviewIdsByType($reviewType) |
|
85 | + { |
|
86 | + $results = $this->db->get_col(" |
|
87 | 87 | SELECT DISTINCT m1.meta_value AS review_id |
88 | 88 | FROM {$this->db->posts} AS p |
89 | 89 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | AND m2.meta_key = '_review_type' |
94 | 94 | AND m2.meta_value = '{$reviewType}' |
95 | 95 | "); |
96 | - return array_keys(array_flip($results)); |
|
97 | - } |
|
96 | + return array_keys(array_flip($results)); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param int $greaterThanId |
|
101 | - * @param int $limit |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
105 | - { |
|
106 | - sort($postIds); |
|
107 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
108 | - $postIds = implode(',', $postIds); |
|
109 | - return (array) $this->db->get_results(" |
|
99 | + /** |
|
100 | + * @param int $greaterThanId |
|
101 | + * @param int $limit |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
105 | + { |
|
106 | + sort($postIds); |
|
107 | + $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
108 | + $postIds = implode(',', $postIds); |
|
109 | + return (array) $this->db->get_results(" |
|
110 | 110 | SELECT p.ID, m.meta_value AS rating |
111 | 111 | FROM {$this->db->posts} AS p |
112 | 112 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -119,17 +119,17 @@ discard block |
||
119 | 119 | ORDER By p.ID ASC |
120 | 120 | LIMIT {$limit} |
121 | 121 | "); |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @param string $key |
|
126 | - * @param string $status |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function getReviewsMeta($key, $status = 'publish') |
|
130 | - { |
|
131 | - $key = glsr(Helper::class)->prefix('_', $key); |
|
132 | - $values = $this->db->get_col(" |
|
124 | + /** |
|
125 | + * @param string $key |
|
126 | + * @param string $status |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function getReviewsMeta($key, $status = 'publish') |
|
130 | + { |
|
131 | + $key = glsr(Helper::class)->prefix('_', $key); |
|
132 | + $values = $this->db->get_col(" |
|
133 | 133 | SELECT DISTINCT m.meta_value |
134 | 134 | FROM {$this->db->postmeta} m |
135 | 135 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -140,42 +140,42 @@ discard block |
||
140 | 140 | GROUP BY p.ID -- remove duplicate meta_value entries |
141 | 141 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
142 | 142 | "); |
143 | - sort($values); |
|
144 | - return $values; |
|
145 | - } |
|
143 | + sort($values); |
|
144 | + return $values; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @param string $and |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - protected function getAndForCounts(array $args, $and = '') |
|
152 | - { |
|
153 | - $postIds = implode(',', array_filter(glsr_get($args, 'post_ids', []))); |
|
154 | - $termIds = implode(',', array_filter(glsr_get($args, 'term_ids', []))); |
|
155 | - if (!empty($args['type'])) { |
|
156 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
157 | - } |
|
158 | - if ($postIds) { |
|
159 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
160 | - } |
|
161 | - if ($termIds) { |
|
162 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
163 | - } |
|
164 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
165 | - } |
|
147 | + /** |
|
148 | + * @param string $and |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + protected function getAndForCounts(array $args, $and = '') |
|
152 | + { |
|
153 | + $postIds = implode(',', array_filter(glsr_get($args, 'post_ids', []))); |
|
154 | + $termIds = implode(',', array_filter(glsr_get($args, 'term_ids', []))); |
|
155 | + if (!empty($args['type'])) { |
|
156 | + $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
157 | + } |
|
158 | + if ($postIds) { |
|
159 | + $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
160 | + } |
|
161 | + if ($termIds) { |
|
162 | + $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
163 | + } |
|
164 | + return apply_filters('site-reviews/query/and-for-counts', $and); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $innerJoin |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
172 | - { |
|
173 | - if (!empty(glsr_get($args, 'post_ids'))) { |
|
174 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
175 | - } |
|
176 | - if (!empty(glsr_get($args, 'term_ids'))) { |
|
177 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
178 | - } |
|
179 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
180 | - } |
|
167 | + /** |
|
168 | + * @param string $innerJoin |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
172 | + { |
|
173 | + if (!empty(glsr_get($args, 'post_ids'))) { |
|
174 | + $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
175 | + } |
|
176 | + if (!empty(glsr_get($args, 'term_ids'))) { |
|
177 | + $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
178 | + } |
|
179 | + return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
180 | + } |
|
181 | 181 | } |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | * @param string $metaReviewId |
22 | 22 | * @return int |
23 | 23 | */ |
24 | - public function getPostIdFromReviewId($metaReviewId) |
|
24 | + public function getPostIdFromReviewId( $metaReviewId ) |
|
25 | 25 | { |
26 | - $postId = $this->db->get_var(" |
|
26 | + $postId = $this->db->get_var( " |
|
27 | 27 | SELECT p.ID |
28 | 28 | FROM {$this->db->posts} AS p |
29 | 29 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
30 | 30 | WHERE p.post_type = '{$this->postType}' |
31 | 31 | AND m.meta_key = '_review_id' |
32 | 32 | AND m.meta_value = '{$metaReviewId}' |
33 | - "); |
|
34 | - return intval($postId); |
|
33 | + " ); |
|
34 | + return intval( $postId ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | * @param int $limit |
40 | 40 | * @return array |
41 | 41 | */ |
42 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
42 | + public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
|
43 | 43 | { |
44 | - return (array) $this->db->get_results(" |
|
44 | + return (array)$this->db->get_results( " |
|
45 | 45 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
46 | 46 | FROM {$this->db->posts} AS p |
47 | 47 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
48 | 48 | INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id |
49 | - {$this->getInnerJoinForCounts($args)} |
|
49 | + {$this->getInnerJoinForCounts( $args )} |
|
50 | 50 | WHERE p.ID > {$lastPostId} |
51 | 51 | AND p.post_status = 'publish' |
52 | 52 | AND p.post_type = '{$this->postType}' |
53 | 53 | AND m1.meta_key = '_rating' |
54 | 54 | AND m2.meta_key = '_review_type' |
55 | - {$this->getAndForCounts($args)} |
|
55 | + {$this->getAndForCounts( $args )} |
|
56 | 56 | ORDER By p.ID ASC |
57 | 57 | LIMIT {$limit} |
58 | - "); |
|
58 | + " ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,17 +63,17 @@ discard block |
||
63 | 63 | * @param string $metaKey |
64 | 64 | * @return array |
65 | 65 | */ |
66 | - public function getReviewCountsFor($metaKey) |
|
66 | + public function getReviewCountsFor( $metaKey ) |
|
67 | 67 | { |
68 | - $metaKey = glsr(Helper::class)->prefix('_', $metaKey); |
|
69 | - return (array) $this->db->get_results(" |
|
68 | + $metaKey = glsr( Helper::class )->prefix( '_', $metaKey ); |
|
69 | + return (array)$this->db->get_results( " |
|
70 | 70 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
71 | 71 | FROM {$this->db->posts} AS p |
72 | 72 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
73 | 73 | WHERE p.post_type = '{$this->postType}' |
74 | 74 | AND m.meta_key = '{$metaKey}' |
75 | 75 | GROUP BY name |
76 | - "); |
|
76 | + " ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | * @param string $reviewType |
82 | 82 | * @return array |
83 | 83 | */ |
84 | - public function getReviewIdsByType($reviewType) |
|
84 | + public function getReviewIdsByType( $reviewType ) |
|
85 | 85 | { |
86 | - $results = $this->db->get_col(" |
|
86 | + $results = $this->db->get_col( " |
|
87 | 87 | SELECT DISTINCT m1.meta_value AS review_id |
88 | 88 | FROM {$this->db->posts} AS p |
89 | 89 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | AND m1.meta_key = '_review_id' |
93 | 93 | AND m2.meta_key = '_review_type' |
94 | 94 | AND m2.meta_value = '{$reviewType}' |
95 | - "); |
|
96 | - return array_keys(array_flip($results)); |
|
95 | + " ); |
|
96 | + return array_keys( array_flip( $results ) ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | * @param int $limit |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
104 | + public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
|
105 | 105 | { |
106 | - sort($postIds); |
|
107 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
108 | - $postIds = implode(',', $postIds); |
|
109 | - return (array) $this->db->get_results(" |
|
106 | + sort( $postIds ); |
|
107 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
108 | + $postIds = implode( ',', $postIds ); |
|
109 | + return (array)$this->db->get_results( " |
|
110 | 110 | SELECT p.ID, m.meta_value AS rating |
111 | 111 | FROM {$this->db->posts} AS p |
112 | 112 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | GROUP BY p.ID |
119 | 119 | ORDER By p.ID ASC |
120 | 120 | LIMIT {$limit} |
121 | - "); |
|
121 | + " ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @param string $status |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function getReviewsMeta($key, $status = 'publish') |
|
129 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
130 | 130 | { |
131 | - $key = glsr(Helper::class)->prefix('_', $key); |
|
132 | - $values = $this->db->get_col(" |
|
131 | + $key = glsr( Helper::class )->prefix( '_', $key ); |
|
132 | + $values = $this->db->get_col( " |
|
133 | 133 | SELECT DISTINCT m.meta_value |
134 | 134 | FROM {$this->db->postmeta} m |
135 | 135 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | AND p.post_status = '{$status}' |
140 | 140 | GROUP BY p.ID -- remove duplicate meta_value entries |
141 | 141 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
142 | - "); |
|
143 | - sort($values); |
|
142 | + " ); |
|
143 | + sort( $values ); |
|
144 | 144 | return $values; |
145 | 145 | } |
146 | 146 | |
@@ -148,34 +148,34 @@ discard block |
||
148 | 148 | * @param string $and |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - protected function getAndForCounts(array $args, $and = '') |
|
151 | + protected function getAndForCounts( array $args, $and = '' ) |
|
152 | 152 | { |
153 | - $postIds = implode(',', array_filter(glsr_get($args, 'post_ids', []))); |
|
154 | - $termIds = implode(',', array_filter(glsr_get($args, 'term_ids', []))); |
|
155 | - if (!empty($args['type'])) { |
|
156 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
153 | + $postIds = implode( ',', array_filter( glsr_get( $args, 'post_ids', [] ) ) ); |
|
154 | + $termIds = implode( ',', array_filter( glsr_get( $args, 'term_ids', [] ) ) ); |
|
155 | + if( !empty($args['type']) ) { |
|
156 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
157 | 157 | } |
158 | - if ($postIds) { |
|
159 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
158 | + if( $postIds ) { |
|
159 | + $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
160 | 160 | } |
161 | - if ($termIds) { |
|
162 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
161 | + if( $termIds ) { |
|
162 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
163 | 163 | } |
164 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
164 | + return apply_filters( 'site-reviews/query/and-for-counts', $and ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | 168 | * @param string $innerJoin |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
171 | + protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
|
172 | 172 | { |
173 | - if (!empty(glsr_get($args, 'post_ids'))) { |
|
174 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
173 | + if( !empty(glsr_get( $args, 'post_ids' )) ) { |
|
174 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
175 | 175 | } |
176 | - if (!empty(glsr_get($args, 'term_ids'))) { |
|
177 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
176 | + if( !empty(glsr_get( $args, 'term_ids' )) ) { |
|
177 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
178 | 178 | } |
179 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
179 | + return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin ); |
|
180 | 180 | } |
181 | 181 | } |
@@ -7,83 +7,83 @@ |
||
7 | 7 | |
8 | 8 | class Wpml implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'WPML'; |
|
11 | - const SUPPORTED_VERSION = '3.3.5'; |
|
10 | + const PLUGIN_NAME = 'WPML'; |
|
11 | + const SUPPORTED_VERSION = '3.3.5'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | - } |
|
25 | - return get_post(intval($postId)); |
|
26 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + } |
|
25 | + return get_post(intval($postId)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - public function getPostIds(array $postIds) |
|
32 | - { |
|
33 | - if (!$this->isEnabled()) { |
|
34 | - return $postIds; |
|
35 | - } |
|
36 | - $newPostIds = []; |
|
37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | - $postType = get_post_type($postId); |
|
39 | - if (!$postType) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $elementType = 'post_'.$postType; |
|
43 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | - if (!is_array($translations)) { |
|
46 | - $translations = []; |
|
47 | - } |
|
48 | - $newPostIds = array_merge( |
|
49 | - $newPostIds, |
|
50 | - array_column($translations, 'element_id') |
|
51 | - ); |
|
52 | - } |
|
53 | - return $this->cleanIds($newPostIds); |
|
54 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + public function getPostIds(array $postIds) |
|
32 | + { |
|
33 | + if (!$this->isEnabled()) { |
|
34 | + return $postIds; |
|
35 | + } |
|
36 | + $newPostIds = []; |
|
37 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | + $postType = get_post_type($postId); |
|
39 | + if (!$postType) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $elementType = 'post_'.$postType; |
|
43 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | + if (!is_array($translations)) { |
|
46 | + $translations = []; |
|
47 | + } |
|
48 | + $newPostIds = array_merge( |
|
49 | + $newPostIds, |
|
50 | + array_column($translations, 'element_id') |
|
51 | + ); |
|
52 | + } |
|
53 | + return $this->cleanIds($newPostIds); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function isActive() |
|
60 | - { |
|
61 | - return defined('ICL_SITEPRESS_VERSION'); |
|
62 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function isActive() |
|
60 | + { |
|
61 | + return defined('ICL_SITEPRESS_VERSION'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - public function isEnabled() |
|
68 | - { |
|
69 | - return $this->isActive() |
|
70 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
71 | - } |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + public function isEnabled() |
|
68 | + { |
|
69 | + return $this->isActive() |
|
70 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function isSupported() |
|
77 | - { |
|
78 | - return $this->isActive() |
|
79 | - && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
80 | - } |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function isSupported() |
|
77 | + { |
|
78 | + return $this->isActive() |
|
79 | + && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function cleanIds(array $postIds) |
|
86 | - { |
|
87 | - return array_filter(array_unique($postIds)); |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function cleanIds(array $postIds) |
|
86 | + { |
|
87 | + return array_filter(array_unique($postIds)); |
|
88 | + } |
|
89 | 89 | } |
@@ -13,44 +13,44 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@inheritdoc} |
15 | 15 | */ |
16 | - public function getPost($postId) |
|
16 | + public function getPost( $postId ) |
|
17 | 17 | { |
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
18 | + $postId = trim( $postId ); |
|
19 | + if( !is_numeric( $postId ) ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - if ($this->isEnabled()) { |
|
23 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
22 | + if( $this->isEnabled() ) { |
|
23 | + $postId = apply_filters( 'wpml_object_id', $postId, 'any', true ); |
|
24 | 24 | } |
25 | - return get_post(intval($postId)); |
|
25 | + return get_post( intval( $postId ) ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * {@inheritdoc} |
30 | 30 | */ |
31 | - public function getPostIds(array $postIds) |
|
31 | + public function getPostIds( array $postIds ) |
|
32 | 32 | { |
33 | - if (!$this->isEnabled()) { |
|
33 | + if( !$this->isEnabled() ) { |
|
34 | 34 | return $postIds; |
35 | 35 | } |
36 | 36 | $newPostIds = []; |
37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | - $postType = get_post_type($postId); |
|
39 | - if (!$postType) { |
|
37 | + foreach( $this->cleanIds( $postIds ) as $postId ) { |
|
38 | + $postType = get_post_type( $postId ); |
|
39 | + if( !$postType ) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | 42 | $elementType = 'post_'.$postType; |
43 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | - if (!is_array($translations)) { |
|
43 | + $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType ); |
|
44 | + $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType ); |
|
45 | + if( !is_array( $translations ) ) { |
|
46 | 46 | $translations = []; |
47 | 47 | } |
48 | 48 | $newPostIds = array_merge( |
49 | 49 | $newPostIds, |
50 | - array_column($translations, 'element_id') |
|
50 | + array_column( $translations, 'element_id' ) |
|
51 | 51 | ); |
52 | 52 | } |
53 | - return $this->cleanIds($newPostIds); |
|
53 | + return $this->cleanIds( $newPostIds ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function isActive() |
60 | 60 | { |
61 | - return defined('ICL_SITEPRESS_VERSION'); |
|
61 | + return defined( 'ICL_SITEPRESS_VERSION' ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function isEnabled() |
68 | 68 | { |
69 | 69 | return $this->isActive() |
70 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
70 | + && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | public function isSupported() |
77 | 77 | { |
78 | 78 | return $this->isActive() |
79 | - && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
79 | + && version_compare( ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>=' ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - protected function cleanIds(array $postIds) |
|
85 | + protected function cleanIds( array $postIds ) |
|
86 | 86 | { |
87 | - return array_filter(array_unique($postIds)); |
|
87 | + return array_filter( array_unique( $postIds ) ); |
|
88 | 88 | } |
89 | 89 | } |
@@ -7,79 +7,79 @@ |
||
7 | 7 | |
8 | 8 | class Polylang implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'Polylang'; |
|
11 | - const SUPPORTED_VERSION = '2.3'; |
|
10 | + const PLUGIN_NAME = 'Polylang'; |
|
11 | + const SUPPORTED_VERSION = '2.3'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | - } |
|
25 | - if (!empty($polylangPostId)) { |
|
26 | - $postId = $polylangPostId; |
|
27 | - } |
|
28 | - return get_post(intval($postId)); |
|
29 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + } |
|
25 | + if (!empty($polylangPostId)) { |
|
26 | + $postId = $polylangPostId; |
|
27 | + } |
|
28 | + return get_post(intval($postId)); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - public function getPostIds(array $postIds) |
|
35 | - { |
|
36 | - if (!$this->isEnabled()) { |
|
37 | - return $postIds; |
|
38 | - } |
|
39 | - $newPostIds = []; |
|
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | - $newPostIds = array_merge( |
|
42 | - $newPostIds, |
|
43 | - array_values(pll_get_post_translations($postId)) |
|
44 | - ); |
|
45 | - } |
|
46 | - return $this->cleanIds($newPostIds); |
|
47 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + public function getPostIds(array $postIds) |
|
35 | + { |
|
36 | + if (!$this->isEnabled()) { |
|
37 | + return $postIds; |
|
38 | + } |
|
39 | + $newPostIds = []; |
|
40 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | + $newPostIds = array_merge( |
|
42 | + $newPostIds, |
|
43 | + array_values(pll_get_post_translations($postId)) |
|
44 | + ); |
|
45 | + } |
|
46 | + return $this->cleanIds($newPostIds); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isActive() |
|
53 | - { |
|
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isActive() |
|
53 | + { |
|
54 | + return function_exists('PLL') |
|
55 | + && function_exists('pll_get_post') |
|
56 | + && function_exists('pll_get_post_language') |
|
57 | + && function_exists('pll_get_post_translations'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function isEnabled() |
|
64 | - { |
|
65 | - return $this->isActive() |
|
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function isEnabled() |
|
64 | + { |
|
65 | + return $this->isActive() |
|
66 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function isSupported() |
|
73 | - { |
|
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | - } |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function isSupported() |
|
73 | + { |
|
74 | + return defined('POLYLANG_VERSION') |
|
75 | + && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function cleanIds(array $postIds) |
|
82 | - { |
|
83 | - return array_filter(array_unique($postIds)); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function cleanIds(array $postIds) |
|
82 | + { |
|
83 | + return array_filter(array_unique($postIds)); |
|
84 | + } |
|
85 | 85 | } |
@@ -13,37 +13,37 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@inheritdoc} |
15 | 15 | */ |
16 | - public function getPost($postId) |
|
16 | + public function getPost( $postId ) |
|
17 | 17 | { |
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
18 | + $postId = trim( $postId ); |
|
19 | + if( !is_numeric( $postId ) ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
22 | + if( $this->isEnabled() ) { |
|
23 | + $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) ); |
|
24 | 24 | } |
25 | - if (!empty($polylangPostId)) { |
|
25 | + if( !empty($polylangPostId) ) { |
|
26 | 26 | $postId = $polylangPostId; |
27 | 27 | } |
28 | - return get_post(intval($postId)); |
|
28 | + return get_post( intval( $postId ) ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * {@inheritdoc} |
33 | 33 | */ |
34 | - public function getPostIds(array $postIds) |
|
34 | + public function getPostIds( array $postIds ) |
|
35 | 35 | { |
36 | - if (!$this->isEnabled()) { |
|
36 | + if( !$this->isEnabled() ) { |
|
37 | 37 | return $postIds; |
38 | 38 | } |
39 | 39 | $newPostIds = []; |
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
40 | + foreach( $this->cleanIds( $postIds ) as $postId ) { |
|
41 | 41 | $newPostIds = array_merge( |
42 | 42 | $newPostIds, |
43 | - array_values(pll_get_post_translations($postId)) |
|
43 | + array_values( pll_get_post_translations( $postId ) ) |
|
44 | 44 | ); |
45 | 45 | } |
46 | - return $this->cleanIds($newPostIds); |
|
46 | + return $this->cleanIds( $newPostIds ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function isActive() |
53 | 53 | { |
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
54 | + return function_exists( 'PLL' ) |
|
55 | + && function_exists( 'pll_get_post' ) |
|
56 | + && function_exists( 'pll_get_post_language' ) |
|
57 | + && function_exists( 'pll_get_post_translations' ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function isEnabled() |
64 | 64 | { |
65 | 65 | return $this->isActive() |
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
66 | + && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,15 +71,15 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function isSupported() |
73 | 73 | { |
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
74 | + return defined( 'POLYLANG_VERSION' ) |
|
75 | + && version_compare( POLYLANG_VERSION, static::SUPPORTED_VERSION, '>=' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - protected function cleanIds(array $postIds) |
|
81 | + protected function cleanIds( array $postIds ) |
|
82 | 82 | { |
83 | - return array_filter(array_unique($postIds)); |
|
83 | + return array_filter( array_unique( $postIds ) ); |
|
84 | 84 | } |
85 | 85 | } |