@@ -8,164 +8,164 @@ |
||
8 | 8 | |
9 | 9 | class Notification |
10 | 10 | { |
11 | - /** |
|
12 | - * @var bool |
|
13 | - */ |
|
14 | - protected $email; |
|
11 | + /** |
|
12 | + * @var bool |
|
13 | + */ |
|
14 | + protected $email; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var Review |
|
18 | - */ |
|
19 | - protected $review; |
|
16 | + /** |
|
17 | + * @var Review |
|
18 | + */ |
|
19 | + protected $review; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var bool |
|
23 | - */ |
|
24 | - protected $slack; |
|
21 | + /** |
|
22 | + * @var bool |
|
23 | + */ |
|
24 | + protected $slack; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $types; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $types; |
|
30 | 30 | |
31 | - public function __construct() |
|
32 | - { |
|
33 | - $types = glsr(OptionManager::class)->get('settings.general.notifications', []); |
|
34 | - $this->email = count(array_intersect(['admin', 'custom'], $types)) > 0; |
|
35 | - $this->slack = in_array('slack', $types); |
|
36 | - $this->types = $types; |
|
37 | - } |
|
31 | + public function __construct() |
|
32 | + { |
|
33 | + $types = glsr(OptionManager::class)->get('settings.general.notifications', []); |
|
34 | + $this->email = count(array_intersect(['admin', 'custom'], $types)) > 0; |
|
35 | + $this->slack = in_array('slack', $types); |
|
36 | + $this->types = $types; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function send(Review $review) |
|
43 | - { |
|
44 | - if (empty($this->types)) { |
|
45 | - return; |
|
46 | - } |
|
47 | - $this->review = $review; |
|
48 | - $args = [ |
|
49 | - 'link' => $this->getLink(), |
|
50 | - 'title' => $this->getTitle(), |
|
51 | - ]; |
|
52 | - $this->sendToEmail($args); |
|
53 | - $this->sendToSlack($args); |
|
54 | - } |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function send(Review $review) |
|
43 | + { |
|
44 | + if (empty($this->types)) { |
|
45 | + return; |
|
46 | + } |
|
47 | + $this->review = $review; |
|
48 | + $args = [ |
|
49 | + 'link' => $this->getLink(), |
|
50 | + 'title' => $this->getTitle(), |
|
51 | + ]; |
|
52 | + $this->sendToEmail($args); |
|
53 | + $this->sendToSlack($args); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return Email |
|
58 | - */ |
|
59 | - protected function buildEmail(array $args) |
|
60 | - { |
|
61 | - return glsr(Email::class)->compose([ |
|
62 | - 'to' => $this->getEmailAddresses(), |
|
63 | - 'subject' => $args['title'], |
|
64 | - 'template' => 'email-notification', |
|
65 | - 'template-tags' => [ |
|
66 | - 'review_author' => $this->review->author ?: __('Anonymous', 'site-reviews'), |
|
67 | - 'review_content' => $this->review->content, |
|
68 | - 'review_email' => $this->review->email, |
|
69 | - 'review_ip' => $this->review->ip_address, |
|
70 | - 'review_link' => sprintf('<a href="%1$s">%1$s</a>', $args['link']), |
|
71 | - 'review_rating' => $this->review->rating, |
|
72 | - 'review_title' => $this->review->title, |
|
73 | - ], |
|
74 | - ]); |
|
75 | - } |
|
56 | + /** |
|
57 | + * @return Email |
|
58 | + */ |
|
59 | + protected function buildEmail(array $args) |
|
60 | + { |
|
61 | + return glsr(Email::class)->compose([ |
|
62 | + 'to' => $this->getEmailAddresses(), |
|
63 | + 'subject' => $args['title'], |
|
64 | + 'template' => 'email-notification', |
|
65 | + 'template-tags' => [ |
|
66 | + 'review_author' => $this->review->author ?: __('Anonymous', 'site-reviews'), |
|
67 | + 'review_content' => $this->review->content, |
|
68 | + 'review_email' => $this->review->email, |
|
69 | + 'review_ip' => $this->review->ip_address, |
|
70 | + 'review_link' => sprintf('<a href="%1$s">%1$s</a>', $args['link']), |
|
71 | + 'review_rating' => $this->review->rating, |
|
72 | + 'review_title' => $this->review->title, |
|
73 | + ], |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return Slack |
|
79 | - */ |
|
80 | - protected function buildSlackNotification(array $args) |
|
81 | - { |
|
82 | - return glsr(Slack::class)->compose($this->review, [ |
|
83 | - 'button_url' => $args['link'], |
|
84 | - 'fallback' => $this->buildEmail($args)->read('plaintext'), |
|
85 | - 'pretext' => $args['title'], |
|
86 | - ]); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return Slack |
|
79 | + */ |
|
80 | + protected function buildSlackNotification(array $args) |
|
81 | + { |
|
82 | + return glsr(Slack::class)->compose($this->review, [ |
|
83 | + 'button_url' => $args['link'], |
|
84 | + 'fallback' => $this->buildEmail($args)->read('plaintext'), |
|
85 | + 'pretext' => $args['title'], |
|
86 | + ]); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - protected function getEmailAddresses() |
|
93 | - { |
|
94 | - $emails = []; |
|
95 | - if (in_array('admin', $this->types)) { |
|
96 | - $emails[] = glsr(OptionManager::class)->getWP('admin_email'); |
|
97 | - } |
|
98 | - if (in_array('author', $this->types)) { |
|
99 | - $assignedPost = get_post(intval($this->review->assigned_to)); |
|
100 | - if ($assignedPost instanceof WP_Post) { |
|
101 | - $this->email = true; |
|
102 | - $emails[] = get_the_author_meta('user_email', intval($assignedPost->post_author)); |
|
103 | - } |
|
104 | - } |
|
105 | - if (in_array('custom', $this->types)) { |
|
106 | - $customEmails = glsr(OptionManager::class)->get('settings.general.notification_email'); |
|
107 | - $customEmails = str_replace([' ', ',', ';'], ',', $customEmails); |
|
108 | - $customEmails = explode(',', $customEmails); |
|
109 | - $emails = array_merge($emails, $customEmails); |
|
110 | - } |
|
111 | - $emails = array_filter(array_keys(array_flip($emails))); |
|
112 | - return apply_filters('site-reviews/notification/emails', $emails, $this->review); |
|
113 | - } |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + protected function getEmailAddresses() |
|
93 | + { |
|
94 | + $emails = []; |
|
95 | + if (in_array('admin', $this->types)) { |
|
96 | + $emails[] = glsr(OptionManager::class)->getWP('admin_email'); |
|
97 | + } |
|
98 | + if (in_array('author', $this->types)) { |
|
99 | + $assignedPost = get_post(intval($this->review->assigned_to)); |
|
100 | + if ($assignedPost instanceof WP_Post) { |
|
101 | + $this->email = true; |
|
102 | + $emails[] = get_the_author_meta('user_email', intval($assignedPost->post_author)); |
|
103 | + } |
|
104 | + } |
|
105 | + if (in_array('custom', $this->types)) { |
|
106 | + $customEmails = glsr(OptionManager::class)->get('settings.general.notification_email'); |
|
107 | + $customEmails = str_replace([' ', ',', ';'], ',', $customEmails); |
|
108 | + $customEmails = explode(',', $customEmails); |
|
109 | + $emails = array_merge($emails, $customEmails); |
|
110 | + } |
|
111 | + $emails = array_filter(array_keys(array_flip($emails))); |
|
112 | + return apply_filters('site-reviews/notification/emails', $emails, $this->review); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getLink() |
|
119 | - { |
|
120 | - return admin_url('post.php?post='.$this->review->ID.'&action=edit'); |
|
121 | - } |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getLink() |
|
119 | + { |
|
120 | + return admin_url('post.php?post='.$this->review->ID.'&action=edit'); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function getTitle() |
|
127 | - { |
|
128 | - $assignedTitle = get_the_title(intval($this->review->assigned_to)); |
|
129 | - $title = _nx( |
|
130 | - 'New %s-star review', |
|
131 | - 'New %s-star review of: %s', |
|
132 | - intval(empty($assignedTitle)), |
|
133 | - 'This string differs depending on whether or not the review has been assigned to a post.', |
|
134 | - 'site-reviews' |
|
135 | - ); |
|
136 | - $title = sprintf('[%s] %s', |
|
137 | - wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES), |
|
138 | - sprintf($title, $this->review->rating, $assignedTitle) |
|
139 | - ); |
|
140 | - return apply_filters('site-reviews/notification/title', $title, $this->review); |
|
141 | - } |
|
123 | + /** |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function getTitle() |
|
127 | + { |
|
128 | + $assignedTitle = get_the_title(intval($this->review->assigned_to)); |
|
129 | + $title = _nx( |
|
130 | + 'New %s-star review', |
|
131 | + 'New %s-star review of: %s', |
|
132 | + intval(empty($assignedTitle)), |
|
133 | + 'This string differs depending on whether or not the review has been assigned to a post.', |
|
134 | + 'site-reviews' |
|
135 | + ); |
|
136 | + $title = sprintf('[%s] %s', |
|
137 | + wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES), |
|
138 | + sprintf($title, $this->review->rating, $assignedTitle) |
|
139 | + ); |
|
140 | + return apply_filters('site-reviews/notification/title', $title, $this->review); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - protected function sendToEmail(array $args) |
|
147 | - { |
|
148 | - $email = $this->buildEmail($args); |
|
149 | - if (empty($email->to)) { |
|
150 | - glsr_log()->error('Email notification was not sent (missing email address)'); |
|
151 | - return; |
|
152 | - } |
|
153 | - $email->send(); |
|
154 | - } |
|
143 | + /** |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + protected function sendToEmail(array $args) |
|
147 | + { |
|
148 | + $email = $this->buildEmail($args); |
|
149 | + if (empty($email->to)) { |
|
150 | + glsr_log()->error('Email notification was not sent (missing email address)'); |
|
151 | + return; |
|
152 | + } |
|
153 | + $email->send(); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - protected function sendToSlack(array $args) |
|
160 | - { |
|
161 | - if (!$this->slack) { |
|
162 | - return; |
|
163 | - } |
|
164 | - $notification = $this->buildSlackNotification($args); |
|
165 | - $result = $notification->send(); |
|
166 | - if (is_wp_error($result)) { |
|
167 | - $notification->review = null; |
|
168 | - glsr_log()->error($result->get_error_message())->debug($notification); |
|
169 | - } |
|
170 | - } |
|
156 | + /** |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + protected function sendToSlack(array $args) |
|
160 | + { |
|
161 | + if (!$this->slack) { |
|
162 | + return; |
|
163 | + } |
|
164 | + $notification = $this->buildSlackNotification($args); |
|
165 | + $result = $notification->send(); |
|
166 | + if (is_wp_error($result)) { |
|
167 | + $notification->review = null; |
|
168 | + glsr_log()->error($result->get_error_message())->debug($notification); |
|
169 | + } |
|
170 | + } |
|
171 | 171 | } |
@@ -7,33 +7,33 @@ |
||
7 | 7 | |
8 | 8 | class Metaboxes |
9 | 9 | { |
10 | - /** |
|
11 | - * @param int $postId |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function saveAssignedToMetabox($postId) |
|
15 | - { |
|
16 | - if (!wp_verify_nonce(glsr(Helper::class)->filterInput('_nonce-assigned-to'), 'assigned_to')) { |
|
17 | - return; |
|
18 | - } |
|
19 | - $assignedTo = strval(glsr(Helper::class)->filterInput('assigned_to')); |
|
20 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
21 | - } |
|
10 | + /** |
|
11 | + * @param int $postId |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function saveAssignedToMetabox($postId) |
|
15 | + { |
|
16 | + if (!wp_verify_nonce(glsr(Helper::class)->filterInput('_nonce-assigned-to'), 'assigned_to')) { |
|
17 | + return; |
|
18 | + } |
|
19 | + $assignedTo = strval(glsr(Helper::class)->filterInput('assigned_to')); |
|
20 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param int $postId |
|
25 | - * @return mixed |
|
26 | - */ |
|
27 | - public function saveResponseMetabox($postId) |
|
28 | - { |
|
29 | - if (!wp_verify_nonce(glsr(Helper::class)->filterInput('_nonce-response'), 'response')) { |
|
30 | - return; |
|
31 | - } |
|
32 | - $response = strval(glsr(Helper::class)->filterInput('response')); |
|
33 | - glsr(Database::class)->update($postId, 'response', trim(wp_kses($response, [ |
|
34 | - 'a' => ['href' => [], 'title' => []], |
|
35 | - 'em' => [], |
|
36 | - 'strong' => [], |
|
37 | - ]))); |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param int $postId |
|
25 | + * @return mixed |
|
26 | + */ |
|
27 | + public function saveResponseMetabox($postId) |
|
28 | + { |
|
29 | + if (!wp_verify_nonce(glsr(Helper::class)->filterInput('_nonce-response'), 'response')) { |
|
30 | + return; |
|
31 | + } |
|
32 | + $response = strval(glsr(Helper::class)->filterInput('response')); |
|
33 | + glsr(Database::class)->update($postId, 'response', trim(wp_kses($response, [ |
|
34 | + 'a' => ['href' => [], 'title' => []], |
|
35 | + 'em' => [], |
|
36 | + 'strong' => [], |
|
37 | + ]))); |
|
38 | + } |
|
39 | 39 | } |
@@ -7,84 +7,84 @@ |
||
7 | 7 | |
8 | 8 | class Customization |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - public function filterEditorSettings(array $settings) |
|
14 | - { |
|
15 | - if ($this->isReviewEditable()) { |
|
16 | - $settings = [ |
|
17 | - 'media_buttons' => false, |
|
18 | - 'quicktags' => false, |
|
19 | - 'textarea_rows' => 12, |
|
20 | - 'tinymce' => false, |
|
21 | - ]; |
|
22 | - } |
|
23 | - return $settings; |
|
24 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + public function filterEditorSettings(array $settings) |
|
14 | + { |
|
15 | + if ($this->isReviewEditable()) { |
|
16 | + $settings = [ |
|
17 | + 'media_buttons' => false, |
|
18 | + 'quicktags' => false, |
|
19 | + 'textarea_rows' => 12, |
|
20 | + 'tinymce' => false, |
|
21 | + ]; |
|
22 | + } |
|
23 | + return $settings; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param string $html |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function filterEditorTextarea($html) |
|
31 | - { |
|
32 | - if ($this->isReviewEditable()) { |
|
33 | - $html = str_replace('<textarea', '<div id="ed_toolbar"></div><textarea', $html); |
|
34 | - } |
|
35 | - return $html; |
|
36 | - } |
|
26 | + /** |
|
27 | + * @param string $html |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function filterEditorTextarea($html) |
|
31 | + { |
|
32 | + if ($this->isReviewEditable()) { |
|
33 | + $html = str_replace('<textarea', '<div id="ed_toolbar"></div><textarea', $html); |
|
34 | + } |
|
35 | + return $html; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function removeAutosave() |
|
42 | - { |
|
43 | - if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
44 | - return; |
|
45 | - } |
|
46 | - wp_deregister_script('autosave'); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function removeAutosave() |
|
42 | + { |
|
43 | + if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
44 | + return; |
|
45 | + } |
|
46 | + wp_deregister_script('autosave'); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function removeMetaBoxes() |
|
53 | - { |
|
54 | - remove_meta_box('slugdiv', Application::POST_TYPE, 'advanced'); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function removeMetaBoxes() |
|
53 | + { |
|
54 | + remove_meta_box('slugdiv', Application::POST_TYPE, 'advanced'); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function removePostTypeSupport() |
|
61 | - { |
|
62 | - if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
63 | - return; |
|
64 | - } |
|
65 | - remove_post_type_support(Application::POST_TYPE, 'title'); |
|
66 | - remove_post_type_support(Application::POST_TYPE, 'editor'); |
|
67 | - } |
|
57 | + /** |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function removePostTypeSupport() |
|
61 | + { |
|
62 | + if (!$this->isReviewEditor() || $this->isReviewEditable()) { |
|
63 | + return; |
|
64 | + } |
|
65 | + remove_post_type_support(Application::POST_TYPE, 'title'); |
|
66 | + remove_post_type_support(Application::POST_TYPE, 'editor'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - protected function isReviewEditable() |
|
73 | - { |
|
74 | - $postId = intval(filter_input(INPUT_GET, 'post')); |
|
75 | - return $postId > 0 |
|
76 | - && 'local' == glsr(Database::class)->get($postId, 'review_type') |
|
77 | - && $this->isReviewEditor(); |
|
78 | - } |
|
69 | + /** |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + protected function isReviewEditable() |
|
73 | + { |
|
74 | + $postId = intval(filter_input(INPUT_GET, 'post')); |
|
75 | + return $postId > 0 |
|
76 | + && 'local' == glsr(Database::class)->get($postId, 'review_type') |
|
77 | + && $this->isReviewEditor(); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - protected function isReviewEditor() |
|
84 | - { |
|
85 | - $screen = glsr_current_screen(); |
|
86 | - return 'post' == $screen->base |
|
87 | - && Application::POST_TYPE == $screen->id |
|
88 | - && Application::POST_TYPE == $screen->post_type; |
|
89 | - } |
|
80 | + /** |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + protected function isReviewEditor() |
|
84 | + { |
|
85 | + $screen = glsr_current_screen(); |
|
86 | + return 'post' == $screen->base |
|
87 | + && Application::POST_TYPE == $screen->id |
|
88 | + && Application::POST_TYPE == $screen->post_type; |
|
89 | + } |
|
90 | 90 | } |
@@ -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 | } |
@@ -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 | } |
@@ -10,223 +10,223 @@ |
||
10 | 10 | |
11 | 11 | abstract class Shortcode implements ShortcodeContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $partialName; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $shortcodeName; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param string|array $atts |
|
25 | - * @param string $type |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
29 | - { |
|
30 | - $this->partialName = $this->getShortcodePartialName(); |
|
31 | - $this->shortcodeName = $this->getShortcodeName(); |
|
32 | - $args = $this->normalizeArgs($args, $type); |
|
33 | - $atts = $this->normalizeAtts($atts, $type); |
|
34 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
35 | - $title = !empty($atts['title']) |
|
36 | - ? $args['before_title'].$atts['title'].$args['after_title'] |
|
37 | - : ''; |
|
38 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
39 | - return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string|array $atts |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function buildShortcode($atts = []) |
|
47 | - { |
|
48 | - return $this->build($atts); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getDefaults($atts) |
|
55 | - { |
|
56 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function getHideOptions() |
|
63 | - { |
|
64 | - $options = $this->hideOptions(); |
|
65 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
72 | - { |
|
73 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getShortcodeDefaultsClassName() |
|
80 | - { |
|
81 | - return glsr(Helper::class)->buildClassName( |
|
82 | - $this->getShortcodeClassName('Defaults'), |
|
83 | - 'Defaults' |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getShortcodeName() |
|
91 | - { |
|
92 | - return glsr(Helper::class)->snakeCase($this->getShortcodeClassName()); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getShortcodePartialName() |
|
99 | - { |
|
100 | - return glsr(Helper::class)->dashCase($this->getShortcodeClassName()); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param array|string $args |
|
105 | - * @param string $type |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public function normalizeArgs($args, $type = 'shortcode') |
|
109 | - { |
|
110 | - $args = wp_parse_args($args, [ |
|
111 | - 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
112 | - 'after_widget' => '</div>', |
|
113 | - 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
114 | - 'after_title' => '</h3>', |
|
115 | - ]); |
|
116 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param array|string $atts |
|
121 | - * @param string $type |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
125 | - { |
|
126 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
127 | - $atts = $this->getDefaults($atts); |
|
128 | - array_walk($atts, function (&$value, $key) { |
|
129 | - $methodName = glsr(Helper::class)->buildMethodName($key, 'normalize'); |
|
130 | - if (!method_exists($this, $methodName)) { |
|
131 | - return; |
|
132 | - } |
|
133 | - $value = $this->$methodName($value); |
|
134 | - }); |
|
135 | - return $atts; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - abstract protected function hideOptions(); |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $postId |
|
145 | - * @return int|string |
|
146 | - */ |
|
147 | - protected function normalizeAssignedTo($postId) |
|
148 | - { |
|
149 | - if ('parent_id' == $postId) { |
|
150 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
151 | - } elseif ('post_id' == $postId) { |
|
152 | - $postId = intval(get_the_ID()); |
|
153 | - } |
|
154 | - return $postId; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param string $postId |
|
159 | - * @return int|string |
|
160 | - */ |
|
161 | - protected function normalizeAssignTo($postId) |
|
162 | - { |
|
163 | - return $this->normalizeAssignedTo($postId); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string|array $hide |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - protected function normalizeHide($hide) |
|
171 | - { |
|
172 | - if (is_string($hide)) { |
|
173 | - $hide = explode(',', $hide); |
|
174 | - } |
|
175 | - $hideKeys = array_keys($this->getHideOptions()); |
|
176 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
177 | - return in_array($value, $hideKeys); |
|
178 | - }); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $id |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - protected function normalizeId($id) |
|
186 | - { |
|
187 | - return sanitize_title($id); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $labels |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - protected function normalizeLabels($labels) |
|
195 | - { |
|
196 | - $defaults = [ |
|
197 | - __('Excellent', 'site-reviews'), |
|
198 | - __('Very good', 'site-reviews'), |
|
199 | - __('Average', 'site-reviews'), |
|
200 | - __('Poor', 'site-reviews'), |
|
201 | - __('Terrible', 'site-reviews'), |
|
202 | - ]; |
|
203 | - $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
204 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
205 | - $labels = array_map('trim', explode(',', $labels)); |
|
206 | - foreach ($defaults as $i => $label) { |
|
207 | - if (empty($labels[$i])) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $defaults[$i] = $labels[$i]; |
|
211 | - } |
|
212 | - return array_combine(range($maxRating, 1), $defaults); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param string $schema |
|
217 | - * @return bool |
|
218 | - */ |
|
219 | - protected function normalizeSchema($schema) |
|
220 | - { |
|
221 | - return wp_validate_boolean($schema); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $text |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - protected function normalizeText($text) |
|
229 | - { |
|
230 | - return trim($text); |
|
231 | - } |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $partialName; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $shortcodeName; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param string|array $atts |
|
25 | + * @param string $type |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function build($atts, array $args = [], $type = 'shortcode') |
|
29 | + { |
|
30 | + $this->partialName = $this->getShortcodePartialName(); |
|
31 | + $this->shortcodeName = $this->getShortcodeName(); |
|
32 | + $args = $this->normalizeArgs($args, $type); |
|
33 | + $atts = $this->normalizeAtts($atts, $type); |
|
34 | + $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
35 | + $title = !empty($atts['title']) |
|
36 | + ? $args['before_title'].$atts['title'].$args['after_title'] |
|
37 | + : ''; |
|
38 | + $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
39 | + return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string|array $atts |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function buildShortcode($atts = []) |
|
47 | + { |
|
48 | + return $this->build($atts); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getDefaults($atts) |
|
55 | + { |
|
56 | + return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function getHideOptions() |
|
63 | + { |
|
64 | + $options = $this->hideOptions(); |
|
65 | + return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
72 | + { |
|
73 | + return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getShortcodeDefaultsClassName() |
|
80 | + { |
|
81 | + return glsr(Helper::class)->buildClassName( |
|
82 | + $this->getShortcodeClassName('Defaults'), |
|
83 | + 'Defaults' |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getShortcodeName() |
|
91 | + { |
|
92 | + return glsr(Helper::class)->snakeCase($this->getShortcodeClassName()); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getShortcodePartialName() |
|
99 | + { |
|
100 | + return glsr(Helper::class)->dashCase($this->getShortcodeClassName()); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param array|string $args |
|
105 | + * @param string $type |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public function normalizeArgs($args, $type = 'shortcode') |
|
109 | + { |
|
110 | + $args = wp_parse_args($args, [ |
|
111 | + 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
112 | + 'after_widget' => '</div>', |
|
113 | + 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
114 | + 'after_title' => '</h3>', |
|
115 | + ]); |
|
116 | + return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param array|string $atts |
|
121 | + * @param string $type |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
125 | + { |
|
126 | + $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
127 | + $atts = $this->getDefaults($atts); |
|
128 | + array_walk($atts, function (&$value, $key) { |
|
129 | + $methodName = glsr(Helper::class)->buildMethodName($key, 'normalize'); |
|
130 | + if (!method_exists($this, $methodName)) { |
|
131 | + return; |
|
132 | + } |
|
133 | + $value = $this->$methodName($value); |
|
134 | + }); |
|
135 | + return $atts; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + abstract protected function hideOptions(); |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $postId |
|
145 | + * @return int|string |
|
146 | + */ |
|
147 | + protected function normalizeAssignedTo($postId) |
|
148 | + { |
|
149 | + if ('parent_id' == $postId) { |
|
150 | + $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
151 | + } elseif ('post_id' == $postId) { |
|
152 | + $postId = intval(get_the_ID()); |
|
153 | + } |
|
154 | + return $postId; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param string $postId |
|
159 | + * @return int|string |
|
160 | + */ |
|
161 | + protected function normalizeAssignTo($postId) |
|
162 | + { |
|
163 | + return $this->normalizeAssignedTo($postId); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string|array $hide |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + protected function normalizeHide($hide) |
|
171 | + { |
|
172 | + if (is_string($hide)) { |
|
173 | + $hide = explode(',', $hide); |
|
174 | + } |
|
175 | + $hideKeys = array_keys($this->getHideOptions()); |
|
176 | + return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
177 | + return in_array($value, $hideKeys); |
|
178 | + }); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $id |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + protected function normalizeId($id) |
|
186 | + { |
|
187 | + return sanitize_title($id); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $labels |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + protected function normalizeLabels($labels) |
|
195 | + { |
|
196 | + $defaults = [ |
|
197 | + __('Excellent', 'site-reviews'), |
|
198 | + __('Very good', 'site-reviews'), |
|
199 | + __('Average', 'site-reviews'), |
|
200 | + __('Poor', 'site-reviews'), |
|
201 | + __('Terrible', 'site-reviews'), |
|
202 | + ]; |
|
203 | + $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
204 | + $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
205 | + $labels = array_map('trim', explode(',', $labels)); |
|
206 | + foreach ($defaults as $i => $label) { |
|
207 | + if (empty($labels[$i])) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $defaults[$i] = $labels[$i]; |
|
211 | + } |
|
212 | + return array_combine(range($maxRating, 1), $defaults); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param string $schema |
|
217 | + * @return bool |
|
218 | + */ |
|
219 | + protected function normalizeSchema($schema) |
|
220 | + { |
|
221 | + return wp_validate_boolean($schema); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $text |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + protected function normalizeText($text) |
|
229 | + { |
|
230 | + return trim($text); |
|
231 | + } |
|
232 | 232 | } |
@@ -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 | } |
@@ -9,239 +9,239 @@ |
||
9 | 9 | |
10 | 10 | class Settings |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - public $settings; |
|
16 | - |
|
17 | - /** |
|
18 | - * @param string $id |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function buildFields($id) |
|
22 | - { |
|
23 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
24 | - $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor'); |
|
25 | - $data = !method_exists($this, $method) |
|
26 | - ? $this->getTemplateData($id) |
|
27 | - : $this->$method($id); |
|
28 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - protected function getFieldDefault(array $field) |
|
35 | - { |
|
36 | - return glsr_get($field, 'default'); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function getFieldNameForDependsOn($path) |
|
43 | - { |
|
44 | - $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey()); |
|
45 | - return $this->isMultiDependency($path) |
|
46 | - ? $fieldName.'[]' |
|
47 | - : $fieldName; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - protected function getSettingFields($path) |
|
54 | - { |
|
55 | - return array_filter($this->settings, function ($key) use ($path) { |
|
56 | - return glsr(Helper::class)->startsWith($path, $key); |
|
57 | - }, ARRAY_FILTER_USE_KEY); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - protected function getSettingRows(array $fields) |
|
64 | - { |
|
65 | - $rows = ''; |
|
66 | - foreach ($fields as $name => $field) { |
|
67 | - $field = wp_parse_args($field, [ |
|
68 | - 'is_setting' => true, |
|
69 | - 'name' => $name, |
|
70 | - ]); |
|
71 | - $rows.= new Field($this->normalize($field)); |
|
72 | - } |
|
73 | - return $rows; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $id |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - protected function getTemplateData($id) |
|
81 | - { |
|
82 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
83 | - return [ |
|
84 | - 'context' => [ |
|
85 | - 'rows' => $this->getSettingRows($fields), |
|
86 | - ], |
|
87 | - ]; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $id |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - protected function getTemplateDataForAddons($id) |
|
95 | - { |
|
96 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
97 | - $settings = glsr(Helper::class)->convertDotNotationArray($fields); |
|
98 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
99 | - $results = []; |
|
100 | - foreach ($settingKeys as $key) { |
|
101 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
102 | - return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path); |
|
103 | - }, ARRAY_FILTER_USE_KEY); |
|
104 | - $results[$key] = $this->getSettingRows($addonFields); |
|
105 | - } |
|
106 | - ksort($results); |
|
107 | - return [ |
|
108 | - 'settings' => $results, |
|
109 | - ]; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @param string $id |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - protected function getTemplateDataForLicenses($id) |
|
117 | - { |
|
118 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
119 | - ksort($fields); |
|
120 | - return [ |
|
121 | - 'context' => [ |
|
122 | - 'rows' => $this->getSettingRows($fields), |
|
123 | - ], |
|
124 | - ]; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - protected function getTemplateDataForTranslations() |
|
131 | - { |
|
132 | - $translations = glsr(Translation::class)->renderAll(); |
|
133 | - $class = empty($translations) |
|
134 | - ? 'glsr-hidden' |
|
135 | - : ''; |
|
136 | - return [ |
|
137 | - 'context' => [ |
|
138 | - 'class' => $class, |
|
139 | - 'database_key' => OptionManager::databaseKey(), |
|
140 | - 'translations' => $translations, |
|
141 | - ], |
|
142 | - ]; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string $path |
|
147 | - * @param string|array $expectedValue |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - protected function isFieldHidden($path, $expectedValue) |
|
151 | - { |
|
152 | - $optionValue = glsr(OptionManager::class)->get( |
|
153 | - $path, |
|
154 | - glsr(Helper::class)->dataGet(glsr()->defaults, $path) |
|
155 | - ); |
|
156 | - if (is_array($expectedValue)) { |
|
157 | - return is_array($optionValue) |
|
158 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
159 | - : !in_array($optionValue, $expectedValue); |
|
160 | - } |
|
161 | - return $optionValue != $expectedValue; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @return bool |
|
166 | - */ |
|
167 | - protected function isMultiDependency($path) |
|
168 | - { |
|
169 | - if (isset($this->settings[$path])) { |
|
170 | - $field = $this->settings[$path]; |
|
171 | - return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
172 | - || !empty($field['multiple']); |
|
173 | - } |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return array |
|
179 | - */ |
|
180 | - protected function normalize(array $field) |
|
181 | - { |
|
182 | - $field = $this->normalizeDependsOn($field); |
|
183 | - $field = $this->normalizeLabelAndLegend($field); |
|
184 | - $field = $this->normalizeValue($field); |
|
185 | - return $field; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function normalizeDependsOn(array $field) |
|
192 | - { |
|
193 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
194 | - $isFieldHidden = false; |
|
195 | - $conditions = []; |
|
196 | - foreach ($field['depends_on'] as $path => $value) { |
|
197 | - $conditions[] = [ |
|
198 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
199 | - 'value' => $value, |
|
200 | - ]; |
|
201 | - if ($this->isFieldHidden($path, $value)) { |
|
202 | - $isFieldHidden = true; |
|
203 | - } |
|
204 | - } |
|
205 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
206 | - $field['is_hidden'] = $isFieldHidden; |
|
207 | - } |
|
208 | - return $field; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - protected function normalizeLabelAndLegend(array $field) |
|
215 | - { |
|
216 | - if (!empty($field['label'])) { |
|
217 | - $field['legend'] = $field['label']; |
|
218 | - unset($field['label']); |
|
219 | - } else { |
|
220 | - $field['is_valid'] = false; |
|
221 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
222 | - } |
|
223 | - return $field; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - protected function normalizeValue(array $field) |
|
230 | - { |
|
231 | - if (!isset($field['value'])) { |
|
232 | - $field['value'] = glsr(OptionManager::class)->get( |
|
233 | - $field['name'], |
|
234 | - $this->getFieldDefault($field) |
|
235 | - ); |
|
236 | - } |
|
237 | - return $field; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - protected function normalizeSettingPath($path) |
|
244 | - { |
|
245 | - return glsr(Helper::class)->prefix('settings.', rtrim($path, '.')); |
|
246 | - } |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + public $settings; |
|
16 | + |
|
17 | + /** |
|
18 | + * @param string $id |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function buildFields($id) |
|
22 | + { |
|
23 | + $this->settings = glsr(DefaultsManager::class)->settings(); |
|
24 | + $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor'); |
|
25 | + $data = !method_exists($this, $method) |
|
26 | + ? $this->getTemplateData($id) |
|
27 | + : $this->$method($id); |
|
28 | + return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + protected function getFieldDefault(array $field) |
|
35 | + { |
|
36 | + return glsr_get($field, 'default'); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function getFieldNameForDependsOn($path) |
|
43 | + { |
|
44 | + $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey()); |
|
45 | + return $this->isMultiDependency($path) |
|
46 | + ? $fieldName.'[]' |
|
47 | + : $fieldName; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + protected function getSettingFields($path) |
|
54 | + { |
|
55 | + return array_filter($this->settings, function ($key) use ($path) { |
|
56 | + return glsr(Helper::class)->startsWith($path, $key); |
|
57 | + }, ARRAY_FILTER_USE_KEY); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + protected function getSettingRows(array $fields) |
|
64 | + { |
|
65 | + $rows = ''; |
|
66 | + foreach ($fields as $name => $field) { |
|
67 | + $field = wp_parse_args($field, [ |
|
68 | + 'is_setting' => true, |
|
69 | + 'name' => $name, |
|
70 | + ]); |
|
71 | + $rows.= new Field($this->normalize($field)); |
|
72 | + } |
|
73 | + return $rows; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $id |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + protected function getTemplateData($id) |
|
81 | + { |
|
82 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
83 | + return [ |
|
84 | + 'context' => [ |
|
85 | + 'rows' => $this->getSettingRows($fields), |
|
86 | + ], |
|
87 | + ]; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $id |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + protected function getTemplateDataForAddons($id) |
|
95 | + { |
|
96 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
97 | + $settings = glsr(Helper::class)->convertDotNotationArray($fields); |
|
98 | + $settingKeys = array_keys($settings['settings']['addons']); |
|
99 | + $results = []; |
|
100 | + foreach ($settingKeys as $key) { |
|
101 | + $addonFields = array_filter($fields, function ($path) use ($key) { |
|
102 | + return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path); |
|
103 | + }, ARRAY_FILTER_USE_KEY); |
|
104 | + $results[$key] = $this->getSettingRows($addonFields); |
|
105 | + } |
|
106 | + ksort($results); |
|
107 | + return [ |
|
108 | + 'settings' => $results, |
|
109 | + ]; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @param string $id |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + protected function getTemplateDataForLicenses($id) |
|
117 | + { |
|
118 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
119 | + ksort($fields); |
|
120 | + return [ |
|
121 | + 'context' => [ |
|
122 | + 'rows' => $this->getSettingRows($fields), |
|
123 | + ], |
|
124 | + ]; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + protected function getTemplateDataForTranslations() |
|
131 | + { |
|
132 | + $translations = glsr(Translation::class)->renderAll(); |
|
133 | + $class = empty($translations) |
|
134 | + ? 'glsr-hidden' |
|
135 | + : ''; |
|
136 | + return [ |
|
137 | + 'context' => [ |
|
138 | + 'class' => $class, |
|
139 | + 'database_key' => OptionManager::databaseKey(), |
|
140 | + 'translations' => $translations, |
|
141 | + ], |
|
142 | + ]; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string $path |
|
147 | + * @param string|array $expectedValue |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + protected function isFieldHidden($path, $expectedValue) |
|
151 | + { |
|
152 | + $optionValue = glsr(OptionManager::class)->get( |
|
153 | + $path, |
|
154 | + glsr(Helper::class)->dataGet(glsr()->defaults, $path) |
|
155 | + ); |
|
156 | + if (is_array($expectedValue)) { |
|
157 | + return is_array($optionValue) |
|
158 | + ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
159 | + : !in_array($optionValue, $expectedValue); |
|
160 | + } |
|
161 | + return $optionValue != $expectedValue; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @return bool |
|
166 | + */ |
|
167 | + protected function isMultiDependency($path) |
|
168 | + { |
|
169 | + if (isset($this->settings[$path])) { |
|
170 | + $field = $this->settings[$path]; |
|
171 | + return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
172 | + || !empty($field['multiple']); |
|
173 | + } |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return array |
|
179 | + */ |
|
180 | + protected function normalize(array $field) |
|
181 | + { |
|
182 | + $field = $this->normalizeDependsOn($field); |
|
183 | + $field = $this->normalizeLabelAndLegend($field); |
|
184 | + $field = $this->normalizeValue($field); |
|
185 | + return $field; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function normalizeDependsOn(array $field) |
|
192 | + { |
|
193 | + if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
194 | + $isFieldHidden = false; |
|
195 | + $conditions = []; |
|
196 | + foreach ($field['depends_on'] as $path => $value) { |
|
197 | + $conditions[] = [ |
|
198 | + 'name' => $this->getFieldNameForDependsOn($path), |
|
199 | + 'value' => $value, |
|
200 | + ]; |
|
201 | + if ($this->isFieldHidden($path, $value)) { |
|
202 | + $isFieldHidden = true; |
|
203 | + } |
|
204 | + } |
|
205 | + $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
206 | + $field['is_hidden'] = $isFieldHidden; |
|
207 | + } |
|
208 | + return $field; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + protected function normalizeLabelAndLegend(array $field) |
|
215 | + { |
|
216 | + if (!empty($field['label'])) { |
|
217 | + $field['legend'] = $field['label']; |
|
218 | + unset($field['label']); |
|
219 | + } else { |
|
220 | + $field['is_valid'] = false; |
|
221 | + glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
222 | + } |
|
223 | + return $field; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + protected function normalizeValue(array $field) |
|
230 | + { |
|
231 | + if (!isset($field['value'])) { |
|
232 | + $field['value'] = glsr(OptionManager::class)->get( |
|
233 | + $field['name'], |
|
234 | + $this->getFieldDefault($field) |
|
235 | + ); |
|
236 | + } |
|
237 | + return $field; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + protected function normalizeSettingPath($path) |
|
244 | + { |
|
245 | + return glsr(Helper::class)->prefix('settings.', rtrim($path, '.')); |
|
246 | + } |
|
247 | 247 | } |
@@ -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 | } |