@@ -6,145 +6,145 @@ |
||
6 | 6 | |
7 | 7 | class CreateReview |
8 | 8 | { |
9 | - public $ajax_request; |
|
10 | - public $assigned_to; |
|
11 | - public $author; |
|
12 | - public $avatar; |
|
13 | - public $blacklisted; |
|
14 | - public $category; |
|
15 | - public $content; |
|
16 | - public $custom; |
|
17 | - public $date; |
|
18 | - public $email; |
|
19 | - public $form_id; |
|
20 | - public $ip_address; |
|
21 | - public $post_id; |
|
22 | - public $rating; |
|
23 | - public $referer; |
|
24 | - public $request; |
|
25 | - public $response; |
|
26 | - public $terms; |
|
27 | - public $title; |
|
28 | - public $url; |
|
9 | + public $ajax_request; |
|
10 | + public $assigned_to; |
|
11 | + public $author; |
|
12 | + public $avatar; |
|
13 | + public $blacklisted; |
|
14 | + public $category; |
|
15 | + public $content; |
|
16 | + public $custom; |
|
17 | + public $date; |
|
18 | + public $email; |
|
19 | + public $form_id; |
|
20 | + public $ip_address; |
|
21 | + public $post_id; |
|
22 | + public $rating; |
|
23 | + public $referer; |
|
24 | + public $request; |
|
25 | + public $response; |
|
26 | + public $terms; |
|
27 | + public $title; |
|
28 | + public $url; |
|
29 | 29 | |
30 | - public function __construct($input) |
|
31 | - { |
|
32 | - $this->request = $input; |
|
33 | - $this->ajax_request = isset($input['_ajax_request']); |
|
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | - $this->avatar = $this->getAvatar(); |
|
37 | - $this->blacklisted = isset($input['blacklisted']); |
|
38 | - $this->category = $this->getCategory(); |
|
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | - $this->custom = $this->getCustom(); |
|
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | - $this->terms = !empty($input['terms']); |
|
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
52 | - } |
|
30 | + public function __construct($input) |
|
31 | + { |
|
32 | + $this->request = $input; |
|
33 | + $this->ajax_request = isset($input['_ajax_request']); |
|
34 | + $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | + $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | + $this->avatar = $this->getAvatar(); |
|
37 | + $this->blacklisted = isset($input['blacklisted']); |
|
38 | + $this->category = $this->getCategory(); |
|
39 | + $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | + $this->custom = $this->getCustom(); |
|
41 | + $this->date = $this->getDate('date'); |
|
42 | + $this->email = sanitize_email($this->getUser('email')); |
|
43 | + $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | + $this->ip_address = $this->get('ip_address'); |
|
45 | + $this->post_id = intval($this->get('_post_id')); |
|
46 | + $this->rating = intval($this->get('rating')); |
|
47 | + $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | + $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | + $this->terms = !empty($input['terms']); |
|
50 | + $this->title = sanitize_text_field($this->get('title')); |
|
51 | + $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $key |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get($key) |
|
59 | - { |
|
60 | - return (string) Arr::get($this->request, $key); |
|
61 | - } |
|
54 | + /** |
|
55 | + * @param string $key |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get($key) |
|
59 | + { |
|
60 | + return (string) Arr::get($this->request, $key); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - protected function getAvatar() |
|
67 | - { |
|
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
71 | - : $avatar; |
|
72 | - } |
|
63 | + /** |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + protected function getAvatar() |
|
67 | + { |
|
68 | + $avatar = $this->get('avatar'); |
|
69 | + return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | + ? (string) get_avatar_url($this->get('email')) |
|
71 | + : $avatar; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function getCategory() |
|
78 | - { |
|
79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function getCategory() |
|
78 | + { |
|
79 | + $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | + return sanitize_key(Arr::get($categories, 0)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getCustom() |
|
87 | - { |
|
88 | - $unset = [ |
|
89 | - '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | - '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | - 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | - ]; |
|
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | - $custom = $this->request; |
|
95 | - foreach ($unset as $key) { |
|
96 | - unset($custom[$key]); |
|
97 | - } |
|
98 | - foreach ($custom as $key => $value) { |
|
99 | - if (is_string($value)) { |
|
100 | - $custom[$key] = sanitize_text_field($value); |
|
101 | - } |
|
102 | - } |
|
103 | - return $custom; |
|
104 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getCustom() |
|
87 | + { |
|
88 | + $unset = [ |
|
89 | + '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | + '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | + 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | + ]; |
|
93 | + $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | + $custom = $this->request; |
|
95 | + foreach ($unset as $key) { |
|
96 | + unset($custom[$key]); |
|
97 | + } |
|
98 | + foreach ($custom as $key => $value) { |
|
99 | + if (is_string($value)) { |
|
100 | + $custom[$key] = sanitize_text_field($value); |
|
101 | + } |
|
102 | + } |
|
103 | + return $custom; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param string $key |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function getDate($key) |
|
111 | - { |
|
112 | - $date = strtotime($this->get($key)); |
|
113 | - if (false === $date) { |
|
114 | - $date = time(); |
|
115 | - } |
|
116 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
117 | - } |
|
106 | + /** |
|
107 | + * @param string $key |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function getDate($key) |
|
111 | + { |
|
112 | + $date = strtotime($this->get($key)); |
|
113 | + if (false === $date) { |
|
114 | + $date = time(); |
|
115 | + } |
|
116 | + return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @param string $key |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function getUser($key) |
|
124 | - { |
|
125 | - $value = $this->get($key); |
|
126 | - if (empty($value)) { |
|
127 | - $user = wp_get_current_user(); |
|
128 | - $userValues = [ |
|
129 | - 'email' => 'user_email', |
|
130 | - 'name' => 'display_name', |
|
131 | - ]; |
|
132 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
133 | - return $user->{$userValues[$key]}; |
|
134 | - } |
|
135 | - } |
|
136 | - return $value; |
|
137 | - } |
|
119 | + /** |
|
120 | + * @param string $key |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function getUser($key) |
|
124 | + { |
|
125 | + $value = $this->get($key); |
|
126 | + if (empty($value)) { |
|
127 | + $user = wp_get_current_user(); |
|
128 | + $userValues = [ |
|
129 | + 'email' => 'user_email', |
|
130 | + 'name' => 'display_name', |
|
131 | + ]; |
|
132 | + if ($user->exists() && array_key_exists($key, $userValues)) { |
|
133 | + return $user->{$userValues[$key]}; |
|
134 | + } |
|
135 | + } |
|
136 | + return $value; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - protected function getNumeric($key) |
|
144 | - { |
|
145 | - $value = $this->get($key); |
|
146 | - return is_numeric($value) |
|
147 | - ? $value |
|
148 | - : ''; |
|
149 | - } |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + protected function getNumeric($key) |
|
144 | + { |
|
145 | + $value = $this->get($key); |
|
146 | + return is_numeric($value) |
|
147 | + ? $value |
|
148 | + : ''; |
|
149 | + } |
|
150 | 150 | } |
@@ -27,37 +27,37 @@ discard block |
||
27 | 27 | public $title; |
28 | 28 | public $url; |
29 | 29 | |
30 | - public function __construct($input) |
|
30 | + public function __construct( $input ) |
|
31 | 31 | { |
32 | 32 | $this->request = $input; |
33 | 33 | $this->ajax_request = isset($input['_ajax_request']); |
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
34 | + $this->assigned_to = $this->getNumeric( 'assign_to' ); |
|
35 | + $this->author = sanitize_text_field( $this->getUser( 'name' ) ); |
|
36 | 36 | $this->avatar = $this->getAvatar(); |
37 | 37 | $this->blacklisted = isset($input['blacklisted']); |
38 | 38 | $this->category = $this->getCategory(); |
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
39 | + $this->content = sanitize_textarea_field( $this->get( 'content' ) ); |
|
40 | 40 | $this->custom = $this->getCustom(); |
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
41 | + $this->date = $this->getDate( 'date' ); |
|
42 | + $this->email = sanitize_email( $this->getUser( 'email' ) ); |
|
43 | + $this->form_id = sanitize_key( $this->get( 'form_id' ) ); |
|
44 | + $this->ip_address = $this->get( 'ip_address' ); |
|
45 | + $this->post_id = intval( $this->get( '_post_id' ) ); |
|
46 | + $this->rating = intval( $this->get( 'rating' ) ); |
|
47 | + $this->referer = sanitize_text_field( $this->get( '_referer' ) ); |
|
48 | + $this->response = sanitize_textarea_field( $this->get( 'response' ) ); |
|
49 | 49 | $this->terms = !empty($input['terms']); |
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
50 | + $this->title = sanitize_text_field( $this->get( 'title' ) ); |
|
51 | + $this->url = esc_url_raw( sanitize_text_field( $this->get( 'url' ) ) ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @param string $key |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - protected function get($key) |
|
58 | + protected function get( $key ) |
|
59 | 59 | { |
60 | - return (string) Arr::get($this->request, $key); |
|
60 | + return (string)Arr::get( $this->request, $key ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function getAvatar() |
67 | 67 | { |
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
68 | + $avatar = $this->get( 'avatar' ); |
|
69 | + return !filter_var( $avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED ) |
|
70 | + ? (string)get_avatar_url( $this->get( 'email' ) ) |
|
71 | 71 | : $avatar; |
72 | 72 | } |
73 | 73 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected function getCategory() |
78 | 78 | { |
79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
79 | + $categories = Arr::convertStringToArray( $this->get( 'category' ) ); |
|
80 | + return sanitize_key( Arr::get( $categories, 0 ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
91 | 91 | 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
92 | 92 | ]; |
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
93 | + $unset = apply_filters( 'site-reviews/create/unset-keys-from-custom', $unset ); |
|
94 | 94 | $custom = $this->request; |
95 | - foreach ($unset as $key) { |
|
95 | + foreach( $unset as $key ) { |
|
96 | 96 | unset($custom[$key]); |
97 | 97 | } |
98 | - foreach ($custom as $key => $value) { |
|
99 | - if (is_string($value)) { |
|
100 | - $custom[$key] = sanitize_text_field($value); |
|
98 | + foreach( $custom as $key => $value ) { |
|
99 | + if( is_string( $value ) ) { |
|
100 | + $custom[$key] = sanitize_text_field( $value ); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | return $custom; |
@@ -107,29 +107,29 @@ discard block |
||
107 | 107 | * @param string $key |
108 | 108 | * @return string |
109 | 109 | */ |
110 | - protected function getDate($key) |
|
110 | + protected function getDate( $key ) |
|
111 | 111 | { |
112 | - $date = strtotime($this->get($key)); |
|
113 | - if (false === $date) { |
|
112 | + $date = strtotime( $this->get( $key ) ); |
|
113 | + if( false === $date ) { |
|
114 | 114 | $date = time(); |
115 | 115 | } |
116 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
116 | + return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date ) ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * @param string $key |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - protected function getUser($key) |
|
123 | + protected function getUser( $key ) |
|
124 | 124 | { |
125 | - $value = $this->get($key); |
|
126 | - if (empty($value)) { |
|
125 | + $value = $this->get( $key ); |
|
126 | + if( empty($value) ) { |
|
127 | 127 | $user = wp_get_current_user(); |
128 | 128 | $userValues = [ |
129 | 129 | 'email' => 'user_email', |
130 | 130 | 'name' => 'display_name', |
131 | 131 | ]; |
132 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
132 | + if( $user->exists() && array_key_exists( $key, $userValues ) ) { |
|
133 | 133 | return $user->{$userValues[$key]}; |
134 | 134 | } |
135 | 135 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param string $key |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - protected function getNumeric($key) |
|
143 | + protected function getNumeric( $key ) |
|
144 | 144 | { |
145 | - $value = $this->get($key); |
|
146 | - return is_numeric($value) |
|
145 | + $value = $this->get( $key ); |
|
146 | + return is_numeric( $value ) |
|
147 | 147 | ? $value |
148 | 148 | : ''; |
149 | 149 | } |
@@ -7,39 +7,39 @@ |
||
7 | 7 | |
8 | 8 | abstract class Widget extends WP_Widget |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $widgetArgs; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $widgetArgs; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @param string $tag |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - protected function renderField($tag, array $args = []) |
|
20 | - { |
|
21 | - $args = $this->normalizeFieldAttributes($tag, $args); |
|
22 | - $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
23 | - echo glsr(Builder::class)->div($field, [ |
|
24 | - 'class' => 'glsr-field', |
|
25 | - ]); |
|
26 | - } |
|
15 | + /** |
|
16 | + * @param string $tag |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + protected function renderField($tag, array $args = []) |
|
20 | + { |
|
21 | + $args = $this->normalizeFieldAttributes($tag, $args); |
|
22 | + $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
23 | + echo glsr(Builder::class)->div($field, [ |
|
24 | + 'class' => 'glsr-field', |
|
25 | + ]); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $tag |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - protected function normalizeFieldAttributes($tag, array $args) |
|
33 | - { |
|
34 | - if (empty($args['value'])) { |
|
35 | - $args['value'] = $this->widgetArgs[$args['name']]; |
|
36 | - } |
|
37 | - if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
38 | - $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
39 | - } |
|
40 | - $args['id'] = $this->get_field_id($args['name']); |
|
41 | - $args['name'] = $this->get_field_name($args['name']); |
|
42 | - $args['is_widget'] = true; |
|
43 | - return $args; |
|
44 | - } |
|
28 | + /** |
|
29 | + * @param string $tag |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + protected function normalizeFieldAttributes($tag, array $args) |
|
33 | + { |
|
34 | + if (empty($args['value'])) { |
|
35 | + $args['value'] = $this->widgetArgs[$args['name']]; |
|
36 | + } |
|
37 | + if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
38 | + $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
39 | + } |
|
40 | + $args['id'] = $this->get_field_id($args['name']); |
|
41 | + $args['name'] = $this->get_field_name($args['name']); |
|
42 | + $args['is_widget'] = true; |
|
43 | + return $args; |
|
44 | + } |
|
45 | 45 | } |
@@ -16,29 +16,29 @@ |
||
16 | 16 | * @param string $tag |
17 | 17 | * @return void |
18 | 18 | */ |
19 | - protected function renderField($tag, array $args = []) |
|
19 | + protected function renderField( $tag, array $args = [] ) |
|
20 | 20 | { |
21 | - $args = $this->normalizeFieldAttributes($tag, $args); |
|
22 | - $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
23 | - echo glsr(Builder::class)->div($field, [ |
|
21 | + $args = $this->normalizeFieldAttributes( $tag, $args ); |
|
22 | + $field = glsr( Builder::class )->$tag( $args['name'], $args ); |
|
23 | + echo glsr( Builder::class )->div( $field, [ |
|
24 | 24 | 'class' => 'glsr-field', |
25 | - ]); |
|
25 | + ] ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param string $tag |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - protected function normalizeFieldAttributes($tag, array $args) |
|
32 | + protected function normalizeFieldAttributes( $tag, array $args ) |
|
33 | 33 | { |
34 | - if (empty($args['value'])) { |
|
34 | + if( empty($args['value']) ) { |
|
35 | 35 | $args['value'] = $this->widgetArgs[$args['name']]; |
36 | 36 | } |
37 | - if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
38 | - $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
37 | + if( empty($this->widgetArgs['options']) && in_array( $tag, ['checkbox', 'radio'] ) ) { |
|
38 | + $args['checked'] = in_array( $args['value'], (array)$this->widgetArgs[$args['name']] ); |
|
39 | 39 | } |
40 | - $args['id'] = $this->get_field_id($args['name']); |
|
41 | - $args['name'] = $this->get_field_name($args['name']); |
|
40 | + $args['id'] = $this->get_field_id( $args['name'] ); |
|
41 | + $args['name'] = $this->get_field_name( $args['name'] ); |
|
42 | 42 | $args['is_widget'] = true; |
43 | 43 | return $args; |
44 | 44 | } |
@@ -8,103 +8,103 @@ |
||
8 | 8 | |
9 | 9 | class SiteReviewsWidget extends Widget |
10 | 10 | { |
11 | - public function __construct() |
|
12 | - { |
|
13 | - $idBase = Application::ID.'_site-reviews'; |
|
14 | - $name = __('Recent Reviews', 'site-reviews'); |
|
15 | - $widgetOptions = [ |
|
16 | - 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
17 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
18 | - ]; |
|
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
20 | - } |
|
11 | + public function __construct() |
|
12 | + { |
|
13 | + $idBase = Application::ID.'_site-reviews'; |
|
14 | + $name = __('Recent Reviews', 'site-reviews'); |
|
15 | + $widgetOptions = [ |
|
16 | + 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
17 | + 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
18 | + ]; |
|
19 | + parent::__construct($idBase, $name, $widgetOptions); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param array $instance |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function form($instance) |
|
27 | - { |
|
28 | - $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
31 | - 'class' => 'widefat', |
|
32 | - 'label' => __('Title', 'site-reviews'), |
|
33 | - 'name' => 'title', |
|
34 | - ]); |
|
35 | - $this->renderField('number', [ |
|
36 | - 'class' => 'small-text', |
|
37 | - 'default' => 10, |
|
38 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
39 | - 'max' => 100, |
|
40 | - 'name' => 'display', |
|
41 | - ]); |
|
42 | - $this->renderField('select', [ |
|
43 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
44 | - 'name' => 'rating', |
|
45 | - 'options' => [ |
|
46 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
47 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
48 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
49 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
50 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
51 | - ], |
|
52 | - ]); |
|
53 | - if (count(glsr()->reviewTypes) > 1) { |
|
54 | - $this->renderField('select', [ |
|
55 | - 'class' => 'widefat', |
|
56 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
57 | - 'name' => 'type', |
|
58 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
59 | - ]); |
|
60 | - } |
|
61 | - if (!empty($terms)) { |
|
62 | - $this->renderField('select', [ |
|
63 | - 'class' => 'widefat', |
|
64 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
65 | - 'name' => 'category', |
|
66 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
67 | - ]); |
|
68 | - } |
|
69 | - $this->renderField('text', [ |
|
70 | - 'class' => 'widefat', |
|
71 | - 'default' => '', |
|
72 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
73 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
74 | - 'name' => 'assigned_to', |
|
75 | - ]); |
|
76 | - $this->renderField('text', [ |
|
77 | - 'class' => 'widefat', |
|
78 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
79 | - 'name' => 'class', |
|
80 | - ]); |
|
81 | - $this->renderField('checkbox', [ |
|
82 | - 'name' => 'hide', |
|
83 | - 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
84 | - ]); |
|
85 | - } |
|
22 | + /** |
|
23 | + * @param array $instance |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function form($instance) |
|
27 | + { |
|
28 | + $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
29 | + $terms = glsr(Database::class)->getTerms(); |
|
30 | + $this->renderField('text', [ |
|
31 | + 'class' => 'widefat', |
|
32 | + 'label' => __('Title', 'site-reviews'), |
|
33 | + 'name' => 'title', |
|
34 | + ]); |
|
35 | + $this->renderField('number', [ |
|
36 | + 'class' => 'small-text', |
|
37 | + 'default' => 10, |
|
38 | + 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
39 | + 'max' => 100, |
|
40 | + 'name' => 'display', |
|
41 | + ]); |
|
42 | + $this->renderField('select', [ |
|
43 | + 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
44 | + 'name' => 'rating', |
|
45 | + 'options' => [ |
|
46 | + '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
47 | + '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
48 | + '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
49 | + '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
50 | + '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
51 | + ], |
|
52 | + ]); |
|
53 | + if (count(glsr()->reviewTypes) > 1) { |
|
54 | + $this->renderField('select', [ |
|
55 | + 'class' => 'widefat', |
|
56 | + 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
57 | + 'name' => 'type', |
|
58 | + 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
59 | + ]); |
|
60 | + } |
|
61 | + if (!empty($terms)) { |
|
62 | + $this->renderField('select', [ |
|
63 | + 'class' => 'widefat', |
|
64 | + 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
65 | + 'name' => 'category', |
|
66 | + 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
67 | + ]); |
|
68 | + } |
|
69 | + $this->renderField('text', [ |
|
70 | + 'class' => 'widefat', |
|
71 | + 'default' => '', |
|
72 | + 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
73 | + 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
74 | + 'name' => 'assigned_to', |
|
75 | + ]); |
|
76 | + $this->renderField('text', [ |
|
77 | + 'class' => 'widefat', |
|
78 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
79 | + 'name' => 'class', |
|
80 | + ]); |
|
81 | + $this->renderField('checkbox', [ |
|
82 | + 'name' => 'hide', |
|
83 | + 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
84 | + ]); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param array $newInstance |
|
89 | - * @param array $oldInstance |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function update($newInstance, $oldInstance) |
|
93 | - { |
|
94 | - if (!is_numeric($newInstance['display'])) { |
|
95 | - $newInstance['display'] = 10; |
|
96 | - } |
|
97 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
98 | - return parent::update($newInstance, $oldInstance); |
|
99 | - } |
|
87 | + /** |
|
88 | + * @param array $newInstance |
|
89 | + * @param array $oldInstance |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function update($newInstance, $oldInstance) |
|
93 | + { |
|
94 | + if (!is_numeric($newInstance['display'])) { |
|
95 | + $newInstance['display'] = 10; |
|
96 | + } |
|
97 | + $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
98 | + return parent::update($newInstance, $oldInstance); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param array $args |
|
103 | - * @param array $instance |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function widget($args, $instance) |
|
107 | - { |
|
108 | - echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
109 | - } |
|
101 | + /** |
|
102 | + * @param array $args |
|
103 | + * @param array $instance |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function widget($args, $instance) |
|
107 | + { |
|
108 | + echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
109 | + } |
|
110 | 110 | } |
@@ -11,77 +11,77 @@ discard block |
||
11 | 11 | public function __construct() |
12 | 12 | { |
13 | 13 | $idBase = Application::ID.'_site-reviews'; |
14 | - $name = __('Recent Reviews', 'site-reviews'); |
|
14 | + $name = __( 'Recent Reviews', 'site-reviews' ); |
|
15 | 15 | $widgetOptions = [ |
16 | 16 | 'class' => 'glsr-widget glsr-widget-site-reviews', |
17 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
17 | + 'description' => __( 'Site Reviews: Display your recent reviews.', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
19 | + parent::__construct( $idBase, $name, $widgetOptions ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param array $instance |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function form($instance) |
|
26 | + public function form( $instance ) |
|
27 | 27 | { |
28 | - $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
28 | + $this->widgetArgs = glsr( SiteReviewsShortcode::class )->normalizeAtts( $instance ); |
|
29 | + $terms = glsr( Database::class )->getTerms(); |
|
30 | + $this->renderField( 'text', [ |
|
31 | 31 | 'class' => 'widefat', |
32 | - 'label' => __('Title', 'site-reviews'), |
|
32 | + 'label' => __( 'Title', 'site-reviews' ), |
|
33 | 33 | 'name' => 'title', |
34 | - ]); |
|
35 | - $this->renderField('number', [ |
|
34 | + ] ); |
|
35 | + $this->renderField( 'number', [ |
|
36 | 36 | 'class' => 'small-text', |
37 | 37 | 'default' => 10, |
38 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
38 | + 'label' => __( 'How many reviews would you like to display?', 'site-reviews' ), |
|
39 | 39 | 'max' => 100, |
40 | 40 | 'name' => 'display', |
41 | - ]); |
|
42 | - $this->renderField('select', [ |
|
43 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
41 | + ] ); |
|
42 | + $this->renderField( 'select', [ |
|
43 | + 'label' => __( 'What is the minimum rating to display?', 'site-reviews' ), |
|
44 | 44 | 'name' => 'rating', |
45 | 45 | 'options' => [ |
46 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
47 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
48 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
49 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
50 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
46 | + '5' => sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ), |
|
47 | + '4' => sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ), |
|
48 | + '3' => sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ), |
|
49 | + '2' => sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ), |
|
50 | + '1' => sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ), |
|
51 | 51 | ], |
52 | - ]); |
|
53 | - if (count(glsr()->reviewTypes) > 1) { |
|
54 | - $this->renderField('select', [ |
|
52 | + ] ); |
|
53 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
54 | + $this->renderField( 'select', [ |
|
55 | 55 | 'class' => 'widefat', |
56 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
56 | + 'label' => __( 'Which type of review would you like to display?', 'site-reviews' ), |
|
57 | 57 | 'name' => 'type', |
58 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
59 | - ]); |
|
58 | + 'options' => ['' => __( 'All Reviews', 'site-reviews' )] + glsr()->reviewTypes, |
|
59 | + ] ); |
|
60 | 60 | } |
61 | - if (!empty($terms)) { |
|
62 | - $this->renderField('select', [ |
|
61 | + if( !empty($terms) ) { |
|
62 | + $this->renderField( 'select', [ |
|
63 | 63 | 'class' => 'widefat', |
64 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
64 | + 'label' => __( 'Limit reviews to this category', 'site-reviews' ), |
|
65 | 65 | 'name' => 'category', |
66 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
67 | - ]); |
|
66 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
67 | + ] ); |
|
68 | 68 | } |
69 | - $this->renderField('text', [ |
|
69 | + $this->renderField( 'text', [ |
|
70 | 70 | 'class' => 'widefat', |
71 | 71 | 'default' => '', |
72 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
73 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
72 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
73 | + 'label' => __( 'Limit reviews to those assigned to this page/post ID', 'site-reviews' ), |
|
74 | 74 | 'name' => 'assigned_to', |
75 | - ]); |
|
76 | - $this->renderField('text', [ |
|
75 | + ] ); |
|
76 | + $this->renderField( 'text', [ |
|
77 | 77 | 'class' => 'widefat', |
78 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
78 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
79 | 79 | 'name' => 'class', |
80 | - ]); |
|
81 | - $this->renderField('checkbox', [ |
|
80 | + ] ); |
|
81 | + $this->renderField( 'checkbox', [ |
|
82 | 82 | 'name' => 'hide', |
83 | - 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
84 | - ]); |
|
83 | + 'options' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
84 | + ] ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * @param array $oldInstance |
90 | 90 | * @return array |
91 | 91 | */ |
92 | - public function update($newInstance, $oldInstance) |
|
92 | + public function update( $newInstance, $oldInstance ) |
|
93 | 93 | { |
94 | - if (!is_numeric($newInstance['display'])) { |
|
94 | + if( !is_numeric( $newInstance['display'] ) ) { |
|
95 | 95 | $newInstance['display'] = 10; |
96 | 96 | } |
97 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
98 | - return parent::update($newInstance, $oldInstance); |
|
97 | + $newInstance['display'] = min( 50, max( 0, intval( $newInstance['display'] ) ) ); |
|
98 | + return parent::update( $newInstance, $oldInstance ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @param array $instance |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function widget($args, $instance) |
|
106 | + public function widget( $args, $instance ) |
|
107 | 107 | { |
108 | - echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
108 | + echo glsr( SiteReviewsShortcode::class )->build( $instance, $args, 'widget' ); |
|
109 | 109 | } |
110 | 110 | } |
@@ -8,66 +8,66 @@ |
||
8 | 8 | |
9 | 9 | class SiteReviewsFormWidget extends Widget |
10 | 10 | { |
11 | - public function __construct() |
|
12 | - { |
|
13 | - $idBase = Application::ID.'_site-reviews-form'; |
|
14 | - $name = __('Submit a Review', 'site-reviews'); |
|
15 | - $widgetOptions = [ |
|
16 | - 'classname' => 'glsr-widget glsr-widget-site-reviews-form', |
|
17 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
18 | - ]; |
|
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
20 | - } |
|
11 | + public function __construct() |
|
12 | + { |
|
13 | + $idBase = Application::ID.'_site-reviews-form'; |
|
14 | + $name = __('Submit a Review', 'site-reviews'); |
|
15 | + $widgetOptions = [ |
|
16 | + 'classname' => 'glsr-widget glsr-widget-site-reviews-form', |
|
17 | + 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
18 | + ]; |
|
19 | + parent::__construct($idBase, $name, $widgetOptions); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param array $instance |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function form($instance) |
|
27 | - { |
|
28 | - $this->widgetArgs = glsr(SiteReviewsFormShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
31 | - 'class' => 'widefat', |
|
32 | - 'label' => __('Title', 'site-reviews'), |
|
33 | - 'name' => 'title', |
|
34 | - ]); |
|
35 | - $this->renderField('textarea', [ |
|
36 | - 'class' => 'widefat', |
|
37 | - 'label' => __('Description', 'site-reviews'), |
|
38 | - 'name' => 'description', |
|
39 | - ]); |
|
40 | - $this->renderField('select', [ |
|
41 | - 'class' => 'widefat', |
|
42 | - 'label' => __('Automatically assign a category', 'site-reviews'), |
|
43 | - 'name' => 'category', |
|
44 | - 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
45 | - ]); |
|
46 | - $this->renderField('text', [ |
|
47 | - 'class' => 'widefat', |
|
48 | - 'default' => '', |
|
49 | - 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
50 | - 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
51 | - 'name' => 'assign_to', |
|
52 | - ]); |
|
53 | - $this->renderField('text', [ |
|
54 | - 'class' => 'widefat', |
|
55 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
56 | - 'name' => 'class', |
|
57 | - ]); |
|
58 | - $this->renderField('checkbox', [ |
|
59 | - 'name' => 'hide', |
|
60 | - 'options' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
61 | - ]); |
|
62 | - } |
|
22 | + /** |
|
23 | + * @param array $instance |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function form($instance) |
|
27 | + { |
|
28 | + $this->widgetArgs = glsr(SiteReviewsFormShortcode::class)->normalizeAtts($instance); |
|
29 | + $terms = glsr(Database::class)->getTerms(); |
|
30 | + $this->renderField('text', [ |
|
31 | + 'class' => 'widefat', |
|
32 | + 'label' => __('Title', 'site-reviews'), |
|
33 | + 'name' => 'title', |
|
34 | + ]); |
|
35 | + $this->renderField('textarea', [ |
|
36 | + 'class' => 'widefat', |
|
37 | + 'label' => __('Description', 'site-reviews'), |
|
38 | + 'name' => 'description', |
|
39 | + ]); |
|
40 | + $this->renderField('select', [ |
|
41 | + 'class' => 'widefat', |
|
42 | + 'label' => __('Automatically assign a category', 'site-reviews'), |
|
43 | + 'name' => 'category', |
|
44 | + 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
45 | + ]); |
|
46 | + $this->renderField('text', [ |
|
47 | + 'class' => 'widefat', |
|
48 | + 'default' => '', |
|
49 | + 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
50 | + 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
51 | + 'name' => 'assign_to', |
|
52 | + ]); |
|
53 | + $this->renderField('text', [ |
|
54 | + 'class' => 'widefat', |
|
55 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
56 | + 'name' => 'class', |
|
57 | + ]); |
|
58 | + $this->renderField('checkbox', [ |
|
59 | + 'name' => 'hide', |
|
60 | + 'options' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
61 | + ]); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param array $args |
|
66 | - * @param array $instance |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function widget($args, $instance) |
|
70 | - { |
|
71 | - echo glsr(SiteReviewsFormShortcode::class)->build($instance, $args, 'widget'); |
|
72 | - } |
|
64 | + /** |
|
65 | + * @param array $args |
|
66 | + * @param array $instance |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function widget($args, $instance) |
|
70 | + { |
|
71 | + echo glsr(SiteReviewsFormShortcode::class)->build($instance, $args, 'widget'); |
|
72 | + } |
|
73 | 73 | } |
@@ -11,54 +11,54 @@ discard block |
||
11 | 11 | public function __construct() |
12 | 12 | { |
13 | 13 | $idBase = Application::ID.'_site-reviews-form'; |
14 | - $name = __('Submit a Review', 'site-reviews'); |
|
14 | + $name = __( 'Submit a Review', 'site-reviews' ); |
|
15 | 15 | $widgetOptions = [ |
16 | 16 | 'classname' => 'glsr-widget glsr-widget-site-reviews-form', |
17 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
17 | + 'description' => __( 'Site Reviews: Display a form to submit reviews.', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
19 | + parent::__construct( $idBase, $name, $widgetOptions ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param array $instance |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function form($instance) |
|
26 | + public function form( $instance ) |
|
27 | 27 | { |
28 | - $this->widgetArgs = glsr(SiteReviewsFormShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
28 | + $this->widgetArgs = glsr( SiteReviewsFormShortcode::class )->normalizeAtts( $instance ); |
|
29 | + $terms = glsr( Database::class )->getTerms(); |
|
30 | + $this->renderField( 'text', [ |
|
31 | 31 | 'class' => 'widefat', |
32 | - 'label' => __('Title', 'site-reviews'), |
|
32 | + 'label' => __( 'Title', 'site-reviews' ), |
|
33 | 33 | 'name' => 'title', |
34 | - ]); |
|
35 | - $this->renderField('textarea', [ |
|
34 | + ] ); |
|
35 | + $this->renderField( 'textarea', [ |
|
36 | 36 | 'class' => 'widefat', |
37 | - 'label' => __('Description', 'site-reviews'), |
|
37 | + 'label' => __( 'Description', 'site-reviews' ), |
|
38 | 38 | 'name' => 'description', |
39 | - ]); |
|
40 | - $this->renderField('select', [ |
|
39 | + ] ); |
|
40 | + $this->renderField( 'select', [ |
|
41 | 41 | 'class' => 'widefat', |
42 | - 'label' => __('Automatically assign a category', 'site-reviews'), |
|
42 | + 'label' => __( 'Automatically assign a category', 'site-reviews' ), |
|
43 | 43 | 'name' => 'category', |
44 | - 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
45 | - ]); |
|
46 | - $this->renderField('text', [ |
|
44 | + 'options' => ['' => __( 'Do not assign a category', 'site-reviews' )] + $terms, |
|
45 | + ] ); |
|
46 | + $this->renderField( 'text', [ |
|
47 | 47 | 'class' => 'widefat', |
48 | 48 | 'default' => '', |
49 | - 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
50 | - 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
49 | + 'description' => sprintf( __( 'You may also enter %s to assign to the current post.', 'site-reviews' ), '<code>post_id</code>' ), |
|
50 | + 'label' => __( 'Assign reviews to a custom page/post ID', 'site-reviews' ), |
|
51 | 51 | 'name' => 'assign_to', |
52 | - ]); |
|
53 | - $this->renderField('text', [ |
|
52 | + ] ); |
|
53 | + $this->renderField( 'text', [ |
|
54 | 54 | 'class' => 'widefat', |
55 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
55 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
56 | 56 | 'name' => 'class', |
57 | - ]); |
|
58 | - $this->renderField('checkbox', [ |
|
57 | + ] ); |
|
58 | + $this->renderField( 'checkbox', [ |
|
59 | 59 | 'name' => 'hide', |
60 | - 'options' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
61 | - ]); |
|
60 | + 'options' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
|
61 | + ] ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @param array $instance |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - public function widget($args, $instance) |
|
69 | + public function widget( $args, $instance ) |
|
70 | 70 | { |
71 | - echo glsr(SiteReviewsFormShortcode::class)->build($instance, $args, 'widget'); |
|
71 | + echo glsr( SiteReviewsFormShortcode::class )->build( $instance, $args, 'widget' ); |
|
72 | 72 | } |
73 | 73 | } |
@@ -8,71 +8,71 @@ |
||
8 | 8 | |
9 | 9 | class SiteReviewsSummaryWidget extends Widget |
10 | 10 | { |
11 | - public function __construct() |
|
12 | - { |
|
13 | - $idBase = Application::ID.'_site-reviews-summary'; |
|
14 | - $name = __('Summary of Reviews', 'site-reviews'); |
|
15 | - $widgetOptions = [ |
|
16 | - 'classname' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
17 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
18 | - ]; |
|
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
20 | - } |
|
11 | + public function __construct() |
|
12 | + { |
|
13 | + $idBase = Application::ID.'_site-reviews-summary'; |
|
14 | + $name = __('Summary of Reviews', 'site-reviews'); |
|
15 | + $widgetOptions = [ |
|
16 | + 'classname' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
17 | + 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
18 | + ]; |
|
19 | + parent::__construct($idBase, $name, $widgetOptions); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param array $instance |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function form($instance) |
|
27 | - { |
|
28 | - $this->widgetArgs = glsr(SiteReviewsSummaryShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
31 | - 'class' => 'widefat', |
|
32 | - 'label' => __('Title', 'site-reviews'), |
|
33 | - 'name' => 'title', |
|
34 | - ]); |
|
35 | - if (count(glsr()->reviewTypes) > 1) { |
|
36 | - $this->renderField('select', [ |
|
37 | - 'class' => 'widefat', |
|
38 | - 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
39 | - 'name' => 'type', |
|
40 | - 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
41 | - ]); |
|
42 | - } |
|
43 | - if (!empty($terms)) { |
|
44 | - $this->renderField('select', [ |
|
45 | - 'class' => 'widefat', |
|
46 | - 'label' => __('Limit summary to this category', 'site-reviews'), |
|
47 | - 'name' => 'category', |
|
48 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
49 | - ]); |
|
50 | - } |
|
51 | - $this->renderField('text', [ |
|
52 | - 'class' => 'widefat', |
|
53 | - 'default' => '', |
|
54 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
55 | - 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
56 | - 'name' => 'assigned_to', |
|
57 | - ]); |
|
58 | - $this->renderField('text', [ |
|
59 | - 'class' => 'widefat', |
|
60 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
61 | - 'name' => 'class', |
|
62 | - ]); |
|
63 | - $this->renderField('checkbox', [ |
|
64 | - 'name' => 'hide', |
|
65 | - 'options' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
66 | - ]); |
|
67 | - } |
|
22 | + /** |
|
23 | + * @param array $instance |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function form($instance) |
|
27 | + { |
|
28 | + $this->widgetArgs = glsr(SiteReviewsSummaryShortcode::class)->normalizeAtts($instance); |
|
29 | + $terms = glsr(Database::class)->getTerms(); |
|
30 | + $this->renderField('text', [ |
|
31 | + 'class' => 'widefat', |
|
32 | + 'label' => __('Title', 'site-reviews'), |
|
33 | + 'name' => 'title', |
|
34 | + ]); |
|
35 | + if (count(glsr()->reviewTypes) > 1) { |
|
36 | + $this->renderField('select', [ |
|
37 | + 'class' => 'widefat', |
|
38 | + 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
39 | + 'name' => 'type', |
|
40 | + 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
41 | + ]); |
|
42 | + } |
|
43 | + if (!empty($terms)) { |
|
44 | + $this->renderField('select', [ |
|
45 | + 'class' => 'widefat', |
|
46 | + 'label' => __('Limit summary to this category', 'site-reviews'), |
|
47 | + 'name' => 'category', |
|
48 | + 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
49 | + ]); |
|
50 | + } |
|
51 | + $this->renderField('text', [ |
|
52 | + 'class' => 'widefat', |
|
53 | + 'default' => '', |
|
54 | + 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
55 | + 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
56 | + 'name' => 'assigned_to', |
|
57 | + ]); |
|
58 | + $this->renderField('text', [ |
|
59 | + 'class' => 'widefat', |
|
60 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
61 | + 'name' => 'class', |
|
62 | + ]); |
|
63 | + $this->renderField('checkbox', [ |
|
64 | + 'name' => 'hide', |
|
65 | + 'options' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
66 | + ]); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param array $args |
|
71 | - * @param array $instance |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function widget($args, $instance) |
|
75 | - { |
|
76 | - echo glsr(SiteReviewsSummaryShortcode::class)->build($instance, $args, 'widget'); |
|
77 | - } |
|
69 | + /** |
|
70 | + * @param array $args |
|
71 | + * @param array $instance |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function widget($args, $instance) |
|
75 | + { |
|
76 | + echo glsr(SiteReviewsSummaryShortcode::class)->build($instance, $args, 'widget'); |
|
77 | + } |
|
78 | 78 | } |
@@ -11,59 +11,59 @@ discard block |
||
11 | 11 | public function __construct() |
12 | 12 | { |
13 | 13 | $idBase = Application::ID.'_site-reviews-summary'; |
14 | - $name = __('Summary of Reviews', 'site-reviews'); |
|
14 | + $name = __( 'Summary of Reviews', 'site-reviews' ); |
|
15 | 15 | $widgetOptions = [ |
16 | 16 | 'classname' => 'glsr-widget glsr-widget-site-reviews-summary', |
17 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
17 | + 'description' => __( 'Site Reviews: Display a summary of your reviews.', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
19 | + parent::__construct( $idBase, $name, $widgetOptions ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param array $instance |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function form($instance) |
|
26 | + public function form( $instance ) |
|
27 | 27 | { |
28 | - $this->widgetArgs = glsr(SiteReviewsSummaryShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
28 | + $this->widgetArgs = glsr( SiteReviewsSummaryShortcode::class )->normalizeAtts( $instance ); |
|
29 | + $terms = glsr( Database::class )->getTerms(); |
|
30 | + $this->renderField( 'text', [ |
|
31 | 31 | 'class' => 'widefat', |
32 | - 'label' => __('Title', 'site-reviews'), |
|
32 | + 'label' => __( 'Title', 'site-reviews' ), |
|
33 | 33 | 'name' => 'title', |
34 | - ]); |
|
35 | - if (count(glsr()->reviewTypes) > 1) { |
|
36 | - $this->renderField('select', [ |
|
34 | + ] ); |
|
35 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
36 | + $this->renderField( 'select', [ |
|
37 | 37 | 'class' => 'widefat', |
38 | - 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
38 | + 'label' => __( 'Which type of review would you like to use?', 'site-reviews' ), |
|
39 | 39 | 'name' => 'type', |
40 | - 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
41 | - ]); |
|
40 | + 'options' => ['' => __( 'All review types', 'site-reviews' )] + glsr()->reviewTypes, |
|
41 | + ] ); |
|
42 | 42 | } |
43 | - if (!empty($terms)) { |
|
44 | - $this->renderField('select', [ |
|
43 | + if( !empty($terms) ) { |
|
44 | + $this->renderField( 'select', [ |
|
45 | 45 | 'class' => 'widefat', |
46 | - 'label' => __('Limit summary to this category', 'site-reviews'), |
|
46 | + 'label' => __( 'Limit summary to this category', 'site-reviews' ), |
|
47 | 47 | 'name' => 'category', |
48 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
49 | - ]); |
|
48 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
49 | + ] ); |
|
50 | 50 | } |
51 | - $this->renderField('text', [ |
|
51 | + $this->renderField( 'text', [ |
|
52 | 52 | 'class' => 'widefat', |
53 | 53 | 'default' => '', |
54 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
55 | - 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
54 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
55 | + 'label' => __( 'Limit summary to reviews assigned to a page/post ID', 'site-reviews' ), |
|
56 | 56 | 'name' => 'assigned_to', |
57 | - ]); |
|
58 | - $this->renderField('text', [ |
|
57 | + ] ); |
|
58 | + $this->renderField( 'text', [ |
|
59 | 59 | 'class' => 'widefat', |
60 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
60 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
61 | 61 | 'name' => 'class', |
62 | - ]); |
|
63 | - $this->renderField('checkbox', [ |
|
62 | + ] ); |
|
63 | + $this->renderField( 'checkbox', [ |
|
64 | 64 | 'name' => 'hide', |
65 | - 'options' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
66 | - ]); |
|
65 | + 'options' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
|
66 | + ] ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * @param array $instance |
72 | 72 | * @return void |
73 | 73 | */ |
74 | - public function widget($args, $instance) |
|
74 | + public function widget( $args, $instance ) |
|
75 | 75 | { |
76 | - echo glsr(SiteReviewsSummaryShortcode::class)->build($instance, $args, 'widget'); |
|
76 | + echo glsr( SiteReviewsSummaryShortcode::class )->build( $instance, $args, 'widget' ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -8,19 +8,19 @@ |
||
8 | 8 | |
9 | 9 | class RegisterWidgets |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function handle(Command $command) |
|
15 | - { |
|
16 | - global $wp_widget_factory; |
|
17 | - foreach ($command->widgets as $widget) { |
|
18 | - $widgetClass = Helper::buildClassName($widget.'-widget', 'Widgets'); |
|
19 | - if (!class_exists($widgetClass)) { |
|
20 | - glsr_log()->error(sprintf('Class missing (%s)', $widgetClass)); |
|
21 | - continue; |
|
22 | - } |
|
23 | - $wp_widget_factory->widgets[$widgetClass] = new $widgetClass(); |
|
24 | - } |
|
25 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function handle(Command $command) |
|
15 | + { |
|
16 | + global $wp_widget_factory; |
|
17 | + foreach ($command->widgets as $widget) { |
|
18 | + $widgetClass = Helper::buildClassName($widget.'-widget', 'Widgets'); |
|
19 | + if (!class_exists($widgetClass)) { |
|
20 | + glsr_log()->error(sprintf('Class missing (%s)', $widgetClass)); |
|
21 | + continue; |
|
22 | + } |
|
23 | + $wp_widget_factory->widgets[$widgetClass] = new $widgetClass(); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | /** |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function handle(Command $command) |
|
14 | + public function handle( Command $command ) |
|
15 | 15 | { |
16 | 16 | global $wp_widget_factory; |
17 | - foreach ($command->widgets as $widget) { |
|
18 | - $widgetClass = Helper::buildClassName($widget.'-widget', 'Widgets'); |
|
19 | - if (!class_exists($widgetClass)) { |
|
20 | - glsr_log()->error(sprintf('Class missing (%s)', $widgetClass)); |
|
17 | + foreach( $command->widgets as $widget ) { |
|
18 | + $widgetClass = Helper::buildClassName( $widget.'-widget', 'Widgets' ); |
|
19 | + if( !class_exists( $widgetClass ) ) { |
|
20 | + glsr_log()->error( sprintf( 'Class missing (%s)', $widgetClass ) ); |
|
21 | 21 | continue; |
22 | 22 | } |
23 | 23 | $wp_widget_factory->widgets[$widgetClass] = new $widgetClass(); |
@@ -10,134 +10,134 @@ |
||
10 | 10 | |
11 | 11 | class Migrate |
12 | 12 | { |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - public $currentVersion; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + public $currentVersion; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $transientKey; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $transientKey; |
|
22 | 22 | |
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->currentVersion = $this->getCurrentVersion(); |
|
26 | - $this->transientKey = Application::PREFIX.'migrations'; |
|
27 | - } |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->currentVersion = $this->getCurrentVersion(); |
|
26 | + $this->transientKey = Application::PREFIX.'migrations'; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function isMigrationNeeded() |
|
33 | - { |
|
34 | - $transient = get_transient($this->transientKey); |
|
35 | - if (false === $transient || !isset($transient[glsr()->version])) { |
|
36 | - $transient = [ |
|
37 | - glsr()->version => !empty($this->getNewMigrationFiles()), |
|
38 | - ]; |
|
39 | - set_transient($this->transientKey, $transient); |
|
40 | - } |
|
41 | - return Helper::castToBool($transient[glsr()->version]); |
|
42 | - } |
|
29 | + /** |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function isMigrationNeeded() |
|
33 | + { |
|
34 | + $transient = get_transient($this->transientKey); |
|
35 | + if (false === $transient || !isset($transient[glsr()->version])) { |
|
36 | + $transient = [ |
|
37 | + glsr()->version => !empty($this->getNewMigrationFiles()), |
|
38 | + ]; |
|
39 | + set_transient($this->transientKey, $transient); |
|
40 | + } |
|
41 | + return Helper::castToBool($transient[glsr()->version]); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function run() |
|
48 | - { |
|
49 | - $this->runMigrations($this->getNewMigrationFiles()); |
|
50 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function run() |
|
48 | + { |
|
49 | + $this->runMigrations($this->getNewMigrationFiles()); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function runAll() |
|
56 | - { |
|
57 | - $this->runMigrations($this->getMigrationFiles()); |
|
58 | - } |
|
52 | + /** |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function runAll() |
|
56 | + { |
|
57 | + $this->runMigrations($this->getMigrationFiles()); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - protected function getCurrentVersion() |
|
64 | - { |
|
65 | - $fallback = '0.0.0'; |
|
66 | - $majorVersions = [4, 3, 2, 1]; |
|
67 | - foreach ($majorVersions as $majorVersion) { |
|
68 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
69 | - $version = Arr::get($settings, 'version', $fallback); |
|
70 | - if (Helper::isGreaterThan($version, $fallback)) { |
|
71 | - return $version; |
|
72 | - } |
|
73 | - } |
|
74 | - return $fallback; |
|
75 | - } |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + protected function getCurrentVersion() |
|
64 | + { |
|
65 | + $fallback = '0.0.0'; |
|
66 | + $majorVersions = [4, 3, 2, 1]; |
|
67 | + foreach ($majorVersions as $majorVersion) { |
|
68 | + $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
69 | + $version = Arr::get($settings, 'version', $fallback); |
|
70 | + if (Helper::isGreaterThan($version, $fallback)) { |
|
71 | + return $version; |
|
72 | + } |
|
73 | + } |
|
74 | + return $fallback; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - protected function getMigrationFiles() |
|
81 | - { |
|
82 | - $files = []; |
|
83 | - $dir = glsr()->path('plugin/Modules/Migrations'); |
|
84 | - if (is_dir($dir)) { |
|
85 | - $iterator = new DirectoryIterator($dir); |
|
86 | - foreach ($iterator as $fileinfo) { |
|
87 | - if ($fileinfo->isFile()) { |
|
88 | - $files[] = $fileinfo->getFilename(); |
|
89 | - } |
|
90 | - } |
|
91 | - natsort($files); |
|
92 | - } |
|
93 | - return $files; |
|
94 | - } |
|
77 | + /** |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + protected function getMigrationFiles() |
|
81 | + { |
|
82 | + $files = []; |
|
83 | + $dir = glsr()->path('plugin/Modules/Migrations'); |
|
84 | + if (is_dir($dir)) { |
|
85 | + $iterator = new DirectoryIterator($dir); |
|
86 | + foreach ($iterator as $fileinfo) { |
|
87 | + if ($fileinfo->isFile()) { |
|
88 | + $files[] = $fileinfo->getFilename(); |
|
89 | + } |
|
90 | + } |
|
91 | + natsort($files); |
|
92 | + } |
|
93 | + return $files; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function getNewMigrationFiles() |
|
100 | - { |
|
101 | - $files = $this->getMigrationFiles(); |
|
102 | - foreach ($files as $index => $file) { |
|
103 | - $className = str_replace('.php', '', $file); |
|
104 | - $migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className); |
|
105 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
106 | - if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) { |
|
107 | - unset($files[$index]); |
|
108 | - } |
|
109 | - } |
|
110 | - return $files; |
|
111 | - } |
|
96 | + /** |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function getNewMigrationFiles() |
|
100 | + { |
|
101 | + $files = $this->getMigrationFiles(); |
|
102 | + foreach ($files as $index => $file) { |
|
103 | + $className = str_replace('.php', '', $file); |
|
104 | + $migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className); |
|
105 | + $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
106 | + if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) { |
|
107 | + unset($files[$index]); |
|
108 | + } |
|
109 | + } |
|
110 | + return $files; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - protected function runMigrations(array $files) |
|
117 | - { |
|
118 | - if (empty($files)) { |
|
119 | - return; |
|
120 | - } |
|
121 | - array_walk($files, function ($file) { |
|
122 | - $className = str_replace('.php', '', $file); |
|
123 | - glsr('Modules\\Migrations\\'.$className)->run(); |
|
124 | - $versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className); |
|
125 | - glsr_log()->debug('migration completed for '.$versionMigrated); |
|
126 | - }); |
|
127 | - if ($this->currentVersion !== glsr()->version) { |
|
128 | - $this->updateVersionFrom($this->currentVersion); |
|
129 | - } |
|
130 | - glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp')); |
|
131 | - delete_transient($this->transientKey); |
|
132 | - } |
|
113 | + /** |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + protected function runMigrations(array $files) |
|
117 | + { |
|
118 | + if (empty($files)) { |
|
119 | + return; |
|
120 | + } |
|
121 | + array_walk($files, function ($file) { |
|
122 | + $className = str_replace('.php', '', $file); |
|
123 | + glsr('Modules\\Migrations\\'.$className)->run(); |
|
124 | + $versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className); |
|
125 | + glsr_log()->debug('migration completed for '.$versionMigrated); |
|
126 | + }); |
|
127 | + if ($this->currentVersion !== glsr()->version) { |
|
128 | + $this->updateVersionFrom($this->currentVersion); |
|
129 | + } |
|
130 | + glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp')); |
|
131 | + delete_transient($this->transientKey); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param string $previousVersion |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - protected function updateVersionFrom($previousVersion) |
|
139 | - { |
|
140 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
141 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
142 | - } |
|
134 | + /** |
|
135 | + * @param string $previousVersion |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + protected function updateVersionFrom($previousVersion) |
|
139 | + { |
|
140 | + glsr(OptionManager::class)->set('version', glsr()->version); |
|
141 | + glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
142 | + } |
|
143 | 143 | } |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function isMigrationNeeded() |
33 | 33 | { |
34 | - $transient = get_transient($this->transientKey); |
|
35 | - if (false === $transient || !isset($transient[glsr()->version])) { |
|
34 | + $transient = get_transient( $this->transientKey ); |
|
35 | + if( false === $transient || !isset($transient[glsr()->version]) ) { |
|
36 | 36 | $transient = [ |
37 | 37 | glsr()->version => !empty($this->getNewMigrationFiles()), |
38 | 38 | ]; |
39 | - set_transient($this->transientKey, $transient); |
|
39 | + set_transient( $this->transientKey, $transient ); |
|
40 | 40 | } |
41 | - return Helper::castToBool($transient[glsr()->version]); |
|
41 | + return Helper::castToBool( $transient[glsr()->version] ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function run() |
48 | 48 | { |
49 | - $this->runMigrations($this->getNewMigrationFiles()); |
|
49 | + $this->runMigrations( $this->getNewMigrationFiles() ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function runAll() |
56 | 56 | { |
57 | - $this->runMigrations($this->getMigrationFiles()); |
|
57 | + $this->runMigrations( $this->getMigrationFiles() ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | { |
65 | 65 | $fallback = '0.0.0'; |
66 | 66 | $majorVersions = [4, 3, 2, 1]; |
67 | - foreach ($majorVersions as $majorVersion) { |
|
68 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
69 | - $version = Arr::get($settings, 'version', $fallback); |
|
70 | - if (Helper::isGreaterThan($version, $fallback)) { |
|
67 | + foreach( $majorVersions as $majorVersion ) { |
|
68 | + $settings = get_option( OptionManager::databaseKey( $majorVersion ) ); |
|
69 | + $version = Arr::get( $settings, 'version', $fallback ); |
|
70 | + if( Helper::isGreaterThan( $version, $fallback ) ) { |
|
71 | 71 | return $version; |
72 | 72 | } |
73 | 73 | } |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | protected function getMigrationFiles() |
81 | 81 | { |
82 | 82 | $files = []; |
83 | - $dir = glsr()->path('plugin/Modules/Migrations'); |
|
84 | - if (is_dir($dir)) { |
|
85 | - $iterator = new DirectoryIterator($dir); |
|
86 | - foreach ($iterator as $fileinfo) { |
|
87 | - if ($fileinfo->isFile()) { |
|
83 | + $dir = glsr()->path( 'plugin/Modules/Migrations' ); |
|
84 | + if( is_dir( $dir ) ) { |
|
85 | + $iterator = new DirectoryIterator( $dir ); |
|
86 | + foreach( $iterator as $fileinfo ) { |
|
87 | + if( $fileinfo->isFile() ) { |
|
88 | 88 | $files[] = $fileinfo->getFilename(); |
89 | 89 | } |
90 | 90 | } |
91 | - natsort($files); |
|
91 | + natsort( $files ); |
|
92 | 92 | } |
93 | 93 | return $files; |
94 | 94 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | protected function getNewMigrationFiles() |
100 | 100 | { |
101 | 101 | $files = $this->getMigrationFiles(); |
102 | - foreach ($files as $index => $file) { |
|
103 | - $className = str_replace('.php', '', $file); |
|
104 | - $migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className); |
|
105 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
106 | - if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) { |
|
102 | + foreach( $files as $index => $file ) { |
|
103 | + $className = str_replace( '.php', '', $file ); |
|
104 | + $migrationVersion = str_replace( ['Migrate_', '_'], ['', '.'], $className ); |
|
105 | + $suffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
|
106 | + if( Helper::isGreaterThanOrEqual( $this->currentVersion, $migrationVersion.$suffix ) ) { |
|
107 | 107 | unset($files[$index]); |
108 | 108 | } |
109 | 109 | } |
@@ -113,31 +113,31 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * @return void |
115 | 115 | */ |
116 | - protected function runMigrations(array $files) |
|
116 | + protected function runMigrations( array $files ) |
|
117 | 117 | { |
118 | - if (empty($files)) { |
|
118 | + if( empty($files) ) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | - array_walk($files, function ($file) { |
|
122 | - $className = str_replace('.php', '', $file); |
|
123 | - glsr('Modules\\Migrations\\'.$className)->run(); |
|
124 | - $versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className); |
|
125 | - glsr_log()->debug('migration completed for '.$versionMigrated); |
|
121 | + array_walk( $files, function( $file ) { |
|
122 | + $className = str_replace( '.php', '', $file ); |
|
123 | + glsr( 'Modules\\Migrations\\'.$className )->run(); |
|
124 | + $versionMigrated = str_replace( ['Migrate_', '_'], ['v', '.'], $className ); |
|
125 | + glsr_log()->debug( 'migration completed for '.$versionMigrated ); |
|
126 | 126 | }); |
127 | - if ($this->currentVersion !== glsr()->version) { |
|
128 | - $this->updateVersionFrom($this->currentVersion); |
|
127 | + if( $this->currentVersion !== glsr()->version ) { |
|
128 | + $this->updateVersionFrom( $this->currentVersion ); |
|
129 | 129 | } |
130 | - glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp')); |
|
131 | - delete_transient($this->transientKey); |
|
130 | + glsr( OptionManager::class )->set( 'last_migration_run', current_time( 'timestamp' ) ); |
|
131 | + delete_transient( $this->transientKey ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param string $previousVersion |
136 | 136 | * @return void |
137 | 137 | */ |
138 | - protected function updateVersionFrom($previousVersion) |
|
138 | + protected function updateVersionFrom( $previousVersion ) |
|
139 | 139 | { |
140 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
141 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
140 | + glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
141 | + glsr( OptionManager::class )->set( 'version_upgraded_from', $previousVersion ); |
|
142 | 142 | } |
143 | 143 | } |
@@ -6,133 +6,133 @@ |
||
6 | 6 | |
7 | 7 | class Role |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $role |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function addCapabilities($role) |
|
14 | - { |
|
15 | - $roleCapabilities = $this->roleCapabilities(); |
|
16 | - $wpRole = get_role($role); |
|
17 | - if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
18 | - return; |
|
19 | - } |
|
20 | - foreach ($roleCapabilities[$role] as $capability) { |
|
21 | - $wpRole->add_cap($this->normalizeCapability($capability)); |
|
22 | - } |
|
23 | - } |
|
9 | + /** |
|
10 | + * @param string $role |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function addCapabilities($role) |
|
14 | + { |
|
15 | + $roleCapabilities = $this->roleCapabilities(); |
|
16 | + $wpRole = get_role($role); |
|
17 | + if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
18 | + return; |
|
19 | + } |
|
20 | + foreach ($roleCapabilities[$role] as $capability) { |
|
21 | + $wpRole->add_cap($this->normalizeCapability($capability)); |
|
22 | + } |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $capability |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function can($capability) |
|
30 | - { |
|
31 | - return in_array($capability, $this->capabilities()) |
|
32 | - ? current_user_can($this->normalizeCapability($capability)) |
|
33 | - : current_user_can($capability); |
|
34 | - } |
|
25 | + /** |
|
26 | + * @param string $capability |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function can($capability) |
|
30 | + { |
|
31 | + return in_array($capability, $this->capabilities()) |
|
32 | + ? current_user_can($this->normalizeCapability($capability)) |
|
33 | + : current_user_can($capability); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $role |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function removeCapabilities($role) |
|
41 | - { |
|
42 | - $wpRole = get_role($role); |
|
43 | - if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
44 | - return; |
|
45 | - } |
|
46 | - foreach ($this->capabilities() as $capability) { |
|
47 | - $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
48 | - } |
|
49 | - } |
|
36 | + /** |
|
37 | + * @param string $role |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function removeCapabilities($role) |
|
41 | + { |
|
42 | + $wpRole = get_role($role); |
|
43 | + if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
44 | + return; |
|
45 | + } |
|
46 | + foreach ($this->capabilities() as $capability) { |
|
47 | + $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function resetAll() |
|
55 | - { |
|
56 | - $roles = array_keys(wp_roles()->roles); |
|
57 | - array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | - $roles = array_keys($this->roleCapabilities()); |
|
59 | - array_walk($roles, [$this, 'addCapabilities']); |
|
60 | - } |
|
51 | + /** |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function resetAll() |
|
55 | + { |
|
56 | + $roles = array_keys(wp_roles()->roles); |
|
57 | + array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | + $roles = array_keys($this->roleCapabilities()); |
|
59 | + array_walk($roles, [$this, 'addCapabilities']); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - protected function capabilities() |
|
66 | - { |
|
67 | - $capabilities = [ |
|
68 | - 'delete_others_posts', |
|
69 | - 'delete_post', |
|
70 | - 'delete_posts', |
|
71 | - 'delete_private_posts', |
|
72 | - 'delete_published_posts', |
|
73 | - 'edit_others_posts', |
|
74 | - 'edit_post', |
|
75 | - 'edit_posts', |
|
76 | - 'edit_private_posts', |
|
77 | - 'edit_published_posts', |
|
78 | - 'publish_posts', |
|
79 | - 'read_post', |
|
80 | - 'read_private_posts', |
|
81 | - ]; |
|
82 | - return apply_filters('site-reviews/capabilities', $capabilities); |
|
83 | - } |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + protected function capabilities() |
|
66 | + { |
|
67 | + $capabilities = [ |
|
68 | + 'delete_others_posts', |
|
69 | + 'delete_post', |
|
70 | + 'delete_posts', |
|
71 | + 'delete_private_posts', |
|
72 | + 'delete_published_posts', |
|
73 | + 'edit_others_posts', |
|
74 | + 'edit_post', |
|
75 | + 'edit_posts', |
|
76 | + 'edit_private_posts', |
|
77 | + 'edit_published_posts', |
|
78 | + 'publish_posts', |
|
79 | + 'read_post', |
|
80 | + 'read_private_posts', |
|
81 | + ]; |
|
82 | + return apply_filters('site-reviews/capabilities', $capabilities); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $capability |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - protected function normalizeCapability($capability) |
|
90 | - { |
|
91 | - return str_replace('post', Application::POST_TYPE, $capability); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @param string $capability |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + protected function normalizeCapability($capability) |
|
90 | + { |
|
91 | + return str_replace('post', Application::POST_TYPE, $capability); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function roleCapabilities() |
|
98 | - { |
|
99 | - $capabilities = [ |
|
100 | - 'administrator' => [ |
|
101 | - 'delete_others_posts', |
|
102 | - 'delete_posts', |
|
103 | - 'delete_private_posts', |
|
104 | - 'delete_published_posts', |
|
105 | - 'edit_others_posts', |
|
106 | - 'edit_posts', |
|
107 | - 'edit_private_posts', |
|
108 | - 'edit_published_posts', |
|
109 | - 'publish_posts', |
|
110 | - 'read_private_posts', |
|
111 | - ], |
|
112 | - 'editor' => [ |
|
113 | - 'delete_others_posts', |
|
114 | - 'delete_posts', |
|
115 | - 'delete_private_posts', |
|
116 | - 'delete_published_posts', |
|
117 | - 'edit_others_posts', |
|
118 | - 'edit_posts', |
|
119 | - 'edit_private_posts', |
|
120 | - 'edit_published_posts', |
|
121 | - 'publish_posts', |
|
122 | - 'read_private_posts', |
|
123 | - ], |
|
124 | - 'author' => [ |
|
125 | - 'delete_posts', |
|
126 | - 'delete_published_posts', |
|
127 | - 'edit_posts', |
|
128 | - 'edit_published_posts', |
|
129 | - 'publish_posts', |
|
130 | - ], |
|
131 | - 'contributor' => [ |
|
132 | - 'delete_posts', |
|
133 | - 'edit_posts', |
|
134 | - ], |
|
135 | - ]; |
|
136 | - return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
137 | - } |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function roleCapabilities() |
|
98 | + { |
|
99 | + $capabilities = [ |
|
100 | + 'administrator' => [ |
|
101 | + 'delete_others_posts', |
|
102 | + 'delete_posts', |
|
103 | + 'delete_private_posts', |
|
104 | + 'delete_published_posts', |
|
105 | + 'edit_others_posts', |
|
106 | + 'edit_posts', |
|
107 | + 'edit_private_posts', |
|
108 | + 'edit_published_posts', |
|
109 | + 'publish_posts', |
|
110 | + 'read_private_posts', |
|
111 | + ], |
|
112 | + 'editor' => [ |
|
113 | + 'delete_others_posts', |
|
114 | + 'delete_posts', |
|
115 | + 'delete_private_posts', |
|
116 | + 'delete_published_posts', |
|
117 | + 'edit_others_posts', |
|
118 | + 'edit_posts', |
|
119 | + 'edit_private_posts', |
|
120 | + 'edit_published_posts', |
|
121 | + 'publish_posts', |
|
122 | + 'read_private_posts', |
|
123 | + ], |
|
124 | + 'author' => [ |
|
125 | + 'delete_posts', |
|
126 | + 'delete_published_posts', |
|
127 | + 'edit_posts', |
|
128 | + 'edit_published_posts', |
|
129 | + 'publish_posts', |
|
130 | + ], |
|
131 | + 'contributor' => [ |
|
132 | + 'delete_posts', |
|
133 | + 'edit_posts', |
|
134 | + ], |
|
135 | + ]; |
|
136 | + return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
137 | + } |
|
138 | 138 | } |
@@ -10,15 +10,15 @@ discard block |
||
10 | 10 | * @param string $role |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function addCapabilities($role) |
|
13 | + public function addCapabilities( $role ) |
|
14 | 14 | { |
15 | 15 | $roleCapabilities = $this->roleCapabilities(); |
16 | - $wpRole = get_role($role); |
|
17 | - if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
16 | + $wpRole = get_role( $role ); |
|
17 | + if( empty($wpRole) || !array_key_exists( $role, $roleCapabilities ) ) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | - foreach ($roleCapabilities[$role] as $capability) { |
|
21 | - $wpRole->add_cap($this->normalizeCapability($capability)); |
|
20 | + foreach( $roleCapabilities[$role] as $capability ) { |
|
21 | + $wpRole->add_cap( $this->normalizeCapability( $capability ) ); |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
@@ -26,25 +26,25 @@ discard block |
||
26 | 26 | * @param string $capability |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function can($capability) |
|
29 | + public function can( $capability ) |
|
30 | 30 | { |
31 | - return in_array($capability, $this->capabilities()) |
|
32 | - ? current_user_can($this->normalizeCapability($capability)) |
|
33 | - : current_user_can($capability); |
|
31 | + return in_array( $capability, $this->capabilities() ) |
|
32 | + ? current_user_can( $this->normalizeCapability( $capability ) ) |
|
33 | + : current_user_can( $capability ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param string $role |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - public function removeCapabilities($role) |
|
40 | + public function removeCapabilities( $role ) |
|
41 | 41 | { |
42 | - $wpRole = get_role($role); |
|
43 | - if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
42 | + $wpRole = get_role( $role ); |
|
43 | + if( empty($wpRole) || 'administrator' === $role ) { // do not remove from administrator role |
|
44 | 44 | return; |
45 | 45 | } |
46 | - foreach ($this->capabilities() as $capability) { |
|
47 | - $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
46 | + foreach( $this->capabilities() as $capability ) { |
|
47 | + $wpRole->remove_cap( $this->normalizeCapability( $capability ) ); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function resetAll() |
55 | 55 | { |
56 | - $roles = array_keys(wp_roles()->roles); |
|
57 | - array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | - $roles = array_keys($this->roleCapabilities()); |
|
59 | - array_walk($roles, [$this, 'addCapabilities']); |
|
56 | + $roles = array_keys( wp_roles()->roles ); |
|
57 | + array_walk( $roles, [$this, 'removeCapabilities'] ); |
|
58 | + $roles = array_keys( $this->roleCapabilities() ); |
|
59 | + array_walk( $roles, [$this, 'addCapabilities'] ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -79,16 +79,16 @@ discard block |
||
79 | 79 | 'read_post', |
80 | 80 | 'read_private_posts', |
81 | 81 | ]; |
82 | - return apply_filters('site-reviews/capabilities', $capabilities); |
|
82 | + return apply_filters( 'site-reviews/capabilities', $capabilities ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * @param string $capability |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - protected function normalizeCapability($capability) |
|
89 | + protected function normalizeCapability( $capability ) |
|
90 | 90 | { |
91 | - return str_replace('post', Application::POST_TYPE, $capability); |
|
91 | + return str_replace( 'post', Application::POST_TYPE, $capability ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -133,6 +133,6 @@ discard block |
||
133 | 133 | 'edit_posts', |
134 | 134 | ], |
135 | 135 | ]; |
136 | - return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
136 | + return apply_filters( 'site-reviews/capabilities/for-roles', $capabilities ); |
|
137 | 137 | } |
138 | 138 | } |
@@ -15,197 +15,197 @@ |
||
15 | 15 | |
16 | 16 | class MenuController extends Controller |
17 | 17 | { |
18 | - /** |
|
19 | - * @return void |
|
20 | - * @action admin_menu |
|
21 | - */ |
|
22 | - public function registerMenuCount() |
|
23 | - { |
|
24 | - global $menu, $typenow; |
|
25 | - foreach ($menu as $key => $value) { |
|
26 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
27 | - continue; |
|
28 | - } |
|
29 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
31 | - 'class' => 'unapproved-count', |
|
32 | - ]); |
|
33 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
34 | - 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
35 | - ]); |
|
36 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | - if (Application::POST_TYPE === $typenow) { |
|
38 | - $menu[$key][4].= ' current'; |
|
39 | - } |
|
40 | - break; |
|
41 | - } |
|
42 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + * @action admin_menu |
|
21 | + */ |
|
22 | + public function registerMenuCount() |
|
23 | + { |
|
24 | + global $menu, $typenow; |
|
25 | + foreach ($menu as $key => $value) { |
|
26 | + if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
27 | + continue; |
|
28 | + } |
|
29 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | + $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
31 | + 'class' => 'unapproved-count', |
|
32 | + ]); |
|
33 | + $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
34 | + 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
35 | + ]); |
|
36 | + $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | + if (Application::POST_TYPE === $typenow) { |
|
38 | + $menu[$key][4].= ' current'; |
|
39 | + } |
|
40 | + break; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - * @action admin_menu |
|
47 | - */ |
|
48 | - public function registerSubMenus() |
|
49 | - { |
|
50 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | - 'settings' => __('Settings', 'site-reviews'), |
|
52 | - 'tools' => __('Tools', 'site-reviews'), |
|
53 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | - 'documentation' => __('Help', 'site-reviews'), |
|
55 | - ]); |
|
56 | - foreach ($pages as $slug => $title) { |
|
57 | - $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | - if (!is_callable($callback)) { |
|
60 | - continue; |
|
61 | - } |
|
62 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
63 | - } |
|
64 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + * @action admin_menu |
|
47 | + */ |
|
48 | + public function registerSubMenus() |
|
49 | + { |
|
50 | + $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | + 'settings' => __('Settings', 'site-reviews'), |
|
52 | + 'tools' => __('Tools', 'site-reviews'), |
|
53 | + 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | + 'documentation' => __('Help', 'site-reviews'), |
|
55 | + ]); |
|
56 | + foreach ($pages as $slug => $title) { |
|
57 | + $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | + $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | + if (!is_callable($callback)) { |
|
60 | + continue; |
|
61 | + } |
|
62 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - * @see $this->registerSubMenus() |
|
69 | - * @callback add_submenu_page |
|
70 | - */ |
|
71 | - public function renderAddonsMenu() |
|
72 | - { |
|
73 | - $this->renderPage('addons', [ |
|
74 | - 'template' => glsr(Template::class), |
|
75 | - ]); |
|
76 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + * @see $this->registerSubMenus() |
|
69 | + * @callback add_submenu_page |
|
70 | + */ |
|
71 | + public function renderAddonsMenu() |
|
72 | + { |
|
73 | + $this->renderPage('addons', [ |
|
74 | + 'template' => glsr(Template::class), |
|
75 | + ]); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @see $this->registerSubMenus() |
|
81 | - * @callback add_submenu_page |
|
82 | - */ |
|
83 | - public function renderDocumentationMenu() |
|
84 | - { |
|
85 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | - 'support' => __('Support', 'site-reviews'), |
|
87 | - 'faq' => __('FAQ', 'site-reviews'), |
|
88 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | - 'functions' => __('Functions', 'site-reviews'), |
|
91 | - 'addons' => __('Addons', 'site-reviews'), |
|
92 | - ]); |
|
93 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | - ksort($addons); |
|
95 | - if (empty($addons)) { |
|
96 | - unset($tabs['addons']); |
|
97 | - } |
|
98 | - $this->renderPage('documentation', [ |
|
99 | - 'addons' => $addons, |
|
100 | - 'tabs' => $tabs, |
|
101 | - ]); |
|
102 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @see $this->registerSubMenus() |
|
81 | + * @callback add_submenu_page |
|
82 | + */ |
|
83 | + public function renderDocumentationMenu() |
|
84 | + { |
|
85 | + $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | + 'support' => __('Support', 'site-reviews'), |
|
87 | + 'faq' => __('FAQ', 'site-reviews'), |
|
88 | + 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | + 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | + 'functions' => __('Functions', 'site-reviews'), |
|
91 | + 'addons' => __('Addons', 'site-reviews'), |
|
92 | + ]); |
|
93 | + $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | + ksort($addons); |
|
95 | + if (empty($addons)) { |
|
96 | + unset($tabs['addons']); |
|
97 | + } |
|
98 | + $this->renderPage('documentation', [ |
|
99 | + 'addons' => $addons, |
|
100 | + 'tabs' => $tabs, |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - * @see $this->registerSubMenus() |
|
107 | - * @callback add_submenu_page |
|
108 | - */ |
|
109 | - public function renderSettingsMenu() |
|
110 | - { |
|
111 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | - 'general' => __('General', 'site-reviews'), |
|
113 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | - 'schema' => __('Schema', 'site-reviews'), |
|
116 | - 'translations' => __('Translations', 'site-reviews'), |
|
117 | - 'addons' => __('Addons', 'site-reviews'), |
|
118 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | - ]); |
|
120 | - if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
121 | - unset($tabs['addons']); |
|
122 | - } |
|
123 | - if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
124 | - unset($tabs['licenses']); |
|
125 | - } |
|
126 | - $this->renderPage('settings', [ |
|
127 | - 'settings' => glsr(Settings::class), |
|
128 | - 'tabs' => $tabs, |
|
129 | - ]); |
|
130 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + * @see $this->registerSubMenus() |
|
107 | + * @callback add_submenu_page |
|
108 | + */ |
|
109 | + public function renderSettingsMenu() |
|
110 | + { |
|
111 | + $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | + 'general' => __('General', 'site-reviews'), |
|
113 | + 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | + 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | + 'schema' => __('Schema', 'site-reviews'), |
|
116 | + 'translations' => __('Translations', 'site-reviews'), |
|
117 | + 'addons' => __('Addons', 'site-reviews'), |
|
118 | + 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | + ]); |
|
120 | + if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
121 | + unset($tabs['addons']); |
|
122 | + } |
|
123 | + if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
124 | + unset($tabs['licenses']); |
|
125 | + } |
|
126 | + $this->renderPage('settings', [ |
|
127 | + 'settings' => glsr(Settings::class), |
|
128 | + 'tabs' => $tabs, |
|
129 | + ]); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - * @see $this->registerSubMenus() |
|
135 | - * @callback add_submenu_page |
|
136 | - */ |
|
137 | - public function renderToolsMenu() |
|
138 | - { |
|
139 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | - 'general' => __('General', 'site-reviews'), |
|
141 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | - 'console' => __('Console', 'site-reviews'), |
|
143 | - 'system-info' => __('System Info', 'site-reviews'), |
|
144 | - ]); |
|
145 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
146 | - unset($tabs['sync']); |
|
147 | - } |
|
148 | - $this->renderPage('tools', [ |
|
149 | - 'data' => [ |
|
150 | - 'context' => [ |
|
151 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | - 'console' => strval(glsr(Console::class)), |
|
153 | - 'id' => Application::ID, |
|
154 | - 'system' => strval(glsr(System::class)), |
|
155 | - ], |
|
156 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
157 | - ], |
|
158 | - 'tabs' => $tabs, |
|
159 | - 'template' => glsr(Template::class), |
|
160 | - ]); |
|
161 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + * @see $this->registerSubMenus() |
|
135 | + * @callback add_submenu_page |
|
136 | + */ |
|
137 | + public function renderToolsMenu() |
|
138 | + { |
|
139 | + $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | + 'general' => __('General', 'site-reviews'), |
|
141 | + 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | + 'console' => __('Console', 'site-reviews'), |
|
143 | + 'system-info' => __('System Info', 'site-reviews'), |
|
144 | + ]); |
|
145 | + if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
146 | + unset($tabs['sync']); |
|
147 | + } |
|
148 | + $this->renderPage('tools', [ |
|
149 | + 'data' => [ |
|
150 | + 'context' => [ |
|
151 | + 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | + 'console' => strval(glsr(Console::class)), |
|
153 | + 'id' => Application::ID, |
|
154 | + 'system' => strval(glsr(System::class)), |
|
155 | + ], |
|
156 | + 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
157 | + ], |
|
158 | + 'tabs' => $tabs, |
|
159 | + 'template' => glsr(Template::class), |
|
160 | + ]); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return void |
|
165 | - * @action admin_init |
|
166 | - */ |
|
167 | - public function setCustomPermissions() |
|
168 | - { |
|
169 | - foreach (wp_roles()->roles as $role => $value) { |
|
170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
171 | - } |
|
172 | - } |
|
163 | + /** |
|
164 | + * @return void |
|
165 | + * @action admin_init |
|
166 | + */ |
|
167 | + public function setCustomPermissions() |
|
168 | + { |
|
169 | + foreach (wp_roles()->roles as $role => $value) { |
|
170 | + wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - protected function getNotices() |
|
178 | - { |
|
179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
180 | - 'id' => 'glsr-notices', |
|
181 | - ]); |
|
182 | - } |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + protected function getNotices() |
|
178 | + { |
|
179 | + return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
180 | + 'id' => 'glsr-notices', |
|
181 | + ]); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @param string $hookSuffix |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
189 | - { |
|
190 | - if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | - $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | - foreach ($args as $tab => $title) { |
|
193 | - if (!glsr()->hasPermission($page, $tab)) { |
|
194 | - unset($args[$tab]); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
199 | - } |
|
184 | + /** |
|
185 | + * @param string $hookSuffix |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + protected function parseWithFilter($hookSuffix, array $args = []) |
|
189 | + { |
|
190 | + if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | + $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | + foreach ($args as $tab => $title) { |
|
193 | + if (!glsr()->hasPermission($page, $tab)) { |
|
194 | + unset($args[$tab]); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @param string $page |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - protected function renderPage($page, array $data = []) |
|
206 | - { |
|
207 | - $data['http_referer'] = (string) wp_get_referer(); |
|
208 | - $data['notices'] = $this->getNotices(); |
|
209 | - glsr()->render('pages/'.$page.'/index', $data); |
|
210 | - } |
|
201 | + /** |
|
202 | + * @param string $page |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + protected function renderPage($page, array $data = []) |
|
206 | + { |
|
207 | + $data['http_referer'] = (string) wp_get_referer(); |
|
208 | + $data['notices'] = $this->getNotices(); |
|
209 | + glsr()->render('pages/'.$page.'/index', $data); |
|
210 | + } |
|
211 | 211 | } |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | public function registerMenuCount() |
23 | 23 | { |
24 | 24 | global $menu, $typenow; |
25 | - foreach ($menu as $key => $value) { |
|
26 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
25 | + foreach( $menu as $key => $value ) { |
|
26 | + if( !isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE ) { |
|
27 | 27 | continue; |
28 | 28 | } |
29 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
29 | + $postCount = wp_count_posts( Application::POST_TYPE ); |
|
30 | + $pendingCount = glsr( Builder::class )->span( number_format_i18n( $postCount->pending ), [ |
|
31 | 31 | 'class' => 'unapproved-count', |
32 | - ]); |
|
33 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
32 | + ] ); |
|
33 | + $awaitingModeration = glsr( Builder::class )->span( $pendingCount, [ |
|
34 | 34 | 'class' => 'awaiting-mod count-'.$postCount->pending, |
35 | - ]); |
|
36 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | - if (Application::POST_TYPE === $typenow) { |
|
38 | - $menu[$key][4].= ' current'; |
|
35 | + ] ); |
|
36 | + $menu[$key][0] .= ' '.$awaitingModeration; |
|
37 | + if( Application::POST_TYPE === $typenow ) { |
|
38 | + $menu[$key][4] .= ' current'; |
|
39 | 39 | } |
40 | 40 | break; |
41 | 41 | } |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function registerSubMenus() |
49 | 49 | { |
50 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | - 'settings' => __('Settings', 'site-reviews'), |
|
52 | - 'tools' => __('Tools', 'site-reviews'), |
|
53 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | - 'documentation' => __('Help', 'site-reviews'), |
|
55 | - ]); |
|
56 | - foreach ($pages as $slug => $title) { |
|
57 | - $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | - if (!is_callable($callback)) { |
|
50 | + $pages = $this->parseWithFilter( 'submenu/pages', [ |
|
51 | + 'settings' => __( 'Settings', 'site-reviews' ), |
|
52 | + 'tools' => __( 'Tools', 'site-reviews' ), |
|
53 | + 'addons' => __( 'Add-ons', 'site-reviews' ), |
|
54 | + 'documentation' => __( 'Help', 'site-reviews' ), |
|
55 | + ] ); |
|
56 | + foreach( $pages as $slug => $title ) { |
|
57 | + $method = Helper::buildMethodName( 'render-'.$slug.'-menu' ); |
|
58 | + $callback = apply_filters( 'site-reviews/addon/submenu/callback', [$this, $method], $slug ); |
|
59 | + if( !is_callable( $callback ) ) { |
|
60 | 60 | continue; |
61 | 61 | } |
62 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
62 | + add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission( $slug ), $slug, $callback ); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function renderAddonsMenu() |
72 | 72 | { |
73 | - $this->renderPage('addons', [ |
|
74 | - 'template' => glsr(Template::class), |
|
75 | - ]); |
|
73 | + $this->renderPage( 'addons', [ |
|
74 | + 'template' => glsr( Template::class ), |
|
75 | + ] ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function renderDocumentationMenu() |
84 | 84 | { |
85 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | - 'support' => __('Support', 'site-reviews'), |
|
87 | - 'faq' => __('FAQ', 'site-reviews'), |
|
88 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | - 'functions' => __('Functions', 'site-reviews'), |
|
91 | - 'addons' => __('Addons', 'site-reviews'), |
|
92 | - ]); |
|
93 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | - ksort($addons); |
|
95 | - if (empty($addons)) { |
|
85 | + $tabs = $this->parseWithFilter( 'documentation/tabs', [ |
|
86 | + 'support' => __( 'Support', 'site-reviews' ), |
|
87 | + 'faq' => __( 'FAQ', 'site-reviews' ), |
|
88 | + 'shortcodes' => __( 'Shortcodes', 'site-reviews' ), |
|
89 | + 'hooks' => __( 'Hooks', 'site-reviews' ), |
|
90 | + 'functions' => __( 'Functions', 'site-reviews' ), |
|
91 | + 'addons' => __( 'Addons', 'site-reviews' ), |
|
92 | + ] ); |
|
93 | + $addons = apply_filters( 'site-reviews/addon/documentation', [] ); |
|
94 | + ksort( $addons ); |
|
95 | + if( empty($addons) ) { |
|
96 | 96 | unset($tabs['addons']); |
97 | 97 | } |
98 | - $this->renderPage('documentation', [ |
|
98 | + $this->renderPage( 'documentation', [ |
|
99 | 99 | 'addons' => $addons, |
100 | 100 | 'tabs' => $tabs, |
101 | - ]); |
|
101 | + ] ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,25 +108,25 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function renderSettingsMenu() |
110 | 110 | { |
111 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | - 'general' => __('General', 'site-reviews'), |
|
113 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | - 'schema' => __('Schema', 'site-reviews'), |
|
116 | - 'translations' => __('Translations', 'site-reviews'), |
|
117 | - 'addons' => __('Addons', 'site-reviews'), |
|
118 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | - ]); |
|
120 | - if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
111 | + $tabs = $this->parseWithFilter( 'settings/tabs', [ |
|
112 | + 'general' => __( 'General', 'site-reviews' ), |
|
113 | + 'reviews' => __( 'Reviews', 'site-reviews' ), |
|
114 | + 'submissions' => __( 'Submissions', 'site-reviews' ), |
|
115 | + 'schema' => __( 'Schema', 'site-reviews' ), |
|
116 | + 'translations' => __( 'Translations', 'site-reviews' ), |
|
117 | + 'addons' => __( 'Addons', 'site-reviews' ), |
|
118 | + 'licenses' => __( 'Licenses', 'site-reviews' ), |
|
119 | + ] ); |
|
120 | + if( empty(Arr::get( glsr()->defaults, 'settings.addons' )) ) { |
|
121 | 121 | unset($tabs['addons']); |
122 | 122 | } |
123 | - if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
123 | + if( empty(Arr::get( glsr()->defaults, 'settings.licenses' )) ) { |
|
124 | 124 | unset($tabs['licenses']); |
125 | 125 | } |
126 | - $this->renderPage('settings', [ |
|
127 | - 'settings' => glsr(Settings::class), |
|
126 | + $this->renderPage( 'settings', [ |
|
127 | + 'settings' => glsr( Settings::class ), |
|
128 | 128 | 'tabs' => $tabs, |
129 | - ]); |
|
129 | + ] ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,28 +136,28 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function renderToolsMenu() |
138 | 138 | { |
139 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | - 'general' => __('General', 'site-reviews'), |
|
141 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | - 'console' => __('Console', 'site-reviews'), |
|
143 | - 'system-info' => __('System Info', 'site-reviews'), |
|
144 | - ]); |
|
145 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
139 | + $tabs = $this->parseWithFilter( 'tools/tabs', [ |
|
140 | + 'general' => __( 'General', 'site-reviews' ), |
|
141 | + 'sync' => __( 'Sync Reviews', 'site-reviews' ), |
|
142 | + 'console' => __( 'Console', 'site-reviews' ), |
|
143 | + 'system-info' => __( 'System Info', 'site-reviews' ), |
|
144 | + ] ); |
|
145 | + if( !apply_filters( 'site-reviews/addon/sync/enable', false ) ) { |
|
146 | 146 | unset($tabs['sync']); |
147 | 147 | } |
148 | - $this->renderPage('tools', [ |
|
148 | + $this->renderPage( 'tools', [ |
|
149 | 149 | 'data' => [ |
150 | 150 | 'context' => [ |
151 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | - 'console' => strval(glsr(Console::class)), |
|
151 | + 'base_url' => admin_url( 'edit.php?post_type='.Application::POST_TYPE ), |
|
152 | + 'console' => strval( glsr( Console::class ) ), |
|
153 | 153 | 'id' => Application::ID, |
154 | - 'system' => strval(glsr(System::class)), |
|
154 | + 'system' => strval( glsr( System::class ) ), |
|
155 | 155 | ], |
156 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
156 | + 'services' => apply_filters( 'site-reviews/addon/sync/services', [] ), |
|
157 | 157 | ], |
158 | 158 | 'tabs' => $tabs, |
159 | - 'template' => glsr(Template::class), |
|
160 | - ]); |
|
159 | + 'template' => glsr( Template::class ), |
|
160 | + ] ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function setCustomPermissions() |
168 | 168 | { |
169 | - foreach (wp_roles()->roles as $role => $value) { |
|
170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
169 | + foreach( wp_roles()->roles as $role => $value ) { |
|
170 | + wp_roles()->remove_cap( $role, 'create_'.Application::POST_TYPE ); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -176,36 +176,36 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function getNotices() |
178 | 178 | { |
179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
179 | + return glsr( Builder::class )->div( glsr( Notice::class )->get(), [ |
|
180 | 180 | 'id' => 'glsr-notices', |
181 | - ]); |
|
181 | + ] ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * @param string $hookSuffix |
186 | 186 | * @return array |
187 | 187 | */ |
188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
188 | + protected function parseWithFilter( $hookSuffix, array $args = [] ) |
|
189 | 189 | { |
190 | - if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | - $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | - foreach ($args as $tab => $title) { |
|
193 | - if (!glsr()->hasPermission($page, $tab)) { |
|
190 | + if( Str::endsWith( '/tabs', $hookSuffix ) ) { |
|
191 | + $page = str_replace( '/tabs', '', $hookSuffix ); |
|
192 | + foreach( $args as $tab => $title ) { |
|
193 | + if( !glsr()->hasPermission( $page, $tab ) ) { |
|
194 | 194 | unset($args[$tab]); |
195 | 195 | } |
196 | 196 | } |
197 | 197 | } |
198 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
198 | + return apply_filters( 'site-reviews/addon/'.$hookSuffix, $args ); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @param string $page |
203 | 203 | * @return void |
204 | 204 | */ |
205 | - protected function renderPage($page, array $data = []) |
|
205 | + protected function renderPage( $page, array $data = [] ) |
|
206 | 206 | { |
207 | - $data['http_referer'] = (string) wp_get_referer(); |
|
207 | + $data['http_referer'] = (string)wp_get_referer(); |
|
208 | 208 | $data['notices'] = $this->getNotices(); |
209 | - glsr()->render('pages/'.$page.'/index', $data); |
|
209 | + glsr()->render( 'pages/'.$page.'/index', $data ); |
|
210 | 210 | } |
211 | 211 | } |