@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->newSettings = $this->getNewSettings(); |
73 | 73 | $this->oldSettings = $this->getOldSettings(); |
74 | - if (empty($this->oldSettings)) { |
|
74 | + if( empty($this->oldSettings) ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
77 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
78 | + if( empty($this->oldSettings[$old]) ) { |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $this->migrateNotificationSettings(); |
84 | 84 | $this->migrateRecaptchaSettings(); |
85 | 85 | $this->migrateRequiredSettings(); |
86 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
86 | + $oldSettings = Arr::convertDotNotationArray( $this->oldSettings ); |
|
87 | + $newSettings = Arr::convertDotNotationArray( $this->newSettings ); |
|
88 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
89 | 89 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
90 | 90 | } |
91 | - glsr(OptionManager::class)->set($newSettings); |
|
91 | + glsr( OptionManager::class )->set( $newSettings ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | protected function getNewSettings() |
98 | 98 | { |
99 | 99 | return wp_parse_args( |
100 | - Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
100 | + Arr::flattenArray( glsr( OptionManager::class )->all() ), |
|
101 | + glsr( DefaultsManager::class )->defaults() |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getOldSettings() |
109 | 109 | { |
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
110 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
111 | + $settings = Arr::flattenArray( (array)get_option( 'geminilabs_site_reviews-v2', [] ) ); |
|
112 | + if( !empty($settings) ) { |
|
113 | + $settings = wp_parse_args( $settings, $defaults ); |
|
114 | 114 | } |
115 | 115 | return $settings; |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | 'webhook' => 'slack', |
127 | 127 | ]; |
128 | 128 | $this->newSettings['settings.general.notifications'] = []; |
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
129 | + foreach( $notifications as $old => $new ) { |
|
130 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
145 | 145 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
146 | 146 | ]; |
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
148 | 148 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
149 | 149 | } |
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
150 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
151 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
152 | 152 | } |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
154 | 154 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function migrateRequiredSettings() |
162 | 162 | { |
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
165 | 165 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
166 | 166 | } |
@@ -8,163 +8,163 @@ |
||
8 | 8 | |
9 | 9 | class Upgrade_3_0_0 |
10 | 10 | { |
11 | - const MAPPED_SETTINGS = [ |
|
12 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | - 'version' => 'version_upgraded_from', |
|
50 | - ]; |
|
11 | + const MAPPED_SETTINGS = [ |
|
12 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | + 'version' => 'version_upgraded_from', |
|
50 | + ]; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $newSettings; |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $newSettings; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $oldSettings; |
|
57 | + /** |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $oldSettings; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function migrateSettings() |
|
66 | - { |
|
67 | - $this->newSettings = $this->getNewSettings(); |
|
68 | - $this->oldSettings = $this->getOldSettings(); |
|
69 | - if (empty($this->oldSettings)) { |
|
70 | - return; |
|
71 | - } |
|
72 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
73 | - if (empty($this->oldSettings[$old])) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
77 | - } |
|
78 | - $this->migrateNotificationSettings(); |
|
79 | - $this->migrateRecaptchaSettings(); |
|
80 | - $this->migrateRequiredSettings(); |
|
81 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
82 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
83 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
84 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
85 | - } |
|
86 | - glsr(OptionManager::class)->set($newSettings); |
|
87 | - } |
|
62 | + /** |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function migrateSettings() |
|
66 | + { |
|
67 | + $this->newSettings = $this->getNewSettings(); |
|
68 | + $this->oldSettings = $this->getOldSettings(); |
|
69 | + if (empty($this->oldSettings)) { |
|
70 | + return; |
|
71 | + } |
|
72 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
73 | + if (empty($this->oldSettings[$old])) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
77 | + } |
|
78 | + $this->migrateNotificationSettings(); |
|
79 | + $this->migrateRecaptchaSettings(); |
|
80 | + $this->migrateRequiredSettings(); |
|
81 | + $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
82 | + $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
83 | + if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
84 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
85 | + } |
|
86 | + glsr(OptionManager::class)->set($newSettings); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function run() |
|
93 | - { |
|
94 | - $this->migrateSettings(); |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function run() |
|
93 | + { |
|
94 | + $this->migrateSettings(); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - protected function getNewSettings() |
|
101 | - { |
|
102 | - return wp_parse_args( |
|
103 | - Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
104 | - glsr(DefaultsManager::class)->defaults() |
|
105 | - ); |
|
106 | - } |
|
97 | + /** |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + protected function getNewSettings() |
|
101 | + { |
|
102 | + return wp_parse_args( |
|
103 | + Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
104 | + glsr(DefaultsManager::class)->defaults() |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - protected function getOldSettings() |
|
112 | - { |
|
113 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
114 | - $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
115 | - if (!empty($settings)) { |
|
116 | - $settings = wp_parse_args($settings, $defaults); |
|
117 | - } |
|
118 | - return $settings; |
|
119 | - } |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + protected function getOldSettings() |
|
112 | + { |
|
113 | + $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
114 | + $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
115 | + if (!empty($settings)) { |
|
116 | + $settings = wp_parse_args($settings, $defaults); |
|
117 | + } |
|
118 | + return $settings; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - protected function migrateNotificationSettings() |
|
125 | - { |
|
126 | - $notifications = [ |
|
127 | - 'custom' => 'custom', |
|
128 | - 'default' => 'admin', |
|
129 | - 'webhook' => 'slack', |
|
130 | - ]; |
|
131 | - $this->newSettings['settings.general.notifications'] = []; |
|
132 | - foreach ($notifications as $old => $new) { |
|
133 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
134 | - continue; |
|
135 | - } |
|
136 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
137 | - } |
|
138 | - } |
|
121 | + /** |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + protected function migrateNotificationSettings() |
|
125 | + { |
|
126 | + $notifications = [ |
|
127 | + 'custom' => 'custom', |
|
128 | + 'default' => 'admin', |
|
129 | + 'webhook' => 'slack', |
|
130 | + ]; |
|
131 | + $this->newSettings['settings.general.notifications'] = []; |
|
132 | + foreach ($notifications as $old => $new) { |
|
133 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
134 | + continue; |
|
135 | + } |
|
136 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function migrateRecaptchaSettings() |
|
144 | - { |
|
145 | - $recaptcha = [ |
|
146 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
147 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
148 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
149 | - ]; |
|
150 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
151 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
152 | - } |
|
153 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
154 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
155 | - } |
|
156 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
157 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
158 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
159 | - } |
|
140 | + /** |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function migrateRecaptchaSettings() |
|
144 | + { |
|
145 | + $recaptcha = [ |
|
146 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
147 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
148 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
149 | + ]; |
|
150 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
151 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
152 | + } |
|
153 | + if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
154 | + $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
155 | + } |
|
156 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
157 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
158 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - protected function migrateRequiredSettings() |
|
165 | - { |
|
166 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
167 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
168 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
169 | - } |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + protected function migrateRequiredSettings() |
|
165 | + { |
|
166 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
167 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
168 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
169 | + } |
|
170 | 170 | } |
@@ -12,144 +12,144 @@ |
||
12 | 12 | |
13 | 13 | class Style |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $fields; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $fields; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $style; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $style; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - public $pagination; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + public $pagination; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $validation; |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $validation; |
|
34 | 34 | |
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | - $this->setConfig(); |
|
39 | - } |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | + $this->setConfig(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $view |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function filterView($view) |
|
46 | - { |
|
47 | - $styledViews = [ |
|
48 | - 'templates/form/field', |
|
49 | - 'templates/form/response', |
|
50 | - 'templates/form/submit-button', |
|
51 | - 'templates/reviews-form', |
|
52 | - ]; |
|
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | - return $view; |
|
55 | - } |
|
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
59 | - continue; |
|
60 | - } |
|
61 | - return Str::removePrefix('views/', $possibleView); |
|
62 | - } |
|
63 | - return $view; |
|
64 | - } |
|
41 | + /** |
|
42 | + * @param string $view |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function filterView($view) |
|
46 | + { |
|
47 | + $styledViews = [ |
|
48 | + 'templates/form/field', |
|
49 | + 'templates/form/response', |
|
50 | + 'templates/form/submit-button', |
|
51 | + 'templates/reviews-form', |
|
52 | + ]; |
|
53 | + if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | + return $view; |
|
55 | + } |
|
56 | + $views = $this->generatePossibleViews($view); |
|
57 | + foreach ($views as $possibleView) { |
|
58 | + if (!file_exists(glsr()->file($possibleView))) { |
|
59 | + continue; |
|
60 | + } |
|
61 | + return Str::removePrefix('views/', $possibleView); |
|
62 | + } |
|
63 | + return $view; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function get() |
|
70 | - { |
|
71 | - return apply_filters('site-reviews/style', $this->style); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function get() |
|
70 | + { |
|
71 | + return apply_filters('site-reviews/style', $this->style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public function setConfig() |
|
78 | - { |
|
79 | - $config = shortcode_atts( |
|
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
82 | - ); |
|
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | - } |
|
74 | + /** |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public function setConfig() |
|
78 | + { |
|
79 | + $config = shortcode_atts( |
|
80 | + array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | + glsr()->config('styles/'.$this->style) |
|
82 | + ); |
|
83 | + $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | + $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | + $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function modifyField(Builder $instance) |
|
92 | - { |
|
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | - return; |
|
95 | - } |
|
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function modifyField(Builder $instance) |
|
92 | + { |
|
93 | + if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | + return; |
|
95 | + } |
|
96 | + call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function paginationArgs(array $args) |
|
103 | - { |
|
104 | - return wp_parse_args($args, $this->pagination); |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function paginationArgs(array $args) |
|
103 | + { |
|
104 | + return wp_parse_args($args, $this->pagination); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - protected function customize(Builder $instance) |
|
111 | - { |
|
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | - $key = $instance->tag.'_'.$args['type']; |
|
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | - } |
|
107 | + /** |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + protected function customize(Builder $instance) |
|
111 | + { |
|
112 | + if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | + $key = $instance->tag.'_'.$args['type']; |
|
117 | + $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | + $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | + do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @param string $view |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - protected function generatePossibleViews($view) |
|
127 | - { |
|
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
130 | - $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | - $parts = explode('_', $basename); |
|
132 | - $views = [ |
|
133 | - $customPath.$basename, |
|
134 | - $customPath.$parts[0], |
|
135 | - $view, |
|
136 | - $basepath.$parts[0], |
|
137 | - ]; |
|
138 | - return array_filter($views); |
|
139 | - } |
|
122 | + /** |
|
123 | + * @param string $view |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + protected function generatePossibleViews($view) |
|
127 | + { |
|
128 | + $basename = basename($view); |
|
129 | + $basepath = rtrim($view, $basename); |
|
130 | + $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | + $parts = explode('_', $basename); |
|
132 | + $views = [ |
|
133 | + $customPath.$basename, |
|
134 | + $customPath.$parts[0], |
|
135 | + $view, |
|
136 | + $basepath.$parts[0], |
|
137 | + ]; |
|
138 | + return array_filter($views); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - protected function isPublicInstance(Builder $instance) |
|
145 | - { |
|
146 | - $args = wp_parse_args($instance->args, [ |
|
147 | - 'is_public' => false, |
|
148 | - 'is_raw' => false, |
|
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | - return false; |
|
152 | - } |
|
153 | - return true; |
|
154 | - } |
|
141 | + /** |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + protected function isPublicInstance(Builder $instance) |
|
145 | + { |
|
146 | + $args = wp_parse_args($instance->args, [ |
|
147 | + 'is_public' => false, |
|
148 | + 'is_raw' => false, |
|
149 | + ]); |
|
150 | + if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | + return false; |
|
152 | + } |
|
153 | + return true; |
|
154 | + } |
|
155 | 155 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct() |
36 | 36 | { |
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
37 | + $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' ); |
|
38 | 38 | $this->setConfig(); |
39 | 39 | } |
40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $view |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function filterView($view) |
|
45 | + public function filterView( $view ) |
|
46 | 46 | { |
47 | 47 | $styledViews = [ |
48 | 48 | 'templates/form/field', |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | 'templates/form/submit-button', |
51 | 51 | 'templates/reviews-form', |
52 | 52 | ]; |
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
54 | 54 | return $view; |
55 | 55 | } |
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
56 | + $views = $this->generatePossibleViews( $view ); |
|
57 | + foreach( $views as $possibleView ) { |
|
58 | + if( !file_exists( glsr()->file( $possibleView ) ) ) { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | - return Str::removePrefix('views/', $possibleView); |
|
61 | + return Str::removePrefix( 'views/', $possibleView ); |
|
62 | 62 | } |
63 | 63 | return $view; |
64 | 64 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function get() |
70 | 70 | { |
71 | - return apply_filters('site-reviews/style', $this->style); |
|
71 | + return apply_filters( 'site-reviews/style', $this->style ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,77 +77,77 @@ discard block |
||
77 | 77 | public function setConfig() |
78 | 78 | { |
79 | 79 | $config = shortcode_atts( |
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
80 | + array_fill_keys( ['fields', 'pagination', 'validation'], [] ), |
|
81 | + glsr()->config( 'styles/'.$this->style ) |
|
82 | 82 | ); |
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
83 | + $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] ); |
|
84 | + $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] ); |
|
85 | + $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function modifyField(Builder $instance) |
|
91 | + public function modifyField( Builder $instance ) |
|
92 | 92 | { |
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
93 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
96 | + call_user_func_array( [$this, 'customize'], [$instance] ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - public function paginationArgs(array $args) |
|
102 | + public function paginationArgs( array $args ) |
|
103 | 103 | { |
104 | - return wp_parse_args($args, $this->pagination); |
|
104 | + return wp_parse_args( $args, $this->pagination ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - protected function customize(Builder $instance) |
|
110 | + protected function customize( Builder $instance ) |
|
111 | 111 | { |
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
112 | + if( !array_key_exists( $instance->tag, $this->fields ) ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
115 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
116 | 116 | $key = $instance->tag.'_'.$args['type']; |
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
117 | + $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) ); |
|
118 | + $instance->args['class'] = trim( $args['class'].' '.$classes ); |
|
119 | + do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string $view |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - protected function generatePossibleViews($view) |
|
126 | + protected function generatePossibleViews( $view ) |
|
127 | 127 | { |
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
128 | + $basename = basename( $view ); |
|
129 | + $basepath = rtrim( $view, $basename ); |
|
130 | 130 | $customPath = 'views/partials/styles/'.$this->style.'/'; |
131 | - $parts = explode('_', $basename); |
|
131 | + $parts = explode( '_', $basename ); |
|
132 | 132 | $views = [ |
133 | 133 | $customPath.$basename, |
134 | 134 | $customPath.$parts[0], |
135 | 135 | $view, |
136 | 136 | $basepath.$parts[0], |
137 | 137 | ]; |
138 | - return array_filter($views); |
|
138 | + return array_filter( $views ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - protected function isPublicInstance(Builder $instance) |
|
144 | + protected function isPublicInstance( Builder $instance ) |
|
145 | 145 | { |
146 | - $args = wp_parse_args($instance->args, [ |
|
146 | + $args = wp_parse_args( $instance->args, [ |
|
147 | 147 | 'is_public' => false, |
148 | 148 | 'is_raw' => false, |
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
149 | + ] ); |
|
150 | + if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | return true; |
@@ -12,173 +12,173 @@ |
||
12 | 12 | |
13 | 13 | class Review implements \ArrayAccess |
14 | 14 | { |
15 | - public $assigned_to; |
|
16 | - public $author; |
|
17 | - public $avatar; |
|
18 | - public $content; |
|
19 | - public $custom; |
|
20 | - public $date; |
|
21 | - public $email; |
|
22 | - public $ID; |
|
23 | - public $ip_address; |
|
24 | - public $modified; |
|
25 | - public $pinned; |
|
26 | - public $rating; |
|
27 | - public $response; |
|
28 | - public $review_id; |
|
29 | - public $review_type; |
|
30 | - public $status; |
|
31 | - public $term_ids; |
|
32 | - public $title; |
|
33 | - public $url; |
|
34 | - public $user_id; |
|
15 | + public $assigned_to; |
|
16 | + public $author; |
|
17 | + public $avatar; |
|
18 | + public $content; |
|
19 | + public $custom; |
|
20 | + public $date; |
|
21 | + public $email; |
|
22 | + public $ID; |
|
23 | + public $ip_address; |
|
24 | + public $modified; |
|
25 | + public $pinned; |
|
26 | + public $rating; |
|
27 | + public $response; |
|
28 | + public $review_id; |
|
29 | + public $review_type; |
|
30 | + public $status; |
|
31 | + public $term_ids; |
|
32 | + public $title; |
|
33 | + public $url; |
|
34 | + public $user_id; |
|
35 | 35 | |
36 | - public function __construct(WP_Post $post) |
|
37 | - { |
|
38 | - if (Application::POST_TYPE != $post->post_type) { |
|
39 | - return; |
|
40 | - } |
|
41 | - $this->content = $post->post_content; |
|
42 | - $this->date = $post->post_date; |
|
43 | - $this->ID = intval($post->ID); |
|
44 | - $this->status = $post->post_status; |
|
45 | - $this->title = $post->post_title; |
|
46 | - $this->user_id = intval($post->post_author); |
|
47 | - $this->setProperties($post); |
|
48 | - $this->setTermIds($post); |
|
49 | - } |
|
36 | + public function __construct(WP_Post $post) |
|
37 | + { |
|
38 | + if (Application::POST_TYPE != $post->post_type) { |
|
39 | + return; |
|
40 | + } |
|
41 | + $this->content = $post->post_content; |
|
42 | + $this->date = $post->post_date; |
|
43 | + $this->ID = intval($post->ID); |
|
44 | + $this->status = $post->post_status; |
|
45 | + $this->title = $post->post_title; |
|
46 | + $this->user_id = intval($post->post_author); |
|
47 | + $this->setProperties($post); |
|
48 | + $this->setTermIds($post); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return mixed |
|
53 | - */ |
|
54 | - public function __get($key) |
|
55 | - { |
|
56 | - return $this->offsetGet($key); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return mixed |
|
53 | + */ |
|
54 | + public function __get($key) |
|
55 | + { |
|
56 | + return $this->offsetGet($key); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function __toString() |
|
63 | - { |
|
64 | - return (string) $this->build(); |
|
65 | - } |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function __toString() |
|
63 | + { |
|
64 | + return (string) $this->build(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return ReviewHtml |
|
69 | - */ |
|
70 | - public function build(array $args = []) |
|
71 | - { |
|
72 | - if (empty($this->ID)) { |
|
73 | - return new ReviewHtml($this); |
|
74 | - } |
|
75 | - $partial = glsr(SiteReviewsPartial::class); |
|
76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | - return $partial->buildReview($this); |
|
79 | - } |
|
67 | + /** |
|
68 | + * @return ReviewHtml |
|
69 | + */ |
|
70 | + public function build(array $args = []) |
|
71 | + { |
|
72 | + if (empty($this->ID)) { |
|
73 | + return new ReviewHtml($this); |
|
74 | + } |
|
75 | + $partial = glsr(SiteReviewsPartial::class); |
|
76 | + $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | + $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | + return $partial->buildReview($this); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function offsetExists($key) |
|
86 | - { |
|
87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
88 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function offsetExists($key) |
|
86 | + { |
|
87 | + return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param mixed $key |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - public function offsetGet($key) |
|
95 | - { |
|
96 | - return property_exists($this, $key) |
|
97 | - ? $this->$key |
|
98 | - : Arr::get($this->custom, $key, null); |
|
99 | - } |
|
90 | + /** |
|
91 | + * @param mixed $key |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + public function offsetGet($key) |
|
95 | + { |
|
96 | + return property_exists($this, $key) |
|
97 | + ? $this->$key |
|
98 | + : Arr::get($this->custom, $key, null); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param mixed $key |
|
103 | - * @param mixed $value |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function offsetSet($key, $value) |
|
107 | - { |
|
108 | - if (property_exists($this, $key)) { |
|
109 | - $this->$key = $value; |
|
110 | - return; |
|
111 | - } |
|
112 | - if (!is_array($this->custom)) { |
|
113 | - $this->custom = array_filter((array) $this->custom); |
|
114 | - } |
|
115 | - $this->custom[$key] = $value; |
|
116 | - } |
|
101 | + /** |
|
102 | + * @param mixed $key |
|
103 | + * @param mixed $value |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function offsetSet($key, $value) |
|
107 | + { |
|
108 | + if (property_exists($this, $key)) { |
|
109 | + $this->$key = $value; |
|
110 | + return; |
|
111 | + } |
|
112 | + if (!is_array($this->custom)) { |
|
113 | + $this->custom = array_filter((array) $this->custom); |
|
114 | + } |
|
115 | + $this->custom[$key] = $value; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @param mixed $key |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function offsetUnset($key) |
|
123 | - { |
|
124 | - $this->offsetSet($key, null); |
|
125 | - } |
|
118 | + /** |
|
119 | + * @param mixed $key |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function offsetUnset($key) |
|
123 | + { |
|
124 | + $this->offsetSet($key, null); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public function render() |
|
131 | - { |
|
132 | - echo $this->build(); |
|
133 | - } |
|
127 | + /** |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function render() |
|
131 | + { |
|
132 | + echo $this->build(); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - protected function isModified(array $properties) |
|
139 | - { |
|
140 | - return $this->date != $properties['date'] |
|
141 | - || $this->content != $properties['content'] |
|
142 | - || $this->title != $properties['title']; |
|
143 | - } |
|
135 | + /** |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + protected function isModified(array $properties) |
|
139 | + { |
|
140 | + return $this->date != $properties['date'] |
|
141 | + || $this->content != $properties['content'] |
|
142 | + || $this->title != $properties['title']; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - protected function setProperties(WP_Post $post) |
|
149 | - { |
|
150 | - $defaults = [ |
|
151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
152 | - 'date' => '', |
|
153 | - 'review_id' => '', |
|
154 | - 'review_type' => 'local', |
|
155 | - ]; |
|
156 | - $meta = array_filter( |
|
157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
158 | - 'strlen' |
|
159 | - ); |
|
160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | - $this->modified = $this->isModified($properties); |
|
163 | - array_walk($properties, function ($value, $key) { |
|
164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
165 | - return; |
|
166 | - } |
|
167 | - $this->$key = maybe_unserialize($value); |
|
168 | - }); |
|
169 | - } |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + protected function setProperties(WP_Post $post) |
|
149 | + { |
|
150 | + $defaults = [ |
|
151 | + 'author' => __('Anonymous', 'site-reviews'), |
|
152 | + 'date' => '', |
|
153 | + 'review_id' => '', |
|
154 | + 'review_type' => 'local', |
|
155 | + ]; |
|
156 | + $meta = array_filter( |
|
157 | + array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
158 | + 'strlen' |
|
159 | + ); |
|
160 | + $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | + $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | + $this->modified = $this->isModified($properties); |
|
163 | + array_walk($properties, function ($value, $key) { |
|
164 | + if (!property_exists($this, $key) || isset($this->$key)) { |
|
165 | + return; |
|
166 | + } |
|
167 | + $this->$key = maybe_unserialize($value); |
|
168 | + }); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - protected function setTermIds(WP_Post $post) |
|
175 | - { |
|
176 | - $this->term_ids = []; |
|
177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
178 | - return; |
|
179 | - } |
|
180 | - foreach ($terms as $term) { |
|
181 | - $this->term_ids[] = $term->term_id; |
|
182 | - } |
|
183 | - } |
|
171 | + /** |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + protected function setTermIds(WP_Post $post) |
|
175 | + { |
|
176 | + $this->term_ids = []; |
|
177 | + if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
178 | + return; |
|
179 | + } |
|
180 | + foreach ($terms as $term) { |
|
181 | + $this->term_ids[] = $term->term_id; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | } |
@@ -33,27 +33,27 @@ discard block |
||
33 | 33 | public $url; |
34 | 34 | public $user_id; |
35 | 35 | |
36 | - public function __construct(WP_Post $post) |
|
36 | + public function __construct( WP_Post $post ) |
|
37 | 37 | { |
38 | - if (Application::POST_TYPE != $post->post_type) { |
|
38 | + if( Application::POST_TYPE != $post->post_type ) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | $this->content = $post->post_content; |
42 | 42 | $this->date = $post->post_date; |
43 | - $this->ID = intval($post->ID); |
|
43 | + $this->ID = intval( $post->ID ); |
|
44 | 44 | $this->status = $post->post_status; |
45 | 45 | $this->title = $post->post_title; |
46 | - $this->user_id = intval($post->post_author); |
|
47 | - $this->setProperties($post); |
|
48 | - $this->setTermIds($post); |
|
46 | + $this->user_id = intval( $post->post_author ); |
|
47 | + $this->setProperties( $post ); |
|
48 | + $this->setTermIds( $post ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - public function __get($key) |
|
54 | + public function __get( $key ) |
|
55 | 55 | { |
56 | - return $this->offsetGet($key); |
|
56 | + return $this->offsetGet( $key ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -61,41 +61,41 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function __toString() |
63 | 63 | { |
64 | - return (string) $this->build(); |
|
64 | + return (string)$this->build(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @return ReviewHtml |
69 | 69 | */ |
70 | - public function build(array $args = []) |
|
70 | + public function build( array $args = [] ) |
|
71 | 71 | { |
72 | - if (empty($this->ID)) { |
|
73 | - return new ReviewHtml($this); |
|
72 | + if( empty($this->ID) ) { |
|
73 | + return new ReviewHtml( $this ); |
|
74 | 74 | } |
75 | - $partial = glsr(SiteReviewsPartial::class); |
|
76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | - return $partial->buildReview($this); |
|
75 | + $partial = glsr( SiteReviewsPartial::class ); |
|
76 | + $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
77 | + $partial->options = Arr::flattenArray( glsr( OptionManager::class )->all() ); |
|
78 | + return $partial->buildReview( $this ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - public function offsetExists($key) |
|
85 | + public function offsetExists( $key ) |
|
86 | 86 | { |
87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
87 | + return property_exists( $this, $key ) || array_key_exists( $key, (array)$this->custom ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @param mixed $key |
92 | 92 | * @return mixed |
93 | 93 | */ |
94 | - public function offsetGet($key) |
|
94 | + public function offsetGet( $key ) |
|
95 | 95 | { |
96 | - return property_exists($this, $key) |
|
96 | + return property_exists( $this, $key ) |
|
97 | 97 | ? $this->$key |
98 | - : Arr::get($this->custom, $key, null); |
|
98 | + : Arr::get( $this->custom, $key, null ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * @param mixed $value |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function offsetSet($key, $value) |
|
106 | + public function offsetSet( $key, $value ) |
|
107 | 107 | { |
108 | - if (property_exists($this, $key)) { |
|
108 | + if( property_exists( $this, $key ) ) { |
|
109 | 109 | $this->$key = $value; |
110 | 110 | return; |
111 | 111 | } |
112 | - if (!is_array($this->custom)) { |
|
113 | - $this->custom = array_filter((array) $this->custom); |
|
112 | + if( !is_array( $this->custom ) ) { |
|
113 | + $this->custom = array_filter( (array)$this->custom ); |
|
114 | 114 | } |
115 | 115 | $this->custom[$key] = $value; |
116 | 116 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @param mixed $key |
120 | 120 | * @return void |
121 | 121 | */ |
122 | - public function offsetUnset($key) |
|
122 | + public function offsetUnset( $key ) |
|
123 | 123 | { |
124 | - $this->offsetSet($key, null); |
|
124 | + $this->offsetSet( $key, null ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @return bool |
137 | 137 | */ |
138 | - protected function isModified(array $properties) |
|
138 | + protected function isModified( array $properties ) |
|
139 | 139 | { |
140 | 140 | return $this->date != $properties['date'] |
141 | 141 | || $this->content != $properties['content'] |
@@ -145,39 +145,39 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @return void |
147 | 147 | */ |
148 | - protected function setProperties(WP_Post $post) |
|
148 | + protected function setProperties( WP_Post $post ) |
|
149 | 149 | { |
150 | 150 | $defaults = [ |
151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
151 | + 'author' => __( 'Anonymous', 'site-reviews' ), |
|
152 | 152 | 'date' => '', |
153 | 153 | 'review_id' => '', |
154 | 154 | 'review_type' => 'local', |
155 | 155 | ]; |
156 | 156 | $meta = array_filter( |
157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
157 | + array_map( 'array_shift', array_filter( (array)get_post_meta( $post->ID ) ) ), |
|
158 | 158 | 'strlen' |
159 | 159 | ); |
160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | - $this->modified = $this->isModified($properties); |
|
163 | - array_walk($properties, function ($value, $key) { |
|
164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
160 | + $meta = array_merge( $defaults, Arr::unprefixArrayKeys( $meta ) ); |
|
161 | + $properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta ) ); |
|
162 | + $this->modified = $this->isModified( $properties ); |
|
163 | + array_walk( $properties, function( $value, $key ) { |
|
164 | + if( !property_exists( $this, $key ) || isset($this->$key) ) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | - $this->$key = maybe_unserialize($value); |
|
167 | + $this->$key = maybe_unserialize( $value ); |
|
168 | 168 | }); |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | 172 | * @return void |
173 | 173 | */ |
174 | - protected function setTermIds(WP_Post $post) |
|
174 | + protected function setTermIds( WP_Post $post ) |
|
175 | 175 | { |
176 | 176 | $this->term_ids = []; |
177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
177 | + if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY ) ) ) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - foreach ($terms as $term) { |
|
180 | + foreach( $terms as $term ) { |
|
181 | 181 | $this->term_ids[] = $term->term_id; |
182 | 182 | } |
183 | 183 | } |
@@ -9,205 +9,205 @@ |
||
9 | 9 | |
10 | 10 | class Email |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - public $attachments; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - public $email; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $headers; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $message; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $subject; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string|array |
|
39 | - */ |
|
40 | - public $to; |
|
41 | - |
|
42 | - /** |
|
43 | - * @return Email |
|
44 | - */ |
|
45 | - public function compose(array $email) |
|
46 | - { |
|
47 | - $this->normalize($email); |
|
48 | - $this->attachments = $this->email['attachments']; |
|
49 | - $this->headers = $this->buildHeaders(); |
|
50 | - $this->message = $this->buildHtmlMessage(); |
|
51 | - $this->subject = $this->email['subject']; |
|
52 | - $this->to = $this->email['to']; |
|
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
54 | - return $this; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $format |
|
59 | - * @return string|null |
|
60 | - */ |
|
61 | - public function read($format = '') |
|
62 | - { |
|
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
66 | - } |
|
67 | - return $this->message; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return void|bool |
|
72 | - */ |
|
73 | - public function send() |
|
74 | - { |
|
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
76 | - return; |
|
77 | - } |
|
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
79 | - $sent = wp_mail( |
|
80 | - $this->to, |
|
81 | - $this->subject, |
|
82 | - $this->message, |
|
83 | - $this->headers, |
|
84 | - $this->attachments |
|
85 | - ); |
|
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
87 | - $this->reset(); |
|
88 | - return $sent; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return void |
|
93 | - * @action phpmailer_init |
|
94 | - */ |
|
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
96 | - { |
|
97 | - if (empty($this->email)) { |
|
98 | - return; |
|
99 | - } |
|
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - protected function buildHeaders() |
|
111 | - { |
|
112 | - $allowed = [ |
|
113 | - 'bcc', 'cc', 'from', 'reply-to', |
|
114 | - ]; |
|
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
118 | - unset($headers[$key]); |
|
119 | - $headers[] = $key.': '.$value; |
|
120 | - } |
|
121 | - $headers[] = 'Content-Type: text/html'; |
|
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function buildHtmlMessage() |
|
129 | - { |
|
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate( |
|
133 | - $template, |
|
134 | - ['context' => $this->email['template-tags']], |
|
135 | - $this->email['template'] |
|
136 | - ); |
|
137 | - } elseif ($this->email['template']) { |
|
138 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
139 | - 'context' => $this->email['template-tags'], |
|
140 | - ]); |
|
141 | - } |
|
142 | - if (!isset($message)) { |
|
143 | - $message = $this->email['message']; |
|
144 | - } |
|
145 | - $message = $this->email['before'].$message.$this->email['after']; |
|
146 | - $message = strip_shortcodes($message); |
|
147 | - $message = wptexturize($message); |
|
148 | - $message = wpautop($message); |
|
149 | - $message = str_replace('<> ', '', $message); |
|
150 | - $message = str_replace(']]>', ']]>', $message); |
|
151 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
152 | - 'context' => ['message' => $message], |
|
153 | - ]); |
|
154 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param \WP_Error $error |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - protected function logMailError($error) |
|
162 | - { |
|
163 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
164 | - ->debug($this) |
|
165 | - ->debug($error); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - protected function normalize(array $email = []) |
|
172 | - { |
|
173 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
174 | - if (empty($email['reply-to'])) { |
|
175 | - $email['reply-to'] = $email['from']; |
|
176 | - } |
|
177 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - protected function reset() |
|
184 | - { |
|
185 | - $this->attachments = []; |
|
186 | - $this->email = []; |
|
187 | - $this->headers = []; |
|
188 | - $this->message = null; |
|
189 | - $this->subject = null; |
|
190 | - $this->to = null; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - protected function stripHtmlTags($string) |
|
197 | - { |
|
198 | - // remove invisible elements |
|
199 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
200 | - // replace certain elements with a line-break |
|
201 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
202 | - // replace other elements with a space |
|
203 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
204 | - // add a placeholder for plain-text bullets to list elements |
|
205 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
206 | - // strip all remaining HTML tags |
|
207 | - $string = wp_strip_all_tags($string); |
|
208 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
209 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
210 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
211 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
212 | - } |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + public $attachments; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + public $email; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $headers; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $message; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $subject; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string|array |
|
39 | + */ |
|
40 | + public $to; |
|
41 | + |
|
42 | + /** |
|
43 | + * @return Email |
|
44 | + */ |
|
45 | + public function compose(array $email) |
|
46 | + { |
|
47 | + $this->normalize($email); |
|
48 | + $this->attachments = $this->email['attachments']; |
|
49 | + $this->headers = $this->buildHeaders(); |
|
50 | + $this->message = $this->buildHtmlMessage(); |
|
51 | + $this->subject = $this->email['subject']; |
|
52 | + $this->to = $this->email['to']; |
|
53 | + add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
54 | + return $this; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $format |
|
59 | + * @return string|null |
|
60 | + */ |
|
61 | + public function read($format = '') |
|
62 | + { |
|
63 | + if ('plaintext' == $format) { |
|
64 | + $message = $this->stripHtmlTags($this->message); |
|
65 | + return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
66 | + } |
|
67 | + return $this->message; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return void|bool |
|
72 | + */ |
|
73 | + public function send() |
|
74 | + { |
|
75 | + if (!$this->message || !$this->subject || !$this->to) { |
|
76 | + return; |
|
77 | + } |
|
78 | + add_action('wp_mail_failed', [$this, 'logMailError']); |
|
79 | + $sent = wp_mail( |
|
80 | + $this->to, |
|
81 | + $this->subject, |
|
82 | + $this->message, |
|
83 | + $this->headers, |
|
84 | + $this->attachments |
|
85 | + ); |
|
86 | + remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
87 | + $this->reset(); |
|
88 | + return $sent; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @action phpmailer_init |
|
94 | + */ |
|
95 | + public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
96 | + { |
|
97 | + if (empty($this->email)) { |
|
98 | + return; |
|
99 | + } |
|
100 | + if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | + $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + protected function buildHeaders() |
|
111 | + { |
|
112 | + $allowed = [ |
|
113 | + 'bcc', 'cc', 'from', 'reply-to', |
|
114 | + ]; |
|
115 | + $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | + $headers = array_filter($headers); |
|
117 | + foreach ($headers as $key => $value) { |
|
118 | + unset($headers[$key]); |
|
119 | + $headers[] = $key.': '.$value; |
|
120 | + } |
|
121 | + $headers[] = 'Content-Type: text/html'; |
|
122 | + return apply_filters('site-reviews/email/headers', $headers, $this); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function buildHtmlMessage() |
|
129 | + { |
|
130 | + $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | + if (!empty($template)) { |
|
132 | + $message = glsr(Template::class)->interpolate( |
|
133 | + $template, |
|
134 | + ['context' => $this->email['template-tags']], |
|
135 | + $this->email['template'] |
|
136 | + ); |
|
137 | + } elseif ($this->email['template']) { |
|
138 | + $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
139 | + 'context' => $this->email['template-tags'], |
|
140 | + ]); |
|
141 | + } |
|
142 | + if (!isset($message)) { |
|
143 | + $message = $this->email['message']; |
|
144 | + } |
|
145 | + $message = $this->email['before'].$message.$this->email['after']; |
|
146 | + $message = strip_shortcodes($message); |
|
147 | + $message = wptexturize($message); |
|
148 | + $message = wpautop($message); |
|
149 | + $message = str_replace('<> ', '', $message); |
|
150 | + $message = str_replace(']]>', ']]>', $message); |
|
151 | + $message = glsr(Template::class)->build('partials/email/index', [ |
|
152 | + 'context' => ['message' => $message], |
|
153 | + ]); |
|
154 | + return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param \WP_Error $error |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + protected function logMailError($error) |
|
162 | + { |
|
163 | + glsr_log()->error('Email was not sent (wp_mail failed)') |
|
164 | + ->debug($this) |
|
165 | + ->debug($error); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + protected function normalize(array $email = []) |
|
172 | + { |
|
173 | + $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
174 | + if (empty($email['reply-to'])) { |
|
175 | + $email['reply-to'] = $email['from']; |
|
176 | + } |
|
177 | + $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + protected function reset() |
|
184 | + { |
|
185 | + $this->attachments = []; |
|
186 | + $this->email = []; |
|
187 | + $this->headers = []; |
|
188 | + $this->message = null; |
|
189 | + $this->subject = null; |
|
190 | + $this->to = null; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + protected function stripHtmlTags($string) |
|
197 | + { |
|
198 | + // remove invisible elements |
|
199 | + $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
200 | + // replace certain elements with a line-break |
|
201 | + $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
202 | + // replace other elements with a space |
|
203 | + $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
204 | + // add a placeholder for plain-text bullets to list elements |
|
205 | + $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
206 | + // strip all remaining HTML tags |
|
207 | + $string = wp_strip_all_tags($string); |
|
208 | + $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
209 | + $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
210 | + $string = str_replace('-o-^-o-', ' - ', $string); |
|
211 | + return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
212 | + } |
|
213 | 213 | } |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return Email |
44 | 44 | */ |
45 | - public function compose(array $email) |
|
45 | + public function compose( array $email ) |
|
46 | 46 | { |
47 | - $this->normalize($email); |
|
47 | + $this->normalize( $email ); |
|
48 | 48 | $this->attachments = $this->email['attachments']; |
49 | 49 | $this->headers = $this->buildHeaders(); |
50 | 50 | $this->message = $this->buildHtmlMessage(); |
51 | 51 | $this->subject = $this->email['subject']; |
52 | 52 | $this->to = $this->email['to']; |
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
53 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | * @param string $format |
59 | 59 | * @return string|null |
60 | 60 | */ |
61 | - public function read($format = '') |
|
61 | + public function read( $format = '' ) |
|
62 | 62 | { |
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
63 | + if( 'plaintext' == $format ) { |
|
64 | + $message = $this->stripHtmlTags( $this->message ); |
|
65 | + return apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
66 | 66 | } |
67 | 67 | return $this->message; |
68 | 68 | } |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function send() |
74 | 74 | { |
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
75 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
78 | + add_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
79 | 79 | $sent = wp_mail( |
80 | 80 | $this->to, |
81 | 81 | $this->subject, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $this->headers, |
84 | 84 | $this->attachments |
85 | 85 | ); |
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
86 | + remove_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
87 | 87 | $this->reset(); |
88 | 88 | return $sent; |
89 | 89 | } |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | * @return void |
93 | 93 | * @action phpmailer_init |
94 | 94 | */ |
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
95 | + public function buildPlainTextMessage( PHPMailer $phpmailer ) |
|
96 | 96 | { |
97 | - if (empty($this->email)) { |
|
97 | + if( empty($this->email) ) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
100 | + if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
103 | + $message = $this->stripHtmlTags( $phpmailer->Body ); |
|
104 | + $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | $allowed = [ |
113 | 113 | 'bcc', 'cc', 'from', 'reply-to', |
114 | 114 | ]; |
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
115 | + $headers = array_intersect_key( $this->email, array_flip( $allowed ) ); |
|
116 | + $headers = array_filter( $headers ); |
|
117 | + foreach( $headers as $key => $value ) { |
|
118 | 118 | unset($headers[$key]); |
119 | 119 | $headers[] = $key.': '.$value; |
120 | 120 | } |
121 | 121 | $headers[] = 'Content-Type: text/html'; |
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
122 | + return apply_filters( 'site-reviews/email/headers', $headers, $this ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,54 +127,54 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildHtmlMessage() |
129 | 129 | { |
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate( |
|
130 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
131 | + if( !empty($template) ) { |
|
132 | + $message = glsr( Template::class )->interpolate( |
|
133 | 133 | $template, |
134 | 134 | ['context' => $this->email['template-tags']], |
135 | 135 | $this->email['template'] |
136 | 136 | ); |
137 | - } elseif ($this->email['template']) { |
|
138 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
137 | + } elseif( $this->email['template'] ) { |
|
138 | + $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [ |
|
139 | 139 | 'context' => $this->email['template-tags'], |
140 | - ]); |
|
140 | + ] ); |
|
141 | 141 | } |
142 | - if (!isset($message)) { |
|
142 | + if( !isset($message) ) { |
|
143 | 143 | $message = $this->email['message']; |
144 | 144 | } |
145 | 145 | $message = $this->email['before'].$message.$this->email['after']; |
146 | - $message = strip_shortcodes($message); |
|
147 | - $message = wptexturize($message); |
|
148 | - $message = wpautop($message); |
|
149 | - $message = str_replace('<> ', '', $message); |
|
150 | - $message = str_replace(']]>', ']]>', $message); |
|
151 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
146 | + $message = strip_shortcodes( $message ); |
|
147 | + $message = wptexturize( $message ); |
|
148 | + $message = wpautop( $message ); |
|
149 | + $message = str_replace( '<> ', '', $message ); |
|
150 | + $message = str_replace( ']]>', ']]>', $message ); |
|
151 | + $message = glsr( Template::class )->build( 'partials/email/index', [ |
|
152 | 152 | 'context' => ['message' => $message], |
153 | - ]); |
|
154 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
153 | + ] ); |
|
154 | + return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * @param \WP_Error $error |
159 | 159 | * @return void |
160 | 160 | */ |
161 | - protected function logMailError($error) |
|
161 | + protected function logMailError( $error ) |
|
162 | 162 | { |
163 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
164 | - ->debug($this) |
|
165 | - ->debug($error); |
|
163 | + glsr_log()->error( 'Email was not sent (wp_mail failed)' ) |
|
164 | + ->debug( $this ) |
|
165 | + ->debug( $error ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - protected function normalize(array $email = []) |
|
171 | + protected function normalize( array $email = [] ) |
|
172 | 172 | { |
173 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
174 | - if (empty($email['reply-to'])) { |
|
173 | + $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email ); |
|
174 | + if( empty($email['reply-to']) ) { |
|
175 | 175 | $email['reply-to'] = $email['from']; |
176 | 176 | } |
177 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
177 | + $this->email = apply_filters( 'site-reviews/email/compose', $email, $this ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -193,21 +193,21 @@ discard block |
||
193 | 193 | /** |
194 | 194 | * @return string |
195 | 195 | */ |
196 | - protected function stripHtmlTags($string) |
|
196 | + protected function stripHtmlTags( $string ) |
|
197 | 197 | { |
198 | 198 | // remove invisible elements |
199 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
199 | + $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string ); |
|
200 | 200 | // replace certain elements with a line-break |
201 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
201 | + $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string ); |
|
202 | 202 | // replace other elements with a space |
203 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
203 | + $string = preg_replace( '@</(td|th)@iu', ' $0', $string ); |
|
204 | 204 | // add a placeholder for plain-text bullets to list elements |
205 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
205 | + $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string ); |
|
206 | 206 | // strip all remaining HTML tags |
207 | - $string = wp_strip_all_tags($string); |
|
208 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
209 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
210 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
211 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
207 | + $string = wp_strip_all_tags( $string ); |
|
208 | + $string = wp_specialchars_decode( $string, ENT_QUOTES ); |
|
209 | + $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); |
|
210 | + $string = str_replace( '-o-^-o-', ' - ', $string ); |
|
211 | + return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); |
|
212 | 212 | } |
213 | 213 | } |
@@ -134,7 +134,8 @@ |
||
134 | 134 | ['context' => $this->email['template-tags']], |
135 | 135 | $this->email['template'] |
136 | 136 | ); |
137 | - } elseif ($this->email['template']) { |
|
137 | + } |
|
138 | + elseif ($this->email['template']) { |
|
138 | 139 | $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
139 | 140 | 'context' => $this->email['template-tags'], |
140 | 141 | ]); |
@@ -1,37 +1,37 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <form method="post" class="glsr-form-sync glsr-status"> |
4 | - <?php $selected = key($services); ?> |
|
4 | + <?php $selected = key( $services ); ?> |
|
5 | 5 | <table class="wp-list-table widefat fixed striped"> |
6 | 6 | <thead> |
7 | 7 | <tr> |
8 | 8 | <td class="check-column glsr-radio-column"><span class="dashicons-before dashicons-update"></span></td> |
9 | - <th scope="col" class="column-primary"><?= __('Service', 'site-reviews'); ?></th> |
|
10 | - <th scope="col" class="column-total_fetched"><?= __('Reviews', 'site-reviews'); ?></th> |
|
11 | - <th scope="col" class="column-last_sync"><?= __('Last Sync', 'site-reviews'); ?></th> |
|
9 | + <th scope="col" class="column-primary"><?= __( 'Service', 'site-reviews' ); ?></th> |
|
10 | + <th scope="col" class="column-total_fetched"><?= __( 'Reviews', 'site-reviews' ); ?></th> |
|
11 | + <th scope="col" class="column-last_sync"><?= __( 'Last Sync', 'site-reviews' ); ?></th> |
|
12 | 12 | </tr> |
13 | 13 | </thead> |
14 | 14 | <tbody> |
15 | - <?php foreach ($services as $slug => $details) : ?> |
|
15 | + <?php foreach( $services as $slug => $details ) : ?> |
|
16 | 16 | <tr class="service-<?= $slug; ?>"> |
17 | 17 | <th scope="row" class="check-column"> |
18 | - <input type="radio" name="{{ id }}[service]" value="<?= $slug; ?>" <?php checked($slug, $selected); ?>> |
|
18 | + <input type="radio" name="{{ id }}[service]" value="<?= $slug; ?>" <?php checked( $slug, $selected ); ?>> |
|
19 | 19 | </th> |
20 | 20 | <td class="column-primary has-row-actions"> |
21 | 21 | <strong><?= $details['name']; ?></strong> |
22 | 22 | <div class="row-actions"> |
23 | - <span><a href="{{ base_url }}&page=settings#!addons"><?= __('Settings', 'site-reviews'); ?></a> | </span> |
|
24 | - <span><a href="{{ base_url }}&page=settings#!licenses"><?= __('License', 'site-reviews'); ?></a> | </span> |
|
25 | - <span><a href="{{ base_url }}&page=documentation#!addons"><?= __('Documentation', 'site-reviews'); ?></a></span> |
|
23 | + <span><a href="{{ base_url }}&page=settings#!addons"><?= __( 'Settings', 'site-reviews' ); ?></a> | </span> |
|
24 | + <span><a href="{{ base_url }}&page=settings#!licenses"><?= __( 'License', 'site-reviews' ); ?></a> | </span> |
|
25 | + <span><a href="{{ base_url }}&page=documentation#!addons"><?= __( 'Documentation', 'site-reviews' ); ?></a></span> |
|
26 | 26 | </div> |
27 | 27 | <button type="button" class="toggle-row"> |
28 | - <span class="screen-reader-text"><?= __('Show more details', 'site-reviews'); ?></span> |
|
28 | + <span class="screen-reader-text"><?= __( 'Show more details', 'site-reviews' ); ?></span> |
|
29 | 29 | </button> |
30 | 30 | </td> |
31 | - <td class="column-total_fetched" data-colname="<?= __('Reviews', 'site-reviews'); ?>"> |
|
31 | + <td class="column-total_fetched" data-colname="<?= __( 'Reviews', 'site-reviews' ); ?>"> |
|
32 | 32 | <a href="<?= $details['reviews_url']; ?>"><?= $details['reviews_count']; ?></a> |
33 | 33 | </td> |
34 | - <td class="column-last_sync" data-colname="<?= __('Last Sync', 'site-reviews'); ?>"> |
|
34 | + <td class="column-last_sync" data-colname="<?= __( 'Last Sync', 'site-reviews' ); ?>"> |
|
35 | 35 | <?= $details['last_sync']; ?> |
36 | 36 | </td> |
37 | 37 | </tr> |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | <tfoot> |
41 | 41 | <tr> |
42 | 42 | <td colspan="4" class="no-items" style="display:table-cell!important;"> |
43 | - <div class="glsr-progress" data-active-text="<?= __('Please wait...', 'site-reviews'); ?>"> |
|
43 | + <div class="glsr-progress" data-active-text="<?= __( 'Please wait...', 'site-reviews' ); ?>"> |
|
44 | 44 | <div class="glsr-progress-bar" style="width: 0%;"> |
45 | - <span class="glsr-progress-status"><?= __('Inactive', 'site-reviews'); ?></span> |
|
45 | + <span class="glsr-progress-status"><?= __( 'Inactive', 'site-reviews' ); ?></span> |
|
46 | 46 | </div> |
47 | 47 | <div class="glsr-progress-background"> |
48 | - <span class="glsr-progress-status"><?= __('Inactive', 'site-reviews'); ?></span> |
|
48 | + <span class="glsr-progress-status"><?= __( 'Inactive', 'site-reviews' ); ?></span> |
|
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | </td> |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | </table> |
55 | 55 | <div class="tablenav bottom"> |
56 | 56 | <button type="submit" class="glsr-button button" id="sync-reviews"> |
57 | - <span data-loading="<?= __('Syncing...', 'site-reviews'); ?>"><?= __('Sync Reviews', 'site-reviews'); ?></span> |
|
57 | + <span data-loading="<?= __( 'Syncing...', 'site-reviews' ); ?>"><?= __( 'Sync Reviews', 'site-reviews' ); ?></span> |
|
58 | 58 | </button> |
59 | 59 | </div> |
60 | 60 | </form> |
@@ -10,97 +10,97 @@ |
||
10 | 10 | |
11 | 11 | class MainController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - * @action init |
|
16 | - */ |
|
17 | - public function registerPostType() |
|
18 | - { |
|
19 | - if (!glsr()->hasPermission()) { |
|
20 | - return; |
|
21 | - } |
|
22 | - $command = new RegisterPostType([ |
|
23 | - 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | - 'columns' => [ |
|
25 | - 'title' => '', |
|
26 | - 'category' => '', |
|
27 | - 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | - 'reviewer' => __('Author', 'site-reviews'), |
|
29 | - 'email' => __('Email', 'site-reviews'), |
|
30 | - 'ip_address' => __('IP Address', 'site-reviews'), |
|
31 | - 'response' => __('Response', 'site-reviews'), |
|
32 | - 'review_type' => __('Type', 'site-reviews'), |
|
33 | - 'rating' => __('Rating', 'site-reviews'), |
|
34 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
35 | - 'date' => '', |
|
36 | - ], |
|
37 | - 'menu_icon' => 'dashicons-star-half', |
|
38 | - 'menu_name' => glsr()->name, |
|
39 | - 'map_meta_cap' => true, |
|
40 | - 'plural' => __('Reviews', 'site-reviews'), |
|
41 | - 'post_type' => Application::POST_TYPE, |
|
42 | - 'rest_controller_class' => RestReviewController::class, |
|
43 | - 'show_in_rest' => true, |
|
44 | - 'single' => __('Review', 'site-reviews'), |
|
45 | - ]); |
|
46 | - $this->execute($command); |
|
47 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + * @action init |
|
16 | + */ |
|
17 | + public function registerPostType() |
|
18 | + { |
|
19 | + if (!glsr()->hasPermission()) { |
|
20 | + return; |
|
21 | + } |
|
22 | + $command = new RegisterPostType([ |
|
23 | + 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | + 'columns' => [ |
|
25 | + 'title' => '', |
|
26 | + 'category' => '', |
|
27 | + 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | + 'reviewer' => __('Author', 'site-reviews'), |
|
29 | + 'email' => __('Email', 'site-reviews'), |
|
30 | + 'ip_address' => __('IP Address', 'site-reviews'), |
|
31 | + 'response' => __('Response', 'site-reviews'), |
|
32 | + 'review_type' => __('Type', 'site-reviews'), |
|
33 | + 'rating' => __('Rating', 'site-reviews'), |
|
34 | + 'pinned' => __('Pinned', 'site-reviews'), |
|
35 | + 'date' => '', |
|
36 | + ], |
|
37 | + 'menu_icon' => 'dashicons-star-half', |
|
38 | + 'menu_name' => glsr()->name, |
|
39 | + 'map_meta_cap' => true, |
|
40 | + 'plural' => __('Reviews', 'site-reviews'), |
|
41 | + 'post_type' => Application::POST_TYPE, |
|
42 | + 'rest_controller_class' => RestReviewController::class, |
|
43 | + 'show_in_rest' => true, |
|
44 | + 'single' => __('Review', 'site-reviews'), |
|
45 | + ]); |
|
46 | + $this->execute($command); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return void |
|
51 | - * @action init |
|
52 | - */ |
|
53 | - public function registerShortcodes() |
|
54 | - { |
|
55 | - $command = new RegisterShortcodes([ |
|
56 | - 'site_reviews', |
|
57 | - 'site_reviews_form', |
|
58 | - 'site_reviews_summary', |
|
59 | - ]); |
|
60 | - $this->execute($command); |
|
61 | - } |
|
49 | + /** |
|
50 | + * @return void |
|
51 | + * @action init |
|
52 | + */ |
|
53 | + public function registerShortcodes() |
|
54 | + { |
|
55 | + $command = new RegisterShortcodes([ |
|
56 | + 'site_reviews', |
|
57 | + 'site_reviews_form', |
|
58 | + 'site_reviews_summary', |
|
59 | + ]); |
|
60 | + $this->execute($command); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return void |
|
65 | - * @action init |
|
66 | - */ |
|
67 | - public function registerTaxonomy() |
|
68 | - { |
|
69 | - $command = new RegisterTaxonomy([ |
|
70 | - 'hierarchical' => true, |
|
71 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
72 | - 'public' => false, |
|
73 | - 'rest_controller_class' => RestCategoryController::class, |
|
74 | - 'show_admin_column' => true, |
|
75 | - 'show_in_rest' => true, |
|
76 | - 'show_ui' => true, |
|
77 | - ]); |
|
78 | - $this->execute($command); |
|
79 | - } |
|
63 | + /** |
|
64 | + * @return void |
|
65 | + * @action init |
|
66 | + */ |
|
67 | + public function registerTaxonomy() |
|
68 | + { |
|
69 | + $command = new RegisterTaxonomy([ |
|
70 | + 'hierarchical' => true, |
|
71 | + 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
72 | + 'public' => false, |
|
73 | + 'rest_controller_class' => RestCategoryController::class, |
|
74 | + 'show_admin_column' => true, |
|
75 | + 'show_in_rest' => true, |
|
76 | + 'show_ui' => true, |
|
77 | + ]); |
|
78 | + $this->execute($command); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return void |
|
83 | - * @action widgets_init |
|
84 | - */ |
|
85 | - public function registerWidgets() |
|
86 | - { |
|
87 | - $command = new RegisterWidgets([ |
|
88 | - 'site-reviews' => [ |
|
89 | - 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
90 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
91 | - 'title' => __('Recent Reviews', 'site-reviews'), |
|
92 | - ], |
|
93 | - 'site-reviews-form' => [ |
|
94 | - 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
95 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
96 | - 'title' => __('Submit a Review', 'site-reviews'), |
|
97 | - ], |
|
98 | - 'site-reviews-summary' => [ |
|
99 | - 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
100 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
101 | - 'title' => __('Summary of Reviews', 'site-reviews'), |
|
102 | - ], |
|
103 | - ]); |
|
104 | - $this->execute($command); |
|
105 | - } |
|
81 | + /** |
|
82 | + * @return void |
|
83 | + * @action widgets_init |
|
84 | + */ |
|
85 | + public function registerWidgets() |
|
86 | + { |
|
87 | + $command = new RegisterWidgets([ |
|
88 | + 'site-reviews' => [ |
|
89 | + 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
90 | + 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
91 | + 'title' => __('Recent Reviews', 'site-reviews'), |
|
92 | + ], |
|
93 | + 'site-reviews-form' => [ |
|
94 | + 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
95 | + 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
96 | + 'title' => __('Submit a Review', 'site-reviews'), |
|
97 | + ], |
|
98 | + 'site-reviews-summary' => [ |
|
99 | + 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
100 | + 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
101 | + 'title' => __('Summary of Reviews', 'site-reviews'), |
|
102 | + ], |
|
103 | + ]); |
|
104 | + $this->execute($command); |
|
105 | + } |
|
106 | 106 | } |
@@ -16,34 +16,34 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function registerPostType() |
18 | 18 | { |
19 | - if (!glsr()->hasPermission()) { |
|
19 | + if( !glsr()->hasPermission() ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - $command = new RegisterPostType([ |
|
22 | + $command = new RegisterPostType( [ |
|
23 | 23 | 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
24 | 24 | 'columns' => [ |
25 | 25 | 'title' => '', |
26 | 26 | 'category' => '', |
27 | - 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | - 'reviewer' => __('Author', 'site-reviews'), |
|
29 | - 'email' => __('Email', 'site-reviews'), |
|
30 | - 'ip_address' => __('IP Address', 'site-reviews'), |
|
31 | - 'response' => __('Response', 'site-reviews'), |
|
32 | - 'review_type' => __('Type', 'site-reviews'), |
|
33 | - 'rating' => __('Rating', 'site-reviews'), |
|
34 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
27 | + 'assigned_to' => __( 'Assigned To', 'site-reviews' ), |
|
28 | + 'reviewer' => __( 'Author', 'site-reviews' ), |
|
29 | + 'email' => __( 'Email', 'site-reviews' ), |
|
30 | + 'ip_address' => __( 'IP Address', 'site-reviews' ), |
|
31 | + 'response' => __( 'Response', 'site-reviews' ), |
|
32 | + 'review_type' => __( 'Type', 'site-reviews' ), |
|
33 | + 'rating' => __( 'Rating', 'site-reviews' ), |
|
34 | + 'pinned' => __( 'Pinned', 'site-reviews' ), |
|
35 | 35 | 'date' => '', |
36 | 36 | ], |
37 | 37 | 'menu_icon' => 'dashicons-star-half', |
38 | 38 | 'menu_name' => glsr()->name, |
39 | 39 | 'map_meta_cap' => true, |
40 | - 'plural' => __('Reviews', 'site-reviews'), |
|
40 | + 'plural' => __( 'Reviews', 'site-reviews' ), |
|
41 | 41 | 'post_type' => Application::POST_TYPE, |
42 | 42 | 'rest_controller_class' => RestReviewController::class, |
43 | 43 | 'show_in_rest' => true, |
44 | - 'single' => __('Review', 'site-reviews'), |
|
45 | - ]); |
|
46 | - $this->execute($command); |
|
44 | + 'single' => __( 'Review', 'site-reviews' ), |
|
45 | + ] ); |
|
46 | + $this->execute( $command ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function registerShortcodes() |
54 | 54 | { |
55 | - $command = new RegisterShortcodes([ |
|
55 | + $command = new RegisterShortcodes( [ |
|
56 | 56 | 'site_reviews', |
57 | 57 | 'site_reviews_form', |
58 | 58 | 'site_reviews_summary', |
59 | - ]); |
|
60 | - $this->execute($command); |
|
59 | + ] ); |
|
60 | + $this->execute( $command ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function registerTaxonomy() |
68 | 68 | { |
69 | - $command = new RegisterTaxonomy([ |
|
69 | + $command = new RegisterTaxonomy( [ |
|
70 | 70 | 'hierarchical' => true, |
71 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
71 | + 'meta_box_cb' => [glsr( EditorController::class ), 'renderTaxonomyMetabox'], |
|
72 | 72 | 'public' => false, |
73 | 73 | 'rest_controller_class' => RestCategoryController::class, |
74 | 74 | 'show_admin_column' => true, |
75 | 75 | 'show_in_rest' => true, |
76 | 76 | 'show_ui' => true, |
77 | - ]); |
|
78 | - $this->execute($command); |
|
77 | + ] ); |
|
78 | + $this->execute( $command ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function registerWidgets() |
86 | 86 | { |
87 | - $command = new RegisterWidgets([ |
|
87 | + $command = new RegisterWidgets( [ |
|
88 | 88 | 'site-reviews' => [ |
89 | 89 | 'class' => 'glsr-widget glsr-widget-site-reviews', |
90 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
91 | - 'title' => __('Recent Reviews', 'site-reviews'), |
|
90 | + 'description' => __( 'Site Reviews: Display your recent reviews.', 'site-reviews' ), |
|
91 | + 'title' => __( 'Recent Reviews', 'site-reviews' ), |
|
92 | 92 | ], |
93 | 93 | 'site-reviews-form' => [ |
94 | 94 | 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
95 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
96 | - 'title' => __('Submit a Review', 'site-reviews'), |
|
95 | + 'description' => __( 'Site Reviews: Display a form to submit reviews.', 'site-reviews' ), |
|
96 | + 'title' => __( 'Submit a Review', 'site-reviews' ), |
|
97 | 97 | ], |
98 | 98 | 'site-reviews-summary' => [ |
99 | 99 | 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
100 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
101 | - 'title' => __('Summary of Reviews', 'site-reviews'), |
|
100 | + 'description' => __( 'Site Reviews: Display a summary of your reviews.', 'site-reviews' ), |
|
101 | + 'title' => __( 'Summary of Reviews', 'site-reviews' ), |
|
102 | 102 | ], |
103 | - ]); |
|
104 | - $this->execute($command); |
|
103 | + ] ); |
|
104 | + $this->execute( $command ); |
|
105 | 105 | } |
106 | 106 | } |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <div class="notice notice-info is-dismissible glsr-notice" data-dismiss="welcome"> |
2 | - <p><?= $text; ?> — <a class="button button-small" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=welcome#!whatsnew'); ?>">See what's new</a></p> |
|
2 | + <p><?= $text; ?> — <a class="button button-small" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=welcome#!whatsnew' ); ?>">See what's new</a></p> |
|
3 | 3 | </div> |
@@ -7,92 +7,92 @@ |
||
7 | 7 | |
8 | 8 | class SiteReviewsWidget extends Widget |
9 | 9 | { |
10 | - /** |
|
11 | - * @param array $instance |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function form($instance) |
|
15 | - { |
|
16 | - $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
17 | - $terms = glsr(Database::class)->getTerms(); |
|
18 | - $this->renderField('text', [ |
|
19 | - 'class' => 'widefat', |
|
20 | - 'label' => __('Title', 'site-reviews'), |
|
21 | - 'name' => 'title', |
|
22 | - ]); |
|
23 | - $this->renderField('number', [ |
|
24 | - 'class' => 'small-text', |
|
25 | - 'default' => 10, |
|
26 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
27 | - 'max' => 100, |
|
28 | - 'name' => 'display', |
|
29 | - ]); |
|
30 | - $this->renderField('select', [ |
|
31 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
32 | - 'name' => 'rating', |
|
33 | - 'options' => [ |
|
34 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
35 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
36 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
37 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
38 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
39 | - ], |
|
40 | - ]); |
|
41 | - if (count(glsr()->reviewTypes) > 1) { |
|
42 | - $this->renderField('select', [ |
|
43 | - 'class' => 'widefat', |
|
44 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
45 | - 'name' => 'type', |
|
46 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
47 | - ]); |
|
48 | - } |
|
49 | - if (!empty($terms)) { |
|
50 | - $this->renderField('select', [ |
|
51 | - 'class' => 'widefat', |
|
52 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
53 | - 'name' => 'category', |
|
54 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
55 | - ]); |
|
56 | - } |
|
57 | - $this->renderField('text', [ |
|
58 | - 'class' => 'widefat', |
|
59 | - 'default' => '', |
|
60 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
61 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
62 | - 'name' => 'assigned_to', |
|
63 | - ]); |
|
64 | - $this->renderField('text', [ |
|
65 | - 'class' => 'widefat', |
|
66 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
67 | - 'name' => 'class', |
|
68 | - ]); |
|
69 | - $this->renderField('checkbox', [ |
|
70 | - 'name' => 'hide', |
|
71 | - 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
72 | - ]); |
|
73 | - } |
|
10 | + /** |
|
11 | + * @param array $instance |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function form($instance) |
|
15 | + { |
|
16 | + $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
17 | + $terms = glsr(Database::class)->getTerms(); |
|
18 | + $this->renderField('text', [ |
|
19 | + 'class' => 'widefat', |
|
20 | + 'label' => __('Title', 'site-reviews'), |
|
21 | + 'name' => 'title', |
|
22 | + ]); |
|
23 | + $this->renderField('number', [ |
|
24 | + 'class' => 'small-text', |
|
25 | + 'default' => 10, |
|
26 | + 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
27 | + 'max' => 100, |
|
28 | + 'name' => 'display', |
|
29 | + ]); |
|
30 | + $this->renderField('select', [ |
|
31 | + 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
32 | + 'name' => 'rating', |
|
33 | + 'options' => [ |
|
34 | + '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
35 | + '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
36 | + '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
37 | + '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
38 | + '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
39 | + ], |
|
40 | + ]); |
|
41 | + if (count(glsr()->reviewTypes) > 1) { |
|
42 | + $this->renderField('select', [ |
|
43 | + 'class' => 'widefat', |
|
44 | + 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
45 | + 'name' => 'type', |
|
46 | + 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
47 | + ]); |
|
48 | + } |
|
49 | + if (!empty($terms)) { |
|
50 | + $this->renderField('select', [ |
|
51 | + 'class' => 'widefat', |
|
52 | + 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
53 | + 'name' => 'category', |
|
54 | + 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
55 | + ]); |
|
56 | + } |
|
57 | + $this->renderField('text', [ |
|
58 | + 'class' => 'widefat', |
|
59 | + 'default' => '', |
|
60 | + 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
61 | + 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
62 | + 'name' => 'assigned_to', |
|
63 | + ]); |
|
64 | + $this->renderField('text', [ |
|
65 | + 'class' => 'widefat', |
|
66 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
67 | + 'name' => 'class', |
|
68 | + ]); |
|
69 | + $this->renderField('checkbox', [ |
|
70 | + 'name' => 'hide', |
|
71 | + 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
72 | + ]); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param array $newInstance |
|
77 | - * @param array $oldInstance |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public function update($newInstance, $oldInstance) |
|
81 | - { |
|
82 | - if (!is_numeric($newInstance['display'])) { |
|
83 | - $newInstance['display'] = 10; |
|
84 | - } |
|
85 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
86 | - return parent::update($newInstance, $oldInstance); |
|
87 | - } |
|
75 | + /** |
|
76 | + * @param array $newInstance |
|
77 | + * @param array $oldInstance |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public function update($newInstance, $oldInstance) |
|
81 | + { |
|
82 | + if (!is_numeric($newInstance['display'])) { |
|
83 | + $newInstance['display'] = 10; |
|
84 | + } |
|
85 | + $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
86 | + return parent::update($newInstance, $oldInstance); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @param array $args |
|
91 | - * @param array $instance |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function widget($args, $instance) |
|
95 | - { |
|
96 | - echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
97 | - } |
|
89 | + /** |
|
90 | + * @param array $args |
|
91 | + * @param array $instance |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function widget($args, $instance) |
|
95 | + { |
|
96 | + echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
97 | + } |
|
98 | 98 | } |
@@ -11,65 +11,65 @@ discard block |
||
11 | 11 | * @param array $instance |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function form($instance) |
|
14 | + public function form( $instance ) |
|
15 | 15 | { |
16 | - $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
17 | - $terms = glsr(Database::class)->getTerms(); |
|
18 | - $this->renderField('text', [ |
|
16 | + $this->widgetArgs = glsr( SiteReviewsShortcode::class )->normalizeAtts( $instance ); |
|
17 | + $terms = glsr( Database::class )->getTerms(); |
|
18 | + $this->renderField( 'text', [ |
|
19 | 19 | 'class' => 'widefat', |
20 | - 'label' => __('Title', 'site-reviews'), |
|
20 | + 'label' => __( 'Title', 'site-reviews' ), |
|
21 | 21 | 'name' => 'title', |
22 | - ]); |
|
23 | - $this->renderField('number', [ |
|
22 | + ] ); |
|
23 | + $this->renderField( 'number', [ |
|
24 | 24 | 'class' => 'small-text', |
25 | 25 | 'default' => 10, |
26 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
26 | + 'label' => __( 'How many reviews would you like to display?', 'site-reviews' ), |
|
27 | 27 | 'max' => 100, |
28 | 28 | 'name' => 'display', |
29 | - ]); |
|
30 | - $this->renderField('select', [ |
|
31 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
29 | + ] ); |
|
30 | + $this->renderField( 'select', [ |
|
31 | + 'label' => __( 'What is the minimum rating to display?', 'site-reviews' ), |
|
32 | 32 | 'name' => 'rating', |
33 | 33 | 'options' => [ |
34 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
35 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
36 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
37 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
38 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
34 | + '5' => sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ), |
|
35 | + '4' => sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ), |
|
36 | + '3' => sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ), |
|
37 | + '2' => sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ), |
|
38 | + '1' => sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ), |
|
39 | 39 | ], |
40 | - ]); |
|
41 | - if (count(glsr()->reviewTypes) > 1) { |
|
42 | - $this->renderField('select', [ |
|
40 | + ] ); |
|
41 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
42 | + $this->renderField( 'select', [ |
|
43 | 43 | 'class' => 'widefat', |
44 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
44 | + 'label' => __( 'Which type of review would you like to display?', 'site-reviews' ), |
|
45 | 45 | 'name' => 'type', |
46 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
47 | - ]); |
|
46 | + 'options' => ['' => __( 'All Reviews', 'site-reviews' )] + glsr()->reviewTypes, |
|
47 | + ] ); |
|
48 | 48 | } |
49 | - if (!empty($terms)) { |
|
50 | - $this->renderField('select', [ |
|
49 | + if( !empty($terms) ) { |
|
50 | + $this->renderField( 'select', [ |
|
51 | 51 | 'class' => 'widefat', |
52 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
52 | + 'label' => __( 'Limit reviews to this category', 'site-reviews' ), |
|
53 | 53 | 'name' => 'category', |
54 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
55 | - ]); |
|
54 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
55 | + ] ); |
|
56 | 56 | } |
57 | - $this->renderField('text', [ |
|
57 | + $this->renderField( 'text', [ |
|
58 | 58 | 'class' => 'widefat', |
59 | 59 | 'default' => '', |
60 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
61 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
60 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
61 | + 'label' => __( 'Limit reviews to those assigned to this page/post ID', 'site-reviews' ), |
|
62 | 62 | 'name' => 'assigned_to', |
63 | - ]); |
|
64 | - $this->renderField('text', [ |
|
63 | + ] ); |
|
64 | + $this->renderField( 'text', [ |
|
65 | 65 | 'class' => 'widefat', |
66 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
66 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
67 | 67 | 'name' => 'class', |
68 | - ]); |
|
69 | - $this->renderField('checkbox', [ |
|
68 | + ] ); |
|
69 | + $this->renderField( 'checkbox', [ |
|
70 | 70 | 'name' => 'hide', |
71 | - 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
72 | - ]); |
|
71 | + 'options' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
72 | + ] ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | * @param array $oldInstance |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - public function update($newInstance, $oldInstance) |
|
80 | + public function update( $newInstance, $oldInstance ) |
|
81 | 81 | { |
82 | - if (!is_numeric($newInstance['display'])) { |
|
82 | + if( !is_numeric( $newInstance['display'] ) ) { |
|
83 | 83 | $newInstance['display'] = 10; |
84 | 84 | } |
85 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
86 | - return parent::update($newInstance, $oldInstance); |
|
85 | + $newInstance['display'] = min( 50, max( 0, intval( $newInstance['display'] ) ) ); |
|
86 | + return parent::update( $newInstance, $oldInstance ); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | * @param array $instance |
92 | 92 | * @return void |
93 | 93 | */ |
94 | - public function widget($args, $instance) |
|
94 | + public function widget( $args, $instance ) |
|
95 | 95 | { |
96 | - echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
96 | + echo glsr( SiteReviewsShortcode::class )->build( $instance, $args, 'widget' ); |
|
97 | 97 | } |
98 | 98 | } |
@@ -4,84 +4,84 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsPopup extends TinymcePopupGenerator |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public function fields() |
|
11 | - { |
|
12 | - return [[ |
|
13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
14 | - 'minWidth' => 320, |
|
15 | - 'type' => 'container', |
|
16 | - ], [ |
|
17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
18 | - 'name' => 'title', |
|
19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
20 | - 'type' => 'textbox', |
|
21 | - ], [ |
|
22 | - 'label' => esc_html__('Display', 'site-reviews'), |
|
23 | - 'maxLength' => 5, |
|
24 | - 'name' => 'display', |
|
25 | - 'size' => 3, |
|
26 | - 'text' => '10', |
|
27 | - 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
28 | - 'type' => 'textbox', |
|
29 | - ], [ |
|
30 | - 'label' => esc_html__('Rating', 'site-reviews'), |
|
31 | - 'name' => 'rating', |
|
32 | - 'options' => [ |
|
33 | - '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
34 | - '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
35 | - '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
36 | - '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
37 | - '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
38 | - '0' => esc_html(__('Unrated', 'site-reviews')), |
|
39 | - ], |
|
40 | - 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
41 | - 'type' => 'listbox', |
|
42 | - ], [ |
|
43 | - 'label' => esc_html__('Pagination', 'site-reviews'), |
|
44 | - 'name' => 'pagination', |
|
45 | - 'options' => [ |
|
46 | - 'true' => esc_html__('Enable', 'site-reviews'), |
|
47 | - 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
48 | - 'false' => esc_html__('Disable', 'site-reviews'), |
|
49 | - ], |
|
50 | - 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
51 | - 'type' => 'listbox', |
|
52 | - ], |
|
53 | - $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
54 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
55 | - [ |
|
56 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
57 | - 'name' => 'assigned_to', |
|
58 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
59 | - 'type' => 'textbox', |
|
60 | - ], [ |
|
61 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
62 | - 'name' => 'schema', |
|
63 | - 'options' => [ |
|
64 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
65 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
66 | - ], |
|
67 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
68 | - 'type' => 'listbox', |
|
69 | - ], [ |
|
70 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
71 | - 'name' => 'class', |
|
72 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
73 | - 'type' => 'textbox', |
|
74 | - ], [ |
|
75 | - 'columns' => 2, |
|
76 | - 'items' => $this->getHideOptions(), |
|
77 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
78 | - 'layout' => 'grid', |
|
79 | - 'spacing' => 5, |
|
80 | - 'type' => 'container', |
|
81 | - ], [ |
|
82 | - 'hidden' => true, |
|
83 | - 'name' => 'id', |
|
84 | - 'type' => 'textbox', |
|
85 | - ], ]; |
|
86 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public function fields() |
|
11 | + { |
|
12 | + return [[ |
|
13 | + 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
14 | + 'minWidth' => 320, |
|
15 | + 'type' => 'container', |
|
16 | + ], [ |
|
17 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
18 | + 'name' => 'title', |
|
19 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
20 | + 'type' => 'textbox', |
|
21 | + ], [ |
|
22 | + 'label' => esc_html__('Display', 'site-reviews'), |
|
23 | + 'maxLength' => 5, |
|
24 | + 'name' => 'display', |
|
25 | + 'size' => 3, |
|
26 | + 'text' => '10', |
|
27 | + 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
28 | + 'type' => 'textbox', |
|
29 | + ], [ |
|
30 | + 'label' => esc_html__('Rating', 'site-reviews'), |
|
31 | + 'name' => 'rating', |
|
32 | + 'options' => [ |
|
33 | + '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
34 | + '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
35 | + '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
36 | + '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
37 | + '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
38 | + '0' => esc_html(__('Unrated', 'site-reviews')), |
|
39 | + ], |
|
40 | + 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
41 | + 'type' => 'listbox', |
|
42 | + ], [ |
|
43 | + 'label' => esc_html__('Pagination', 'site-reviews'), |
|
44 | + 'name' => 'pagination', |
|
45 | + 'options' => [ |
|
46 | + 'true' => esc_html__('Enable', 'site-reviews'), |
|
47 | + 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
48 | + 'false' => esc_html__('Disable', 'site-reviews'), |
|
49 | + ], |
|
50 | + 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
51 | + 'type' => 'listbox', |
|
52 | + ], |
|
53 | + $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
54 | + $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
55 | + [ |
|
56 | + 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
57 | + 'name' => 'assigned_to', |
|
58 | + 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
59 | + 'type' => 'textbox', |
|
60 | + ], [ |
|
61 | + 'label' => esc_html__('Schema', 'site-reviews'), |
|
62 | + 'name' => 'schema', |
|
63 | + 'options' => [ |
|
64 | + 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
65 | + 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
66 | + ], |
|
67 | + 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
68 | + 'type' => 'listbox', |
|
69 | + ], [ |
|
70 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
71 | + 'name' => 'class', |
|
72 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
73 | + 'type' => 'textbox', |
|
74 | + ], [ |
|
75 | + 'columns' => 2, |
|
76 | + 'items' => $this->getHideOptions(), |
|
77 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
78 | + 'layout' => 'grid', |
|
79 | + 'spacing' => 5, |
|
80 | + 'type' => 'container', |
|
81 | + ], [ |
|
82 | + 'hidden' => true, |
|
83 | + 'name' => 'id', |
|
84 | + 'type' => 'textbox', |
|
85 | + ], ]; |
|
86 | + } |
|
87 | 87 | } |
@@ -10,71 +10,71 @@ |
||
10 | 10 | public function fields() |
11 | 11 | { |
12 | 12 | return [[ |
13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
13 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
14 | 14 | 'minWidth' => 320, |
15 | 15 | 'type' => 'container', |
16 | 16 | ], [ |
17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
18 | 18 | 'name' => 'title', |
19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
20 | 20 | 'type' => 'textbox', |
21 | 21 | ], [ |
22 | - 'label' => esc_html__('Display', 'site-reviews'), |
|
22 | + 'label' => esc_html__( 'Display', 'site-reviews' ), |
|
23 | 23 | 'maxLength' => 5, |
24 | 24 | 'name' => 'display', |
25 | 25 | 'size' => 3, |
26 | 26 | 'text' => '10', |
27 | - 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
27 | + 'tooltip' => __( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ), |
|
28 | 28 | 'type' => 'textbox', |
29 | 29 | ], [ |
30 | - 'label' => esc_html__('Rating', 'site-reviews'), |
|
30 | + 'label' => esc_html__( 'Rating', 'site-reviews' ), |
|
31 | 31 | 'name' => 'rating', |
32 | 32 | 'options' => [ |
33 | - '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
34 | - '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
35 | - '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
36 | - '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
37 | - '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
38 | - '0' => esc_html(__('Unrated', 'site-reviews')), |
|
33 | + '5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ) ), |
|
34 | + '4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ) ), |
|
35 | + '3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ) ), |
|
36 | + '2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ) ), |
|
37 | + '1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ) ), |
|
38 | + '0' => esc_html( __( 'Unrated', 'site-reviews' ) ), |
|
39 | 39 | ], |
40 | - 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
40 | + 'tooltip' => __( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ), |
|
41 | 41 | 'type' => 'listbox', |
42 | 42 | ], [ |
43 | - 'label' => esc_html__('Pagination', 'site-reviews'), |
|
43 | + 'label' => esc_html__( 'Pagination', 'site-reviews' ), |
|
44 | 44 | 'name' => 'pagination', |
45 | 45 | 'options' => [ |
46 | - 'true' => esc_html__('Enable', 'site-reviews'), |
|
47 | - 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
48 | - 'false' => esc_html__('Disable', 'site-reviews'), |
|
46 | + 'true' => esc_html__( 'Enable', 'site-reviews' ), |
|
47 | + 'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ), |
|
48 | + 'false' => esc_html__( 'Disable', 'site-reviews' ), |
|
49 | 49 | ], |
50 | - 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
50 | + 'tooltip' => __( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ), |
|
51 | 51 | 'type' => 'listbox', |
52 | 52 | ], |
53 | - $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
54 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
53 | + $this->getTypes( __( 'Which type of review would you like to display?', 'site-reviews' ) ), |
|
54 | + $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ), |
|
55 | 55 | [ |
56 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
56 | + 'label' => esc_html__( 'Assigned To', 'site-reviews' ), |
|
57 | 57 | 'name' => 'assigned_to', |
58 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
58 | + 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews' ), |
|
59 | 59 | 'type' => 'textbox', |
60 | 60 | ], [ |
61 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
61 | + 'label' => esc_html__( 'Schema', 'site-reviews' ), |
|
62 | 62 | 'name' => 'schema', |
63 | 63 | 'options' => [ |
64 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
65 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
64 | + 'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ), |
|
65 | + 'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ), |
|
66 | 66 | ], |
67 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
67 | + 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
|
68 | 68 | 'type' => 'listbox', |
69 | 69 | ], [ |
70 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
70 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
71 | 71 | 'name' => 'class', |
72 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
72 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
73 | 73 | 'type' => 'textbox', |
74 | 74 | ], [ |
75 | 75 | 'columns' => 2, |
76 | 76 | 'items' => $this->getHideOptions(), |
77 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
77 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
78 | 78 | 'layout' => 'grid', |
79 | 79 | 'spacing' => 5, |
80 | 80 | 'type' => 'container', |