Completed
Push — master ( 322b62...9c0738 )
by Askupa
01:44
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   +6 added lines, -6 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,9 +29,9 @@  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
\ No newline at end of file
Please login to merge, or discard this patch.
Field.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@
 block discarded – undo
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()
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
     
Please login to merge, or discard this patch.
Manager.php 2 patches
Spacing   +22 added lines, -22 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
             static::$instance->init();
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,8 +49,9 @@
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.