Completed
Push — master ( 0ef81c...0f100c )
by Askupa
01:49
created
Form.php 1 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,14 +108,14 @@  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 117
             $term_meta = filter_input(INPUT_POST, $name);
118
-            if( null !== $term_meta )
118
+            if (null !== $term_meta)
119 119
             {
120 120
                 update_term_meta($term_id, $name, $term_meta);
121 121
             }
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
      * @param array $columns
129 129
      * @return array
130 130
      */
131
-    function modify_table_columns( $columns )
131
+    function modify_table_columns($columns)
132 132
     {   
133
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$columns ) 
133
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$columns) 
134 134
         {
135
-            if( $props['table']['show'] )
135
+            if ($props['table']['show'])
136 136
             {
137 137
                 $columns[$name] = $props['label'];
138 138
             }
@@ -150,12 +150,12 @@  discard block
 block discarded – undo
150 150
      * @param type $term_id
151 151
      * @return type
152 152
      */
153
-    function modify_table_content( $content, $column_name, $term_id )
153
+    function modify_table_content($content, $column_name, $term_id)
154 154
     {   
155 155
         $term = \get_term($term_id);
156
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$content, $column_name, $term ) 
156
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$content, $column_name, $term) 
157 157
         {
158
-            if( $props['table']['show'] && 
158
+            if ($props['table']['show'] && 
159 159
                 $term->taxonomy === $taxonomy &&
160 160
                 $name === $column_name
161 161
             ) {
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
      * @param array $columns
172 172
      * @return string
173 173
      */
174
-    function modify_table_sortable_columns( $columns )
174
+    function modify_table_sortable_columns($columns)
175 175
     {
176
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$columns ) 
176
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$columns) 
177 177
         {
178
-            if( $props['table']['show'] && 
178
+            if ($props['table']['show'] && 
179 179
                 $props['table']['sortable']
180 180
             ) {
181 181
                 $columns[$name] = $name;
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
      * @param type $args
196 196
      * @return string
197 197
      */
198
-    public function sort_custom_column( $clauses, $taxonomies, $args )
198
+    public function sort_custom_column($clauses, $taxonomies, $args)
199 199
     {
200
-        $this->traverse_fields(function( $taxonomy, $name, $props ) use ( &$clauses, $args ) 
200
+        $this->traverse_fields(function($taxonomy, $name, $props) use (&$clauses, $args) 
201 201
         {
202
-            if( in_array($taxonomy, $args['taxonomy']) && 
202
+            if (in_array($taxonomy, $args['taxonomy']) && 
203 203
                 $props['table']['sortable'] &&
204 204
                 $name === $args['orderby']
205 205
             )
@@ -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.