@@ -8,86 +8,86 @@ |
||
8 | 8 | |
9 | 9 | class NoticeController extends Controller |
10 | 10 | { |
11 | - const USER_META_KEY = '_glsr_notices'; |
|
11 | + const USER_META_KEY = '_glsr_notices'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return void |
|
15 | - * @action admin_notices |
|
16 | - */ |
|
17 | - public function filterAdminNotices() |
|
18 | - { |
|
19 | - $screen = glsr_current_screen(); |
|
20 | - $this->renderRebusifyNotice($screen->post_type); |
|
21 | - $this->renderAddonsNotice($screen->id); |
|
22 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + * @action admin_notices |
|
16 | + */ |
|
17 | + public function filterAdminNotices() |
|
18 | + { |
|
19 | + $screen = glsr_current_screen(); |
|
20 | + $this->renderRebusifyNotice($screen->post_type); |
|
21 | + $this->renderAddonsNotice($screen->id); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function routerDismissNotice(array $request) |
|
28 | - { |
|
29 | - $key = glsr_get($request, 'notice'); |
|
30 | - $method = glsr(Helper::class)->buildMethodName($key, 'dismiss'); |
|
31 | - if (method_exists($this, $method)) { |
|
32 | - call_user_func([$this, $method], $key); |
|
33 | - } |
|
34 | - } |
|
24 | + /** |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function routerDismissNotice(array $request) |
|
28 | + { |
|
29 | + $key = glsr_get($request, 'notice'); |
|
30 | + $method = glsr(Helper::class)->buildMethodName($key, 'dismiss'); |
|
31 | + if (method_exists($this, $method)) { |
|
32 | + call_user_func([$this, $method], $key); |
|
33 | + } |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $key |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - protected function dismissRebusify($key) |
|
41 | - { |
|
42 | - $this->setUserMeta($key, glsr()->version('major')); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param string $key |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + protected function dismissRebusify($key) |
|
41 | + { |
|
42 | + $this->setUserMeta($key, glsr()->version('major')); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $key |
|
47 | - * @param mixed $fallback |
|
48 | - * @return mixed |
|
49 | - */ |
|
50 | - protected function getUserMeta($key, $fallback) |
|
51 | - { |
|
52 | - $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true); |
|
53 | - return glsr_get($meta, $key, $fallback); |
|
54 | - } |
|
45 | + /** |
|
46 | + * @param string $key |
|
47 | + * @param mixed $fallback |
|
48 | + * @return mixed |
|
49 | + */ |
|
50 | + protected function getUserMeta($key, $fallback) |
|
51 | + { |
|
52 | + $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true); |
|
53 | + return glsr_get($meta, $key, $fallback); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $screenId |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - protected function renderAddonsNotice($screenId) |
|
61 | - { |
|
62 | - if (Application::POST_TYPE.'_page_addons' == $screenId) { |
|
63 | - echo glsr()->render('partials/notices/addons'); |
|
64 | - } |
|
65 | - } |
|
56 | + /** |
|
57 | + * @param string $screenId |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + protected function renderAddonsNotice($screenId) |
|
61 | + { |
|
62 | + if (Application::POST_TYPE.'_page_addons' == $screenId) { |
|
63 | + echo glsr()->render('partials/notices/addons'); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param string $screenPostType |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - protected function renderRebusifyNotice($screenPostType) |
|
72 | - { |
|
73 | - if (Application::POST_TYPE == $screenPostType |
|
74 | - && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>') |
|
75 | - && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) { |
|
76 | - echo glsr()->render('partials/notices/rebusify'); |
|
77 | - } |
|
78 | - } |
|
67 | + /** |
|
68 | + * @param string $screenPostType |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + protected function renderRebusifyNotice($screenPostType) |
|
72 | + { |
|
73 | + if (Application::POST_TYPE == $screenPostType |
|
74 | + && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>') |
|
75 | + && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) { |
|
76 | + echo glsr()->render('partials/notices/rebusify'); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $key |
|
82 | - * @param mixed $fallback |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - protected function setUserMeta($key, $value) |
|
86 | - { |
|
87 | - $userId = get_current_user_id(); |
|
88 | - $meta = (array) get_user_meta($userId, static::USER_META_KEY, true); |
|
89 | - $meta = array_filter(wp_parse_args($meta, [])); |
|
90 | - $meta[$key] = $value; |
|
91 | - update_user_meta($userId, static::USER_META_KEY, $meta); |
|
92 | - } |
|
80 | + /** |
|
81 | + * @param string $key |
|
82 | + * @param mixed $fallback |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + protected function setUserMeta($key, $value) |
|
86 | + { |
|
87 | + $userId = get_current_user_id(); |
|
88 | + $meta = (array) get_user_meta($userId, static::USER_META_KEY, true); |
|
89 | + $meta = array_filter(wp_parse_args($meta, [])); |
|
90 | + $meta[$key] = $value; |
|
91 | + update_user_meta($userId, static::USER_META_KEY, $meta); |
|
92 | + } |
|
93 | 93 | } |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | public function filterAdminNotices() |
18 | 18 | { |
19 | 19 | $screen = glsr_current_screen(); |
20 | - $this->renderRebusifyNotice($screen->post_type); |
|
21 | - $this->renderAddonsNotice($screen->id); |
|
20 | + $this->renderRebusifyNotice( $screen->post_type ); |
|
21 | + $this->renderAddonsNotice( $screen->id ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @return void |
26 | 26 | */ |
27 | - public function routerDismissNotice(array $request) |
|
27 | + public function routerDismissNotice( array $request ) |
|
28 | 28 | { |
29 | - $key = glsr_get($request, 'notice'); |
|
30 | - $method = glsr(Helper::class)->buildMethodName($key, 'dismiss'); |
|
31 | - if (method_exists($this, $method)) { |
|
32 | - call_user_func([$this, $method], $key); |
|
29 | + $key = glsr_get( $request, 'notice' ); |
|
30 | + $method = glsr( Helper::class )->buildMethodName( $key, 'dismiss' ); |
|
31 | + if( method_exists( $this, $method ) ) { |
|
32 | + call_user_func( [$this, $method], $key ); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * @param string $key |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - protected function dismissRebusify($key) |
|
40 | + protected function dismissRebusify( $key ) |
|
41 | 41 | { |
42 | - $this->setUserMeta($key, glsr()->version('major')); |
|
42 | + $this->setUserMeta( $key, glsr()->version( 'major' ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | * @param mixed $fallback |
48 | 48 | * @return mixed |
49 | 49 | */ |
50 | - protected function getUserMeta($key, $fallback) |
|
50 | + protected function getUserMeta( $key, $fallback ) |
|
51 | 51 | { |
52 | - $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true); |
|
53 | - return glsr_get($meta, $key, $fallback); |
|
52 | + $meta = get_user_meta( get_current_user_id(), static::USER_META_KEY, true ); |
|
53 | + return glsr_get( $meta, $key, $fallback ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @param string $screenId |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - protected function renderAddonsNotice($screenId) |
|
60 | + protected function renderAddonsNotice( $screenId ) |
|
61 | 61 | { |
62 | - if (Application::POST_TYPE.'_page_addons' == $screenId) { |
|
63 | - echo glsr()->render('partials/notices/addons'); |
|
62 | + if( Application::POST_TYPE.'_page_addons' == $screenId ) { |
|
63 | + echo glsr()->render( 'partials/notices/addons' ); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | * @param string $screenPostType |
69 | 69 | * @return void |
70 | 70 | */ |
71 | - protected function renderRebusifyNotice($screenPostType) |
|
71 | + protected function renderRebusifyNotice( $screenPostType ) |
|
72 | 72 | { |
73 | - if (Application::POST_TYPE == $screenPostType |
|
74 | - && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>') |
|
75 | - && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) { |
|
76 | - echo glsr()->render('partials/notices/rebusify'); |
|
73 | + if( Application::POST_TYPE == $screenPostType |
|
74 | + && version_compare( glsr()->version( 'major' ), $this->getUserMeta( 'rebusify', 0 ), '>' ) |
|
75 | + && !glsr( OptionManager::class )->getBool( 'settings.general.rebusify' ) ) { |
|
76 | + echo glsr()->render( 'partials/notices/rebusify' ); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | * @param mixed $fallback |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - protected function setUserMeta($key, $value) |
|
85 | + protected function setUserMeta( $key, $value ) |
|
86 | 86 | { |
87 | 87 | $userId = get_current_user_id(); |
88 | - $meta = (array) get_user_meta($userId, static::USER_META_KEY, true); |
|
89 | - $meta = array_filter(wp_parse_args($meta, [])); |
|
88 | + $meta = (array)get_user_meta( $userId, static::USER_META_KEY, true ); |
|
89 | + $meta = array_filter( wp_parse_args( $meta, [] ) ); |
|
90 | 90 | $meta[$key] = $value; |
91 | - update_user_meta($userId, static::USER_META_KEY, $meta); |
|
91 | + update_user_meta( $userId, static::USER_META_KEY, $meta ); |
|
92 | 92 | } |
93 | 93 | } |
@@ -6,60 +6,60 @@ |
||
6 | 6 | |
7 | 7 | class DefaultsManager |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function defaults() |
|
13 | - { |
|
14 | - $settings = $this->settings(); |
|
15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | - return wp_parse_args($defaults, [ |
|
17 | - 'version' => '', |
|
18 | - 'version_upgraded_from' => '', |
|
19 | - ]); |
|
20 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function defaults() |
|
13 | + { |
|
14 | + $settings = $this->settings(); |
|
15 | + $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | + return wp_parse_args($defaults, [ |
|
17 | + 'version' => '', |
|
18 | + 'version_upgraded_from' => '', |
|
19 | + ]); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function get() |
|
26 | - { |
|
27 | - return glsr(Helper::class)->convertDotNotationArray($this->defaults()); |
|
28 | - } |
|
22 | + /** |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function get() |
|
26 | + { |
|
27 | + return glsr(Helper::class)->convertDotNotationArray($this->defaults()); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function set() |
|
34 | - { |
|
35 | - $settings = glsr(OptionManager::class)->all(); |
|
36 | - $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings); |
|
37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
40 | - return $defaultSettings; |
|
41 | - } |
|
30 | + /** |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function set() |
|
34 | + { |
|
35 | + $settings = glsr(OptionManager::class)->all(); |
|
36 | + $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings); |
|
37 | + $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | + $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | + update_option(OptionManager::databaseKey(), $updatedSettings); |
|
40 | + return $defaultSettings; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function settings() |
|
47 | - { |
|
48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | - return $this->normalize($settings); |
|
50 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function settings() |
|
47 | + { |
|
48 | + $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | + return $this->normalize($settings); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - protected function normalize(array $settings) |
|
56 | - { |
|
57 | - array_walk($settings, function (&$setting) { |
|
58 | - if (isset($setting['default'])) { |
|
59 | - return; |
|
60 | - } |
|
61 | - $setting['default'] = ''; |
|
62 | - }); |
|
63 | - return $settings; |
|
64 | - } |
|
52 | + /** |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + protected function normalize(array $settings) |
|
56 | + { |
|
57 | + array_walk($settings, function (&$setting) { |
|
58 | + if (isset($setting['default'])) { |
|
59 | + return; |
|
60 | + } |
|
61 | + $setting['default'] = ''; |
|
62 | + }); |
|
63 | + return $settings; |
|
64 | + } |
|
65 | 65 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | public function defaults() |
13 | 13 | { |
14 | 14 | $settings = $this->settings(); |
15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | - return wp_parse_args($defaults, [ |
|
15 | + $defaults = (array)array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' ) ); |
|
16 | + return wp_parse_args( $defaults, [ |
|
17 | 17 | 'version' => '', |
18 | 18 | 'version_upgraded_from' => '', |
19 | - ]); |
|
19 | + ] ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function get() |
26 | 26 | { |
27 | - return glsr(Helper::class)->convertDotNotationArray($this->defaults()); |
|
27 | + return glsr( Helper::class )->convertDotNotationArray( $this->defaults() ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function set() |
34 | 34 | { |
35 | - $settings = glsr(OptionManager::class)->all(); |
|
36 | - $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings); |
|
37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
35 | + $settings = glsr( OptionManager::class )->all(); |
|
36 | + $currentSettings = glsr( Helper::class )->removeEmptyArrayValues( $settings ); |
|
37 | + $defaultSettings = array_replace_recursive( $this->get(), $currentSettings ); |
|
38 | + $updatedSettings = array_replace_recursive( $settings, $defaultSettings ); |
|
39 | + update_option( OptionManager::databaseKey(), $updatedSettings ); |
|
40 | 40 | return $defaultSettings; |
41 | 41 | } |
42 | 42 | |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function settings() |
47 | 47 | { |
48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | - return $this->normalize($settings); |
|
48 | + $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' ) ); |
|
49 | + return $this->normalize( $settings ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - protected function normalize(array $settings) |
|
55 | + protected function normalize( array $settings ) |
|
56 | 56 | { |
57 | - array_walk($settings, function (&$setting) { |
|
58 | - if (isset($setting['default'])) { |
|
57 | + array_walk( $settings, function( &$setting ) { |
|
58 | + if( isset($setting['default']) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | $setting['default'] = ''; |
@@ -101,7 +101,8 @@ |
||
101 | 101 | { |
102 | 102 | if (is_wp_error($response)) { |
103 | 103 | $this->message = $response->get_error_message(); |
104 | - } else { |
|
104 | + } |
|
105 | + else { |
|
105 | 106 | $responseBody = wp_remote_retrieve_body($response); |
106 | 107 | $responseCode = wp_remote_retrieve_response_code($response); |
107 | 108 | $responseData = (array) json_decode($responseBody, true); |
@@ -9,143 +9,143 @@ |
||
9 | 9 | |
10 | 10 | class Rebusify |
11 | 11 | { |
12 | - const API_URL = 'https://www.rebusify.com/api/rbs/'; |
|
13 | - const WEB_URL = 'https://rebusify.com/plans?ref=105'; |
|
12 | + const API_URL = 'https://www.rebusify.com/api/rbs/'; |
|
13 | + const WEB_URL = 'https://rebusify.com/plans?ref=105'; |
|
14 | 14 | |
15 | - public $message; |
|
16 | - public $response; |
|
17 | - public $success; |
|
15 | + public $message; |
|
16 | + public $response; |
|
17 | + public $success; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @return mixed |
|
21 | - */ |
|
22 | - public function __get($key) |
|
23 | - { |
|
24 | - return property_exists($this, $key) |
|
25 | - ? $this->$key |
|
26 | - : glsr_get($this->response, $key, null); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @return mixed |
|
21 | + */ |
|
22 | + public function __get($key) |
|
23 | + { |
|
24 | + return property_exists($this, $key) |
|
25 | + ? $this->$key |
|
26 | + : glsr_get($this->response, $key, null); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return self |
|
31 | - */ |
|
32 | - public function activateKey($apiKey = '', $email = '') |
|
33 | - { |
|
34 | - $this->send('api_key_activation.php', [ |
|
35 | - 'body' => [ |
|
36 | - 'apikey' => $apiKey ?: 0, |
|
37 | - 'domain' => get_home_url(), |
|
38 | - 'email' => $email ?: 0, |
|
39 | - ], |
|
40 | - ]); |
|
41 | - return $this; |
|
42 | - } |
|
29 | + /** |
|
30 | + * @return self |
|
31 | + */ |
|
32 | + public function activateKey($apiKey = '', $email = '') |
|
33 | + { |
|
34 | + $this->send('api_key_activation.php', [ |
|
35 | + 'body' => [ |
|
36 | + 'apikey' => $apiKey ?: 0, |
|
37 | + 'domain' => get_home_url(), |
|
38 | + 'email' => $email ?: 0, |
|
39 | + ], |
|
40 | + ]); |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return self |
|
46 | - */ |
|
47 | - public function reset() |
|
48 | - { |
|
49 | - $this->message = ''; |
|
50 | - $this->response = []; |
|
51 | - $this->success = false; |
|
52 | - return $this; |
|
53 | - } |
|
44 | + /** |
|
45 | + * @return self |
|
46 | + */ |
|
47 | + public function reset() |
|
48 | + { |
|
49 | + $this->message = ''; |
|
50 | + $this->response = []; |
|
51 | + $this->success = false; |
|
52 | + return $this; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public function sendReview(Review $review) |
|
59 | - { |
|
60 | - $this->send('index.php', [ |
|
61 | - 'body' => $this->getBodyForReview($review), |
|
62 | - 'timeout' => 120, |
|
63 | - ]); |
|
64 | - return $this; |
|
65 | - } |
|
55 | + /** |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public function sendReview(Review $review) |
|
59 | + { |
|
60 | + $this->send('index.php', [ |
|
61 | + 'body' => $this->getBodyForReview($review), |
|
62 | + 'timeout' => 120, |
|
63 | + ]); |
|
64 | + return $this; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public function sendReviewResponse(Review $review) |
|
71 | - { |
|
72 | - $this->send('fetch_customer_reply.php', [ |
|
73 | - 'body' => $this->getBodyForResponse($review), |
|
74 | - ]); |
|
75 | - return $this; |
|
76 | - } |
|
67 | + /** |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public function sendReviewResponse(Review $review) |
|
71 | + { |
|
72 | + $this->send('fetch_customer_reply.php', [ |
|
73 | + 'body' => $this->getBodyForResponse($review), |
|
74 | + ]); |
|
75 | + return $this; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function getBodyForResponse(Review $review) |
|
82 | - { |
|
83 | - $rebusifyResponse = [ |
|
84 | - 'reply' => glsr(Helper::class)->truncate($review->response, 300), |
|
85 | - 'review_id' => glsr(Database::class)->get($review->ID, 'rebusify'), // this is the rebusify review ID |
|
86 | - 'review_transaction_id' => $review->review_id, |
|
87 | - 'type' => 'M', |
|
88 | - ]; |
|
89 | - return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review); |
|
90 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function getBodyForResponse(Review $review) |
|
82 | + { |
|
83 | + $rebusifyResponse = [ |
|
84 | + 'reply' => glsr(Helper::class)->truncate($review->response, 300), |
|
85 | + 'review_id' => glsr(Database::class)->get($review->ID, 'rebusify'), // this is the rebusify review ID |
|
86 | + 'review_transaction_id' => $review->review_id, |
|
87 | + 'type' => 'M', |
|
88 | + ]; |
|
89 | + return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getBodyForReview(Review $review) |
|
96 | - { |
|
97 | - $rebusifyReview = [ |
|
98 | - 'domain' => get_home_url(), |
|
99 | - 'firstname' => glsr(Helper::class)->truncate(glsr(Helper::class)->convertName($review->author, 'first'), 25), |
|
100 | - 'rate' => $review->rating, |
|
101 | - 'review_transaction_id' => $review->review_id, |
|
102 | - 'reviews' => glsr(Helper::class)->truncate($review->content, 280), |
|
103 | - 'title' => glsr(Helper::class)->truncate($review->title, 35), |
|
104 | - 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
|
105 | - ]; |
|
106 | - return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review); |
|
107 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getBodyForReview(Review $review) |
|
96 | + { |
|
97 | + $rebusifyReview = [ |
|
98 | + 'domain' => get_home_url(), |
|
99 | + 'firstname' => glsr(Helper::class)->truncate(glsr(Helper::class)->convertName($review->author, 'first'), 25), |
|
100 | + 'rate' => $review->rating, |
|
101 | + 'review_transaction_id' => $review->review_id, |
|
102 | + 'reviews' => glsr(Helper::class)->truncate($review->content, 280), |
|
103 | + 'title' => glsr(Helper::class)->truncate($review->title, 35), |
|
104 | + 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
|
105 | + ]; |
|
106 | + return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param \WP_Error|array $response |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - protected function handleResponse($response) |
|
114 | - { |
|
115 | - if (is_wp_error($response)) { |
|
116 | - $this->message = $response->get_error_message(); |
|
117 | - } else { |
|
118 | - $responseBody = wp_remote_retrieve_body($response); |
|
119 | - $responseCode = wp_remote_retrieve_response_code($response); |
|
120 | - $responseData = (array) json_decode($responseBody, true); |
|
121 | - $this->response = array_shift($responseData); |
|
122 | - $this->message = glsr_get($this->response, 'msg'); |
|
123 | - $this->success = 'success' === glsr_get($this->response, 'result') || 'yes' === glsr_get($this->response, 'success'); // @todo remove this ugly hack! |
|
124 | - if (200 !== $responseCode) { |
|
125 | - glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
126 | - } |
|
127 | - if (!$this->success) { |
|
128 | - glsr_log()->error($this->message); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
109 | + /** |
|
110 | + * @param \WP_Error|array $response |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + protected function handleResponse($response) |
|
114 | + { |
|
115 | + if (is_wp_error($response)) { |
|
116 | + $this->message = $response->get_error_message(); |
|
117 | + } else { |
|
118 | + $responseBody = wp_remote_retrieve_body($response); |
|
119 | + $responseCode = wp_remote_retrieve_response_code($response); |
|
120 | + $responseData = (array) json_decode($responseBody, true); |
|
121 | + $this->response = array_shift($responseData); |
|
122 | + $this->message = glsr_get($this->response, 'msg'); |
|
123 | + $this->success = 'success' === glsr_get($this->response, 'result') || 'yes' === glsr_get($this->response, 'success'); // @todo remove this ugly hack! |
|
124 | + if (200 !== $responseCode) { |
|
125 | + glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
126 | + } |
|
127 | + if (!$this->success) { |
|
128 | + glsr_log()->error($this->message); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @param string $endpoint |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - protected function send($endpoint, array $args = []) |
|
138 | - { |
|
139 | - $args = wp_parse_args($args, [ |
|
140 | - 'body' => null, |
|
141 | - 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
|
142 | - 'redirection' => 5, |
|
143 | - 'sslverify' => false, |
|
144 | - 'timeout' => 5, |
|
145 | - ]); |
|
146 | - $this->reset(); |
|
147 | - $this->handleResponse( |
|
148 | - wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
149 | - ); |
|
150 | - } |
|
133 | + /** |
|
134 | + * @param string $endpoint |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + protected function send($endpoint, array $args = []) |
|
138 | + { |
|
139 | + $args = wp_parse_args($args, [ |
|
140 | + 'body' => null, |
|
141 | + 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
|
142 | + 'redirection' => 5, |
|
143 | + 'sslverify' => false, |
|
144 | + 'timeout' => 5, |
|
145 | + ]); |
|
146 | + $this->reset(); |
|
147 | + $this->handleResponse( |
|
148 | + wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | } |
@@ -19,25 +19,25 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @return mixed |
21 | 21 | */ |
22 | - public function __get($key) |
|
22 | + public function __get( $key ) |
|
23 | 23 | { |
24 | - return property_exists($this, $key) |
|
24 | + return property_exists( $this, $key ) |
|
25 | 25 | ? $this->$key |
26 | - : glsr_get($this->response, $key, null); |
|
26 | + : glsr_get( $this->response, $key, null ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @return self |
31 | 31 | */ |
32 | - public function activateKey($apiKey = '', $email = '') |
|
32 | + public function activateKey( $apiKey = '', $email = '' ) |
|
33 | 33 | { |
34 | - $this->send('api_key_activation.php', [ |
|
34 | + $this->send( 'api_key_activation.php', [ |
|
35 | 35 | 'body' => [ |
36 | 36 | 'apikey' => $apiKey ?: 0, |
37 | 37 | 'domain' => get_home_url(), |
38 | 38 | 'email' => $email ?: 0, |
39 | 39 | ], |
40 | - ]); |
|
40 | + ] ); |
|
41 | 41 | return $this; |
42 | 42 | } |
43 | 43 | |
@@ -55,77 +55,77 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @return self |
57 | 57 | */ |
58 | - public function sendReview(Review $review) |
|
58 | + public function sendReview( Review $review ) |
|
59 | 59 | { |
60 | - $this->send('index.php', [ |
|
61 | - 'body' => $this->getBodyForReview($review), |
|
60 | + $this->send( 'index.php', [ |
|
61 | + 'body' => $this->getBodyForReview( $review ), |
|
62 | 62 | 'timeout' => 120, |
63 | - ]); |
|
63 | + ] ); |
|
64 | 64 | return $this; |
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @return self |
69 | 69 | */ |
70 | - public function sendReviewResponse(Review $review) |
|
70 | + public function sendReviewResponse( Review $review ) |
|
71 | 71 | { |
72 | - $this->send('fetch_customer_reply.php', [ |
|
73 | - 'body' => $this->getBodyForResponse($review), |
|
74 | - ]); |
|
72 | + $this->send( 'fetch_customer_reply.php', [ |
|
73 | + 'body' => $this->getBodyForResponse( $review ), |
|
74 | + ] ); |
|
75 | 75 | return $this; |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - protected function getBodyForResponse(Review $review) |
|
81 | + protected function getBodyForResponse( Review $review ) |
|
82 | 82 | { |
83 | 83 | $rebusifyResponse = [ |
84 | - 'reply' => glsr(Helper::class)->truncate($review->response, 300), |
|
85 | - 'review_id' => glsr(Database::class)->get($review->ID, 'rebusify'), // this is the rebusify review ID |
|
84 | + 'reply' => glsr( Helper::class )->truncate( $review->response, 300 ), |
|
85 | + 'review_id' => glsr( Database::class )->get( $review->ID, 'rebusify' ), // this is the rebusify review ID |
|
86 | 86 | 'review_transaction_id' => $review->review_id, |
87 | 87 | 'type' => 'M', |
88 | 88 | ]; |
89 | - return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review); |
|
89 | + return apply_filters( 'site-reviews/rebusify/response', $rebusifyResponse, $review ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * @return array |
94 | 94 | */ |
95 | - protected function getBodyForReview(Review $review) |
|
95 | + protected function getBodyForReview( Review $review ) |
|
96 | 96 | { |
97 | 97 | $rebusifyReview = [ |
98 | 98 | 'domain' => get_home_url(), |
99 | - 'firstname' => glsr(Helper::class)->truncate(glsr(Helper::class)->convertName($review->author, 'first'), 25), |
|
99 | + 'firstname' => glsr( Helper::class )->truncate( glsr( Helper::class )->convertName( $review->author, 'first' ), 25 ), |
|
100 | 100 | 'rate' => $review->rating, |
101 | 101 | 'review_transaction_id' => $review->review_id, |
102 | - 'reviews' => glsr(Helper::class)->truncate($review->content, 280), |
|
103 | - 'title' => glsr(Helper::class)->truncate($review->title, 35), |
|
102 | + 'reviews' => glsr( Helper::class )->truncate( $review->content, 280 ), |
|
103 | + 'title' => glsr( Helper::class )->truncate( $review->title, 35 ), |
|
104 | 104 | 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
105 | 105 | ]; |
106 | - return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review); |
|
106 | + return apply_filters( 'site-reviews/rebusify/review', $rebusifyReview, $review ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @param \WP_Error|array $response |
111 | 111 | * @return void |
112 | 112 | */ |
113 | - protected function handleResponse($response) |
|
113 | + protected function handleResponse( $response ) |
|
114 | 114 | { |
115 | - if (is_wp_error($response)) { |
|
115 | + if( is_wp_error( $response ) ) { |
|
116 | 116 | $this->message = $response->get_error_message(); |
117 | 117 | } else { |
118 | - $responseBody = wp_remote_retrieve_body($response); |
|
119 | - $responseCode = wp_remote_retrieve_response_code($response); |
|
120 | - $responseData = (array) json_decode($responseBody, true); |
|
121 | - $this->response = array_shift($responseData); |
|
122 | - $this->message = glsr_get($this->response, 'msg'); |
|
123 | - $this->success = 'success' === glsr_get($this->response, 'result') || 'yes' === glsr_get($this->response, 'success'); // @todo remove this ugly hack! |
|
124 | - if (200 !== $responseCode) { |
|
125 | - glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
118 | + $responseBody = wp_remote_retrieve_body( $response ); |
|
119 | + $responseCode = wp_remote_retrieve_response_code( $response ); |
|
120 | + $responseData = (array)json_decode( $responseBody, true ); |
|
121 | + $this->response = array_shift( $responseData ); |
|
122 | + $this->message = glsr_get( $this->response, 'msg' ); |
|
123 | + $this->success = 'success' === glsr_get( $this->response, 'result' ) || 'yes' === glsr_get( $this->response, 'success' ); // @todo remove this ugly hack! |
|
124 | + if( 200 !== $responseCode ) { |
|
125 | + glsr_log()->error( 'Bad response code ['.$responseCode.']' ); |
|
126 | 126 | } |
127 | - if (!$this->success) { |
|
128 | - glsr_log()->error($this->message); |
|
127 | + if( !$this->success ) { |
|
128 | + glsr_log()->error( $this->message ); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
@@ -134,18 +134,18 @@ discard block |
||
134 | 134 | * @param string $endpoint |
135 | 135 | * @return void |
136 | 136 | */ |
137 | - protected function send($endpoint, array $args = []) |
|
137 | + protected function send( $endpoint, array $args = [] ) |
|
138 | 138 | { |
139 | - $args = wp_parse_args($args, [ |
|
139 | + $args = wp_parse_args( $args, [ |
|
140 | 140 | 'body' => null, |
141 | 141 | 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
142 | 142 | 'redirection' => 5, |
143 | 143 | 'sslverify' => false, |
144 | 144 | 'timeout' => 5, |
145 | - ]); |
|
145 | + ] ); |
|
146 | 146 | $this->reset(); |
147 | 147 | $this->handleResponse( |
148 | - wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
148 | + wp_remote_post( trailingslashit( static::API_URL ).$endpoint, $args ) |
|
149 | 149 | ); |
150 | 150 | } |
151 | 151 | } |
@@ -7,153 +7,153 @@ |
||
7 | 7 | |
8 | 8 | class OptionManager |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $options; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $options; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public static function databaseKey($version = null) |
|
19 | - { |
|
20 | - if (null === $version) { |
|
21 | - $version = explode('.', glsr()->version); |
|
22 | - $version = array_shift($version); |
|
23 | - } |
|
24 | - return glsr(Helper::class)->snakeCase( |
|
25 | - Application::ID.'-v'.intval($version) |
|
26 | - ); |
|
27 | - } |
|
15 | + /** |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public static function databaseKey($version = null) |
|
19 | + { |
|
20 | + if (null === $version) { |
|
21 | + $version = explode('.', glsr()->version); |
|
22 | + $version = array_shift($version); |
|
23 | + } |
|
24 | + return glsr(Helper::class)->snakeCase( |
|
25 | + Application::ID.'-v'.intval($version) |
|
26 | + ); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function all() |
|
33 | - { |
|
34 | - if (empty($this->options)) { |
|
35 | - $this->reset(); |
|
36 | - } |
|
37 | - return $this->options; |
|
38 | - } |
|
29 | + /** |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function all() |
|
33 | + { |
|
34 | + if (empty($this->options)) { |
|
35 | + $this->reset(); |
|
36 | + } |
|
37 | + return $this->options; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $path |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function delete($path) |
|
45 | - { |
|
46 | - $keys = explode('.', $path); |
|
47 | - $last = array_pop($keys); |
|
48 | - $options = $this->all(); |
|
49 | - $pointer = &$options; |
|
50 | - foreach ($keys as $key) { |
|
51 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
52 | - continue; |
|
53 | - } |
|
54 | - $pointer = &$pointer[$key]; |
|
55 | - } |
|
56 | - unset($pointer[$last]); |
|
57 | - return $this->set($options); |
|
58 | - } |
|
40 | + /** |
|
41 | + * @param string $path |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function delete($path) |
|
45 | + { |
|
46 | + $keys = explode('.', $path); |
|
47 | + $last = array_pop($keys); |
|
48 | + $options = $this->all(); |
|
49 | + $pointer = &$options; |
|
50 | + foreach ($keys as $key) { |
|
51 | + if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
52 | + continue; |
|
53 | + } |
|
54 | + $pointer = &$pointer[$key]; |
|
55 | + } |
|
56 | + unset($pointer[$last]); |
|
57 | + return $this->set($options); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param string $path |
|
62 | - * @param mixed $fallback |
|
63 | - * @param string $cast |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - public function get($path = '', $fallback = '', $cast = '') |
|
67 | - { |
|
68 | - $result = glsr(Helper::class)->dataGet($this->all(), $path, $fallback); |
|
69 | - return glsr(Helper::class)->castTo($cast, $result); |
|
70 | - } |
|
60 | + /** |
|
61 | + * @param string $path |
|
62 | + * @param mixed $fallback |
|
63 | + * @param string $cast |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + public function get($path = '', $fallback = '', $cast = '') |
|
67 | + { |
|
68 | + $result = glsr(Helper::class)->dataGet($this->all(), $path, $fallback); |
|
69 | + return glsr(Helper::class)->castTo($cast, $result); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param string $path |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function getBool($path) |
|
77 | - { |
|
78 | - return glsr(Helper::class)->castTo('bool', $this->get($path)); |
|
79 | - } |
|
72 | + /** |
|
73 | + * @param string $path |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function getBool($path) |
|
77 | + { |
|
78 | + return glsr(Helper::class)->castTo('bool', $this->get($path)); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param string $path |
|
83 | - * @param mixed $fallback |
|
84 | - * @param string $cast |
|
85 | - * @return mixed |
|
86 | - */ |
|
87 | - public function getWP($path, $fallback = '', $cast = '') |
|
88 | - { |
|
89 | - $option = get_option($path, $fallback); |
|
90 | - if (empty($option)) { |
|
91 | - $option = $fallback; |
|
92 | - } |
|
93 | - return glsr(Helper::class)->castTo($cast, $option); |
|
94 | - } |
|
81 | + /** |
|
82 | + * @param string $path |
|
83 | + * @param mixed $fallback |
|
84 | + * @param string $cast |
|
85 | + * @return mixed |
|
86 | + */ |
|
87 | + public function getWP($path, $fallback = '', $cast = '') |
|
88 | + { |
|
89 | + $option = get_option($path, $fallback); |
|
90 | + if (empty($option)) { |
|
91 | + $option = $fallback; |
|
92 | + } |
|
93 | + return glsr(Helper::class)->castTo($cast, $option); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function json() |
|
100 | - { |
|
101 | - return json_encode($this->all()); |
|
102 | - } |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function json() |
|
100 | + { |
|
101 | + return json_encode($this->all()); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - public function normalize(array $options = []) |
|
108 | - { |
|
109 | - $options = wp_parse_args( |
|
110 | - glsr(Helper::class)->flattenArray($options), |
|
111 | - glsr(DefaultsManager::class)->defaults() |
|
112 | - ); |
|
113 | - array_walk($options, function (&$value) { |
|
114 | - if (!is_string($value)) { |
|
115 | - return; |
|
116 | - } |
|
117 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
118 | - }); |
|
119 | - return glsr(Helper::class)->convertDotNotationArray($options); |
|
120 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + public function normalize(array $options = []) |
|
108 | + { |
|
109 | + $options = wp_parse_args( |
|
110 | + glsr(Helper::class)->flattenArray($options), |
|
111 | + glsr(DefaultsManager::class)->defaults() |
|
112 | + ); |
|
113 | + array_walk($options, function (&$value) { |
|
114 | + if (!is_string($value)) { |
|
115 | + return; |
|
116 | + } |
|
117 | + $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
118 | + }); |
|
119 | + return glsr(Helper::class)->convertDotNotationArray($options); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return bool |
|
124 | - */ |
|
125 | - public function isRecaptchaEnabled() |
|
126 | - { |
|
127 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
128 | - return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
129 | - } |
|
122 | + /** |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | + public function isRecaptchaEnabled() |
|
126 | + { |
|
127 | + $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
128 | + return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - public function reset() |
|
135 | - { |
|
136 | - $options = $this->getWP(static::databaseKey(), []); |
|
137 | - if (!is_array($options) || empty($options)) { |
|
138 | - delete_option(static::databaseKey()); |
|
139 | - $options = glsr()->defaults ?: []; |
|
140 | - } |
|
141 | - $this->options = $options; |
|
142 | - } |
|
131 | + /** |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + public function reset() |
|
135 | + { |
|
136 | + $options = $this->getWP(static::databaseKey(), []); |
|
137 | + if (!is_array($options) || empty($options)) { |
|
138 | + delete_option(static::databaseKey()); |
|
139 | + $options = glsr()->defaults ?: []; |
|
140 | + } |
|
141 | + $this->options = $options; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string|array $pathOrOptions |
|
146 | - * @param mixed $value |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function set($pathOrOptions, $value = '') |
|
150 | - { |
|
151 | - if (is_string($pathOrOptions)) { |
|
152 | - $pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value); |
|
153 | - } |
|
154 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
155 | - $this->reset(); |
|
156 | - } |
|
157 | - return $result; |
|
158 | - } |
|
144 | + /** |
|
145 | + * @param string|array $pathOrOptions |
|
146 | + * @param mixed $value |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function set($pathOrOptions, $value = '') |
|
150 | + { |
|
151 | + if (is_string($pathOrOptions)) { |
|
152 | + $pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value); |
|
153 | + } |
|
154 | + if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
155 | + $this->reset(); |
|
156 | + } |
|
157 | + return $result; |
|
158 | + } |
|
159 | 159 | } |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @return string |
17 | 17 | */ |
18 | - public static function databaseKey($version = null) |
|
18 | + public static function databaseKey( $version = null ) |
|
19 | 19 | { |
20 | - if (null === $version) { |
|
21 | - $version = explode('.', glsr()->version); |
|
22 | - $version = array_shift($version); |
|
20 | + if( null === $version ) { |
|
21 | + $version = explode( '.', glsr()->version ); |
|
22 | + $version = array_shift( $version ); |
|
23 | 23 | } |
24 | - return glsr(Helper::class)->snakeCase( |
|
25 | - Application::ID.'-v'.intval($version) |
|
24 | + return glsr( Helper::class )->snakeCase( |
|
25 | + Application::ID.'-v'.intval( $version ) |
|
26 | 26 | ); |
27 | 27 | } |
28 | 28 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function all() |
33 | 33 | { |
34 | - if (empty($this->options)) { |
|
34 | + if( empty($this->options) ) { |
|
35 | 35 | $this->reset(); |
36 | 36 | } |
37 | 37 | return $this->options; |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | * @param string $path |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public function delete($path) |
|
44 | + public function delete( $path ) |
|
45 | 45 | { |
46 | - $keys = explode('.', $path); |
|
47 | - $last = array_pop($keys); |
|
46 | + $keys = explode( '.', $path ); |
|
47 | + $last = array_pop( $keys ); |
|
48 | 48 | $options = $this->all(); |
49 | 49 | $pointer = &$options; |
50 | - foreach ($keys as $key) { |
|
51 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
50 | + foreach( $keys as $key ) { |
|
51 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) { |
|
52 | 52 | continue; |
53 | 53 | } |
54 | 54 | $pointer = &$pointer[$key]; |
55 | 55 | } |
56 | 56 | unset($pointer[$last]); |
57 | - return $this->set($options); |
|
57 | + return $this->set( $options ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | * @param string $cast |
64 | 64 | * @return mixed |
65 | 65 | */ |
66 | - public function get($path = '', $fallback = '', $cast = '') |
|
66 | + public function get( $path = '', $fallback = '', $cast = '' ) |
|
67 | 67 | { |
68 | - $result = glsr(Helper::class)->dataGet($this->all(), $path, $fallback); |
|
69 | - return glsr(Helper::class)->castTo($cast, $result); |
|
68 | + $result = glsr( Helper::class )->dataGet( $this->all(), $path, $fallback ); |
|
69 | + return glsr( Helper::class )->castTo( $cast, $result ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @param string $path |
74 | 74 | * @return bool |
75 | 75 | */ |
76 | - public function getBool($path) |
|
76 | + public function getBool( $path ) |
|
77 | 77 | { |
78 | - return glsr(Helper::class)->castTo('bool', $this->get($path)); |
|
78 | + return glsr( Helper::class )->castTo( 'bool', $this->get( $path ) ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * @param string $cast |
85 | 85 | * @return mixed |
86 | 86 | */ |
87 | - public function getWP($path, $fallback = '', $cast = '') |
|
87 | + public function getWP( $path, $fallback = '', $cast = '' ) |
|
88 | 88 | { |
89 | - $option = get_option($path, $fallback); |
|
90 | - if (empty($option)) { |
|
89 | + $option = get_option( $path, $fallback ); |
|
90 | + if( empty($option) ) { |
|
91 | 91 | $option = $fallback; |
92 | 92 | } |
93 | - return glsr(Helper::class)->castTo($cast, $option); |
|
93 | + return glsr( Helper::class )->castTo( $cast, $option ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -98,25 +98,25 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function json() |
100 | 100 | { |
101 | - return json_encode($this->all()); |
|
101 | + return json_encode( $this->all() ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - public function normalize(array $options = []) |
|
107 | + public function normalize( array $options = [] ) |
|
108 | 108 | { |
109 | 109 | $options = wp_parse_args( |
110 | - glsr(Helper::class)->flattenArray($options), |
|
111 | - glsr(DefaultsManager::class)->defaults() |
|
110 | + glsr( Helper::class )->flattenArray( $options ), |
|
111 | + glsr( DefaultsManager::class )->defaults() |
|
112 | 112 | ); |
113 | - array_walk($options, function (&$value) { |
|
114 | - if (!is_string($value)) { |
|
113 | + array_walk( $options, function( &$value ) { |
|
114 | + if( !is_string( $value ) ) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
117 | + $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) ); |
|
118 | 118 | }); |
119 | - return glsr(Helper::class)->convertDotNotationArray($options); |
|
119 | + return glsr( Helper::class )->convertDotNotationArray( $options ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function isRecaptchaEnabled() |
126 | 126 | { |
127 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
127 | + $integration = $this->get( 'settings.submissions.recaptcha.integration' ); |
|
128 | 128 | return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
129 | 129 | } |
130 | 130 | |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function reset() |
135 | 135 | { |
136 | - $options = $this->getWP(static::databaseKey(), []); |
|
137 | - if (!is_array($options) || empty($options)) { |
|
138 | - delete_option(static::databaseKey()); |
|
136 | + $options = $this->getWP( static::databaseKey(), [] ); |
|
137 | + if( !is_array( $options ) || empty($options) ) { |
|
138 | + delete_option( static::databaseKey() ); |
|
139 | 139 | $options = glsr()->defaults ?: []; |
140 | 140 | } |
141 | 141 | $this->options = $options; |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * @param mixed $value |
147 | 147 | * @return bool |
148 | 148 | */ |
149 | - public function set($pathOrOptions, $value = '') |
|
149 | + public function set( $pathOrOptions, $value = '' ) |
|
150 | 150 | { |
151 | - if (is_string($pathOrOptions)) { |
|
152 | - $pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value); |
|
151 | + if( is_string( $pathOrOptions ) ) { |
|
152 | + $pathOrOptions = glsr( Helper::class )->dataSet( $this->all(), $pathOrOptions, $value ); |
|
153 | 153 | } |
154 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
154 | + if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) { |
|
155 | 155 | $this->reset(); |
156 | 156 | } |
157 | 157 | return $result; |
@@ -14,69 +14,69 @@ |
||
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 $public; |
|
24 | - protected $rebusify; |
|
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 $public; |
|
24 | + protected $rebusify; |
|
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->public = $app->make(PublicController::class); |
|
37 | - $this->rebusify = $app->make(RebusifyController::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->public = $app->make(PublicController::class); |
|
37 | + $this->rebusify = $app->make(RebusifyController::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('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
73 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
74 | - add_filter('gettext', [$this->translator, 'filterGettext'], 10, 3); |
|
75 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4); |
|
76 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 10, 5); |
|
77 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6); |
|
78 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
79 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
80 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
81 | - } |
|
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('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
73 | + add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
74 | + add_filter('gettext', [$this->translator, 'filterGettext'], 10, 3); |
|
75 | + add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4); |
|
76 | + add_filter('ngettext', [$this->translator, 'filterNgettext'], 10, 5); |
|
77 | + add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6); |
|
78 | + add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
79 | + add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
80 | + add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
81 | + } |
|
82 | 82 | } |
@@ -25,18 +25,18 @@ discard block |
||
25 | 25 | protected $translator; |
26 | 26 | protected $welcome; |
27 | 27 | |
28 | - public function __construct(Application $app) |
|
28 | + public function __construct( Application $app ) |
|
29 | 29 | { |
30 | 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->public = $app->make(PublicController::class); |
|
37 | - $this->rebusify = $app->make(RebusifyController::class); |
|
38 | - $this->translator = $app->make(Translator::class); |
|
39 | - $this->welcome = $app->make(WelcomeController::class); |
|
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->public = $app->make( PublicController::class ); |
|
37 | + $this->rebusify = $app->make( RebusifyController::class ); |
|
38 | + $this->translator = $app->make( Translator::class ); |
|
39 | + $this->welcome = $app->make( WelcomeController::class ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -44,39 +44,39 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function run() |
46 | 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('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
73 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
74 | - add_filter('gettext', [$this->translator, 'filterGettext'], 10, 3); |
|
75 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4); |
|
76 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 10, 5); |
|
77 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6); |
|
78 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
79 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
80 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
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( 'site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback'] ); |
|
73 | + add_filter( 'site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3 ); |
|
74 | + add_filter( 'gettext', [$this->translator, 'filterGettext'], 10, 3 ); |
|
75 | + add_filter( 'gettext_with_context', [$this->translator, 'filterGettextWithContext'], 10, 4 ); |
|
76 | + add_filter( 'ngettext', [$this->translator, 'filterNgettext'], 10, 5 ); |
|
77 | + add_filter( 'ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 10, 6 ); |
|
78 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9 ); |
|
79 | + add_filter( 'admin_title', [$this->welcome, 'filterAdminTitle'] ); |
|
80 | + add_filter( 'admin_footer_text', [$this->welcome, 'filterFooterText'] ); |
|
81 | 81 | } |
82 | 82 | } |
@@ -8,241 +8,241 @@ |
||
8 | 8 | |
9 | 9 | class Field |
10 | 10 | { |
11 | - /** |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - public $field; |
|
15 | - |
|
16 | - public function __construct(array $field = []) |
|
17 | - { |
|
18 | - $this->field = wp_parse_args($field, [ |
|
19 | - 'errors' => false, |
|
20 | - 'is_hidden' => false, |
|
21 | - 'is_multi' => false, |
|
22 | - 'is_public' => false, |
|
23 | - 'is_raw' => false, |
|
24 | - 'is_setting' => false, |
|
25 | - 'is_valid' => true, |
|
26 | - 'is_widget' => false, |
|
27 | - 'path' => '', |
|
28 | - ]); |
|
29 | - $this->normalize(); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function __toString() |
|
36 | - { |
|
37 | - return (string) $this->build(); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return void|string |
|
42 | - */ |
|
43 | - public function build() |
|
44 | - { |
|
45 | - if (!$this->field['is_valid']) { |
|
46 | - return; |
|
47 | - } |
|
48 | - if ($this->field['is_raw']) { |
|
49 | - return glsr(Builder::class)->{$this->field['type']}($this->field); |
|
50 | - } |
|
51 | - if (!$this->field['is_setting']) { |
|
52 | - return $this->buildField(); |
|
53 | - } |
|
54 | - if (!$this->field['is_multi']) { |
|
55 | - return $this->buildSettingField(); |
|
56 | - } |
|
57 | - return $this->buildSettingMultiField(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function render() |
|
64 | - { |
|
65 | - echo $this->build(); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - protected function buildField() |
|
72 | - { |
|
73 | - $field = glsr(Template::class)->build('templates/form/field_'.$this->field['type'], [ |
|
74 | - 'context' => [ |
|
75 | - 'class' => $this->getFieldClass(), |
|
76 | - 'errors' => $this->getFieldErrors(), |
|
77 | - 'field' => glsr(Builder::class)->raw($this->field), |
|
78 | - 'label' => glsr(Builder::class)->label([ |
|
79 | - 'class' => 'glsr-'.$this->field['type'].'-label', |
|
80 | - 'for' => $this->field['id'], |
|
81 | - 'is_public' => $this->field['is_public'], |
|
82 | - 'text' => $this->field['label'].'<span></span>', |
|
83 | - 'type' => $this->field['type'], |
|
84 | - ]), |
|
85 | - ], |
|
86 | - 'field' => $this->field, |
|
87 | - ]); |
|
88 | - return apply_filters('site-reviews/rendered/field', $field, $this->field['type'], $this->field); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - protected function buildSettingField() |
|
95 | - { |
|
96 | - return glsr(Template::class)->build('partials/form/table-row', [ |
|
97 | - 'context' => [ |
|
98 | - 'class' => $this->getFieldClass(), |
|
99 | - 'field' => glsr(Builder::class)->{$this->field['type']}($this->field), |
|
100 | - 'label' => glsr(Builder::class)->label($this->field['legend'], ['for' => $this->field['id']]), |
|
101 | - ], |
|
102 | - 'field' => $this->field, |
|
103 | - ]); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function buildSettingMultiField() |
|
110 | - { |
|
111 | - $dependsOn = $this->getFieldDependsOn(); |
|
112 | - unset($this->field['data-depends']); |
|
113 | - return glsr(Template::class)->build('partials/form/table-row-multiple', [ |
|
114 | - 'context' => [ |
|
115 | - 'class' => $this->getFieldClass(), |
|
116 | - 'depends_on' => $dependsOn, |
|
117 | - 'field' => glsr(Builder::class)->{$this->field['type']}($this->field), |
|
118 | - 'label' => glsr(Builder::class)->label($this->field['legend'], ['for' => $this->field['id']]), |
|
119 | - 'legend' => $this->field['legend'], |
|
120 | - ], |
|
121 | - 'field' => $this->field, |
|
122 | - ]); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function getFieldClass() |
|
129 | - { |
|
130 | - $classes = []; |
|
131 | - if (!empty($this->field['errors'])) { |
|
132 | - $classes[] = 'glsr-has-error'; |
|
133 | - } |
|
134 | - if ($this->field['is_hidden']) { |
|
135 | - $classes[] = 'hidden'; |
|
136 | - } |
|
137 | - if (!empty($this->field['required'])) { |
|
138 | - $classes[] = 'glsr-required'; |
|
139 | - } |
|
140 | - $classes = apply_filters('site-reviews/rendered/field/classes', $classes, $this->field); |
|
141 | - return implode(' ', $classes); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - protected function getFieldDependsOn() |
|
148 | - { |
|
149 | - return !empty($this->field['data-depends']) |
|
150 | - ? $this->field['data-depends'] |
|
151 | - : ''; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @return void|string |
|
156 | - */ |
|
157 | - protected function getFieldErrors() |
|
158 | - { |
|
159 | - if (empty($this->field['errors']) || !is_array($this->field['errors'])) { |
|
160 | - return; |
|
161 | - } |
|
162 | - $errors = array_reduce($this->field['errors'], function ($carry, $error) { |
|
163 | - return $carry.glsr(Builder::class)->span($error, ['class' => 'glsr-field-error']); |
|
164 | - }); |
|
165 | - return glsr(Template::class)->build('templates/form/field-errors', [ |
|
166 | - 'context' => [ |
|
167 | - 'errors' => $errors, |
|
168 | - ], |
|
169 | - 'field' => $this->field, |
|
170 | - ]); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - protected function getFieldPrefix() |
|
177 | - { |
|
178 | - return $this->field['is_setting'] |
|
179 | - ? OptionManager::databaseKey() |
|
180 | - : Application::ID; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - protected function isFieldValid() |
|
187 | - { |
|
188 | - $missingValues = []; |
|
189 | - $requiredValues = [ |
|
190 | - 'name', 'type', |
|
191 | - ]; |
|
192 | - foreach ($requiredValues as $value) { |
|
193 | - if (isset($this->field[$value])) { |
|
194 | - continue; |
|
195 | - } |
|
196 | - $missingValues[] = $value; |
|
197 | - $this->field['is_valid'] = false; |
|
198 | - } |
|
199 | - if (!empty($missingValues)) { |
|
200 | - glsr_log() |
|
201 | - ->warning('Field is missing: '.implode(', ', $missingValues)) |
|
202 | - ->debug($this->field); |
|
203 | - } |
|
204 | - return $this->field['is_valid']; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - protected function normalize() |
|
211 | - { |
|
212 | - if (!$this->isFieldValid()) { |
|
213 | - return; |
|
214 | - } |
|
215 | - $this->field['path'] = $this->field['name']; |
|
216 | - $className = glsr(Helper::class)->buildClassName($this->field['type'], __NAMESPACE__.'\Fields'); |
|
217 | - if (class_exists($className)) { |
|
218 | - $this->field = $className::merge($this->field); |
|
219 | - } |
|
220 | - $this->normalizeFieldId(); |
|
221 | - $this->normalizeFieldName(); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @return void |
|
226 | - */ |
|
227 | - protected function normalizeFieldId() |
|
228 | - { |
|
229 | - if (isset($this->field['id']) || $this->field['is_raw']) { |
|
230 | - return; |
|
231 | - } |
|
232 | - $this->field['id'] = glsr(Helper::class)->convertPathToId( |
|
233 | - $this->field['path'], |
|
234 | - $this->getFieldPrefix() |
|
235 | - ); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @return void |
|
240 | - */ |
|
241 | - protected function normalizeFieldName() |
|
242 | - { |
|
243 | - $this->field['name'] = glsr(Helper::class)->convertPathToName( |
|
244 | - $this->field['path'], |
|
245 | - $this->getFieldPrefix() |
|
246 | - ); |
|
247 | - } |
|
11 | + /** |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + public $field; |
|
15 | + |
|
16 | + public function __construct(array $field = []) |
|
17 | + { |
|
18 | + $this->field = wp_parse_args($field, [ |
|
19 | + 'errors' => false, |
|
20 | + 'is_hidden' => false, |
|
21 | + 'is_multi' => false, |
|
22 | + 'is_public' => false, |
|
23 | + 'is_raw' => false, |
|
24 | + 'is_setting' => false, |
|
25 | + 'is_valid' => true, |
|
26 | + 'is_widget' => false, |
|
27 | + 'path' => '', |
|
28 | + ]); |
|
29 | + $this->normalize(); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function __toString() |
|
36 | + { |
|
37 | + return (string) $this->build(); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return void|string |
|
42 | + */ |
|
43 | + public function build() |
|
44 | + { |
|
45 | + if (!$this->field['is_valid']) { |
|
46 | + return; |
|
47 | + } |
|
48 | + if ($this->field['is_raw']) { |
|
49 | + return glsr(Builder::class)->{$this->field['type']}($this->field); |
|
50 | + } |
|
51 | + if (!$this->field['is_setting']) { |
|
52 | + return $this->buildField(); |
|
53 | + } |
|
54 | + if (!$this->field['is_multi']) { |
|
55 | + return $this->buildSettingField(); |
|
56 | + } |
|
57 | + return $this->buildSettingMultiField(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function render() |
|
64 | + { |
|
65 | + echo $this->build(); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + protected function buildField() |
|
72 | + { |
|
73 | + $field = glsr(Template::class)->build('templates/form/field_'.$this->field['type'], [ |
|
74 | + 'context' => [ |
|
75 | + 'class' => $this->getFieldClass(), |
|
76 | + 'errors' => $this->getFieldErrors(), |
|
77 | + 'field' => glsr(Builder::class)->raw($this->field), |
|
78 | + 'label' => glsr(Builder::class)->label([ |
|
79 | + 'class' => 'glsr-'.$this->field['type'].'-label', |
|
80 | + 'for' => $this->field['id'], |
|
81 | + 'is_public' => $this->field['is_public'], |
|
82 | + 'text' => $this->field['label'].'<span></span>', |
|
83 | + 'type' => $this->field['type'], |
|
84 | + ]), |
|
85 | + ], |
|
86 | + 'field' => $this->field, |
|
87 | + ]); |
|
88 | + return apply_filters('site-reviews/rendered/field', $field, $this->field['type'], $this->field); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + protected function buildSettingField() |
|
95 | + { |
|
96 | + return glsr(Template::class)->build('partials/form/table-row', [ |
|
97 | + 'context' => [ |
|
98 | + 'class' => $this->getFieldClass(), |
|
99 | + 'field' => glsr(Builder::class)->{$this->field['type']}($this->field), |
|
100 | + 'label' => glsr(Builder::class)->label($this->field['legend'], ['for' => $this->field['id']]), |
|
101 | + ], |
|
102 | + 'field' => $this->field, |
|
103 | + ]); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function buildSettingMultiField() |
|
110 | + { |
|
111 | + $dependsOn = $this->getFieldDependsOn(); |
|
112 | + unset($this->field['data-depends']); |
|
113 | + return glsr(Template::class)->build('partials/form/table-row-multiple', [ |
|
114 | + 'context' => [ |
|
115 | + 'class' => $this->getFieldClass(), |
|
116 | + 'depends_on' => $dependsOn, |
|
117 | + 'field' => glsr(Builder::class)->{$this->field['type']}($this->field), |
|
118 | + 'label' => glsr(Builder::class)->label($this->field['legend'], ['for' => $this->field['id']]), |
|
119 | + 'legend' => $this->field['legend'], |
|
120 | + ], |
|
121 | + 'field' => $this->field, |
|
122 | + ]); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function getFieldClass() |
|
129 | + { |
|
130 | + $classes = []; |
|
131 | + if (!empty($this->field['errors'])) { |
|
132 | + $classes[] = 'glsr-has-error'; |
|
133 | + } |
|
134 | + if ($this->field['is_hidden']) { |
|
135 | + $classes[] = 'hidden'; |
|
136 | + } |
|
137 | + if (!empty($this->field['required'])) { |
|
138 | + $classes[] = 'glsr-required'; |
|
139 | + } |
|
140 | + $classes = apply_filters('site-reviews/rendered/field/classes', $classes, $this->field); |
|
141 | + return implode(' ', $classes); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + protected function getFieldDependsOn() |
|
148 | + { |
|
149 | + return !empty($this->field['data-depends']) |
|
150 | + ? $this->field['data-depends'] |
|
151 | + : ''; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @return void|string |
|
156 | + */ |
|
157 | + protected function getFieldErrors() |
|
158 | + { |
|
159 | + if (empty($this->field['errors']) || !is_array($this->field['errors'])) { |
|
160 | + return; |
|
161 | + } |
|
162 | + $errors = array_reduce($this->field['errors'], function ($carry, $error) { |
|
163 | + return $carry.glsr(Builder::class)->span($error, ['class' => 'glsr-field-error']); |
|
164 | + }); |
|
165 | + return glsr(Template::class)->build('templates/form/field-errors', [ |
|
166 | + 'context' => [ |
|
167 | + 'errors' => $errors, |
|
168 | + ], |
|
169 | + 'field' => $this->field, |
|
170 | + ]); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + protected function getFieldPrefix() |
|
177 | + { |
|
178 | + return $this->field['is_setting'] |
|
179 | + ? OptionManager::databaseKey() |
|
180 | + : Application::ID; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + protected function isFieldValid() |
|
187 | + { |
|
188 | + $missingValues = []; |
|
189 | + $requiredValues = [ |
|
190 | + 'name', 'type', |
|
191 | + ]; |
|
192 | + foreach ($requiredValues as $value) { |
|
193 | + if (isset($this->field[$value])) { |
|
194 | + continue; |
|
195 | + } |
|
196 | + $missingValues[] = $value; |
|
197 | + $this->field['is_valid'] = false; |
|
198 | + } |
|
199 | + if (!empty($missingValues)) { |
|
200 | + glsr_log() |
|
201 | + ->warning('Field is missing: '.implode(', ', $missingValues)) |
|
202 | + ->debug($this->field); |
|
203 | + } |
|
204 | + return $this->field['is_valid']; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + protected function normalize() |
|
211 | + { |
|
212 | + if (!$this->isFieldValid()) { |
|
213 | + return; |
|
214 | + } |
|
215 | + $this->field['path'] = $this->field['name']; |
|
216 | + $className = glsr(Helper::class)->buildClassName($this->field['type'], __NAMESPACE__.'\Fields'); |
|
217 | + if (class_exists($className)) { |
|
218 | + $this->field = $className::merge($this->field); |
|
219 | + } |
|
220 | + $this->normalizeFieldId(); |
|
221 | + $this->normalizeFieldName(); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @return void |
|
226 | + */ |
|
227 | + protected function normalizeFieldId() |
|
228 | + { |
|
229 | + if (isset($this->field['id']) || $this->field['is_raw']) { |
|
230 | + return; |
|
231 | + } |
|
232 | + $this->field['id'] = glsr(Helper::class)->convertPathToId( |
|
233 | + $this->field['path'], |
|
234 | + $this->getFieldPrefix() |
|
235 | + ); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @return void |
|
240 | + */ |
|
241 | + protected function normalizeFieldName() |
|
242 | + { |
|
243 | + $this->field['name'] = glsr(Helper::class)->convertPathToName( |
|
244 | + $this->field['path'], |
|
245 | + $this->getFieldPrefix() |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public $field; |
15 | 15 | |
16 | - public function __construct(array $field = []) |
|
16 | + public function __construct( array $field = [] ) |
|
17 | 17 | { |
18 | - $this->field = wp_parse_args($field, [ |
|
18 | + $this->field = wp_parse_args( $field, [ |
|
19 | 19 | 'errors' => false, |
20 | 20 | 'is_hidden' => false, |
21 | 21 | 'is_multi' => false, |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | 'is_valid' => true, |
26 | 26 | 'is_widget' => false, |
27 | 27 | 'path' => '', |
28 | - ]); |
|
28 | + ] ); |
|
29 | 29 | $this->normalize(); |
30 | 30 | } |
31 | 31 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __toString() |
36 | 36 | { |
37 | - return (string) $this->build(); |
|
37 | + return (string)$this->build(); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function build() |
44 | 44 | { |
45 | - if (!$this->field['is_valid']) { |
|
45 | + if( !$this->field['is_valid'] ) { |
|
46 | 46 | return; |
47 | 47 | } |
48 | - if ($this->field['is_raw']) { |
|
49 | - return glsr(Builder::class)->{$this->field['type']}($this->field); |
|
48 | + if( $this->field['is_raw'] ) { |
|
49 | + return glsr( Builder::class )->{$this->field['type']}($this->field); |
|
50 | 50 | } |
51 | - if (!$this->field['is_setting']) { |
|
51 | + if( !$this->field['is_setting'] ) { |
|
52 | 52 | return $this->buildField(); |
53 | 53 | } |
54 | - if (!$this->field['is_multi']) { |
|
54 | + if( !$this->field['is_multi'] ) { |
|
55 | 55 | return $this->buildSettingField(); |
56 | 56 | } |
57 | 57 | return $this->buildSettingMultiField(); |
@@ -70,22 +70,22 @@ discard block |
||
70 | 70 | */ |
71 | 71 | protected function buildField() |
72 | 72 | { |
73 | - $field = glsr(Template::class)->build('templates/form/field_'.$this->field['type'], [ |
|
73 | + $field = glsr( Template::class )->build( 'templates/form/field_'.$this->field['type'], [ |
|
74 | 74 | 'context' => [ |
75 | 75 | 'class' => $this->getFieldClass(), |
76 | 76 | 'errors' => $this->getFieldErrors(), |
77 | - 'field' => glsr(Builder::class)->raw($this->field), |
|
78 | - 'label' => glsr(Builder::class)->label([ |
|
77 | + 'field' => glsr( Builder::class )->raw( $this->field ), |
|
78 | + 'label' => glsr( Builder::class )->label( [ |
|
79 | 79 | 'class' => 'glsr-'.$this->field['type'].'-label', |
80 | 80 | 'for' => $this->field['id'], |
81 | 81 | 'is_public' => $this->field['is_public'], |
82 | 82 | 'text' => $this->field['label'].'<span></span>', |
83 | 83 | 'type' => $this->field['type'], |
84 | - ]), |
|
84 | + ] ), |
|
85 | 85 | ], |
86 | 86 | 'field' => $this->field, |
87 | - ]); |
|
88 | - return apply_filters('site-reviews/rendered/field', $field, $this->field['type'], $this->field); |
|
87 | + ] ); |
|
88 | + return apply_filters( 'site-reviews/rendered/field', $field, $this->field['type'], $this->field ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | */ |
94 | 94 | protected function buildSettingField() |
95 | 95 | { |
96 | - return glsr(Template::class)->build('partials/form/table-row', [ |
|
96 | + return glsr( Template::class )->build( 'partials/form/table-row', [ |
|
97 | 97 | 'context' => [ |
98 | 98 | 'class' => $this->getFieldClass(), |
99 | - 'field' => glsr(Builder::class)->{$this->field['type']}($this->field), |
|
100 | - 'label' => glsr(Builder::class)->label($this->field['legend'], ['for' => $this->field['id']]), |
|
99 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
100 | + 'label' => glsr( Builder::class )->label( $this->field['legend'], ['for' => $this->field['id']] ), |
|
101 | 101 | ], |
102 | 102 | 'field' => $this->field, |
103 | - ]); |
|
103 | + ] ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | { |
111 | 111 | $dependsOn = $this->getFieldDependsOn(); |
112 | 112 | unset($this->field['data-depends']); |
113 | - return glsr(Template::class)->build('partials/form/table-row-multiple', [ |
|
113 | + return glsr( Template::class )->build( 'partials/form/table-row-multiple', [ |
|
114 | 114 | 'context' => [ |
115 | 115 | 'class' => $this->getFieldClass(), |
116 | 116 | 'depends_on' => $dependsOn, |
117 | - 'field' => glsr(Builder::class)->{$this->field['type']}($this->field), |
|
118 | - 'label' => glsr(Builder::class)->label($this->field['legend'], ['for' => $this->field['id']]), |
|
117 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
118 | + 'label' => glsr( Builder::class )->label( $this->field['legend'], ['for' => $this->field['id']] ), |
|
119 | 119 | 'legend' => $this->field['legend'], |
120 | 120 | ], |
121 | 121 | 'field' => $this->field, |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | protected function getFieldClass() |
129 | 129 | { |
130 | 130 | $classes = []; |
131 | - if (!empty($this->field['errors'])) { |
|
131 | + if( !empty($this->field['errors']) ) { |
|
132 | 132 | $classes[] = 'glsr-has-error'; |
133 | 133 | } |
134 | - if ($this->field['is_hidden']) { |
|
134 | + if( $this->field['is_hidden'] ) { |
|
135 | 135 | $classes[] = 'hidden'; |
136 | 136 | } |
137 | - if (!empty($this->field['required'])) { |
|
137 | + if( !empty($this->field['required']) ) { |
|
138 | 138 | $classes[] = 'glsr-required'; |
139 | 139 | } |
140 | - $classes = apply_filters('site-reviews/rendered/field/classes', $classes, $this->field); |
|
141 | - return implode(' ', $classes); |
|
140 | + $classes = apply_filters( 'site-reviews/rendered/field/classes', $classes, $this->field ); |
|
141 | + return implode( ' ', $classes ); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -156,18 +156,18 @@ discard block |
||
156 | 156 | */ |
157 | 157 | protected function getFieldErrors() |
158 | 158 | { |
159 | - if (empty($this->field['errors']) || !is_array($this->field['errors'])) { |
|
159 | + if( empty($this->field['errors']) || !is_array( $this->field['errors'] ) ) { |
|
160 | 160 | return; |
161 | 161 | } |
162 | - $errors = array_reduce($this->field['errors'], function ($carry, $error) { |
|
163 | - return $carry.glsr(Builder::class)->span($error, ['class' => 'glsr-field-error']); |
|
162 | + $errors = array_reduce( $this->field['errors'], function( $carry, $error ) { |
|
163 | + return $carry.glsr( Builder::class )->span( $error, ['class' => 'glsr-field-error'] ); |
|
164 | 164 | }); |
165 | - return glsr(Template::class)->build('templates/form/field-errors', [ |
|
165 | + return glsr( Template::class )->build( 'templates/form/field-errors', [ |
|
166 | 166 | 'context' => [ |
167 | 167 | 'errors' => $errors, |
168 | 168 | ], |
169 | 169 | 'field' => $this->field, |
170 | - ]); |
|
170 | + ] ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | $requiredValues = [ |
190 | 190 | 'name', 'type', |
191 | 191 | ]; |
192 | - foreach ($requiredValues as $value) { |
|
193 | - if (isset($this->field[$value])) { |
|
192 | + foreach( $requiredValues as $value ) { |
|
193 | + if( isset($this->field[$value]) ) { |
|
194 | 194 | continue; |
195 | 195 | } |
196 | 196 | $missingValues[] = $value; |
197 | 197 | $this->field['is_valid'] = false; |
198 | 198 | } |
199 | - if (!empty($missingValues)) { |
|
199 | + if( !empty($missingValues) ) { |
|
200 | 200 | glsr_log() |
201 | - ->warning('Field is missing: '.implode(', ', $missingValues)) |
|
202 | - ->debug($this->field); |
|
201 | + ->warning( 'Field is missing: '.implode( ', ', $missingValues ) ) |
|
202 | + ->debug( $this->field ); |
|
203 | 203 | } |
204 | 204 | return $this->field['is_valid']; |
205 | 205 | } |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function normalize() |
211 | 211 | { |
212 | - if (!$this->isFieldValid()) { |
|
212 | + if( !$this->isFieldValid() ) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | $this->field['path'] = $this->field['name']; |
216 | - $className = glsr(Helper::class)->buildClassName($this->field['type'], __NAMESPACE__.'\Fields'); |
|
217 | - if (class_exists($className)) { |
|
218 | - $this->field = $className::merge($this->field); |
|
216 | + $className = glsr( Helper::class )->buildClassName( $this->field['type'], __NAMESPACE__.'\Fields' ); |
|
217 | + if( class_exists( $className ) ) { |
|
218 | + $this->field = $className::merge( $this->field ); |
|
219 | 219 | } |
220 | 220 | $this->normalizeFieldId(); |
221 | 221 | $this->normalizeFieldName(); |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | */ |
227 | 227 | protected function normalizeFieldId() |
228 | 228 | { |
229 | - if (isset($this->field['id']) || $this->field['is_raw']) { |
|
229 | + if( isset($this->field['id']) || $this->field['is_raw'] ) { |
|
230 | 230 | return; |
231 | 231 | } |
232 | - $this->field['id'] = glsr(Helper::class)->convertPathToId( |
|
232 | + $this->field['id'] = glsr( Helper::class )->convertPathToId( |
|
233 | 233 | $this->field['path'], |
234 | 234 | $this->getFieldPrefix() |
235 | 235 | ); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function normalizeFieldName() |
242 | 242 | { |
243 | - $this->field['name'] = glsr(Helper::class)->convertPathToName( |
|
243 | + $this->field['name'] = glsr( Helper::class )->convertPathToName( |
|
244 | 244 | $this->field['path'], |
245 | 245 | $this->getFieldPrefix() |
246 | 246 | ); |
@@ -6,78 +6,78 @@ |
||
6 | 6 | |
7 | 7 | class Template |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $templatePath |
|
11 | - * @return void|string |
|
12 | - */ |
|
13 | - public function build($templatePath, array $data = []) |
|
14 | - { |
|
15 | - $data = $this->normalize($data); |
|
16 | - ob_start(); |
|
17 | - glsr()->render($templatePath, $data); |
|
18 | - $template = ob_get_clean(); |
|
19 | - $path = glsr(Helper::class)->removePrefix('templates/', $templatePath); |
|
20 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
21 | - $template = $this->interpolate($template, $data, $path); |
|
22 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
23 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
24 | - return $template; |
|
25 | - } |
|
9 | + /** |
|
10 | + * @param string $templatePath |
|
11 | + * @return void|string |
|
12 | + */ |
|
13 | + public function build($templatePath, array $data = []) |
|
14 | + { |
|
15 | + $data = $this->normalize($data); |
|
16 | + ob_start(); |
|
17 | + glsr()->render($templatePath, $data); |
|
18 | + $template = ob_get_clean(); |
|
19 | + $path = glsr(Helper::class)->removePrefix('templates/', $templatePath); |
|
20 | + $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
21 | + $template = $this->interpolate($template, $data, $path); |
|
22 | + $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
23 | + $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
24 | + return $template; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Interpolate context values into template placeholders. |
|
29 | - * @param string $template |
|
30 | - * @param string $templatePath |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function interpolate($template, array $data = [], $templatePath) |
|
34 | - { |
|
35 | - $context = $this->normalizeContext(glsr_get($data, 'context', [])); |
|
36 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
37 | - foreach ($context as $key => $value) { |
|
38 | - $template = strtr( |
|
39 | - $template, |
|
40 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
41 | - ); |
|
42 | - } |
|
43 | - return trim($template); |
|
44 | - } |
|
27 | + /** |
|
28 | + * Interpolate context values into template placeholders. |
|
29 | + * @param string $template |
|
30 | + * @param string $templatePath |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function interpolate($template, array $data = [], $templatePath) |
|
34 | + { |
|
35 | + $context = $this->normalizeContext(glsr_get($data, 'context', [])); |
|
36 | + $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
37 | + foreach ($context as $key => $value) { |
|
38 | + $template = strtr( |
|
39 | + $template, |
|
40 | + array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
41 | + ); |
|
42 | + } |
|
43 | + return trim($template); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $templatePath |
|
48 | - * @return void|string |
|
49 | - */ |
|
50 | - public function render($templatePath, array $data = []) |
|
51 | - { |
|
52 | - echo $this->build($templatePath, $data); |
|
53 | - } |
|
46 | + /** |
|
47 | + * @param string $templatePath |
|
48 | + * @return void|string |
|
49 | + */ |
|
50 | + public function render($templatePath, array $data = []) |
|
51 | + { |
|
52 | + echo $this->build($templatePath, $data); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - protected function normalize(array $data) |
|
59 | - { |
|
60 | - $arrayKeys = ['context', 'globals']; |
|
61 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
62 | - foreach ($arrayKeys as $key) { |
|
63 | - if (is_array($data[$key])) { |
|
64 | - continue; |
|
65 | - } |
|
66 | - $data[$key] = []; |
|
67 | - } |
|
68 | - return $data; |
|
69 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + protected function normalize(array $data) |
|
59 | + { |
|
60 | + $arrayKeys = ['context', 'globals']; |
|
61 | + $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
62 | + foreach ($arrayKeys as $key) { |
|
63 | + if (is_array($data[$key])) { |
|
64 | + continue; |
|
65 | + } |
|
66 | + $data[$key] = []; |
|
67 | + } |
|
68 | + return $data; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - protected function normalizeContext(array $context) |
|
75 | - { |
|
76 | - $context = array_filter($context, function ($value) { |
|
77 | - return !is_array($value) && !is_object($value); |
|
78 | - }); |
|
79 | - return array_map(function ($value) { |
|
80 | - return (string) $value; |
|
81 | - }, $context); |
|
82 | - } |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + protected function normalizeContext(array $context) |
|
75 | + { |
|
76 | + $context = array_filter($context, function ($value) { |
|
77 | + return !is_array($value) && !is_object($value); |
|
78 | + }); |
|
79 | + return array_map(function ($value) { |
|
80 | + return (string) $value; |
|
81 | + }, $context); |
|
82 | + } |
|
83 | 83 | } |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | * @param string $templatePath |
11 | 11 | * @return void|string |
12 | 12 | */ |
13 | - public function build($templatePath, array $data = []) |
|
13 | + public function build( $templatePath, array $data = [] ) |
|
14 | 14 | { |
15 | - $data = $this->normalize($data); |
|
15 | + $data = $this->normalize( $data ); |
|
16 | 16 | ob_start(); |
17 | - glsr()->render($templatePath, $data); |
|
17 | + glsr()->render( $templatePath, $data ); |
|
18 | 18 | $template = ob_get_clean(); |
19 | - $path = glsr(Helper::class)->removePrefix('templates/', $templatePath); |
|
20 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
21 | - $template = $this->interpolate($template, $data, $path); |
|
22 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
23 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
19 | + $path = glsr( Helper::class )->removePrefix( 'templates/', $templatePath ); |
|
20 | + $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data ); |
|
21 | + $template = $this->interpolate( $template, $data, $path ); |
|
22 | + $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data ); |
|
23 | + $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data ); |
|
24 | 24 | return $template; |
25 | 25 | } |
26 | 26 | |
@@ -30,37 +30,37 @@ discard block |
||
30 | 30 | * @param string $templatePath |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function interpolate($template, array $data = [], $templatePath) |
|
33 | + public function interpolate( $template, array $data = [], $templatePath ) |
|
34 | 34 | { |
35 | - $context = $this->normalizeContext(glsr_get($data, 'context', [])); |
|
36 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
37 | - foreach ($context as $key => $value) { |
|
35 | + $context = $this->normalizeContext( glsr_get( $data, 'context', [] ) ); |
|
36 | + $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data ); |
|
37 | + foreach( $context as $key => $value ) { |
|
38 | 38 | $template = strtr( |
39 | 39 | $template, |
40 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
40 | + array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value ) |
|
41 | 41 | ); |
42 | 42 | } |
43 | - return trim($template); |
|
43 | + return trim( $template ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param string $templatePath |
48 | 48 | * @return void|string |
49 | 49 | */ |
50 | - public function render($templatePath, array $data = []) |
|
50 | + public function render( $templatePath, array $data = [] ) |
|
51 | 51 | { |
52 | - echo $this->build($templatePath, $data); |
|
52 | + echo $this->build( $templatePath, $data ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - protected function normalize(array $data) |
|
58 | + protected function normalize( array $data ) |
|
59 | 59 | { |
60 | 60 | $arrayKeys = ['context', 'globals']; |
61 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
62 | - foreach ($arrayKeys as $key) { |
|
63 | - if (is_array($data[$key])) { |
|
61 | + $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) ); |
|
62 | + foreach( $arrayKeys as $key ) { |
|
63 | + if( is_array( $data[$key] ) ) { |
|
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | $data[$key] = []; |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - protected function normalizeContext(array $context) |
|
74 | + protected function normalizeContext( array $context ) |
|
75 | 75 | { |
76 | - $context = array_filter($context, function ($value) { |
|
77 | - return !is_array($value) && !is_object($value); |
|
76 | + $context = array_filter( $context, function( $value ) { |
|
77 | + return !is_array( $value ) && !is_object( $value ); |
|
78 | 78 | }); |
79 | - return array_map(function ($value) { |
|
80 | - return (string) $value; |
|
81 | - }, $context); |
|
79 | + return array_map( function( $value ) { |
|
80 | + return (string)$value; |
|
81 | + }, $context ); |
|
82 | 82 | } |
83 | 83 | } |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | } |
53 | 53 | if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
54 | 54 | $button = $this->buildUpgradeButton(); |
55 | - } else { |
|
55 | + } |
|
56 | + else { |
|
56 | 57 | $button = $this->buildCreateButton(); |
57 | 58 | } |
58 | 59 | $context['field'].= $button; |
@@ -208,7 +209,8 @@ discard block |
||
208 | 209 | ); |
209 | 210 | if ($rebusify->success) { |
210 | 211 | update_option($this->rebusifyKey, glsr_get($rebusify->response, 'producttype')); |
211 | - } else { |
|
212 | + } |
|
213 | + else { |
|
212 | 214 | delete_option($this->rebusifyKey); |
213 | 215 | $settings = glsr(Helper::class)->dataSet($settings, $this->enabledKey, 'no'); |
214 | 216 | glsr(Notice::class)->addError(sprintf( |
@@ -12,231 +12,231 @@ |
||
12 | 12 | |
13 | 13 | class RebusifyController extends Controller |
14 | 14 | { |
15 | - protected $apiKey = 'settings.general.rebusify_serial'; |
|
16 | - protected $emailKey = 'settings.general.rebusify_email'; |
|
17 | - protected $enabledKey = 'settings.general.rebusify'; |
|
18 | - protected $rebusifyKey = '_glsr_rebusify'; |
|
19 | - |
|
20 | - /** |
|
21 | - * @return array |
|
22 | - * @filter site-reviews/settings/callback |
|
23 | - */ |
|
24 | - public function filterSettingsCallback(array $settings) |
|
25 | - { |
|
26 | - if ('yes' !== glsr_get($settings, $this->enabledKey)) { |
|
27 | - return $settings; |
|
28 | - } |
|
29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeRebusifySettings($settings); |
|
34 | - } |
|
35 | - return $settings; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $template |
|
40 | - * @return array |
|
41 | - * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
42 | - */ |
|
43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
44 | - { |
|
45 | - if ($this->enabledKey !== glsr_get($data, 'field.path')) { |
|
46 | - return $context; |
|
47 | - } |
|
48 | - $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | - if ('P' === $rebusifyProductType) { |
|
50 | - return $context; |
|
51 | - } |
|
52 | - if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
53 | - $button = $this->buildUpgradeButton(); |
|
54 | - } else { |
|
55 | - $button = $this->buildCreateButton(); |
|
56 | - } |
|
57 | - $context['field'].= $button; |
|
58 | - return $context; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Triggered when a review is created. |
|
63 | - * @return void |
|
64 | - * @action site-reviews/review/created |
|
65 | - */ |
|
66 | - public function onCreated(Review $review) |
|
67 | - { |
|
68 | - if (!$this->canPostReview($review)) { |
|
69 | - return; |
|
70 | - } |
|
71 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | - if ($rebusify->success) { |
|
73 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
79 | - * @return void |
|
80 | - * @action site-reviews/review/reverted |
|
81 | - */ |
|
82 | - public function onReverted(Review $review) |
|
83 | - { |
|
84 | - if (!$this->canPostReview($review)) { |
|
85 | - return; |
|
86 | - } |
|
87 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | - if ($rebusify->success) { |
|
89 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Triggered when an existing review is updated. |
|
95 | - * @return void |
|
96 | - * @action site-reviews/review/saved |
|
97 | - */ |
|
98 | - public function onSaved(Review $review) |
|
99 | - { |
|
100 | - if (!$this->canPostReview($review)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | - if ($rebusify->success) { |
|
105 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Triggered when a review's response is added or updated. |
|
111 | - * @param int $metaId |
|
112 | - * @param int $postId |
|
113 | - * @param string $metaKey |
|
114 | - * @return void |
|
115 | - * @action updated_postmeta |
|
116 | - */ |
|
117 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
118 | - { |
|
119 | - $review = glsr_get_review($postId); |
|
120 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | - if ($rebusify->success) { |
|
125 | - glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - protected function buildCreateButton() |
|
133 | - { |
|
134 | - return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
135 | - 'class' => 'button', |
|
136 | - 'href' => Rebusify::WEB_URL, |
|
137 | - 'target' => '_blank', |
|
138 | - ]); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - protected function buildUpgradeButton() |
|
145 | - { |
|
146 | - $build = glsr(Builder::class); |
|
147 | - $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | - $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
149 | - 'class' => 'button', |
|
150 | - 'href' => Rebusify::WEB_URL, |
|
151 | - 'target' => '_blank', |
|
152 | - ]); |
|
153 | - return $build->div($notice.$button, [ |
|
154 | - 'class' => 'glsr-notice-inline', |
|
155 | - ]); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - protected function canPostResponse(Review $review) |
|
162 | - { |
|
163 | - $requiredValues = [ |
|
164 | - glsr(Database::class)->get($review->ID, 'rebusify'), |
|
165 | - $review->response, |
|
166 | - $review->review_id, |
|
167 | - ]; |
|
168 | - return $this->canProceed($review, 'rebusify_response') |
|
169 | - && 'publish' === $review->status |
|
170 | - && 3 === count(array_filter($requiredValues)); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - protected function canPostReview(Review $review) |
|
177 | - { |
|
178 | - $requiredValues = [ |
|
179 | - $review->author, |
|
180 | - $review->content, |
|
181 | - $review->rating, |
|
182 | - $review->review_id, |
|
183 | - $review->title, |
|
184 | - ]; |
|
185 | - return $this->canProceed($review) |
|
186 | - && 'publish' === $review->status |
|
187 | - && 5 === count(array_filter($requiredValues)); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $metaKey |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
195 | - { |
|
196 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | - && $this->isReviewPostId($review->ID) |
|
198 | - && !$this->hasMetaKey($review, $metaKey); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $metaKey |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
206 | - { |
|
207 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $key |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - protected function isEmptyOrModified($key, array $settings) |
|
215 | - { |
|
216 | - $oldValue = glsr_get_option($key); |
|
217 | - $newValue = glsr_get($settings, $key); |
|
218 | - return empty($newValue) || $newValue !== $oldValue; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - protected function sanitizeRebusifySettings(array $settings) |
|
225 | - { |
|
226 | - $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | - glsr_get($settings, $this->apiKey), |
|
228 | - glsr_get($settings, $this->emailKey) |
|
229 | - ); |
|
230 | - if ($rebusify->success) { |
|
231 | - update_option($this->rebusifyKey, glsr_get($rebusify->response, 'producttype')); |
|
232 | - } else { |
|
233 | - delete_option($this->rebusifyKey); |
|
234 | - $settings = glsr(Helper::class)->dataSet($settings, $this->enabledKey, 'no'); |
|
235 | - glsr(Notice::class)->addError(sprintf( |
|
236 | - __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
237 | - '('.$rebusify->message.')' |
|
238 | - )); |
|
239 | - } |
|
240 | - return $settings; |
|
241 | - } |
|
15 | + protected $apiKey = 'settings.general.rebusify_serial'; |
|
16 | + protected $emailKey = 'settings.general.rebusify_email'; |
|
17 | + protected $enabledKey = 'settings.general.rebusify'; |
|
18 | + protected $rebusifyKey = '_glsr_rebusify'; |
|
19 | + |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + * @filter site-reviews/settings/callback |
|
23 | + */ |
|
24 | + public function filterSettingsCallback(array $settings) |
|
25 | + { |
|
26 | + if ('yes' !== glsr_get($settings, $this->enabledKey)) { |
|
27 | + return $settings; |
|
28 | + } |
|
29 | + $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | + $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | + $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | + if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | + $settings = $this->sanitizeRebusifySettings($settings); |
|
34 | + } |
|
35 | + return $settings; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $template |
|
40 | + * @return array |
|
41 | + * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
42 | + */ |
|
43 | + public function filterSettingsTableRow(array $context, $template, array $data) |
|
44 | + { |
|
45 | + if ($this->enabledKey !== glsr_get($data, 'field.path')) { |
|
46 | + return $context; |
|
47 | + } |
|
48 | + $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | + if ('P' === $rebusifyProductType) { |
|
50 | + return $context; |
|
51 | + } |
|
52 | + if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
53 | + $button = $this->buildUpgradeButton(); |
|
54 | + } else { |
|
55 | + $button = $this->buildCreateButton(); |
|
56 | + } |
|
57 | + $context['field'].= $button; |
|
58 | + return $context; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Triggered when a review is created. |
|
63 | + * @return void |
|
64 | + * @action site-reviews/review/created |
|
65 | + */ |
|
66 | + public function onCreated(Review $review) |
|
67 | + { |
|
68 | + if (!$this->canPostReview($review)) { |
|
69 | + return; |
|
70 | + } |
|
71 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | + if ($rebusify->success) { |
|
73 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
79 | + * @return void |
|
80 | + * @action site-reviews/review/reverted |
|
81 | + */ |
|
82 | + public function onReverted(Review $review) |
|
83 | + { |
|
84 | + if (!$this->canPostReview($review)) { |
|
85 | + return; |
|
86 | + } |
|
87 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | + if ($rebusify->success) { |
|
89 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Triggered when an existing review is updated. |
|
95 | + * @return void |
|
96 | + * @action site-reviews/review/saved |
|
97 | + */ |
|
98 | + public function onSaved(Review $review) |
|
99 | + { |
|
100 | + if (!$this->canPostReview($review)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | + if ($rebusify->success) { |
|
105 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Triggered when a review's response is added or updated. |
|
111 | + * @param int $metaId |
|
112 | + * @param int $postId |
|
113 | + * @param string $metaKey |
|
114 | + * @return void |
|
115 | + * @action updated_postmeta |
|
116 | + */ |
|
117 | + public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
118 | + { |
|
119 | + $review = glsr_get_review($postId); |
|
120 | + if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | + if ($rebusify->success) { |
|
125 | + glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + protected function buildCreateButton() |
|
133 | + { |
|
134 | + return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
135 | + 'class' => 'button', |
|
136 | + 'href' => Rebusify::WEB_URL, |
|
137 | + 'target' => '_blank', |
|
138 | + ]); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + protected function buildUpgradeButton() |
|
145 | + { |
|
146 | + $build = glsr(Builder::class); |
|
147 | + $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | + $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
149 | + 'class' => 'button', |
|
150 | + 'href' => Rebusify::WEB_URL, |
|
151 | + 'target' => '_blank', |
|
152 | + ]); |
|
153 | + return $build->div($notice.$button, [ |
|
154 | + 'class' => 'glsr-notice-inline', |
|
155 | + ]); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + protected function canPostResponse(Review $review) |
|
162 | + { |
|
163 | + $requiredValues = [ |
|
164 | + glsr(Database::class)->get($review->ID, 'rebusify'), |
|
165 | + $review->response, |
|
166 | + $review->review_id, |
|
167 | + ]; |
|
168 | + return $this->canProceed($review, 'rebusify_response') |
|
169 | + && 'publish' === $review->status |
|
170 | + && 3 === count(array_filter($requiredValues)); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + protected function canPostReview(Review $review) |
|
177 | + { |
|
178 | + $requiredValues = [ |
|
179 | + $review->author, |
|
180 | + $review->content, |
|
181 | + $review->rating, |
|
182 | + $review->review_id, |
|
183 | + $review->title, |
|
184 | + ]; |
|
185 | + return $this->canProceed($review) |
|
186 | + && 'publish' === $review->status |
|
187 | + && 5 === count(array_filter($requiredValues)); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $metaKey |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
195 | + { |
|
196 | + return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | + && $this->isReviewPostId($review->ID) |
|
198 | + && !$this->hasMetaKey($review, $metaKey); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $metaKey |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
206 | + { |
|
207 | + return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $key |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + protected function isEmptyOrModified($key, array $settings) |
|
215 | + { |
|
216 | + $oldValue = glsr_get_option($key); |
|
217 | + $newValue = glsr_get($settings, $key); |
|
218 | + return empty($newValue) || $newValue !== $oldValue; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + protected function sanitizeRebusifySettings(array $settings) |
|
225 | + { |
|
226 | + $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | + glsr_get($settings, $this->apiKey), |
|
228 | + glsr_get($settings, $this->emailKey) |
|
229 | + ); |
|
230 | + if ($rebusify->success) { |
|
231 | + update_option($this->rebusifyKey, glsr_get($rebusify->response, 'producttype')); |
|
232 | + } else { |
|
233 | + delete_option($this->rebusifyKey); |
|
234 | + $settings = glsr(Helper::class)->dataSet($settings, $this->enabledKey, 'no'); |
|
235 | + glsr(Notice::class)->addError(sprintf( |
|
236 | + __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
237 | + '('.$rebusify->message.')' |
|
238 | + )); |
|
239 | + } |
|
240 | + return $settings; |
|
241 | + } |
|
242 | 242 | } |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | * @return array |
22 | 22 | * @filter site-reviews/settings/callback |
23 | 23 | */ |
24 | - public function filterSettingsCallback(array $settings) |
|
24 | + public function filterSettingsCallback( array $settings ) |
|
25 | 25 | { |
26 | - if ('yes' !== glsr_get($settings, $this->enabledKey)) { |
|
26 | + if( 'yes' !== glsr_get( $settings, $this->enabledKey ) ) { |
|
27 | 27 | return $settings; |
28 | 28 | } |
29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeRebusifySettings($settings); |
|
29 | + $isApiKeyModified = $this->isEmptyOrModified( $this->apiKey, $settings ); |
|
30 | + $isEmailModified = $this->isEmptyOrModified( $this->emailKey, $settings ); |
|
31 | + $isAccountVerified = glsr( OptionManager::class )->getWP( $this->rebusifyKey, false ); |
|
32 | + if( !$isAccountVerified || $isApiKeyModified || $isEmailModified ) { |
|
33 | + $settings = $this->sanitizeRebusifySettings( $settings ); |
|
34 | 34 | } |
35 | 35 | return $settings; |
36 | 36 | } |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | * @filter site-reviews/interpolate/partials/form/table-row-multiple |
42 | 42 | */ |
43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
43 | + public function filterSettingsTableRow( array $context, $template, array $data ) |
|
44 | 44 | { |
45 | - if ($this->enabledKey !== glsr_get($data, 'field.path')) { |
|
45 | + if( $this->enabledKey !== glsr_get( $data, 'field.path' ) ) { |
|
46 | 46 | return $context; |
47 | 47 | } |
48 | - $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | - if ('P' === $rebusifyProductType) { |
|
48 | + $rebusifyProductType = glsr( OptionManager::class )->getWP( $this->rebusifyKey ); |
|
49 | + if( 'P' === $rebusifyProductType ) { |
|
50 | 50 | return $context; |
51 | 51 | } |
52 | - if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
52 | + if( 'F' === $rebusifyProductType && 'yes' === glsr_get_option( 'general.rebusify' ) ) { |
|
53 | 53 | $button = $this->buildUpgradeButton(); |
54 | 54 | } else { |
55 | 55 | $button = $this->buildCreateButton(); |
56 | 56 | } |
57 | - $context['field'].= $button; |
|
57 | + $context['field'] .= $button; |
|
58 | 58 | return $context; |
59 | 59 | } |
60 | 60 | |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | * @action site-reviews/review/created |
65 | 65 | */ |
66 | - public function onCreated(Review $review) |
|
66 | + public function onCreated( Review $review ) |
|
67 | 67 | { |
68 | - if (!$this->canPostReview($review)) { |
|
68 | + if( !$this->canPostReview( $review ) ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | - if ($rebusify->success) { |
|
73 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
71 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
72 | + if( $rebusify->success ) { |
|
73 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | * @action site-reviews/review/reverted |
81 | 81 | */ |
82 | - public function onReverted(Review $review) |
|
82 | + public function onReverted( Review $review ) |
|
83 | 83 | { |
84 | - if (!$this->canPostReview($review)) { |
|
84 | + if( !$this->canPostReview( $review ) ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | - if ($rebusify->success) { |
|
89 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
87 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
88 | + if( $rebusify->success ) { |
|
89 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | * @action site-reviews/review/saved |
97 | 97 | */ |
98 | - public function onSaved(Review $review) |
|
98 | + public function onSaved( Review $review ) |
|
99 | 99 | { |
100 | - if (!$this->canPostReview($review)) { |
|
100 | + if( !$this->canPostReview( $review ) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | - if ($rebusify->success) { |
|
105 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
103 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
104 | + if( $rebusify->success ) { |
|
105 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * @return void |
115 | 115 | * @action updated_postmeta |
116 | 116 | */ |
117 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
117 | + public function onUpdatedMeta( $metaId, $postId, $metaKey ) |
|
118 | 118 | { |
119 | - $review = glsr_get_review($postId); |
|
120 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
119 | + $review = glsr_get_review( $postId ); |
|
120 | + if( !$this->canPostResponse( $review ) || '_response' !== $metaKey ) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | - $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | - if ($rebusify->success) { |
|
125 | - glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
123 | + $rebusify = glsr( Rebusify::class )->sendReviewResponse( $review ); |
|
124 | + if( $rebusify->success ) { |
|
125 | + glsr( Database::class )->set( $review->ID, 'rebusify_response', true ); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function buildCreateButton() |
133 | 133 | { |
134 | - return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
134 | + return glsr( Builder::class )->a( __( 'Create Your Rebusify Account', 'site-reviews' ), [ |
|
135 | 135 | 'class' => 'button', |
136 | 136 | 'href' => Rebusify::WEB_URL, |
137 | 137 | 'target' => '_blank', |
138 | - ]); |
|
138 | + ] ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,37 +143,37 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function buildUpgradeButton() |
145 | 145 | { |
146 | - $build = glsr(Builder::class); |
|
147 | - $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | - $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
146 | + $build = glsr( Builder::class ); |
|
147 | + $notice = $build->p( __( 'Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews' ) ); |
|
148 | + $button = $build->a( __( 'Upgrade Your Rebusify Plan', 'site-reviews' ), [ |
|
149 | 149 | 'class' => 'button', |
150 | 150 | 'href' => Rebusify::WEB_URL, |
151 | 151 | 'target' => '_blank', |
152 | - ]); |
|
153 | - return $build->div($notice.$button, [ |
|
152 | + ] ); |
|
153 | + return $build->div( $notice.$button, [ |
|
154 | 154 | 'class' => 'glsr-notice-inline', |
155 | - ]); |
|
155 | + ] ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @return bool |
160 | 160 | */ |
161 | - protected function canPostResponse(Review $review) |
|
161 | + protected function canPostResponse( Review $review ) |
|
162 | 162 | { |
163 | 163 | $requiredValues = [ |
164 | - glsr(Database::class)->get($review->ID, 'rebusify'), |
|
164 | + glsr( Database::class )->get( $review->ID, 'rebusify' ), |
|
165 | 165 | $review->response, |
166 | 166 | $review->review_id, |
167 | 167 | ]; |
168 | - return $this->canProceed($review, 'rebusify_response') |
|
168 | + return $this->canProceed( $review, 'rebusify_response' ) |
|
169 | 169 | && 'publish' === $review->status |
170 | - && 3 === count(array_filter($requiredValues)); |
|
170 | + && 3 === count( array_filter( $requiredValues ) ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - protected function canPostReview(Review $review) |
|
176 | + protected function canPostReview( Review $review ) |
|
177 | 177 | { |
178 | 178 | $requiredValues = [ |
179 | 179 | $review->author, |
@@ -182,60 +182,60 @@ discard block |
||
182 | 182 | $review->review_id, |
183 | 183 | $review->title, |
184 | 184 | ]; |
185 | - return $this->canProceed($review) |
|
185 | + return $this->canProceed( $review ) |
|
186 | 186 | && 'publish' === $review->status |
187 | - && 5 === count(array_filter($requiredValues)); |
|
187 | + && 5 === count( array_filter( $requiredValues ) ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @param string $metaKey |
192 | 192 | * @return bool |
193 | 193 | */ |
194 | - protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
194 | + protected function canProceed( Review $review, $metaKey = 'rebusify' ) |
|
195 | 195 | { |
196 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | - && $this->isReviewPostId($review->ID) |
|
198 | - && !$this->hasMetaKey($review, $metaKey); |
|
196 | + return glsr( OptionManager::class )->getBool( $this->enabledKey ) |
|
197 | + && $this->isReviewPostId( $review->ID ) |
|
198 | + && !$this->hasMetaKey( $review, $metaKey ); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @param string $metaKey |
203 | 203 | * @return bool |
204 | 204 | */ |
205 | - protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
205 | + protected function hasMetaKey( Review $review, $metaKey = 'rebusify' ) |
|
206 | 206 | { |
207 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
207 | + return '' !== glsr( Database::class )->get( $review->ID, $metaKey ); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @param string $key |
212 | 212 | * @return bool |
213 | 213 | */ |
214 | - protected function isEmptyOrModified($key, array $settings) |
|
214 | + protected function isEmptyOrModified( $key, array $settings ) |
|
215 | 215 | { |
216 | - $oldValue = glsr_get_option($key); |
|
217 | - $newValue = glsr_get($settings, $key); |
|
216 | + $oldValue = glsr_get_option( $key ); |
|
217 | + $newValue = glsr_get( $settings, $key ); |
|
218 | 218 | return empty($newValue) || $newValue !== $oldValue; |
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - protected function sanitizeRebusifySettings(array $settings) |
|
224 | + protected function sanitizeRebusifySettings( array $settings ) |
|
225 | 225 | { |
226 | - $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | - glsr_get($settings, $this->apiKey), |
|
228 | - glsr_get($settings, $this->emailKey) |
|
226 | + $rebusify = glsr( Rebusify::class )->activateKey( |
|
227 | + glsr_get( $settings, $this->apiKey ), |
|
228 | + glsr_get( $settings, $this->emailKey ) |
|
229 | 229 | ); |
230 | - if ($rebusify->success) { |
|
231 | - update_option($this->rebusifyKey, glsr_get($rebusify->response, 'producttype')); |
|
230 | + if( $rebusify->success ) { |
|
231 | + update_option( $this->rebusifyKey, glsr_get( $rebusify->response, 'producttype' ) ); |
|
232 | 232 | } else { |
233 | - delete_option($this->rebusifyKey); |
|
234 | - $settings = glsr(Helper::class)->dataSet($settings, $this->enabledKey, 'no'); |
|
235 | - glsr(Notice::class)->addError(sprintf( |
|
236 | - __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
233 | + delete_option( $this->rebusifyKey ); |
|
234 | + $settings = glsr( Helper::class )->dataSet( $settings, $this->enabledKey, 'no' ); |
|
235 | + glsr( Notice::class )->addError( sprintf( |
|
236 | + __( 'Your Rebusify account details could not be verified, please try again. %s', 'site-reviews' ), |
|
237 | 237 | '('.$rebusify->message.')' |
238 | - )); |
|
238 | + ) ); |
|
239 | 239 | } |
240 | 240 | return $settings; |
241 | 241 | } |
@@ -9,67 +9,67 @@ |
||
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.general.rebusify', 'no'); |
|
44 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify_email', ''); |
|
45 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify_serial', ''); |
|
46 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.reviews.name.format', ''); |
|
47 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.reviews.name.initial', ''); |
|
48 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
49 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit', ''); |
|
50 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
51 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
52 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
53 | - unset($settings['settings']['general']['support']); |
|
54 | - update_option(OptionManager::databaseKey(4), $settings); |
|
55 | - } |
|
56 | - } |
|
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.general.rebusify', 'no'); |
|
44 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify_email', ''); |
|
45 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify_serial', ''); |
|
46 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.reviews.name.format', ''); |
|
47 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.reviews.name.initial', ''); |
|
48 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
49 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit', ''); |
|
50 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
51 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
52 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
53 | + unset($settings['settings']['general']['support']); |
|
54 | + update_option(OptionManager::databaseKey(4), $settings); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public function protectMetaKeys() |
|
62 | - { |
|
63 | - global $wpdb; |
|
64 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
65 | - $keys = implode("','", $keys); |
|
66 | - $postType = Application::POST_TYPE; |
|
67 | - $wpdb->query(" |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public function protectMetaKeys() |
|
62 | + { |
|
63 | + global $wpdb; |
|
64 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
65 | + $keys = implode("','", $keys); |
|
66 | + $postType = Application::POST_TYPE; |
|
67 | + $wpdb->query(" |
|
68 | 68 | UPDATE {$wpdb->postmeta} pm |
69 | 69 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
70 | 70 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
71 | 71 | WHERE pm.meta_key IN ('{$keys}') |
72 | 72 | AND p.post_type = '{$postType}' |
73 | 73 | "); |
74 | - } |
|
74 | + } |
|
75 | 75 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $this->migrateSettings(); |
15 | 15 | $this->protectMetaKeys(); |
16 | 16 | $this->deleteSessions(); |
17 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
17 | + delete_transient( Application::ID.'_cloudflare_ips' ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | public function deleteSessions() |
24 | 24 | { |
25 | 25 | global $wpdb; |
26 | - $wpdb->query(" |
|
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 | 33 | /** |
@@ -35,23 +35,23 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function migrateSettings() |
37 | 37 | { |
38 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
39 | - $multilingual = 'yes' == glsr(Helper::class)->dataGet($settings, 'settings.general.support.polylang') |
|
38 | + if( $settings = get_option( OptionManager::databaseKey( 3 ) ) ) { |
|
39 | + $multilingual = 'yes' == glsr( Helper::class )->dataGet( $settings, 'settings.general.support.polylang' ) |
|
40 | 40 | ? 'polylang' |
41 | 41 | : ''; |
42 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.multilingual', $multilingual); |
|
43 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify', 'no'); |
|
44 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify_email', ''); |
|
45 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.rebusify_serial', ''); |
|
46 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.reviews.name.format', ''); |
|
47 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.reviews.name.initial', ''); |
|
48 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
49 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit', ''); |
|
50 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
51 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
52 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
42 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.general.multilingual', $multilingual ); |
|
43 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.general.rebusify', 'no' ); |
|
44 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.general.rebusify_email', '' ); |
|
45 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.general.rebusify_serial', '' ); |
|
46 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.reviews.name.format', '' ); |
|
47 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.reviews.name.initial', '' ); |
|
48 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.submissions.blacklist.integration', '' ); |
|
49 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.submissions.limit', '' ); |
|
50 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.submissions.limit_whitelist.email', '' ); |
|
51 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.submissions.limit_whitelist.ip_address', '' ); |
|
52 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.submissions.limit_whitelist.username', '' ); |
|
53 | 53 | unset($settings['settings']['general']['support']); |
54 | - update_option(OptionManager::databaseKey(4), $settings); |
|
54 | + update_option( OptionManager::databaseKey( 4 ), $settings ); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | public function protectMetaKeys() |
62 | 62 | { |
63 | 63 | global $wpdb; |
64 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
65 | - $keys = implode("','", $keys); |
|
64 | + $keys = array_keys( glsr( CreateReviewDefaults::class )->defaults() ); |
|
65 | + $keys = implode( "','", $keys ); |
|
66 | 66 | $postType = Application::POST_TYPE; |
67 | - $wpdb->query(" |
|
67 | + $wpdb->query( " |
|
68 | 68 | UPDATE {$wpdb->postmeta} pm |
69 | 69 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
70 | 70 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
71 | 71 | WHERE pm.meta_key IN ('{$keys}') |
72 | 72 | AND p.post_type = '{$postType}' |
73 | - "); |
|
73 | + " ); |
|
74 | 74 | } |
75 | 75 | } |