@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function get_instance() |
31 | 31 | { |
32 | - if( null === static::$instance ) |
|
32 | + if (null === static::$instance) |
|
33 | 33 | { |
34 | 34 | static::$instance = new static(); |
35 | 35 | } |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * @param array $args |
52 | 52 | * @throws \RuntimeException if the given metabox id has already been registered |
53 | 53 | */ |
54 | - public function add( $id, array $args ) |
|
54 | + public function add($id, array $args) |
|
55 | 55 | { |
56 | - if( !in_array($id, $this->metaboxes) ) |
|
56 | + if (!in_array($id, $this->metaboxes)) |
|
57 | 57 | { |
58 | 58 | $this->metaboxes[$id] = array_merge($this->default_args(), $args); |
59 | 59 | $this->metaboxes[$id]['form'] = new \Amarkal\UI\Form($args['fields']); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param WP_Post $post |
68 | 68 | * @param array $args |
69 | 69 | */ |
70 | - public function render( $post, $args ) |
|
70 | + public function render($post, $args) |
|
71 | 71 | { |
72 | 72 | $metabox = $this->metaboxes[$args['id']]; |
73 | 73 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function add_meta_boxes() |
95 | 95 | { |
96 | - foreach( $this->metaboxes as $id => $args ) |
|
96 | + foreach ($this->metaboxes as $id => $args) |
|
97 | 97 | { |
98 | 98 | \add_meta_box( |
99 | 99 | $id, |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @param number $post_id |
113 | 113 | */ |
114 | - public function save_meta_boxes( $post_id ) |
|
114 | + public function save_meta_boxes($post_id) |
|
115 | 115 | { |
116 | 116 | /** |
117 | 117 | * A note on security: |
@@ -129,22 +129,22 @@ discard block |
||
129 | 129 | * If this is an autosave, our form has not been submitted, |
130 | 130 | * so we don't want to do anything. |
131 | 131 | */ |
132 | - if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
132 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
133 | 133 | { |
134 | 134 | return $post_id; |
135 | 135 | } |
136 | 136 | |
137 | 137 | // Check the user's permissions. |
138 | 138 | $post_type = filter_input(INPUT_POST, 'post_type'); |
139 | - if( null !== $post_type && !current_user_can('edit_'.$post_type, $post_id) ) |
|
139 | + if (null !== $post_type && !current_user_can('edit_'.$post_type, $post_id)) |
|
140 | 140 | { |
141 | 141 | return $post_id; |
142 | 142 | } |
143 | 143 | |
144 | 144 | // Update the meta fields. |
145 | - foreach( $this->metaboxes as $id => $metabox ) |
|
145 | + foreach ($this->metaboxes as $id => $metabox) |
|
146 | 146 | { |
147 | - $this->save_meta_box( $post_id, $id, $metabox ); |
|
147 | + $this->save_meta_box($post_id, $id, $metabox); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | * @param string $id |
156 | 156 | * @param array $metabox |
157 | 157 | */ |
158 | - public function save_meta_box( $post_id, $id, $metabox ) |
|
158 | + public function save_meta_box($post_id, $id, $metabox) |
|
159 | 159 | { |
160 | 160 | $nonce_name = $id.'_nonce'; |
161 | 161 | $nonce_value = filter_input(INPUT_POST, $nonce_name); |
162 | 162 | $new_instance = filter_input_array(INPUT_POST); |
163 | 163 | |
164 | 164 | // Check if our nonce is set and verify it |
165 | - if( null === $nonce_value || !wp_verify_nonce($nonce_value, self::NONCE_ACTION) ) |
|
165 | + if (null === $nonce_value || !wp_verify_nonce($nonce_value, self::NONCE_ACTION)) |
|
166 | 166 | { |
167 | 167 | return $post_id; |
168 | 168 | } |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | { |
178 | 178 | $cs = get_current_screen(); |
179 | 179 | |
180 | - foreach( $this->metaboxes as $metabox ) |
|
180 | + foreach ($this->metaboxes as $metabox) |
|
181 | 181 | { |
182 | - if( $metabox['screen'] === $cs->id ) |
|
182 | + if ($metabox['screen'] === $cs->id) |
|
183 | 183 | { |
184 | 184 | echo '<style>'; |
185 | 185 | include 'metabox.css'; |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | * @param number $post_id |
196 | 196 | * @param array $metabox |
197 | 197 | */ |
198 | - public function print_errors( $post_id, $metabox ) |
|
198 | + public function print_errors($post_id, $metabox) |
|
199 | 199 | { |
200 | - $errors = \get_transient("amarkal_metabox_errors_$post_id"); |
|
200 | + $errors = \get_transient("amarkal_metabox_errors_$post_id"); |
|
201 | 201 | |
202 | - if( $errors ) |
|
202 | + if ($errors) |
|
203 | 203 | { |
204 | - foreach( $errors as $name => $error ) |
|
204 | + foreach ($errors as $name => $error) |
|
205 | 205 | { |
206 | 206 | $component = $metabox['form']->get_component($name); |
207 | 207 | echo "<div class=\"notice notice-error\"><p><strong>{$component->title}</strong> $error</p></div>"; |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function init() |
218 | 218 | { |
219 | - \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
220 | - \add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); |
|
221 | - \add_action( 'admin_footer', array( $this, 'print_style' ) ); |
|
219 | + \add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
220 | + \add_action('save_post', array($this, 'save_meta_boxes')); |
|
221 | + \add_action('admin_footer', array($this, 'print_style')); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | * @param number $post_id |
231 | 231 | * @param array $new_instance |
232 | 232 | */ |
233 | - private function update_form( $metabox, $post_id, array $new_instance = array() ) |
|
233 | + private function update_form($metabox, $post_id, array $new_instance = array()) |
|
234 | 234 | { |
235 | 235 | $old_instance = $this->get_old_instance($metabox, $post_id); |
236 | - $final_instance = $metabox['form']->update( $new_instance, $old_instance ); |
|
236 | + $final_instance = $metabox['form']->update($new_instance, $old_instance); |
|
237 | 237 | |
238 | 238 | // Update db if there is new data to be saved |
239 | - if( array() !== $new_instance ) |
|
239 | + if (array() !== $new_instance) |
|
240 | 240 | { |
241 | 241 | $this->update_post_meta($final_instance, $post_id); |
242 | 242 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * a redirect to post.php and then back to our post, which clears |
246 | 246 | * the execution thread. See https://www.sitepoint.com/displaying-errors-from-the-save_post-hook-in-wordpress/ |
247 | 247 | */ |
248 | - \set_transient( "amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60 ); |
|
248 | + \set_transient("amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | * @param type $final_instance |
256 | 256 | * @param type $post_id |
257 | 257 | */ |
258 | - private function update_post_meta( $final_instance, $post_id ) |
|
258 | + private function update_post_meta($final_instance, $post_id) |
|
259 | 259 | { |
260 | - foreach( $final_instance as $name => $value ) |
|
260 | + foreach ($final_instance as $name => $value) |
|
261 | 261 | { |
262 | - \update_post_meta( $post_id, $name, $value ); |
|
262 | + \update_post_meta($post_id, $name, $value); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
@@ -270,15 +270,15 @@ discard block |
||
270 | 270 | * @param number $post_id |
271 | 271 | * @return array |
272 | 272 | */ |
273 | - private function get_old_instance( $metabox, $post_id ) |
|
273 | + private function get_old_instance($metabox, $post_id) |
|
274 | 274 | { |
275 | 275 | $old_instance = array(); |
276 | 276 | |
277 | - foreach( $metabox['fields'] as $field ) |
|
277 | + foreach ($metabox['fields'] as $field) |
|
278 | 278 | { |
279 | - if( in_array($field['name'], get_post_custom_keys($post_id)) ) |
|
279 | + if (in_array($field['name'], get_post_custom_keys($post_id))) |
|
280 | 280 | { |
281 | - $old_instance[$field['name']] = \get_post_meta( $post_id, $field['name'], true ); |
|
281 | + $old_instance[$field['name']] = \get_post_meta($post_id, $field['name'], true); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 |