@@ -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,11 +67,11 @@ 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 | wp_nonce_field(self::NONCE_ACTION, $args['id'].'_nonce'); |
74 | - foreach( $metabox['fields'] as $field ) |
|
74 | + foreach ($metabox['fields'] as $field) |
|
75 | 75 | { |
76 | 76 | $field['post_id'] = $post->ID; |
77 | 77 | $field_template = new Field($field); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function add_meta_boxes() |
86 | 86 | { |
87 | - foreach( $this->metaboxes as $id => $args ) |
|
87 | + foreach ($this->metaboxes as $id => $args) |
|
88 | 88 | { |
89 | 89 | \add_meta_box( |
90 | 90 | $id, |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @param number $post_id |
104 | 104 | */ |
105 | - public function save_meta_boxes( $post_id ) |
|
105 | + public function save_meta_boxes($post_id) |
|
106 | 106 | { |
107 | 107 | /** |
108 | 108 | * A note on security: |
@@ -120,22 +120,22 @@ discard block |
||
120 | 120 | * If this is an autosave, our form has not been submitted, |
121 | 121 | * so we don't want to do anything. |
122 | 122 | */ |
123 | - if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
123 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
124 | 124 | { |
125 | 125 | return $post_id; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Check the user's permissions. |
129 | 129 | $post_type = filter_input(INPUT_POST, 'post_type'); |
130 | - if( null !== $post_type && !current_user_can('edit_'.$post_type, $post_id) ) |
|
130 | + if (null !== $post_type && !current_user_can('edit_'.$post_type, $post_id)) |
|
131 | 131 | { |
132 | 132 | return $post_id; |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Update the meta fields. |
136 | - foreach( $this->metaboxes as $id => $metabox ) |
|
136 | + foreach ($this->metaboxes as $id => $metabox) |
|
137 | 137 | { |
138 | - $this->save_meta_box( $post_id, $id, $metabox ); |
|
138 | + $this->save_meta_box($post_id, $id, $metabox); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | * @param string $id |
147 | 147 | * @param array $metabox |
148 | 148 | */ |
149 | - public function save_meta_box( $post_id, $id, $metabox ) |
|
149 | + public function save_meta_box($post_id, $id, $metabox) |
|
150 | 150 | { |
151 | 151 | $nonce_name = $id.'_nonce'; |
152 | 152 | $nonce_value = filter_input(INPUT_POST, $nonce_name); |
153 | 153 | |
154 | 154 | // Check if our nonce is set and verify it |
155 | - if( null === $nonce_value || !wp_verify_nonce($nonce_value, self::NONCE_ACTION) ) |
|
155 | + if (null === $nonce_value || !wp_verify_nonce($nonce_value, self::NONCE_ACTION)) |
|
156 | 156 | { |
157 | 157 | return $post_id; |
158 | 158 | } |
159 | 159 | |
160 | - foreach( $this->get_form_data($metabox, $post_id) as $name => $value ) |
|
160 | + foreach ($this->get_form_data($metabox, $post_id) as $name => $value) |
|
161 | 161 | { |
162 | - \update_post_meta( $post_id, $name, $value ); |
|
162 | + \update_post_meta($post_id, $name, $value); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | { |
171 | 171 | $cs = get_current_screen(); |
172 | 172 | |
173 | - foreach( $this->metaboxes as $metabox ) |
|
173 | + foreach ($this->metaboxes as $metabox) |
|
174 | 174 | { |
175 | - if( $metabox['screen'] === $cs->id ) |
|
175 | + if ($metabox['screen'] === $cs->id) |
|
176 | 176 | { |
177 | 177 | echo '<style>'; |
178 | 178 | include 'metabox.css'; |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | */ |
188 | 188 | private function init() |
189 | 189 | { |
190 | - \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
191 | - \add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); |
|
192 | - \add_action( 'admin_footer', array( $this, 'print_style' ) ); |
|
190 | + \add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
191 | + \add_action('save_post', array($this, 'save_meta_boxes')); |
|
192 | + \add_action('admin_footer', array($this, 'print_style')); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -199,20 +199,20 @@ discard block |
||
199 | 199 | * @param number $post_id |
200 | 200 | * @return array |
201 | 201 | */ |
202 | - private function get_form_data( $metabox, $post_id ) |
|
202 | + private function get_form_data($metabox, $post_id) |
|
203 | 203 | { |
204 | 204 | $old_instance = array(); |
205 | 205 | $new_instance = filter_input_array(INPUT_POST); |
206 | 206 | |
207 | - foreach( $metabox['fields'] as $field ) |
|
207 | + foreach ($metabox['fields'] as $field) |
|
208 | 208 | { |
209 | - if( in_array($field['name'], get_post_custom_keys($post_id)) ) |
|
209 | + if (in_array($field['name'], get_post_custom_keys($post_id))) |
|
210 | 210 | { |
211 | - $old_instance[$field['name']] = \get_post_meta( $post_id, $field['name'], true ); |
|
211 | + $old_instance[$field['name']] = \get_post_meta($post_id, $field['name'], true); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - return $metabox['form']->update( $new_instance, $old_instance ); |
|
215 | + return $metabox['form']->update($new_instance, $old_instance); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -57,8 +57,9 @@ |
||
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']); |
60 | + } else { |
|
61 | + throw new \RuntimeException("A metabox with id '$id' has already been registered."); |
|
60 | 62 | } |
61 | - else throw new \RuntimeException("A metabox with id '$id' has already been registered."); |
|
62 | 63 | } |
63 | 64 | |
64 | 65 | /** |