@@ -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,25 +112,25 @@ 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 | - if( isset($_POST['post_type']) && 'page' == $_POST['post_type'] ) |
|
| 121 | + if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) |
|
| 122 | 122 | { |
| 123 | - if( !current_user_can('edit_page', $post_id) ) return $post_id; |
|
| 123 | + if (!current_user_can('edit_page', $post_id)) return $post_id; |
|
| 124 | 124 | } |
| 125 | 125 | else |
| 126 | 126 | { |
| 127 | - if( !current_user_can('edit_post', $post_id) ) return $post_id; |
|
| 127 | + if (!current_user_can('edit_post', $post_id)) return $post_id; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Update the meta fields. |
| 131 | - foreach( $this->metaboxes as $id => $metabox ) |
|
| 131 | + foreach ($this->metaboxes as $id => $metabox) |
|
| 132 | 132 | { |
| 133 | - $this->save_meta_box( $post_id, $id, $metabox ); |
|
| 133 | + $this->save_meta_box($post_id, $id, $metabox); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -141,25 +141,25 @@ discard block |
||
| 141 | 141 | * @param string $id |
| 142 | 142 | * @param array $metabox |
| 143 | 143 | */ |
| 144 | - public function save_meta_box( $post_id, $id, $metabox ) |
|
| 144 | + public function save_meta_box($post_id, $id, $metabox) |
|
| 145 | 145 | { |
| 146 | 146 | $nonce_name = $id.'_nonce'; |
| 147 | 147 | // Check if our nonce is set. |
| 148 | - if ( !isset($_POST[$nonce_name]) ) { |
|
| 148 | + if (!isset($_POST[$nonce_name])) { |
|
| 149 | 149 | return $post_id; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $nonce = $_POST[$nonce_name]; |
| 153 | 153 | |
| 154 | 154 | // Verify that the nonce is valid. |
| 155 | - if ( !wp_verify_nonce( $nonce, self::NONCE_ACTION ) ) { |
|
| 155 | + if (!wp_verify_nonce($nonce, self::NONCE_ACTION)) { |
|
| 156 | 156 | return $post_id; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - foreach( $metabox['fields'] as $field ) |
|
| 159 | + foreach ($metabox['fields'] as $field) |
|
| 160 | 160 | { |
| 161 | - $data = filter_input( INPUT_POST, $field['name'] ); |
|
| 162 | - \update_post_meta( $post_id, $field['name'], $data ); |
|
| 161 | + $data = filter_input(INPUT_POST, $field['name']); |
|
| 162 | + \update_post_meta($post_id, $field['name'], $data); |
|
| 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 | /** |
@@ -49,8 +49,9 @@ discard block |
||
| 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 | /** |
@@ -120,11 +121,14 @@ discard block |
||
| 120 | 121 | // Check the user's permissions. |
| 121 | 122 | if( isset($_POST['post_type']) && 'page' == $_POST['post_type'] ) |
| 122 | 123 | { |
| 123 | - if( !current_user_can('edit_page', $post_id) ) return $post_id; |
|
| 124 | - } |
|
| 125 | - else |
|
| 124 | + if( !current_user_can('edit_page', $post_id) ) { |
|
| 125 | + return $post_id; |
|
| 126 | + } |
|
| 127 | + } else |
|
| 126 | 128 | { |
| 127 | - if( !current_user_can('edit_post', $post_id) ) return $post_id; |
|
| 129 | + if( !current_user_can('edit_post', $post_id) ) { |
|
| 130 | + return $post_id; |
|
| 131 | + } |
|
| 128 | 132 | } |
| 129 | 133 | |
| 130 | 134 | // Update the meta fields. |
@@ -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() |