Completed
Push — master ( d503c6...f36f04 )
by Askupa
02:05
created
bootstrap.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@
 block discarded – undo
16 16
 /**
17 17
  * Prevent loading the library more than once
18 18
  */
19
-if( defined( 'AMARKAL_TAXONOMY' ) ) return;
19
+if( defined( 'AMARKAL_TAXONOMY' ) ) {
20
+    return;
21
+}
20 22
 define( 'AMARKAL_TAXONOMY', true );
21 23
 
22 24
 /**
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,25 +11,25 @@  discard block
 block discarded – undo
11 11
  * @link      https://github.com/askupasoftware/amarkal-taxonomy
12 12
  * @copyright 2017 Askupa Software
13 13
  */
14
-defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
14
+defined('ABSPATH') or die('No script kiddies please!');
15 15
 
16 16
 /**
17 17
  * Prevent loading the library more than once
18 18
  */
19
-if( defined( 'AMARKAL_TAXONOMY' ) ) return;
20
-define( 'AMARKAL_TAXONOMY', true );
19
+if (defined('AMARKAL_TAXONOMY')) return;
20
+define('AMARKAL_TAXONOMY', true);
21 21
 
22 22
 /**
23 23
  * Load required classes if not using composer
24 24
  */
25
-if( !class_exists('Composer\\Autoload\\ClassLoader') )
25
+if (!class_exists('Composer\\Autoload\\ClassLoader'))
26 26
 {
27 27
     require_once 'form.php';
28 28
     require_once 'add-field.php';
29 29
     require_once 'edit-field.php';
30 30
 }
31 31
 
