Completed
Push — master ( 69a7c5...7cc7cb )
by Askupa
01:55
created
Manager.php 1 patch
Spacing   +37 added lines, -37 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,14 +105,14 @@  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
-        if($this->can_save($post_id))
110
+        if ($this->can_save($post_id))
111 111
         {
112 112
             // Update the meta fields.
113
-            foreach( $this->metaboxes as $id => $metabox )
113
+            foreach ($this->metaboxes as $id => $metabox)
114 114
             {
115
-                $this->save_meta_box( $post_id, $id, $metabox );
115
+                $this->save_meta_box($post_id, $id, $metabox);
116 116
             }
117 117
         }
118 118
         return $post_id;
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
      * @param string $id
126 126
      * @param array $metabox
127 127
      */
128
-    public function save_meta_box( $post_id, $id, $metabox )
128
+    public function save_meta_box($post_id, $id, $metabox)
129 129
     {
130 130
         $nonce_name   = $id.'_nonce';
131 131
         $nonce_value  = filter_input(INPUT_POST, $nonce_name);
132 132
         $new_instance = filter_input_array(INPUT_POST);
133 133
         
134 134
         // Check if our nonce is set and verify it
135
-        if( null === $nonce_value || !wp_verify_nonce($nonce_value, self::NONCE_ACTION) ) 
135
+        if (null === $nonce_value || !wp_verify_nonce($nonce_value, self::NONCE_ACTION)) 
136 136
         {
137 137
             return $post_id;
138 138
         }
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
      * @param number $post_id
149 149
      * @return mix
150 150
      */
151
-    public function get_meta_box_value( $metabox_id, $name, $post_id )
151
+    public function get_meta_box_value($metabox_id, $name, $post_id)
152 152
     {
153 153
         // Check if the meta key exists
154
-        if( in_array($name, get_post_custom_keys($post_id)) )
154
+        if (in_array($name, get_post_custom_keys($post_id)))
155 155
         {
156
-            return get_post_meta( $post_id, $name, true );
156
+            return get_post_meta($post_id, $name, true);
157 157
         }
158 158
         
159 159
         // If no meta key exists in the db, use default value
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
     {
169 169
         $cs = get_current_screen();
170 170
         
171
-        foreach( $this->metaboxes as $metabox )
171
+        foreach ($this->metaboxes as $metabox)
172 172
         {
173
-            if( $metabox['screen'] === $cs->id )
173
+            if ($metabox['screen'] === $cs->id)
174 174
             {
175 175
                 echo '<style>';
176 176
                 include 'metabox.css';
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
      * @param number $post_id
187 187
      * @param array $metabox
188 188
      */
189
-    public function print_errors( $post_id, $metabox )
189
+    public function print_errors($post_id, $metabox)
190 190
     {
191
-        $errors  = \get_transient("amarkal_metabox_errors_$post_id");
191
+        $errors = \get_transient("amarkal_metabox_errors_$post_id");
192 192
         
193
-        if( $errors )
193
+        if ($errors)
194 194
         {
195
-            foreach( $errors as $name => $error )
195
+            foreach ($errors as $name => $error)
196 196
             {
197 197
                 $component = $metabox['form']->get_component($name);
198 198
                 echo "<div class=\"notice notice-error\"><p><strong>{$component->title}</strong> $error</p></div>";
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
      */
208 208
     private function init()
209 209
     {
210
-        \add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
211
-        \add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
212
-        \add_action( 'admin_footer', array( $this, 'print_style' ) );
210
+        \add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
211
+        \add_action('save_post', array($this, 'save_meta_boxes'));
212
+        \add_action('admin_footer', array($this, 'print_style'));
213 213
     }
214 214
     
215 215
     /**
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
      * @param number $post_id
222 222
      * @param array $new_instance
223 223
      */
224
-    private function update_form( $metabox, $post_id, array $new_instance = array() )
224
+    private function update_form($metabox, $post_id, array $new_instance = array())
225 225
     {
226 226
         $old_instance   = $this->get_old_instance($metabox, $post_id);
227
-        $final_instance = $metabox['form']->update( $new_instance, $old_instance );
227
+        $final_instance = $metabox['form']->update($new_instance, $old_instance);
228 228
 
229 229
         // Update db if there is new data to be saved
230
-        if( array() !== $new_instance )
230
+        if (array() !== $new_instance)
231 231
         {
232 232
             $this->update_post_meta($final_instance, $post_id);
233 233
             
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
              * a redirect to post.php and then back to our post, which clears
237 237
              * the execution thread. See https://www.sitepoint.com/displaying-errors-from-the-save_post-hook-in-wordpress/
238 238
              */
239
-            \set_transient( "amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60 );
239
+            \set_transient("amarkal_metabox_errors_$post_id", $metabox['form']->get_errors(), 60);
240 240
         }
241 241
     }
242 242
     
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
      * @param type $final_instance
247 247
      * @param type $post_id
248 248
      */
249
-    private function update_post_meta( $final_instance, $post_id )
249
+    private function update_post_meta($final_instance, $post_id)
250 250
     {
251
-        foreach( $final_instance as $name => $value )
251
+        foreach ($final_instance as $name => $value)
252 252
         {
253
-            \update_post_meta( $post_id, $name, $value );
253
+            \update_post_meta($post_id, $name, $value);
254 254
         }
255 255
     }
256 256
     
@@ -265,20 +265,20 @@  discard block
 block discarded – undo
265 265
      * (and is actually from where you think it is) prior to processing any data.
266 266
      * @see http://wordpress.stackexchange.com/a/49460/25959
267 267
      */
268
-    private function can_save( $post_id )
268
+    private function can_save($post_id)
269 269
     {
270 270
         /*
271 271
          * If this is an autosave, our form has not been submitted,
272 272
          * so we don't want to do anything.
273 273
          */
274
-        if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
274
+        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 
275 275
         {
276 276
             return false;
277 277
         }
278 278
 
279 279
         // Check the user's permissions.
280 280
         $post_type = filter_input(INPUT_POST, 'post_type');
281
-        if( null !== $post_type && !current_user_can('edit_'.$post_type, $post_id) )
281
+        if (null !== $post_type && !current_user_can('edit_'.$post_type, $post_id))
282 282
         {
283 283
             return false;
284 284
         }
@@ -293,15 +293,15 @@  discard block
 block discarded – undo
293 293
      * @param number $post_id
294 294
      * @return array
295 295
      */
296
-    private function get_old_instance( $metabox, $post_id )
296
+    private function get_old_instance($metabox, $post_id)
297 297
     {
298 298
         $old_instance = array();
299 299
         
300
-        foreach( $metabox['fields'] as $field )
300
+        foreach ($metabox['fields'] as $field)
301 301
         {
302
-            if( in_array($field['name'], get_post_custom_keys($post_id)) )
302
+            if (in_array($field['name'], get_post_custom_keys($post_id)))
303 303
             {
304
-                $old_instance[$field['name']] = \get_post_meta( $post_id, $field['name'], true );
304
+                $old_instance[$field['name']] = \get_post_meta($post_id, $field['name'], true);
305 305
             }
306 306
         }
307 307
         
Please login to merge, or discard this patch.