Completed
Push — master ( 4e3489...c50a66 )
by Askupa
01:53
created
composer.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
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';
Please login to merge, or discard this patch.
functions.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@
 block discarded – undo
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'))
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Manager.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,8 +57,9 @@
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function add_meta_boxes()
89 89
     {
90
-        foreach( $this->metaboxes as $id => $args )
90
+        foreach ($this->metaboxes as $id => $args)
91 91
         {
92 92
             \add_meta_box(
93 93
                 $id,
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      * 
106 106
      * @param number $post_id
107 107
      */
108
-    public function save_meta_boxes( $post_id )
108
+    public function save_meta_boxes($post_id)
109 109
     {
110 110
         /**
111 111
          * A note on security:
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
          * Bail if this is an autosave, or if the current user does not have 
126 126
          * sufficient permissions
127 127
          */
128
-        if( (defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE) ||
129
-            (null !== $post_type && !current_user_can('edit_'.$post_type, $post_id)) ) 
128
+        if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) ||
129
+            (null !== $post_type && !current_user_can('edit_'.$post_type, $post_id))) 
130 130
         {
131 131
             return;
132 132
         }
133 133
 
134 134
         // Update the meta fields.
135
-        foreach( $this->metaboxes as $id => $metabox )
135
+        foreach ($this->metaboxes as $id => $metabox)
136 136
         {
137
-            $this->save_meta_box( $post_id, $id, $metabox );
137
+            $this->save_meta_box($post_id, $id, $metabox);
138 138
         }
139 139
     }
140 140
     
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
      * @param string $id
146 146
      * @param array $metabox
147 147
      */
148
-    public function save_meta_box( $post_id, $id, $metabox )
148
+    public function save_meta_box($post_id, $id, $metabox)
149 149
     {
150 150
         $nonce_name   = $id.'_nonce';
151 151
         $nonce_value  = filter_input(INPUT_POST, $nonce_name);
152 152
         $new_instance = filter_input_array(INPUT_POST);
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
         }
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
      * @param number $post_id
169 169
      * @return mix
170 170
      */
171
-    public function get_meta_box_value( $metabox_id, $name, $post_id )
171
+    public function get_meta_box_value($metabox_id, $name, $post_id)
172 172
     {
173 173
         // Check if the meta key exists
174
-        if( in_array($name, get_post_custom_keys($post_id)) )
174
+        if (in_array($name, get_post_custom_keys($post_id)))
175 175
         {
176
-            return get_post_meta( $post_id, $name, true );
176
+            return get_post_meta($post_id, $name, true);
177 177
         }
178 178
         
179 179
         // If no meta key exists in the db, use default value
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
     {
189 189
         $cs = get_current_screen();
190 190
         
191
-        foreach( $this->metaboxes as $metabox )
191
+        foreach ($this->metaboxes as $metabox)
192 192
         {
193
-            if( $metabox['screen'] === $cs->id )
193
+            if ($metabox['screen'] === $cs->id)
194 194
             {
195 195
                 echo '<style>';
196 196
                 include 'metabox.css';
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
      * @param number $post_id
207 207
      * @param array $metabox
208 208
      */
209
-    public function print_errors( $post_id, $metabox )
209
+    public function print_errors($post_id, $metabox)
210 210
     {
211
-        $errors  = \get_transient("amarkal_metabox_errors_$post_id");
211
+        $errors = \get_transient("amarkal_metabox_errors_$post_id");
212 212
         
213
-        if( $errors )
213
+        if ($errors)
214 214
         {
215
-            foreach( $errors as $name => $error )
215
+            foreach ($errors as $name => $error)
216 216
             {
217 217
                 $component = $metabox['form']->get_component($name);
218 218
                 echo "<div class=\"notice notice-error\"><p><strong>{$component->title}</strong> $error</p></div>";
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
      */
228 228
     private function init()
229 229
     {
230
-        \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
231
-        \add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
232
-        \add_action( 'admin_footer', array( $this, 'print_style' ) );
230
+        \add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
231
+        \add_action('save_post', array($this, 'save_meta_boxes'));
232
+        \add_action('admin_footer', array($this, 'print_style'));
233 233
     }
234 234
     
235 235
     /**
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
      * @param number $post_id
242 242
      * @param array $new_instance
243 243
      */
244
-    private function update_form( $metabox, $post_id, array $new_instance = array() )
244
+    private function update_form($metabox, $post_id, array $new_instance = array())
245 245
     {
246 246
         $old_instance   = $this->get_old_instance($metabox, $post_id);
247
-        $final_instance = $metabox['form']->update( $new_instance, $old_instance );
247
+        $final_instance = $metabox['form']->update($new_instance, $old_instance);
248 248
 
249 249
         // Update db if there is new data to be saved
250
-        if( array() !== $new_instance )
250
+        if (array() !== $new_instance)
251 251
         {
252 252
             $this->update_post_meta($final_instance, $post_id);
253 253
             
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
              * a redirect to post.php and then back to our post, which clears
257 257
              * the execution thread. See https://www.sitepoint.com/displaying-errors-from-the-save_post-hook-in-wordpress/
258 258
              */
259
-            \set_transient( "amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60 );
259
+            \set_transient("amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60);
260 260
         }
261 261
     }
262 262
     
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
      * @param type $final_instance
267 267
      * @param type $post_id
268 268
      */
269
-    private function update_post_meta( $final_instance, $post_id )
269
+    private function update_post_meta($final_instance, $post_id)
270 270
     {
271
-        foreach( $final_instance as $name => $value )
271
+        foreach ($final_instance as $name => $value)
272 272
         {
273
-            \update_post_meta( $post_id, $name, $value );
273
+            \update_post_meta($post_id, $name, $value);
274 274
         }
275 275
     }
276 276
     
@@ -281,15 +281,15 @@  discard block
 block discarded – undo
281 281
      * @param number $post_id
282 282
      * @return array
283 283
      */
284
-    private function get_old_instance( $metabox, $post_id )
284
+    private function get_old_instance($metabox, $post_id)
285 285
     {
286 286
         $old_instance = array();
287 287
         
288
-        foreach( $metabox['fields'] as $field )
288
+        foreach ($metabox['fields'] as $field)
289 289
         {
290
-            if( in_array($field['name'], get_post_custom_keys($post_id)) )
290
+            if (in_array($field['name'], get_post_custom_keys($post_id)))
291 291
             {
292
-                $old_instance[$field['name']] = \get_post_meta( $post_id, $field['name'], true );
292
+                $old_instance[$field['name']] = \get_post_meta($post_id, $field['name'], true);
293 293
             }
294 294
         }
295 295
         
Please login to merge, or discard this patch.
bootstrap.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
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
     require_once 'Manager.php';
Please login to merge, or discard this patch.