@@ -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 | 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( array_key_exists('post_type', $_POST) && 'page' == filter_input(INPUT_POST, 'post_type') ) |
|
121 | + if (array_key_exists('post_type', $_POST) && 'page' == filter_input(INPUT_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,12 +141,12 @@ 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 | |
148 | 148 | // Check if our nonce is set. |
149 | - if( !array_key_exists($nonce_name, $_POST) ) |
|
149 | + if (!array_key_exists($nonce_name, $_POST)) |
|
150 | 150 | { |
151 | 151 | return $post_id; |
152 | 152 | } |
@@ -154,15 +154,15 @@ discard block |
||
154 | 154 | $nonce = filter_input(INPUT_POST, $nonce_name); |
155 | 155 | |
156 | 156 | // Verify that the nonce is valid. |
157 | - if ( !wp_verify_nonce($nonce, self::NONCE_ACTION) ) |
|
157 | + if (!wp_verify_nonce($nonce, self::NONCE_ACTION)) |
|
158 | 158 | { |
159 | 159 | return $post_id; |
160 | 160 | } |
161 | 161 | |
162 | - foreach( $metabox['fields'] as $field ) |
|
162 | + foreach ($metabox['fields'] as $field) |
|
163 | 163 | { |
164 | - $data = filter_input( INPUT_POST, $field['name'] ); |
|
165 | - \update_post_meta( $post_id, $field['name'], $data ); |
|
164 | + $data = filter_input(INPUT_POST, $field['name']); |
|
165 | + \update_post_meta($post_id, $field['name'], $data); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | { |
174 | 174 | $cs = get_current_screen(); |
175 | 175 | |
176 | - foreach( $this->metaboxes as $metabox ) |
|
176 | + foreach ($this->metaboxes as $metabox) |
|
177 | 177 | { |
178 | - if( $metabox['screen'] === $cs->id ) |
|
178 | + if ($metabox['screen'] === $cs->id) |
|
179 | 179 | { |
180 | 180 | echo '<style>'; |
181 | 181 | include 'metabox.css'; |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | */ |
191 | 191 | private function init() |
192 | 192 | { |
193 | - \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
|
194 | - \add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); |
|
195 | - \add_action( 'admin_footer', array( $this, 'print_style' ) ); |
|
193 | + \add_action('add_meta_boxes', array($this, 'add_meta_boxes')); |
|
194 | + \add_action('save_post', array($this, 'save_meta_boxes')); |
|
195 | + \add_action('admin_footer', array($this, 'print_style')); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -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( array_key_exists('post_type', $_POST) && 'page' == filter_input(INPUT_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. |