@@ -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 | } |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | * @param number $post_id |
| 179 | 179 | * @return mix |
| 180 | 180 | */ |
| 181 | - public function get_meta_box_value( $metabox_id, $name, $post_id ) |
|
| 181 | + public function get_meta_box_value($metabox_id, $name, $post_id) |
|
| 182 | 182 | { |
| 183 | 183 | // Check if the meta key exists |
| 184 | - if( in_array($name, get_post_custom_keys($post_id)) ) |
|
| 184 | + if (in_array($name, get_post_custom_keys($post_id))) |
|
| 185 | 185 | { |
| 186 | - return get_post_meta( $post_id, $name, true ); |
|
| 186 | + return get_post_meta($post_id, $name, true); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // If no meta key exists in the db, use default value |
@@ -198,9 +198,9 @@ discard block |
||
| 198 | 198 | { |
| 199 | 199 | $cs = get_current_screen(); |
| 200 | 200 | |
| 201 | - foreach( $this->metaboxes as $metabox ) |
|
| 201 | + foreach ($this->metaboxes as $metabox) |
|
| 202 | 202 | { |
| 203 | - if( $metabox['screen'] === $cs->id ) |
|
| 203 | + if ($metabox['screen'] === $cs->id) |
|
| 204 | 204 | { |
| 205 | 205 | echo '<style>'; |
| 206 | 206 | include 'metabox.css'; |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | * @param number $post_id |
| 217 | 217 | * @param array $metabox |
| 218 | 218 | */ |
| 219 | - public function print_errors( $post_id, $metabox ) |
|
| 219 | + public function print_errors($post_id, $metabox) |
|
| 220 | 220 | { |
| 221 | - $errors = \get_transient("amarkal_metabox_errors_$post_id"); |
|
| 221 | + $errors = \get_transient("amarkal_metabox_errors_$post_id"); |
|
| 222 | 222 | |
| 223 | - if( $errors ) |
|
| 223 | + if ($errors) |
|
| 224 | 224 | { |
| 225 | - foreach( $errors as $name => $error ) |
|
| 225 | + foreach ($errors as $name => $error) |
|
| 226 | 226 | { |
| 227 | 227 | $component = $metabox['form']->get_component($name); |
| 228 | 228 | echo "<div class=\"notice notice-error\"><p><strong>{$component->title}</strong> $error</p></div>"; |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | private function init() |
| 239 | 239 | { |
| 240 | - \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
| 241 | - \add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); |
|
| 242 | - \add_action( 'admin_footer', array( $this, 'print_style' ) ); |
|
| 240 | + \add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
| 241 | + \add_action('save_post', array($this, 'save_meta_boxes')); |
|
| 242 | + \add_action('admin_footer', array($this, 'print_style')); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -251,13 +251,13 @@ discard block |
||
| 251 | 251 | * @param number $post_id |
| 252 | 252 | * @param array $new_instance |
| 253 | 253 | */ |
| 254 | - private function update_form( $metabox, $post_id, array $new_instance = array() ) |
|
| 254 | + private function update_form($metabox, $post_id, array $new_instance = array()) |
|
| 255 | 255 | { |
| 256 | 256 | $old_instance = $this->get_old_instance($metabox, $post_id); |
| 257 | - $final_instance = $metabox['form']->update( $new_instance, $old_instance ); |
|
| 257 | + $final_instance = $metabox['form']->update($new_instance, $old_instance); |
|
| 258 | 258 | |
| 259 | 259 | // Update db if there is new data to be saved |
| 260 | - if( array() !== $new_instance ) |
|
| 260 | + if (array() !== $new_instance) |
|
| 261 | 261 | { |
| 262 | 262 | $this->update_post_meta($final_instance, $post_id); |
| 263 | 263 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * a redirect to post.php and then back to our post, which clears |
| 267 | 267 | * the execution thread. See https://www.sitepoint.com/displaying-errors-from-the-save_post-hook-in-wordpress/ |
| 268 | 268 | */ |
| 269 | - \set_transient( "amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60 ); |
|
| 269 | + \set_transient("amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | * @param type $final_instance |
| 277 | 277 | * @param type $post_id |
| 278 | 278 | */ |
| 279 | - private function update_post_meta( $final_instance, $post_id ) |
|
| 279 | + private function update_post_meta($final_instance, $post_id) |
|
| 280 | 280 | { |
| 281 | - foreach( $final_instance as $name => $value ) |
|
| 281 | + foreach ($final_instance as $name => $value) |
|
| 282 | 282 | { |
| 283 | - \update_post_meta( $post_id, $name, $value ); |
|
| 283 | + \update_post_meta($post_id, $name, $value); |
|
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | |
@@ -291,15 +291,15 @@ discard block |
||
| 291 | 291 | * @param number $post_id |
| 292 | 292 | * @return array |
| 293 | 293 | */ |
| 294 | - private function get_old_instance( $metabox, $post_id ) |
|
| 294 | + private function get_old_instance($metabox, $post_id) |
|
| 295 | 295 | { |
| 296 | 296 | $old_instance = array(); |
| 297 | 297 | |
| 298 | - foreach( $metabox['fields'] as $field ) |
|
| 298 | + foreach ($metabox['fields'] as $field) |
|
| 299 | 299 | { |
| 300 | - if( in_array($field['name'], get_post_custom_keys($post_id)) ) |
|
| 300 | + if (in_array($field['name'], get_post_custom_keys($post_id))) |
|
| 301 | 301 | { |
| 302 | - $old_instance[$field['name']] = \get_post_meta( $post_id, $field['name'], true ); |
|
| 302 | + $old_instance[$field['name']] = \get_post_meta($post_id, $field['name'], true); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -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,14 +29,14 @@ 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 | |
| 39 | -if(!function_exists('amarkal_get_meta_box_value')) |
|
| 39 | +if (!function_exists('amarkal_get_meta_box_value')) |
|
| 40 | 40 | { |
| 41 | 41 | /** |
| 42 | 42 | * Get the value of the given field, optionally returning the default value |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | * @param number $post_id |
| 48 | 48 | * @return mix |
| 49 | 49 | */ |
| 50 | - function amarkal_get_meta_box_value( $metabox_id, $name, $post_id ) |
|
| 50 | + function amarkal_get_meta_box_value($metabox_id, $name, $post_id) |
|
| 51 | 51 | { |
| 52 | 52 | $mb = Amarkal\Metabox\Manager::get_instance(); |
| 53 | - return $mb->get_meta_box_value( $metabox_id, $name, $post_id ); |
|
| 53 | + return $mb->get_meta_box_value($metabox_id, $name, $post_id); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |