@@ -9,125 +9,125 @@ |
||
9 | 9 | |
10 | 10 | class Helper |
11 | 11 | { |
12 | - use Arr; |
|
13 | - use Str; |
|
12 | + use Arr; |
|
13 | + use Str; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @param string $name |
|
17 | - * @param string $path |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function buildClassName($name, $path = '') |
|
21 | - { |
|
22 | - $className = $this->camelCase($name); |
|
23 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
24 | - return !empty($path) |
|
25 | - ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
26 | - : $className; |
|
27 | - } |
|
15 | + /** |
|
16 | + * @param string $name |
|
17 | + * @param string $path |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function buildClassName($name, $path = '') |
|
21 | + { |
|
22 | + $className = $this->camelCase($name); |
|
23 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
24 | + return !empty($path) |
|
25 | + ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
26 | + : $className; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param string $name |
|
31 | - * @param string $prefix |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function buildMethodName($name, $prefix = '') |
|
35 | - { |
|
36 | - return lcfirst($prefix.$this->buildClassName($name)); |
|
37 | - } |
|
29 | + /** |
|
30 | + * @param string $name |
|
31 | + * @param string $prefix |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function buildMethodName($name, $prefix = '') |
|
35 | + { |
|
36 | + return lcfirst($prefix.$this->buildClassName($name)); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function buildPropertyName($name) |
|
44 | - { |
|
45 | - return lcfirst($this->buildClassName($name)); |
|
46 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function buildPropertyName($name) |
|
44 | + { |
|
45 | + return lcfirst($this->buildClassName($name)); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $cast |
|
50 | - * @param mixed $value |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - public function castTo($cast = '', $value) |
|
54 | - { |
|
55 | - switch ($cast) { |
|
56 | - case 'array': |
|
57 | - return (array) $value; |
|
58 | - case 'boolean': |
|
59 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
60 | - case 'float': |
|
61 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
62 | - case 'integer': |
|
63 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
64 | - case 'object': |
|
65 | - return (object) (array) $value; |
|
66 | - case 'string': |
|
67 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
68 | - return (string) $value->__toString(); |
|
69 | - } |
|
70 | - if (is_array($value) || is_object($value)) { |
|
71 | - return serialize($value); |
|
72 | - } |
|
73 | - return (string) $value; |
|
74 | - default: |
|
75 | - return $value; |
|
76 | - } |
|
77 | - } |
|
48 | + /** |
|
49 | + * @param string $cast |
|
50 | + * @param mixed $value |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + public function castTo($cast = '', $value) |
|
54 | + { |
|
55 | + switch ($cast) { |
|
56 | + case 'array': |
|
57 | + return (array) $value; |
|
58 | + case 'boolean': |
|
59 | + return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
60 | + case 'float': |
|
61 | + return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
62 | + case 'integer': |
|
63 | + return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
64 | + case 'object': |
|
65 | + return (object) (array) $value; |
|
66 | + case 'string': |
|
67 | + if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
68 | + return (string) $value->__toString(); |
|
69 | + } |
|
70 | + if (is_array($value) || is_object($value)) { |
|
71 | + return serialize($value); |
|
72 | + } |
|
73 | + return (string) $value; |
|
74 | + default: |
|
75 | + return $value; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $key |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - public function filterInput($key, array $request = []) |
|
84 | - { |
|
85 | - if (isset($request[$key])) { |
|
86 | - return $request[$key]; |
|
87 | - } |
|
88 | - $variable = filter_input(INPUT_POST, $key); |
|
89 | - if (is_null($variable) && isset($_POST[$key])) { |
|
90 | - $variable = $_POST[$key]; |
|
91 | - } |
|
92 | - return $variable; |
|
93 | - } |
|
79 | + /** |
|
80 | + * @param string $key |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + public function filterInput($key, array $request = []) |
|
84 | + { |
|
85 | + if (isset($request[$key])) { |
|
86 | + return $request[$key]; |
|
87 | + } |
|
88 | + $variable = filter_input(INPUT_POST, $key); |
|
89 | + if (is_null($variable) && isset($_POST[$key])) { |
|
90 | + $variable = $_POST[$key]; |
|
91 | + } |
|
92 | + return $variable; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param string $key |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function filterInputArray($key) |
|
100 | - { |
|
101 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
102 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
103 | - $variable = $_POST[$key]; |
|
104 | - } |
|
105 | - return (array) $variable; |
|
106 | - } |
|
95 | + /** |
|
96 | + * @param string $key |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function filterInputArray($key) |
|
100 | + { |
|
101 | + $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
102 | + if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
103 | + $variable = $_POST[$key]; |
|
104 | + } |
|
105 | + return (array) $variable; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function getIpAddress() |
|
112 | - { |
|
113 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
114 | - $ipv6 = defined('AF_INET6') |
|
115 | - ? $cloudflareIps['v6'] |
|
116 | - : []; |
|
117 | - $whitelist = apply_filters('site-reviews/whip/whitelist', [ |
|
118 | - Whip::CLOUDFLARE_HEADERS => [ |
|
119 | - Whip::IPV4 => $cloudflareIps['v4'], |
|
120 | - Whip::IPV6 => $ipv6, |
|
121 | - ], |
|
122 | - Whip::CUSTOM_HEADERS => [ |
|
123 | - Whip::IPV4 => ['127.0.0.1'], |
|
124 | - Whip::IPV6 => ['::1'], |
|
125 | - ], |
|
126 | - ]); |
|
127 | - $methods = Whip::CUSTOM_HEADERS | Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR; |
|
128 | - $methods = apply_filters('site-reviews/whip/methods', $methods); |
|
129 | - $whip = new Whip($methods, $whitelist); |
|
130 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
131 | - return (string) $whip->getValidIpAddress(); |
|
132 | - } |
|
108 | + /** |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function getIpAddress() |
|
112 | + { |
|
113 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
114 | + $ipv6 = defined('AF_INET6') |
|
115 | + ? $cloudflareIps['v6'] |
|
116 | + : []; |
|
117 | + $whitelist = apply_filters('site-reviews/whip/whitelist', [ |
|
118 | + Whip::CLOUDFLARE_HEADERS => [ |
|
119 | + Whip::IPV4 => $cloudflareIps['v4'], |
|
120 | + Whip::IPV6 => $ipv6, |
|
121 | + ], |
|
122 | + Whip::CUSTOM_HEADERS => [ |
|
123 | + Whip::IPV4 => ['127.0.0.1'], |
|
124 | + Whip::IPV6 => ['::1'], |
|
125 | + ], |
|
126 | + ]); |
|
127 | + $methods = Whip::CUSTOM_HEADERS | Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR; |
|
128 | + $methods = apply_filters('site-reviews/whip/methods', $methods); |
|
129 | + $whip = new Whip($methods, $whitelist); |
|
130 | + do_action_ref_array('site-reviews/whip', [$whip]); |
|
131 | + return (string) $whip->getValidIpAddress(); |
|
132 | + } |
|
133 | 133 | } |
@@ -9,62 +9,62 @@ |
||
9 | 9 | |
10 | 10 | class Upgrade_4_0_0 |
11 | 11 | { |
12 | - public function __construct() |
|
13 | - { |
|
14 | - $this->migrateSettings(); |
|
15 | - $this->protectMetaKeys(); |
|
16 | - $this->deleteSessions(); |
|
17 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
18 | - } |
|
12 | + public function __construct() |
|
13 | + { |
|
14 | + $this->migrateSettings(); |
|
15 | + $this->protectMetaKeys(); |
|
16 | + $this->deleteSessions(); |
|
17 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function deleteSessions() |
|
24 | - { |
|
25 | - global $wpdb; |
|
26 | - $wpdb->query(" |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function deleteSessions() |
|
24 | + { |
|
25 | + global $wpdb; |
|
26 | + $wpdb->query(" |
|
27 | 27 | DELETE |
28 | 28 | FROM {$wpdb->options} |
29 | 29 | WHERE option_name LIKE '_glsr_session%' |
30 | 30 | "); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function migrateSettings() |
|
37 | - { |
|
38 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
39 | - $multilingual = 'yes' == glsr(Helper::class)->dataGet($settings, 'settings.general.support.polylang') |
|
40 | - ? 'polylang' |
|
41 | - : ''; |
|
42 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.multilingual', $multilingual); |
|
43 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
44 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit', ''); |
|
45 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
46 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
47 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
48 | - unset($settings['settings']['general']['support']); |
|
49 | - update_option(OptionManager::databaseKey(4), $settings); |
|
50 | - } |
|
51 | - } |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function migrateSettings() |
|
37 | + { |
|
38 | + if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
39 | + $multilingual = 'yes' == glsr(Helper::class)->dataGet($settings, 'settings.general.support.polylang') |
|
40 | + ? 'polylang' |
|
41 | + : ''; |
|
42 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.multilingual', $multilingual); |
|
43 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
44 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit', ''); |
|
45 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
46 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
47 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
48 | + unset($settings['settings']['general']['support']); |
|
49 | + update_option(OptionManager::databaseKey(4), $settings); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function protectMetaKeys() |
|
57 | - { |
|
58 | - global $wpdb; |
|
59 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
60 | - $keys = implode("','", $keys); |
|
61 | - $postType = Application::POST_TYPE; |
|
62 | - $wpdb->query(" |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function protectMetaKeys() |
|
57 | + { |
|
58 | + global $wpdb; |
|
59 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
60 | + $keys = implode("','", $keys); |
|
61 | + $postType = Application::POST_TYPE; |
|
62 | + $wpdb->query(" |
|
63 | 63 | UPDATE {$wpdb->postmeta} pm |
64 | 64 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
65 | 65 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
66 | 66 | WHERE pm.meta_key IN ('{$keys}') |
67 | 67 | AND p.post_type = '{$postType}' |
68 | 68 | "); |
69 | - } |
|
69 | + } |
|
70 | 70 | } |
@@ -12,288 +12,288 @@ |
||
12 | 12 | |
13 | 13 | class ValidateReview |
14 | 14 | { |
15 | - const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
15 | + const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
16 | 16 | |
17 | - const RECAPTCHA_DISABLED = 0; |
|
18 | - const RECAPTCHA_EMPTY = 1; |
|
19 | - const RECAPTCHA_FAILED = 2; |
|
20 | - const RECAPTCHA_INVALID = 3; |
|
21 | - const RECAPTCHA_VALID = 4; |
|
17 | + const RECAPTCHA_DISABLED = 0; |
|
18 | + const RECAPTCHA_EMPTY = 1; |
|
19 | + const RECAPTCHA_FAILED = 2; |
|
20 | + const RECAPTCHA_INVALID = 3; |
|
21 | + const RECAPTCHA_VALID = 4; |
|
22 | 22 | |
23 | - const VALIDATION_RULES = [ |
|
24 | - 'content' => 'required', |
|
25 | - 'email' => 'required|email', |
|
26 | - 'name' => 'required', |
|
27 | - 'rating' => 'required|number|between:1,5', |
|
28 | - 'terms' => 'accepted', |
|
29 | - 'title' => 'required', |
|
30 | - ]; |
|
23 | + const VALIDATION_RULES = [ |
|
24 | + 'content' => 'required', |
|
25 | + 'email' => 'required|email', |
|
26 | + 'name' => 'required', |
|
27 | + 'rating' => 'required|number|between:1,5', |
|
28 | + 'terms' => 'accepted', |
|
29 | + 'title' => 'required', |
|
30 | + ]; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var string|void |
|
34 | - */ |
|
35 | - public $error; |
|
32 | + /** |
|
33 | + * @var string|void |
|
34 | + */ |
|
35 | + public $error; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $form_id; |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $form_id; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var bool |
|
44 | - */ |
|
45 | - public $recaptchaIsUnset = false; |
|
42 | + /** |
|
43 | + * @var bool |
|
44 | + */ |
|
45 | + public $recaptchaIsUnset = false; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - public $request; |
|
47 | + /** |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + public $request; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $options; |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $options; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return static |
|
59 | - */ |
|
60 | - public function validate(array $request) |
|
61 | - { |
|
62 | - $this->form_id = $request['form_id']; |
|
63 | - $this->options = glsr(OptionManager::class)->all(); |
|
64 | - $this->request = $this->validateRequest($request); |
|
65 | - $this->validateCustom(); |
|
66 | - $this->validateHoneyPot(); |
|
67 | - $this->validateReviewLimits(); |
|
68 | - $this->validateBlacklist(); |
|
69 | - $this->validateAkismet(); |
|
70 | - $this->validateRecaptcha(); |
|
71 | - if (!empty($this->error)) { |
|
72 | - $this->setSessionValues('message', $this->error); |
|
73 | - } |
|
74 | - return $this; |
|
75 | - } |
|
57 | + /** |
|
58 | + * @return static |
|
59 | + */ |
|
60 | + public function validate(array $request) |
|
61 | + { |
|
62 | + $this->form_id = $request['form_id']; |
|
63 | + $this->options = glsr(OptionManager::class)->all(); |
|
64 | + $this->request = $this->validateRequest($request); |
|
65 | + $this->validateCustom(); |
|
66 | + $this->validateHoneyPot(); |
|
67 | + $this->validateReviewLimits(); |
|
68 | + $this->validateBlacklist(); |
|
69 | + $this->validateAkismet(); |
|
70 | + $this->validateRecaptcha(); |
|
71 | + if (!empty($this->error)) { |
|
72 | + $this->setSessionValues('message', $this->error); |
|
73 | + } |
|
74 | + return $this; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string $path |
|
79 | - * @param mixed $fallback |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - protected function getOption($path, $fallback = '') |
|
83 | - { |
|
84 | - return glsr(Helper::class)->dataGet($this->options, $path, $fallback); |
|
85 | - } |
|
77 | + /** |
|
78 | + * @param string $path |
|
79 | + * @param mixed $fallback |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + protected function getOption($path, $fallback = '') |
|
83 | + { |
|
84 | + return glsr(Helper::class)->dataGet($this->options, $path, $fallback); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return int |
|
89 | - */ |
|
90 | - protected function getRecaptchaStatus() |
|
91 | - { |
|
92 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
93 | - return static::RECAPTCHA_DISABLED; |
|
94 | - } |
|
95 | - if (empty($this->request['_recaptcha-token'])) { |
|
96 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
97 | - ? static::RECAPTCHA_EMPTY |
|
98 | - : static::RECAPTCHA_FAILED; |
|
99 | - } |
|
100 | - return $this->getRecaptchaTokenStatus(); |
|
101 | - } |
|
87 | + /** |
|
88 | + * @return int |
|
89 | + */ |
|
90 | + protected function getRecaptchaStatus() |
|
91 | + { |
|
92 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
93 | + return static::RECAPTCHA_DISABLED; |
|
94 | + } |
|
95 | + if (empty($this->request['_recaptcha-token'])) { |
|
96 | + return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
97 | + ? static::RECAPTCHA_EMPTY |
|
98 | + : static::RECAPTCHA_FAILED; |
|
99 | + } |
|
100 | + return $this->getRecaptchaTokenStatus(); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - protected function getRecaptchaTokenStatus() |
|
107 | - { |
|
108 | - $endpoint = add_query_arg([ |
|
109 | - 'remoteip' => glsr(Helper::class)->getIpAddress(), |
|
110 | - 'response' => $this->request['_recaptcha-token'], |
|
111 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
112 | - ], static::RECAPTCHA_ENDPOINT); |
|
113 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
114 | - glsr_log()->error($response->get_error_message()); |
|
115 | - return static::RECAPTCHA_FAILED; |
|
116 | - } |
|
117 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
118 | - if (!empty($response->success)) { |
|
119 | - return boolval($response->success) |
|
120 | - ? static::RECAPTCHA_VALID |
|
121 | - : static::RECAPTCHA_INVALID; |
|
122 | - } |
|
123 | - foreach ($response->{'error-codes'} as $error) { |
|
124 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
125 | - } |
|
126 | - return static::RECAPTCHA_INVALID; |
|
127 | - } |
|
103 | + /** |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + protected function getRecaptchaTokenStatus() |
|
107 | + { |
|
108 | + $endpoint = add_query_arg([ |
|
109 | + 'remoteip' => glsr(Helper::class)->getIpAddress(), |
|
110 | + 'response' => $this->request['_recaptcha-token'], |
|
111 | + 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
112 | + ], static::RECAPTCHA_ENDPOINT); |
|
113 | + if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
114 | + glsr_log()->error($response->get_error_message()); |
|
115 | + return static::RECAPTCHA_FAILED; |
|
116 | + } |
|
117 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
118 | + if (!empty($response->success)) { |
|
119 | + return boolval($response->success) |
|
120 | + ? static::RECAPTCHA_VALID |
|
121 | + : static::RECAPTCHA_INVALID; |
|
122 | + } |
|
123 | + foreach ($response->{'error-codes'} as $error) { |
|
124 | + glsr_log()->error('reCAPTCHA error: '.$error); |
|
125 | + } |
|
126 | + return static::RECAPTCHA_INVALID; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - protected function getValidationRules(array $request) |
|
133 | - { |
|
134 | - $rules = array_intersect_key( |
|
135 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
136 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
137 | - ); |
|
138 | - $excluded = explode(',', glsr_get($request, 'excluded')); |
|
139 | - return array_diff_key($rules, array_flip($excluded)); |
|
140 | - } |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + protected function getValidationRules(array $request) |
|
133 | + { |
|
134 | + $rules = array_intersect_key( |
|
135 | + apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
136 | + array_flip($this->getOption('settings.submissions.required', [])) |
|
137 | + ); |
|
138 | + $excluded = explode(',', glsr_get($request, 'excluded')); |
|
139 | + return array_diff_key($rules, array_flip($excluded)); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - protected function isRequestValid(array $request) |
|
146 | - { |
|
147 | - $rules = $this->getValidationRules($request); |
|
148 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
149 | - if (empty($errors)) { |
|
150 | - return true; |
|
151 | - } |
|
152 | - $this->setSessionValues('errors', $errors); |
|
153 | - $this->setSessionValues('values', $request); |
|
154 | - return false; |
|
155 | - } |
|
142 | + /** |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + protected function isRequestValid(array $request) |
|
146 | + { |
|
147 | + $rules = $this->getValidationRules($request); |
|
148 | + $errors = glsr(Validator::class)->validate($request, $rules); |
|
149 | + if (empty($errors)) { |
|
150 | + return true; |
|
151 | + } |
|
152 | + $this->setSessionValues('errors', $errors); |
|
153 | + $this->setSessionValues('values', $request); |
|
154 | + return false; |
|
155 | + } |
|
156 | 156 | |
157 | - protected function setError($message, $loggedMessage = '') |
|
158 | - { |
|
159 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
160 | - $this->error = $message; |
|
161 | - } |
|
157 | + protected function setError($message, $loggedMessage = '') |
|
158 | + { |
|
159 | + $this->setSessionValues('errors', [], $loggedMessage); |
|
160 | + $this->error = $message; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @param string $type |
|
165 | - * @param mixed $value |
|
166 | - * @param string $loggedMessage |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
170 | - { |
|
171 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
172 | - if (!empty($loggedMessage)) { |
|
173 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
174 | - } |
|
175 | - } |
|
163 | + /** |
|
164 | + * @param string $type |
|
165 | + * @param mixed $value |
|
166 | + * @param string $loggedMessage |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + protected function setSessionValues($type, $value, $loggedMessage = '') |
|
170 | + { |
|
171 | + glsr()->sessionSet($this->form_id.$type, $value); |
|
172 | + if (!empty($loggedMessage)) { |
|
173 | + glsr_log()->warning($loggedMessage)->debug($this->request); |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - protected function validateAkismet() |
|
181 | - { |
|
182 | - if (!empty($this->error)) { |
|
183 | - return; |
|
184 | - } |
|
185 | - if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
186 | - return; |
|
187 | - } |
|
188 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
189 | - 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
190 | - ); |
|
191 | - } |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + protected function validateAkismet() |
|
181 | + { |
|
182 | + if (!empty($this->error)) { |
|
183 | + return; |
|
184 | + } |
|
185 | + if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
186 | + return; |
|
187 | + } |
|
188 | + $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
189 | + 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
190 | + ); |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * @return void |
|
195 | - */ |
|
196 | - protected function validateBlacklist() |
|
197 | - { |
|
198 | - if (!empty($this->error)) { |
|
199 | - return; |
|
200 | - } |
|
201 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
202 | - return; |
|
203 | - } |
|
204 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
205 | - if ('reject' != $blacklistAction) { |
|
206 | - $this->request['blacklisted'] = true; |
|
207 | - return; |
|
208 | - } |
|
209 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
210 | - 'Blacklisted submission detected:' |
|
211 | - ); |
|
212 | - } |
|
193 | + /** |
|
194 | + * @return void |
|
195 | + */ |
|
196 | + protected function validateBlacklist() |
|
197 | + { |
|
198 | + if (!empty($this->error)) { |
|
199 | + return; |
|
200 | + } |
|
201 | + if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
202 | + return; |
|
203 | + } |
|
204 | + $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
205 | + if ('reject' != $blacklistAction) { |
|
206 | + $this->request['blacklisted'] = true; |
|
207 | + return; |
|
208 | + } |
|
209 | + $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
210 | + 'Blacklisted submission detected:' |
|
211 | + ); |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * @return void |
|
216 | - */ |
|
217 | - protected function validateCustom() |
|
218 | - { |
|
219 | - if (!empty($this->error)) { |
|
220 | - return; |
|
221 | - } |
|
222 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
223 | - if (true === $validated) { |
|
224 | - return; |
|
225 | - } |
|
226 | - $errorMessage = is_string($validated) |
|
227 | - ? $validated |
|
228 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
229 | - $this->setError($errorMessage); |
|
230 | - $this->setSessionValues('values', $this->request); |
|
231 | - } |
|
214 | + /** |
|
215 | + * @return void |
|
216 | + */ |
|
217 | + protected function validateCustom() |
|
218 | + { |
|
219 | + if (!empty($this->error)) { |
|
220 | + return; |
|
221 | + } |
|
222 | + $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
223 | + if (true === $validated) { |
|
224 | + return; |
|
225 | + } |
|
226 | + $errorMessage = is_string($validated) |
|
227 | + ? $validated |
|
228 | + : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
229 | + $this->setError($errorMessage); |
|
230 | + $this->setSessionValues('values', $this->request); |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - protected function validateHoneyPot() |
|
237 | - { |
|
238 | - if (!empty($this->error)) { |
|
239 | - return; |
|
240 | - } |
|
241 | - if (empty($this->request['gotcha'])) { |
|
242 | - return; |
|
243 | - } |
|
244 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
245 | - 'The Honeypot caught a bad submission:' |
|
246 | - ); |
|
247 | - } |
|
233 | + /** |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + protected function validateHoneyPot() |
|
237 | + { |
|
238 | + if (!empty($this->error)) { |
|
239 | + return; |
|
240 | + } |
|
241 | + if (empty($this->request['gotcha'])) { |
|
242 | + return; |
|
243 | + } |
|
244 | + $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
245 | + 'The Honeypot caught a bad submission:' |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @return void |
|
251 | - */ |
|
252 | - protected function validateReviewLimits() |
|
253 | - { |
|
254 | - if (!empty($this->error)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - if (!glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
258 | - return; |
|
259 | - } |
|
260 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
261 | - } |
|
249 | + /** |
|
250 | + * @return void |
|
251 | + */ |
|
252 | + protected function validateReviewLimits() |
|
253 | + { |
|
254 | + if (!empty($this->error)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + if (!glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
258 | + return; |
|
259 | + } |
|
260 | + $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * @return void |
|
265 | - */ |
|
266 | - protected function validateRecaptcha() |
|
267 | - { |
|
268 | - if (!empty($this->error)) { |
|
269 | - return; |
|
270 | - } |
|
271 | - $status = $this->getRecaptchaStatus(); |
|
272 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
273 | - return; |
|
274 | - } |
|
275 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
276 | - $this->setSessionValues('recaptcha', 'unset'); |
|
277 | - $this->recaptchaIsUnset = true; |
|
278 | - return; |
|
279 | - } |
|
280 | - $this->setSessionValues('recaptcha', 'reset'); |
|
281 | - $errors = [ |
|
282 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
283 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
284 | - ]; |
|
285 | - $this->setError($errors[$status]); |
|
286 | - } |
|
263 | + /** |
|
264 | + * @return void |
|
265 | + */ |
|
266 | + protected function validateRecaptcha() |
|
267 | + { |
|
268 | + if (!empty($this->error)) { |
|
269 | + return; |
|
270 | + } |
|
271 | + $status = $this->getRecaptchaStatus(); |
|
272 | + if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
273 | + return; |
|
274 | + } |
|
275 | + if (static::RECAPTCHA_EMPTY === $status) { |
|
276 | + $this->setSessionValues('recaptcha', 'unset'); |
|
277 | + $this->recaptchaIsUnset = true; |
|
278 | + return; |
|
279 | + } |
|
280 | + $this->setSessionValues('recaptcha', 'reset'); |
|
281 | + $errors = [ |
|
282 | + static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
283 | + static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
284 | + ]; |
|
285 | + $this->setError($errors[$status]); |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * @return array |
|
290 | - */ |
|
291 | - protected function validateRequest(array $request) |
|
292 | - { |
|
293 | - if (!$this->isRequestValid($request)) { |
|
294 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
295 | - return $request; |
|
296 | - } |
|
297 | - return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
298 | - } |
|
288 | + /** |
|
289 | + * @return array |
|
290 | + */ |
|
291 | + protected function validateRequest(array $request) |
|
292 | + { |
|
293 | + if (!$this->isRequestValid($request)) { |
|
294 | + $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
295 | + return $request; |
|
296 | + } |
|
297 | + return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
298 | + } |
|
299 | 299 | } |
@@ -7,103 +7,103 @@ |
||
7 | 7 | |
8 | 8 | class ReviewLimits |
9 | 9 | { |
10 | - protected $request; |
|
10 | + protected $request; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @return array |
|
14 | - * @filter site-reviews/get/reviews/query |
|
15 | - */ |
|
16 | - public function filterReviewsQuery(array $parameters, array $args) |
|
17 | - { |
|
18 | - if ($authorId = get_current_user_id()) { |
|
19 | - $parameters['author'] = $authorId; |
|
20 | - } |
|
21 | - $parameters['post_status'] = ['pending', 'publish']; |
|
22 | - return apply_filters('site-reviews/reviews-limits/query', $parameters, $args); |
|
23 | - } |
|
12 | + /** |
|
13 | + * @return array |
|
14 | + * @filter site-reviews/get/reviews/query |
|
15 | + */ |
|
16 | + public function filterReviewsQuery(array $parameters, array $args) |
|
17 | + { |
|
18 | + if ($authorId = get_current_user_id()) { |
|
19 | + $parameters['author'] = $authorId; |
|
20 | + } |
|
21 | + $parameters['post_status'] = ['pending', 'publish']; |
|
22 | + return apply_filters('site-reviews/reviews-limits/query', $parameters, $args); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function hasReachedLimit(array $request = []) |
|
29 | - { |
|
30 | - $this->request = $request; |
|
31 | - $method = glsr(Helper::class)->buildMethodName( |
|
32 | - glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
33 | - ); |
|
34 | - return method_exists($this, $method) |
|
35 | - ? !call_user_func([$this, $method]) |
|
36 | - : false; |
|
37 | - } |
|
25 | + /** |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function hasReachedLimit(array $request = []) |
|
29 | + { |
|
30 | + $this->request = $request; |
|
31 | + $method = glsr(Helper::class)->buildMethodName( |
|
32 | + glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
33 | + ); |
|
34 | + return method_exists($this, $method) |
|
35 | + ? !call_user_func([$this, $method]) |
|
36 | + : false; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $value |
|
41 | - * @param string $whitelist |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function isWhitelisted($value, $whitelist) |
|
45 | - { |
|
46 | - if (empty($whitelist)) { |
|
47 | - return false; |
|
48 | - } |
|
49 | - return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
50 | - } |
|
39 | + /** |
|
40 | + * @param string $value |
|
41 | + * @param string $whitelist |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function isWhitelisted($value, $whitelist) |
|
45 | + { |
|
46 | + if (empty($whitelist)) { |
|
47 | + return false; |
|
48 | + } |
|
49 | + return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $whitelistName |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function getWhitelist($whitelistName) |
|
57 | - { |
|
58 | - return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
59 | - } |
|
52 | + /** |
|
53 | + * @param string $whitelistName |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function getWhitelist($whitelistName) |
|
57 | + { |
|
58 | + return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - protected function validate($key, $value, $addMetaQuery = true) |
|
65 | - { |
|
66 | - if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
67 | - return true; |
|
68 | - } |
|
69 | - add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
70 | - $args = ['assigned_to' => glsr_get($this->request, 'assign_to')]; |
|
71 | - if ($addMetaQuery) { |
|
72 | - $args[$key] = $value; |
|
73 | - } |
|
74 | - $reviews = glsr_get_reviews($args); |
|
75 | - remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
76 | - return 0 === count($reviews); |
|
77 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + protected function validate($key, $value, $addMetaQuery = true) |
|
65 | + { |
|
66 | + if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
67 | + return true; |
|
68 | + } |
|
69 | + add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
70 | + $args = ['assigned_to' => glsr_get($this->request, 'assign_to')]; |
|
71 | + if ($addMetaQuery) { |
|
72 | + $args[$key] = $value; |
|
73 | + } |
|
74 | + $reviews = glsr_get_reviews($args); |
|
75 | + remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
76 | + return 0 === count($reviews); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - protected function validateByEmail() |
|
83 | - { |
|
84 | - glsr_log()->debug('Email is: '.glsr_get($this->request, 'email')); |
|
85 | - return $this->validate('email', glsr_get($this->request, 'email')); |
|
86 | - } |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + protected function validateByEmail() |
|
83 | + { |
|
84 | + glsr_log()->debug('Email is: '.glsr_get($this->request, 'email')); |
|
85 | + return $this->validate('email', glsr_get($this->request, 'email')); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - protected function validateByIpAddress() |
|
92 | - { |
|
93 | - glsr_log()->debug('IP Address is: '.glsr_get($this->request, 'ip_address')); |
|
94 | - return $this->validate('ip_address', glsr_get($this->request, 'ip_address')); |
|
95 | - } |
|
88 | + /** |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + protected function validateByIpAddress() |
|
92 | + { |
|
93 | + glsr_log()->debug('IP Address is: '.glsr_get($this->request, 'ip_address')); |
|
94 | + return $this->validate('ip_address', glsr_get($this->request, 'ip_address')); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - protected function validateByUsername() |
|
101 | - { |
|
102 | - $user = wp_get_current_user(); |
|
103 | - if (!$user->exists()) { |
|
104 | - return true; |
|
105 | - } |
|
106 | - glsr_log()->debug('Username is: '.$user->user_login); |
|
107 | - return $this->validate('username', $user->user_login, false); |
|
108 | - } |
|
97 | + /** |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + protected function validateByUsername() |
|
101 | + { |
|
102 | + $user = wp_get_current_user(); |
|
103 | + if (!$user->exists()) { |
|
104 | + return true; |
|
105 | + } |
|
106 | + glsr_log()->debug('Username is: '.$user->user_login); |
|
107 | + return $this->validate('username', $user->user_login, false); |
|
108 | + } |
|
109 | 109 | } |
@@ -10,158 +10,158 @@ |
||
10 | 10 | |
11 | 11 | class EnqueueAdminAssets |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $pointers; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $pointers; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function handle(Command $command) |
|
22 | - { |
|
23 | - $this->generatePointers($command->pointers); |
|
24 | - $this->enqueueAssets(); |
|
25 | - $this->localizeAssets(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function handle(Command $command) |
|
22 | + { |
|
23 | + $this->generatePointers($command->pointers); |
|
24 | + $this->enqueueAssets(); |
|
25 | + $this->localizeAssets(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function enqueueAssets() |
|
32 | - { |
|
33 | - wp_enqueue_style( |
|
34 | - Application::ID, |
|
35 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
36 | - [], |
|
37 | - glsr()->version |
|
38 | - ); |
|
39 | - if (!$this->isCurrentScreen()) { |
|
40 | - return; |
|
41 | - } |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID, |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | - $this->getDependencies(), |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
52 | - } |
|
53 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function enqueueAssets() |
|
32 | + { |
|
33 | + wp_enqueue_style( |
|
34 | + Application::ID, |
|
35 | + glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
36 | + [], |
|
37 | + glsr()->version |
|
38 | + ); |
|
39 | + if (!$this->isCurrentScreen()) { |
|
40 | + return; |
|
41 | + } |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID, |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | + $this->getDependencies(), |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + if (!empty($this->pointers)) { |
|
50 | + wp_enqueue_style('wp-pointer'); |
|
51 | + wp_enqueue_script('wp-pointer'); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function localizeAssets() |
|
59 | - { |
|
60 | - $variables = [ |
|
61 | - 'action' => Application::PREFIX.'action', |
|
62 | - 'addons' => [], |
|
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | - 'hideoptions' => [ |
|
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | - ], |
|
69 | - 'nameprefix' => Application::ID, |
|
70 | - 'nonce' => [ |
|
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | - ], |
|
79 | - 'pointers' => $this->pointers, |
|
80 | - 'shortcodes' => [], |
|
81 | - 'tinymce' => [ |
|
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | - ], |
|
84 | - ]; |
|
85 | - if (user_can_richedit()) { |
|
86 | - $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | - } |
|
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function localizeAssets() |
|
59 | + { |
|
60 | + $variables = [ |
|
61 | + 'action' => Application::PREFIX.'action', |
|
62 | + 'addons' => [], |
|
63 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | + 'hideoptions' => [ |
|
65 | + 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | + ], |
|
69 | + 'nameprefix' => Application::ID, |
|
70 | + 'nonce' => [ |
|
71 | + 'change-status' => wp_create_nonce('change-status'), |
|
72 | + 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | + 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | + 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | + 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | + 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | + 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | + ], |
|
79 | + 'pointers' => $this->pointers, |
|
80 | + 'shortcodes' => [], |
|
81 | + 'tinymce' => [ |
|
82 | + 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | + ], |
|
84 | + ]; |
|
85 | + if (user_can_richedit()) { |
|
86 | + $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | + } |
|
88 | + $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | + wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getDependencies() |
|
96 | - { |
|
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
99 | - 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | - ]); |
|
101 | - return $dependencies; |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getDependencies() |
|
96 | + { |
|
97 | + $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | + $dependencies = array_merge($dependencies, [ |
|
99 | + 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | + ]); |
|
101 | + return $dependencies; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function generatePointer(array $pointer) |
|
108 | - { |
|
109 | - return [ |
|
110 | - 'id' => $pointer['id'], |
|
111 | - 'options' => [ |
|
112 | - 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | - 'position' => $pointer['position'], |
|
114 | - ], |
|
115 | - 'screen' => $pointer['screen'], |
|
116 | - 'target' => $pointer['target'], |
|
117 | - ]; |
|
118 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function generatePointer(array $pointer) |
|
108 | + { |
|
109 | + return [ |
|
110 | + 'id' => $pointer['id'], |
|
111 | + 'options' => [ |
|
112 | + 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | + 'position' => $pointer['position'], |
|
114 | + ], |
|
115 | + 'screen' => $pointer['screen'], |
|
116 | + 'target' => $pointer['target'], |
|
117 | + ]; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function generatePointers(array $pointers) |
|
124 | - { |
|
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | - $generatedPointers = []; |
|
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | - } |
|
137 | - $this->pointers = $generatedPointers; |
|
138 | - } |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function generatePointers(array $pointers) |
|
124 | + { |
|
125 | + $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | + $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | + $generatedPointers = []; |
|
128 | + foreach ($pointers as $pointer) { |
|
129 | + if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | + } |
|
137 | + $this->pointers = $generatedPointers; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isCurrentScreen() |
|
144 | - { |
|
145 | - $screen = glsr_current_screen(); |
|
146 | - return Application::POST_TYPE == $screen->post_type |
|
147 | - || 'dashboard' == $screen->id |
|
148 | - || 'plugins_page_'.Application::ID == $screen->id |
|
149 | - || 'post' == $screen->base |
|
150 | - || 'widgets' == $screen->id; |
|
151 | - } |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isCurrentScreen() |
|
144 | + { |
|
145 | + $screen = glsr_current_screen(); |
|
146 | + return Application::POST_TYPE == $screen->post_type |
|
147 | + || 'dashboard' == $screen->id |
|
148 | + || 'plugins_page_'.Application::ID == $screen->id |
|
149 | + || 'post' == $screen->base |
|
150 | + || 'widgets' == $screen->id; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function localizeShortcodes() |
|
157 | - { |
|
158 | - $variables = []; |
|
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - $variables[$tag] = $args['required']; |
|
164 | - } |
|
165 | - return $variables; |
|
166 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function localizeShortcodes() |
|
157 | + { |
|
158 | + $variables = []; |
|
159 | + foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | + if (empty($args['required'])) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + $variables[$tag] = $args['required']; |
|
164 | + } |
|
165 | + return $variables; |
|
166 | + } |
|
167 | 167 | } |
@@ -15,222 +15,222 @@ |
||
15 | 15 | |
16 | 16 | class AdminController extends Controller |
17 | 17 | { |
18 | - /** |
|
19 | - * @return void |
|
20 | - * @action admin_enqueue_scripts |
|
21 | - */ |
|
22 | - public function enqueueAssets() |
|
23 | - { |
|
24 | - $command = new EnqueueAdminAssets([ |
|
25 | - 'pointers' => [[ |
|
26 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
27 | - 'id' => 'glsr-pointer-pinned', |
|
28 | - 'position' => [ |
|
29 | - 'edge' => 'right', |
|
30 | - 'align' => 'middle', |
|
31 | - ], |
|
32 | - 'screen' => Application::POST_TYPE, |
|
33 | - 'target' => '#misc-pub-pinned', |
|
34 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
35 | - ]], |
|
36 | - ]); |
|
37 | - $this->execute($command); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return array |
|
42 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
43 | - */ |
|
44 | - public function filterActionLinks(array $links) |
|
45 | - { |
|
46 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
47 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
48 | - ]); |
|
49 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
50 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
51 | - ]); |
|
52 | - return $links; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array $capabilities |
|
57 | - * @param string $capability |
|
58 | - * @return array |
|
59 | - * @filter map_meta_cap |
|
60 | - */ |
|
61 | - public function filterCreateCapability($capabilities, $capability) |
|
62 | - { |
|
63 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
64 | - $capabilities[] = 'do_not_allow'; |
|
65 | - } |
|
66 | - return $capabilities; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @param array $items |
|
71 | - * @return array |
|
72 | - * @filter dashboard_glance_items |
|
73 | - */ |
|
74 | - public function filterDashboardGlanceItems($items) |
|
75 | - { |
|
76 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
77 | - if (empty($postCount->publish)) { |
|
78 | - return $items; |
|
79 | - } |
|
80 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
81 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
82 | - $items = glsr(Helper::class)->consolidateArray($items); |
|
83 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
84 | - ? glsr(Builder::class)->a($text, [ |
|
85 | - 'class' => 'glsr-review-count', |
|
86 | - 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
87 | - ]) |
|
88 | - : glsr(Builder::class)->span($text, [ |
|
89 | - 'class' => 'glsr-review-count', |
|
90 | - ]); |
|
91 | - return $items; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param array $plugins |
|
96 | - * @return array |
|
97 | - * @filter mce_external_plugins |
|
98 | - */ |
|
99 | - public function filterTinymcePlugins($plugins) |
|
100 | - { |
|
101 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
102 | - $plugins = glsr(Helper::class)->consolidateArray($plugins); |
|
103 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
104 | - } |
|
105 | - return $plugins; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @return void |
|
110 | - * @action admin_init |
|
111 | - */ |
|
112 | - public function registerTinymcePopups() |
|
113 | - { |
|
114 | - $command = new RegisterTinymcePopups([ |
|
115 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
116 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
117 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
118 | - ]); |
|
119 | - $this->execute($command); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param string $editorId |
|
124 | - * @return void|null |
|
125 | - * @action media_buttons |
|
126 | - */ |
|
127 | - public function renderTinymceButton($editorId) |
|
128 | - { |
|
129 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
130 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
131 | - return; |
|
132 | - } |
|
133 | - $shortcodes = []; |
|
134 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
135 | - $shortcodes[$shortcode] = $values; |
|
136 | - } |
|
137 | - if (empty($shortcodes)) { |
|
138 | - return; |
|
139 | - } |
|
140 | - glsr()->render('partials/editor/tinymce', [ |
|
141 | - 'shortcodes' => $shortcodes, |
|
142 | - ]); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public function routerClearConsole() |
|
149 | - { |
|
150 | - glsr(Console::class)->clear(); |
|
151 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function routerFetchConsole() |
|
158 | - { |
|
159 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @param bool $showNotice |
|
164 | - * @return void |
|
165 | - */ |
|
166 | - public function routerCountReviews($showNotice = true) |
|
167 | - { |
|
168 | - glsr(CountsManager::class)->countAll(); |
|
169 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
170 | - if ($showNotice) { |
|
171 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - public function routerDownloadConsole() |
|
179 | - { |
|
180 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public function routerDownloadSystemInfo() |
|
187 | - { |
|
188 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - public function routerExportSettings() |
|
195 | - { |
|
196 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public function routerImportSettings() |
|
203 | - { |
|
204 | - $file = $_FILES['import-file']; |
|
205 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
206 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
207 | - } |
|
208 | - if ('application/json' !== $file['type'] || !glsr(Helper::class)->endsWith('.json', $file['name'])) { |
|
209 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
210 | - } |
|
211 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
212 | - if (empty($settings)) { |
|
213 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
214 | - } |
|
215 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
216 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @param int $errorCode |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - protected function getUploadError($errorCode) |
|
224 | - { |
|
225 | - $errors = [ |
|
226 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
227 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
228 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
229 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
230 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
231 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
232 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
233 | - ]; |
|
234 | - return glsr_get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
235 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + * @action admin_enqueue_scripts |
|
21 | + */ |
|
22 | + public function enqueueAssets() |
|
23 | + { |
|
24 | + $command = new EnqueueAdminAssets([ |
|
25 | + 'pointers' => [[ |
|
26 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
27 | + 'id' => 'glsr-pointer-pinned', |
|
28 | + 'position' => [ |
|
29 | + 'edge' => 'right', |
|
30 | + 'align' => 'middle', |
|
31 | + ], |
|
32 | + 'screen' => Application::POST_TYPE, |
|
33 | + 'target' => '#misc-pub-pinned', |
|
34 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
35 | + ]], |
|
36 | + ]); |
|
37 | + $this->execute($command); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
43 | + */ |
|
44 | + public function filterActionLinks(array $links) |
|
45 | + { |
|
46 | + $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
47 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
48 | + ]); |
|
49 | + $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
50 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
51 | + ]); |
|
52 | + return $links; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array $capabilities |
|
57 | + * @param string $capability |
|
58 | + * @return array |
|
59 | + * @filter map_meta_cap |
|
60 | + */ |
|
61 | + public function filterCreateCapability($capabilities, $capability) |
|
62 | + { |
|
63 | + if ($capability == 'create_'.Application::POST_TYPE) { |
|
64 | + $capabilities[] = 'do_not_allow'; |
|
65 | + } |
|
66 | + return $capabilities; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @param array $items |
|
71 | + * @return array |
|
72 | + * @filter dashboard_glance_items |
|
73 | + */ |
|
74 | + public function filterDashboardGlanceItems($items) |
|
75 | + { |
|
76 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
77 | + if (empty($postCount->publish)) { |
|
78 | + return $items; |
|
79 | + } |
|
80 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
81 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
82 | + $items = glsr(Helper::class)->consolidateArray($items); |
|
83 | + $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
84 | + ? glsr(Builder::class)->a($text, [ |
|
85 | + 'class' => 'glsr-review-count', |
|
86 | + 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
87 | + ]) |
|
88 | + : glsr(Builder::class)->span($text, [ |
|
89 | + 'class' => 'glsr-review-count', |
|
90 | + ]); |
|
91 | + return $items; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param array $plugins |
|
96 | + * @return array |
|
97 | + * @filter mce_external_plugins |
|
98 | + */ |
|
99 | + public function filterTinymcePlugins($plugins) |
|
100 | + { |
|
101 | + if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
102 | + $plugins = glsr(Helper::class)->consolidateArray($plugins); |
|
103 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
104 | + } |
|
105 | + return $plugins; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @return void |
|
110 | + * @action admin_init |
|
111 | + */ |
|
112 | + public function registerTinymcePopups() |
|
113 | + { |
|
114 | + $command = new RegisterTinymcePopups([ |
|
115 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
116 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
117 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
118 | + ]); |
|
119 | + $this->execute($command); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param string $editorId |
|
124 | + * @return void|null |
|
125 | + * @action media_buttons |
|
126 | + */ |
|
127 | + public function renderTinymceButton($editorId) |
|
128 | + { |
|
129 | + $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
130 | + if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
131 | + return; |
|
132 | + } |
|
133 | + $shortcodes = []; |
|
134 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
135 | + $shortcodes[$shortcode] = $values; |
|
136 | + } |
|
137 | + if (empty($shortcodes)) { |
|
138 | + return; |
|
139 | + } |
|
140 | + glsr()->render('partials/editor/tinymce', [ |
|
141 | + 'shortcodes' => $shortcodes, |
|
142 | + ]); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public function routerClearConsole() |
|
149 | + { |
|
150 | + glsr(Console::class)->clear(); |
|
151 | + glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function routerFetchConsole() |
|
158 | + { |
|
159 | + glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @param bool $showNotice |
|
164 | + * @return void |
|
165 | + */ |
|
166 | + public function routerCountReviews($showNotice = true) |
|
167 | + { |
|
168 | + glsr(CountsManager::class)->countAll(); |
|
169 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
170 | + if ($showNotice) { |
|
171 | + glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + public function routerDownloadConsole() |
|
179 | + { |
|
180 | + $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public function routerDownloadSystemInfo() |
|
187 | + { |
|
188 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + public function routerExportSettings() |
|
195 | + { |
|
196 | + $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public function routerImportSettings() |
|
203 | + { |
|
204 | + $file = $_FILES['import-file']; |
|
205 | + if (UPLOAD_ERR_OK !== $file['error']) { |
|
206 | + return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
207 | + } |
|
208 | + if ('application/json' !== $file['type'] || !glsr(Helper::class)->endsWith('.json', $file['name'])) { |
|
209 | + return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
210 | + } |
|
211 | + $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
212 | + if (empty($settings)) { |
|
213 | + return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
214 | + } |
|
215 | + glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
216 | + glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @param int $errorCode |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + protected function getUploadError($errorCode) |
|
224 | + { |
|
225 | + $errors = [ |
|
226 | + UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
227 | + UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
228 | + UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
229 | + UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
230 | + UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
231 | + UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
232 | + UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
233 | + ]; |
|
234 | + return glsr_get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
235 | + } |
|
236 | 236 | } |
@@ -7,40 +7,40 @@ |
||
7 | 7 | |
8 | 8 | class EmailDefaults extends Defaults |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - protected function defaults() |
|
14 | - { |
|
15 | - return [ |
|
16 | - 'after' => '', |
|
17 | - 'attachments' => [], |
|
18 | - 'bcc' => '', |
|
19 | - 'before' => '', |
|
20 | - 'cc' => '', |
|
21 | - 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
22 | - 'message' => '', |
|
23 | - 'reply-to' => '', |
|
24 | - 'subject' => '', |
|
25 | - 'template' => '', |
|
26 | - 'template-tags' => [], |
|
27 | - 'to' => '', |
|
28 | - ]; |
|
29 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + protected function defaults() |
|
14 | + { |
|
15 | + return [ |
|
16 | + 'after' => '', |
|
17 | + 'attachments' => [], |
|
18 | + 'bcc' => '', |
|
19 | + 'before' => '', |
|
20 | + 'cc' => '', |
|
21 | + 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
22 | + 'message' => '', |
|
23 | + 'reply-to' => '', |
|
24 | + 'subject' => '', |
|
25 | + 'template' => '', |
|
26 | + 'template-tags' => [], |
|
27 | + 'to' => '', |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - protected function getFromEmail() |
|
35 | - { |
|
36 | - return glsr(OptionManager::class)->getWP('admin_email'); |
|
37 | - } |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + protected function getFromEmail() |
|
35 | + { |
|
36 | + return glsr(OptionManager::class)->getWP('admin_email'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function getFromName() |
|
43 | - { |
|
44 | - return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function getFromName() |
|
43 | + { |
|
44 | + return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
45 | + } |
|
46 | 46 | } |
@@ -14,67 +14,67 @@ |
||
14 | 14 | |
15 | 15 | class Filters implements HooksContract |
16 | 16 | { |
17 | - protected $admin; |
|
18 | - protected $app; |
|
19 | - protected $basename; |
|
20 | - protected $blocks; |
|
21 | - protected $editor; |
|
22 | - protected $listtable; |
|
23 | - protected $main; |
|
24 | - protected $public; |
|
25 | - protected $translator; |
|
26 | - protected $welcome; |
|
17 | + protected $admin; |
|
18 | + protected $app; |
|
19 | + protected $basename; |
|
20 | + protected $blocks; |
|
21 | + protected $editor; |
|
22 | + protected $listtable; |
|
23 | + protected $main; |
|
24 | + protected $public; |
|
25 | + protected $translator; |
|
26 | + protected $welcome; |
|
27 | 27 | |
28 | - public function __construct(Application $app) |
|
29 | - { |
|
30 | - $this->app = $app; |
|
31 | - $this->admin = $app->make(AdminController::class); |
|
32 | - $this->basename = plugin_basename($app->file); |
|
33 | - $this->blocks = $app->make(BlocksController::class); |
|
34 | - $this->editor = $app->make(EditorController::class); |
|
35 | - $this->listtable = $app->make(ListTableController::class); |
|
36 | - $this->main = $app->make(MainController::class); |
|
37 | - $this->public = $app->make(PublicController::class); |
|
38 | - $this->translator = $app->make(Translator::class); |
|
39 | - $this->welcome = $app->make(WelcomeController::class); |
|
40 | - } |
|
28 | + public function __construct(Application $app) |
|
29 | + { |
|
30 | + $this->app = $app; |
|
31 | + $this->admin = $app->make(AdminController::class); |
|
32 | + $this->basename = plugin_basename($app->file); |
|
33 | + $this->blocks = $app->make(BlocksController::class); |
|
34 | + $this->editor = $app->make(EditorController::class); |
|
35 | + $this->listtable = $app->make(ListTableController::class); |
|
36 | + $this->main = $app->make(MainController::class); |
|
37 | + $this->public = $app->make(PublicController::class); |
|
38 | + $this->translator = $app->make(Translator::class); |
|
39 | + $this->welcome = $app->make(WelcomeController::class); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function run() |
|
46 | - { |
|
47 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
48 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
49 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
50 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
51 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
52 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
53 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
54 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
55 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
56 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
57 | - add_filter('gettext', [$this->editor, 'filterPostStatusLabels'], 10, 3); |
|
58 | - add_filter('gettext_with_context', [$this->editor, 'filterPostStatusLabelsWithContext'], 10, 4); |
|
59 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
60 | - add_filter('bulk_post_updated_messages', [$this->listtable, 'filterBulkUpdateMessages'], 10, 2); |
|
61 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
62 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
63 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
64 | - add_filter('display_post_states', [$this->listtable, 'filterPostStates'], 10, 2); |
|
65 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
66 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
67 | - add_filter('ngettext', [$this->listtable, 'filterStatusText'], 10, 5); |
|
68 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
69 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
70 | - add_filter('query_vars', [$this->public, 'filterQueryVars']); |
|
71 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
72 | - add_filter('gettext', [$this->translator, 'filterGettext'], 10, 3); |
|
73 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4); |
|
74 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 10, 5); |
|
75 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6); |
|
76 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
77 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
78 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
79 | - } |
|
42 | + /** |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function run() |
|
46 | + { |
|
47 | + add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
48 | + add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
49 | + add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
50 | + add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
51 | + add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
52 | + add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
53 | + add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
54 | + add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
55 | + add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
56 | + add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
57 | + add_filter('gettext', [$this->editor, 'filterPostStatusLabels'], 10, 3); |
|
58 | + add_filter('gettext_with_context', [$this->editor, 'filterPostStatusLabelsWithContext'], 10, 4); |
|
59 | + add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
60 | + add_filter('bulk_post_updated_messages', [$this->listtable, 'filterBulkUpdateMessages'], 10, 2); |
|
61 | + add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
62 | + add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
63 | + add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
64 | + add_filter('display_post_states', [$this->listtable, 'filterPostStates'], 10, 2); |
|
65 | + add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
66 | + add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
67 | + add_filter('ngettext', [$this->listtable, 'filterStatusText'], 10, 5); |
|
68 | + add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
69 | + add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
70 | + add_filter('query_vars', [$this->public, 'filterQueryVars']); |
|
71 | + add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
72 | + add_filter('gettext', [$this->translator, 'filterGettext'], 10, 3); |
|
73 | + add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4); |
|
74 | + add_filter('ngettext', [$this->translator, 'filterNgettext'], 10, 5); |
|
75 | + add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6); |
|
76 | + add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
77 | + add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
78 | + add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
79 | + } |
|
80 | 80 | } |
@@ -10,94 +10,94 @@ |
||
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 | - 'review_type' => __('Type', 'site-reviews'), |
|
30 | - 'rating' => __('Rating', 'site-reviews'), |
|
31 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
32 | - 'date' => '', |
|
33 | - ], |
|
34 | - 'menu_icon' => 'dashicons-star-half', |
|
35 | - 'menu_name' => glsr()->name, |
|
36 | - 'map_meta_cap' => true, |
|
37 | - 'plural' => __('Reviews', 'site-reviews'), |
|
38 | - 'post_type' => Application::POST_TYPE, |
|
39 | - 'rest_controller_class' => RestReviewController::class, |
|
40 | - 'show_in_rest' => true, |
|
41 | - 'single' => __('Review', 'site-reviews'), |
|
42 | - ]); |
|
43 | - $this->execute($command); |
|
44 | - } |
|
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 | + 'review_type' => __('Type', 'site-reviews'), |
|
30 | + 'rating' => __('Rating', 'site-reviews'), |
|
31 | + 'pinned' => __('Pinned', 'site-reviews'), |
|
32 | + 'date' => '', |
|
33 | + ], |
|
34 | + 'menu_icon' => 'dashicons-star-half', |
|
35 | + 'menu_name' => glsr()->name, |
|
36 | + 'map_meta_cap' => true, |
|
37 | + 'plural' => __('Reviews', 'site-reviews'), |
|
38 | + 'post_type' => Application::POST_TYPE, |
|
39 | + 'rest_controller_class' => RestReviewController::class, |
|
40 | + 'show_in_rest' => true, |
|
41 | + 'single' => __('Review', 'site-reviews'), |
|
42 | + ]); |
|
43 | + $this->execute($command); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return void |
|
48 | - * @action init |
|
49 | - */ |
|
50 | - public function registerShortcodes() |
|
51 | - { |
|
52 | - $command = new RegisterShortcodes([ |
|
53 | - 'site_reviews', |
|
54 | - 'site_reviews_form', |
|
55 | - 'site_reviews_summary', |
|
56 | - ]); |
|
57 | - $this->execute($command); |
|
58 | - } |
|
46 | + /** |
|
47 | + * @return void |
|
48 | + * @action init |
|
49 | + */ |
|
50 | + public function registerShortcodes() |
|
51 | + { |
|
52 | + $command = new RegisterShortcodes([ |
|
53 | + 'site_reviews', |
|
54 | + 'site_reviews_form', |
|
55 | + 'site_reviews_summary', |
|
56 | + ]); |
|
57 | + $this->execute($command); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - * @action init |
|
63 | - */ |
|
64 | - public function registerTaxonomy() |
|
65 | - { |
|
66 | - $command = new RegisterTaxonomy([ |
|
67 | - 'hierarchical' => true, |
|
68 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
69 | - 'public' => false, |
|
70 | - 'rest_controller_class' => RestCategoryController::class, |
|
71 | - 'show_admin_column' => true, |
|
72 | - 'show_in_rest' => true, |
|
73 | - 'show_ui' => true, |
|
74 | - ]); |
|
75 | - $this->execute($command); |
|
76 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + * @action init |
|
63 | + */ |
|
64 | + public function registerTaxonomy() |
|
65 | + { |
|
66 | + $command = new RegisterTaxonomy([ |
|
67 | + 'hierarchical' => true, |
|
68 | + 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
69 | + 'public' => false, |
|
70 | + 'rest_controller_class' => RestCategoryController::class, |
|
71 | + 'show_admin_column' => true, |
|
72 | + 'show_in_rest' => true, |
|
73 | + 'show_ui' => true, |
|
74 | + ]); |
|
75 | + $this->execute($command); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @action widgets_init |
|
81 | - */ |
|
82 | - public function registerWidgets() |
|
83 | - { |
|
84 | - $command = new RegisterWidgets([ |
|
85 | - 'site-reviews' => [ |
|
86 | - 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
87 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
88 | - 'title' => __('Recent Reviews', 'site-reviews'), |
|
89 | - ], |
|
90 | - 'site-reviews-form' => [ |
|
91 | - 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
92 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
93 | - 'title' => __('Submit a Review', 'site-reviews'), |
|
94 | - ], |
|
95 | - 'site-reviews-summary' => [ |
|
96 | - 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
97 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
98 | - 'title' => __('Summary of Reviews', 'site-reviews'), |
|
99 | - ], |
|
100 | - ]); |
|
101 | - $this->execute($command); |
|
102 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @action widgets_init |
|
81 | + */ |
|
82 | + public function registerWidgets() |
|
83 | + { |
|
84 | + $command = new RegisterWidgets([ |
|
85 | + 'site-reviews' => [ |
|
86 | + 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
87 | + 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
88 | + 'title' => __('Recent Reviews', 'site-reviews'), |
|
89 | + ], |
|
90 | + 'site-reviews-form' => [ |
|
91 | + 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
92 | + 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
93 | + 'title' => __('Submit a Review', 'site-reviews'), |
|
94 | + ], |
|
95 | + 'site-reviews-summary' => [ |
|
96 | + 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
97 | + 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
98 | + 'title' => __('Summary of Reviews', 'site-reviews'), |
|
99 | + ], |
|
100 | + ]); |
|
101 | + $this->execute($command); |
|
102 | + } |
|
103 | 103 | } |