@@ -6,7 +6,7 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | // Load module functions |
12 | 12 | require_once 'functions.php'; |
@@ -18,7 +18,9 @@ |
||
18 | 18 | /** |
19 | 19 | * Prevent loading the library more than once |
20 | 20 | */ |
21 | -if( defined( 'AMARKAL_METABOX' ) ) return false; |
|
21 | +if( defined( 'AMARKAL_METABOX' ) ) { |
|
22 | + return false; |
|
23 | +} |
|
22 | 24 | define( 'AMARKAL_METABOX', true ); |
23 | 25 | |
24 | 26 | if(!function_exists('amarkal_add_meta_box')) |
@@ -13,15 +13,15 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | // Prevent direct file access |
16 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
16 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Prevent loading the library more than once |
20 | 20 | */ |
21 | -if( defined( 'AMARKAL_METABOX' ) ) return false; |
|
22 | -define( 'AMARKAL_METABOX', true ); |
|
21 | +if (defined('AMARKAL_METABOX')) return false; |
|
22 | +define('AMARKAL_METABOX', true); |
|
23 | 23 | |
24 | -if(!function_exists('amarkal_add_meta_box')) |
|
24 | +if (!function_exists('amarkal_add_meta_box')) |
|
25 | 25 | { |
26 | 26 | /** |
27 | 27 | * Add a meta box to a given post type |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param string $id |
30 | 30 | * @param array $args |
31 | 31 | */ |
32 | - function amarkal_add_meta_box( $id, array $args ) |
|
32 | + function amarkal_add_meta_box($id, array $args) |
|
33 | 33 | { |
34 | 34 | $mb = Amarkal\Metabox\Manager::get_instance(); |
35 | - $mb->add( $id, $args ); |
|
35 | + $mb->add($id, $args); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | \ No newline at end of file |
@@ -16,8 +16,8 @@ |
||
16 | 16 | |
17 | 17 | protected function on_created() |
18 | 18 | { |
19 | - \get_post_meta( $this->post_id, $this->name, true ); |
|
20 | - $this->model['value'] = \get_post_meta( $this->post_id, $this->name, true ); |
|
19 | + \get_post_meta($this->post_id, $this->name, true); |
|
20 | + $this->model['value'] = \get_post_meta($this->post_id, $this->name, true); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function get_template_path() |
@@ -6,13 +6,13 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Load module functions. If this amarkal module has not been loaded, |
13 | 13 | * functions.php will not return false. |
14 | 14 | */ |
15 | -if(false !== (require_once 'functions.php')) |
|
15 | +if (false !== (require_once 'functions.php')) |
|
16 | 16 | { |
17 | 17 | // Load required classes if not using composer |
18 | 18 |
@@ -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 | /** |