@@ -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 | static::$instance->init(); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @param array $args |
45 | 45 | * @throws \RuntimeException if the given metabox id has already been registered |
46 | 46 | */ |
47 | - public function add( $id, array $args ) |
|
47 | + public function add($id, array $args) |
|
48 | 48 | { |
49 | - if( !in_array($id, $this->metaboxes) ) |
|
49 | + if (!in_array($id, $this->metaboxes)) |
|
50 | 50 | { |
51 | 51 | $this->metaboxes[$id] = array_merge($this->default_args(), $args); |
52 | 52 | } |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | * @param WP_Post $post |
60 | 60 | * @param array $args |
61 | 61 | */ |
62 | - public function render( $post, $args ) |
|
62 | + public function render($post, $args) |
|
63 | 63 | { |
64 | 64 | $metabox = $this->metaboxes[$args['id']]; |
65 | 65 | wp_nonce_field(self::NONCE_ACTION, $args['id'].'_nonce'); |
66 | - foreach( $metabox['fields'] as $field ) |
|
66 | + foreach ($metabox['fields'] as $field) |
|
67 | 67 | { |
68 | 68 | $field['post_id'] = $post->ID; |
69 | 69 | $field_template = new Field($field); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function add_meta_boxes() |
78 | 78 | { |
79 | - foreach( $this->metaboxes as $id => $args ) |
|
79 | + foreach ($this->metaboxes as $id => $args) |
|
80 | 80 | { |
81 | 81 | \add_meta_box( |
82 | 82 | $id, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param number $post_id |
96 | 96 | */ |
97 | - public function save_meta_boxes( $post_id ) |
|
97 | + public function save_meta_boxes($post_id) |
|
98 | 98 | { |
99 | 99 | /** |
100 | 100 | * A note on security: |
@@ -112,22 +112,22 @@ discard block |
||
112 | 112 | * If this is an autosave, our form has not been submitted, |
113 | 113 | * so we don't want to do anything. |
114 | 114 | */ |
115 | - if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
115 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
116 | 116 | { |
117 | 117 | return $post_id; |
118 | 118 | } |
119 | 119 | |
120 | 120 | // Check the user's permissions. |
121 | 121 | $post_type = filter_input(INPUT_POST, 'post_type'); |
122 | - if( null !== $post_type && !current_user_can('edit_'.$post_type, $post_id) ) |
|
122 | + if (null !== $post_type && !current_user_can('edit_'.$post_type, $post_id)) |
|
123 | 123 | { |
124 | 124 | return $post_id; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Update the meta fields. |
128 | - foreach( $this->metaboxes as $id => $metabox ) |
|
128 | + foreach ($this->metaboxes as $id => $metabox) |
|
129 | 129 | { |
130 | - $this->save_meta_box( $post_id, $id, $metabox ); |
|
130 | + $this->save_meta_box($post_id, $id, $metabox); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -138,27 +138,27 @@ discard block |
||
138 | 138 | * @param string $id |
139 | 139 | * @param array $metabox |
140 | 140 | */ |
141 | - public function save_meta_box( $post_id, $id, $metabox ) |
|
141 | + public function save_meta_box($post_id, $id, $metabox) |
|
142 | 142 | { |
143 | 143 | $nonce_name = $id.'_nonce'; |
144 | 144 | $nonce_value = filter_input(INPUT_POST, $nonce_name); |
145 | 145 | |
146 | 146 | // Check if our nonce is set. |
147 | - if( null === $nonce_value ) |
|
147 | + if (null === $nonce_value) |
|
148 | 148 | { |
149 | 149 | return $post_id; |
150 | 150 | } |
151 | 151 | |
152 | 152 | // Verify that the nonce is valid. |
153 | - if ( !wp_verify_nonce($nonce_value, self::NONCE_ACTION) ) |
|
153 | + if (!wp_verify_nonce($nonce_value, self::NONCE_ACTION)) |
|
154 | 154 | { |
155 | 155 | return $post_id; |
156 | 156 | } |
157 | 157 | |
158 | - foreach( $metabox['fields'] as $field ) |
|
158 | + foreach ($metabox['fields'] as $field) |
|
159 | 159 | { |
160 | - $data = filter_input( INPUT_POST, $field['name'] ); |
|
161 | - \update_post_meta( $post_id, $field['name'], $data ); |
|
160 | + $data = filter_input(INPUT_POST, $field['name']); |
|
161 | + \update_post_meta($post_id, $field['name'], $data); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | { |
170 | 170 | $cs = get_current_screen(); |
171 | 171 | |
172 | - foreach( $this->metaboxes as $metabox ) |
|
172 | + foreach ($this->metaboxes as $metabox) |
|
173 | 173 | { |
174 | - if( $metabox['screen'] === $cs->id ) |
|
174 | + if ($metabox['screen'] === $cs->id) |
|
175 | 175 | { |
176 | 176 | echo '<style>'; |
177 | 177 | include 'metabox.css'; |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function init() |
188 | 188 | { |
189 | - \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
190 | - \add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); |
|
191 | - \add_action( 'admin_footer', array( $this, 'print_style' ) ); |
|
189 | + \add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
190 | + \add_action('save_post', array($this, 'save_meta_boxes')); |
|
191 | + \add_action('admin_footer', array($this, 'print_style')); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -49,8 +49,9 @@ |
||
49 | 49 | if( !in_array($id, $this->metaboxes) ) |
50 | 50 | { |
51 | 51 | $this->metaboxes[$id] = array_merge($this->default_args(), $args); |
52 | + } else { |
|
53 | + throw new \RuntimeException("A metabox with id '$id' has already been registered."); |
|
52 | 54 | } |
53 | - else throw new \RuntimeException("A metabox with id '$id' has already been registered."); |
|
54 | 55 | } |
55 | 56 | |
56 | 57 | /** |