@@ -24,7 +24,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,13 +127,13 @@ discard block |
||
| 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 | - foreach( $this->fields as $fields ) |
|
| 132 | + foreach ($this->fields as $fields) |
|
| 133 | 133 | { |
| 134 | - foreach( $fields as $name => $props ) |
|
| 134 | + foreach ($fields as $name => $props) |
|
| 135 | 135 | { |
| 136 | - if( $props['table']['show'] ) |
|
| 136 | + if ($props['table']['show']) |
|
| 137 | 137 | { |
| 138 | 138 | $columns[$name] = $props['label']; |
| 139 | 139 | } |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | * @param type $term_id |
| 153 | 153 | * @return type |
| 154 | 154 | */ |
| 155 | - function modify_table_content( $content, $column_name, $term_id ) |
|
| 155 | + function modify_table_content($content, $column_name, $term_id) |
|
| 156 | 156 | { |
| 157 | 157 | $term = \get_term($term_id); |
| 158 | - foreach( $this->fields as $taxonomy => $fields ) |
|
| 158 | + foreach ($this->fields as $taxonomy => $fields) |
|
| 159 | 159 | { |
| 160 | - foreach( $fields as $name => $props ) |
|
| 160 | + foreach ($fields as $name => $props) |
|
| 161 | 161 | { |
| 162 | - if( $props['table']['show'] && |
|
| 162 | + if ($props['table']['show'] && |
|
| 163 | 163 | $term->taxonomy === $taxonomy && |
| 164 | 164 | $name === $column_name |
| 165 | 165 | ) { |
@@ -176,13 +176,13 @@ discard block |
||
| 176 | 176 | * @param array $columns |
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | - function modify_table_sortable_columns( $columns ) |
|
| 179 | + function modify_table_sortable_columns($columns) |
|
| 180 | 180 | { |
| 181 | - foreach( $this->fields as $taxonomy => $fields ) |
|
| 181 | + foreach ($this->fields as $taxonomy => $fields) |
|
| 182 | 182 | { |
| 183 | - foreach( $fields as $name => $props ) |
|
| 183 | + foreach ($fields as $name => $props) |
|
| 184 | 184 | { |
| 185 | - if( $props['table']['show'] && |
|
| 185 | + if ($props['table']['show'] && |
|
| 186 | 186 | $props['table']['sortable'] |
| 187 | 187 | ) { |
| 188 | 188 | $columns[$name] = $name; |
@@ -203,20 +203,20 @@ discard block |
||
| 203 | 203 | * @param type $args |
| 204 | 204 | * @return string |
| 205 | 205 | */ |
| 206 | - function sort_custom_column( $clauses, $taxonomies, $args ) |
|
| 206 | + function sort_custom_column($clauses, $taxonomies, $args) |
|
| 207 | 207 | { |
| 208 | - foreach( $this->fields as $taxonomy => $fields ) |
|
| 208 | + foreach ($this->fields as $taxonomy => $fields) |
|
| 209 | 209 | { |
| 210 | 210 | // if( in_array($taxonomy, $args['taxonomy']) && 'icon' === $args['orderby']) |
| 211 | - foreach( $fields as $name => $props ) |
|
| 211 | + foreach ($fields as $name => $props) |
|
| 212 | 212 | { |
| 213 | - if( in_array($taxonomy, $args['taxonomy']) && |
|
| 213 | + if (in_array($taxonomy, $args['taxonomy']) && |
|
| 214 | 214 | $props['table']['show'] && |
| 215 | 215 | $props['table']['sortable'] && |
| 216 | 216 | $name === $args['orderby'] |
| 217 | 217 | ) |
| 218 | 218 | { |
| 219 | - $this->modify_term_clauses( $clauses, $taxonomy, $name ); |
|
| 219 | + $this->modify_term_clauses($clauses, $taxonomy, $name); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @param string $taxonomy |
| 231 | 231 | * @param string $termmeta |
| 232 | 232 | */ |
| 233 | - function modify_term_clauses( &$clauses, $taxonomy, $termmeta ) |
|
| 233 | + function modify_term_clauses(&$clauses, $taxonomy, $termmeta) |
|
| 234 | 234 | { |
| 235 | 235 | global $wpdb; |
| 236 | 236 | // tt refers to the $wpdb->term_taxonomy table |
@@ -63,8 +63,9 @@ |
||
| 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 | /** |