32
-if(!function_exists('amarkal_taxonomy_add_field'))
32
+if (!function_exists('amarkal_taxonomy_add_field'))
33 33
 {
34 34
     /**
35 35
      * Add a field to the add & edit forms of a given taxonomy.
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
      * amarkal-ui components or a registered custom component.
40 40
      * @param array $field_props The field's properties
41 41
      */
42
-    function amarkal_taxonomy_add_field( $taxonomy_name, $field_name, $field_props )
42
+    function amarkal_taxonomy_add_field($taxonomy_name, $field_name, $field_props)
43 43
     {
44 44
         $form = Amarkal\Taxonomy\Form::get_instance();
45
-        $form->add_field( $taxonomy_name, $field_name, $field_props );
45
+        $form->add_field($taxonomy_name, $field_name, $field_props);
46 46
     }
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
Form.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -237,7 +237,7 @@
 block discarded – undo
237 237
     /**
238 238
      * Treverse the $fields array.
239 239
      * 
240
-     * @param collable $callback Called on each iteration
240
+     * @param \Closure $callback Called on each iteration
241 241
      */
242 242
     private function traverse_fields( $callback )
243 243
     {
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public static function get_instance()
26 26
     {
27
-        if( null === static::$instance ) 
27
+        if (null === static::$instance) 
28 28
         {
29 29
             static::$instance = new static();
30 30
         }
@@ -39,30 +39,30 @@  discard block
 block discarded – undo
39 39
      * @param array $field_props
40 40
      * @throws \RuntimeException if duplicate names are registered under the same taxonomy
41 41
      */
42
-    public function add_field( $taxonomy_name, $field_name, $field_props )
42
+    public function add_field($taxonomy_name, $field_name, $field_props)
43 43
     {
44
-        if( !isset($this->fields[$taxonomy_name]) )
44
+        if (!isset($this->fields[$taxonomy_name]))
45 45
         {
46 46
             // Add fields to taxonomy add and edit forms 
47
-            add_action( "{$taxonomy_name}_add_form_fields", array($this, 'render_add_form') );
48
-            add_action( "{$taxonomy_name}_edit_form_fields", array($this, 'render_edit_form') );
47
+            add_action("{$taxonomy_name}_add_form_fields", array($this, 'render_add_form'));
48
+            add_action("{$taxonomy_name}_edit_form_fields", array($this, 'render_edit_form'));
49 49
             
50 50
             // Save the data from taxonomy add and edit forms
51
-            add_action( "create_{$taxonomy_name}", array($this, 'update_term') );
52
-            add_action( "edited_{$taxonomy_name}", array($this, 'update_term') );
51
+            add_action("create_{$taxonomy_name}", array($this, 'update_term'));
52
+            add_action("edited_{$taxonomy_name}", array($this, 'update_term'));
53 53
             
54 54
             // Modify the taxonomy term table
55
-            add_filter( "manage_edit-{$taxonomy_name}_columns", array($this, 'modify_table_columns') );
56
-            add_filter( "manage_{$taxonomy_name}_custom_column", array($this, 'modify_table_content'), 10, 3 );
57
-            add_filter( "manage_edit-{$taxonomy_name}_sortable_columns", array($this, 'modify_table_sortable_columns') );
58
-            add_filter( 'terms_clauses', array($this, 'sort_custom_column'), 10, 3 );
55
+            add_filter("manage_edit-{$taxonomy_name}_columns", array($this, 'modify_table_columns'));
56
+            add_filter("manage_{$taxonomy_name}_custom_column", array($this, 'modify_table_content'), 10, 3);
57
+            add_filter("manage_edit-{$taxonomy_name}_sortable_columns", array($this, 'modify_table_sortable_columns'));
58
+            add_filter('terms_clauses', array($this, 'sort_custom_column'), 10, 3);
59 59
             
60 60
             $this->fields[$taxonomy_name] = array();
61 61
         }
62 62
 
63
-        if( !isset($this->fields[$taxonomy_name][$field_name]))
63
+        if (!isset($this->fields[$taxonomy_name][$field_name]))
64 64
         {
65
-            $this->fields[$taxonomy_name][$field_name] = array_merge( $this->default_props(), $field_props );
65
+            $this->fields[$taxonomy_name][$field_name] = array_merge($this->default_props(), $field_props);
66 66
         }
67 67
         else throw new \RuntimeException("A field named '$field_name' has already been registered in '$taxonomy_name'");
68 68
     }
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
      * 
73 73
      * @param object $term Taxonomy term
74 74
      */
75
-    public function render_edit_form( $term )
75
+    public function render_edit_form($term)
76 76
     {
77 77
         $fields = $this->fields[$term->taxonomy];
78 78
         
79
-        foreach( $fields as $name => $props )
79
+        foreach ($fields as $name => $props)
80 80
         {
81 81
             $props['name'] = $name;
82 82
             $props['term_id'] = $term->term_id;
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
      * 
91 91
      * @param string $taxonomy Taxonomy name
92 92
      */
93
-    public function render_add_form( $taxonomy )
93
+    public function render_add_form($taxonomy)
94 94
     {
95 95
         $fields = $this->fields[$taxonomy];
96 96
         
97
-        foreach( $fields as $name => $props )
97
+        foreach ($fields as $name => $props)
98 98
         {
99 99
             $props['name'] = $name;
100 100
             $field = new AddField($props);
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
      * 
109 109
      * @param type $term_id
110 110
      */
111
-    function update_term( $term_id ) 
111
+    function update_term($term_id) 
112 112
     {
113
-        $term = \get_term( $term_id );
113
+        $term = \get_term($term_id);
114 114
         
115
-        foreach( $this->fields[$term->taxonomy] as $name => $props )
115
+        foreach ($this->fields[$term->taxonomy] as $name => $props)
116 116
         {
117
-            if( isset($_POST[$name]) )
117
+            if (isset($_POST[$name]))
118 118
             {
119 119
                 update_term_meta($term_id, $name, filter_input(INPUT_POST, $name));
120 120
             }
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
      * @param array $columns
128 128
      * @return array
129 129
      */
130
-    function modify_table_columns( $columns )
130
+    function modify_table_columns($columns)
131 131
     {   
132
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$columns ) 
132
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$columns) 
133 133
         {
134
-            if( $props['table']['show'] )
134
+            if ($props['table']['show'])
135 135
             {
136 136
                 $columns[$name] = $props['label'];
137 137
             }
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
      * @param type $term_id
150 150
      * @return type
151 151
      */
152
-    function modify_table_content( $content, $column_name, $term_id )
152
+    function modify_table_content($content, $column_name, $term_id)
153 153
     {   
154 154
         $term = \get_term($term_id);
155
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$content, $column_name, $term ) 
155
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$content, $column_name, $term) 
156 156
         {
157
-            if( $props['table']['show'] && 
157
+            if ($props['table']['show'] && 
158 158
                 $term->taxonomy === $taxonomy &&
159 159
                 $name === $column_name
160 160
             ) {
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
      * @param array $columns
171 171
      * @return string
172 172
      */
173
-    function modify_table_sortable_columns( $columns )
173
+    function modify_table_sortable_columns($columns)
174 174
     {
175
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$columns ) 
175
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$columns) 
176 176
         {
177
-            if( $props['table']['show'] && 
177
+            if ($props['table']['show'] && 
178 178
                 $props['table']['sortable']
179 179
             ) {
180 180
                 $columns[$name] = $name;
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
      * @param type $args
195 195
      * @return string
196 196
      */
197
-    function sort_custom_column( $clauses, $taxonomies, $args )
197
+    function sort_custom_column($clauses, $taxonomies, $args)
198 198
     {
199
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$clauses, $args ) 
199
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$clauses, $args) 
200 200
         {
201
-            if( in_array($taxonomy, $args['taxonomy']) && 
201
+            if (in_array($taxonomy, $args['taxonomy']) && 
202 202
                 $props['table']['show'] && 
203 203
                 $props['table']['sortable'] &&
204 204
                 $name === $args['orderby']
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
      * 
240 240
      * @param collable $callback Called on each iteration
241 241
      */
242
-    private function traverse_fields( $callback )
242
+    private function traverse_fields($callback)
243 243
     {
244
-        foreach( $this->fields as $taxonomy => $fields )
244
+        foreach ($this->fields as $taxonomy => $fields)
245 245
         {
246
-            foreach( $fields as $name => $props )
246
+            foreach ($fields as $name => $props)
247 247
             {
248
-                $callback( $taxonomy, $name, $props );
248
+                $callback($taxonomy, $name, $props);
249 249
             }
250 250
         }
251 251
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,8 +63,9 @@
 block discarded – undo
63 63
         if( !isset($this->fields[$taxonomy_name][$field_name]))
64 64
         {
65 65
             $this->fields[$taxonomy_name][$field_name] = array_merge( $this->default_props(), $field_props );
66
+        } else {
67
+            throw new \RuntimeException("A field named '$field_name' has already been registered in '$taxonomy_name'");
66 68
         }
67
-        else throw new \RuntimeException("A field named '$field_name' has already been registered in '$taxonomy_name'");
68 69
     }
69 70
     
70 71
     /**
Please login to merge, or discard this patch.