@@ -232,7 +232,7 @@ |
||
| 232 | 232 | /** |
| 233 | 233 | * Treverse the $fields array. |
| 234 | 234 | * |
| 235 | - * @param collable $callback Called on each iteration |
|
| 235 | + * @param \Closure $callback Called on each iteration |
|
| 236 | 236 | */ |
| 237 | 237 | private function traverse_components( $callback ) |
| 238 | 238 | { |
@@ -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 | } |
@@ -38,29 +38,29 @@ discard block |
||
| 38 | 38 | * @param array $component |
| 39 | 39 | * @throws \RuntimeException if duplicate names are registered under the same taxonomy |
| 40 | 40 | */ |
| 41 | - public function add_field( $taxonomy_name, $component ) |
|
| 41 | + public function add_field($taxonomy_name, $component) |
|
| 42 | 42 | { |
| 43 | - if( !isset($this->forms[$taxonomy_name]) ) |
|
| 43 | + if (!isset($this->forms[$taxonomy_name])) |
|
| 44 | 44 | { |
| 45 | 45 | // Add fields to taxonomy add and edit forms |
| 46 | - add_action( "{$taxonomy_name}_add_form_fields", array($this, 'render_add_form') ); |
|
| 47 | - add_action( "{$taxonomy_name}_edit_form_fields", array($this, 'render_edit_form') ); |
|
| 46 | + add_action("{$taxonomy_name}_add_form_fields", array($this, 'render_add_form')); |
|
| 47 | + add_action("{$taxonomy_name}_edit_form_fields", array($this, 'render_edit_form')); |
|
| 48 | 48 | |
| 49 | 49 | // Save the data from taxonomy add and edit forms |
| 50 | - add_action( "create_{$taxonomy_name}", array($this, 'update_term') ); |
|
| 51 | - add_action( "edited_{$taxonomy_name}", array($this, 'update_term') ); |
|
| 50 | + add_action("create_{$taxonomy_name}", array($this, 'update_term')); |
|
| 51 | + add_action("edited_{$taxonomy_name}", array($this, 'update_term')); |
|
| 52 | 52 | |
| 53 | 53 | // Modify the taxonomy term table |
| 54 | - add_filter( "manage_edit-{$taxonomy_name}_columns", array($this, 'modify_table_columns') ); |
|
| 55 | - add_filter( "manage_{$taxonomy_name}_custom_column", array($this, 'modify_table_content'), 10, 3 ); |
|
| 56 | - add_filter( "manage_edit-{$taxonomy_name}_sortable_columns", array($this, 'modify_table_sortable_columns') ); |
|
| 57 | - add_filter( 'terms_clauses', array($this, 'sort_custom_column'), 10, 3 ); |
|
| 54 | + add_filter("manage_edit-{$taxonomy_name}_columns", array($this, 'modify_table_columns')); |
|
| 55 | + add_filter("manage_{$taxonomy_name}_custom_column", array($this, 'modify_table_content'), 10, 3); |
|
| 56 | + add_filter("manage_edit-{$taxonomy_name}_sortable_columns", array($this, 'modify_table_sortable_columns')); |
|
| 57 | + add_filter('terms_clauses', array($this, 'sort_custom_column'), 10, 3); |
|
| 58 | 58 | |
| 59 | 59 | $this->forms[$taxonomy_name] = new \Amarkal\UI\Form(); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $this->forms[$taxonomy_name]->add_component( |
| 63 | - array_merge( $this->default_props(), $component ) |
|
| 63 | + array_merge($this->default_props(), $component) |
|
| 64 | 64 | ); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @param object $term Taxonomy term |
| 71 | 71 | */ |
| 72 | - public function render_edit_form( $term ) |
|
| 72 | + public function render_edit_form($term) |
|
| 73 | 73 | { |
| 74 | 74 | $form = $this->forms[$term->taxonomy]; |
| 75 | 75 | $new_instance = array(); |
| 76 | 76 | |
| 77 | - foreach( $form->get_components() as $component ) |
|
| 77 | + foreach ($form->get_components() as $component) |
|
| 78 | 78 | { |
| 79 | 79 | $new_instance[$component->name] = \get_term_meta($term->term_id, $component->name, true); |
| 80 | 80 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @param string $taxonomy Taxonomy name |
| 91 | 91 | */ |
| 92 | - public function render_add_form( $taxonomy ) |
|
| 92 | + public function render_add_form($taxonomy) |
|
| 93 | 93 | { |
| 94 | 94 | $form = $this->forms[$taxonomy]; |
| 95 | 95 | $form->update(); |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @param type $term_id |
| 105 | 105 | */ |
| 106 | - function update_term( $term_id ) |
|
| 106 | + function update_term($term_id) |
|
| 107 | 107 | { |
| 108 | - $term = \get_term( $term_id ); |
|
| 108 | + $term = \get_term($term_id); |
|
| 109 | 109 | |
| 110 | - foreach( $this->forms[$term->taxonomy]->get_components() as $component ) |
|
| 110 | + foreach ($this->forms[$term->taxonomy]->get_components() as $component) |
|
| 111 | 111 | { |
| 112 | 112 | $term_meta = filter_input(INPUT_POST, $component->name); |
| 113 | - if( null !== $term_meta ) |
|
| 113 | + if (null !== $term_meta) |
|
| 114 | 114 | { |
| 115 | 115 | \update_term_meta($term_id, $component->name, $term_meta); |
| 116 | 116 | } |
@@ -123,11 +123,11 @@ discard block |
||
| 123 | 123 | * @param array $columns |
| 124 | 124 | * @return array |
| 125 | 125 | */ |
| 126 | - function modify_table_columns( $columns ) |
|
| 126 | + function modify_table_columns($columns) |
|
| 127 | 127 | { |
| 128 | - $this->traverse_components(function( $taxonomy, $component ) use ( &$columns ) |
|
| 128 | + $this->traverse_components(function($taxonomy, $component) use (&$columns) |
|
| 129 | 129 | { |
| 130 | - if( $component->table['show'] ) |
|
| 130 | + if ($component->table['show']) |
|
| 131 | 131 | { |
| 132 | 132 | $columns[$component->name] = $component->title; |
| 133 | 133 | } |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | * @param type $term_id |
| 146 | 146 | * @return type |
| 147 | 147 | */ |
| 148 | - function modify_table_content( $content, $column_name, $term_id ) |
|
| 148 | + function modify_table_content($content, $column_name, $term_id) |
|
| 149 | 149 | { |
| 150 | 150 | $term = \get_term($term_id); |
| 151 | - $this->traverse_components(function( $taxonomy, $component ) use ( &$content, $column_name, $term ) |
|
| 151 | + $this->traverse_components(function($taxonomy, $component) use (&$content, $column_name, $term) |
|
| 152 | 152 | { |
| 153 | - if( $component->table['show'] && |
|
| 153 | + if ($component->table['show'] && |
|
| 154 | 154 | $term->taxonomy === $taxonomy && |
| 155 | 155 | $component->name === $column_name |
| 156 | 156 | ) { |
@@ -166,11 +166,11 @@ discard block |
||
| 166 | 166 | * @param array $columns |
| 167 | 167 | * @return string |
| 168 | 168 | */ |
| 169 | - function modify_table_sortable_columns( $columns ) |
|
| 169 | + function modify_table_sortable_columns($columns) |
|
| 170 | 170 | { |
| 171 | - $this->traverse_components(function( $taxonomy, $component ) use ( &$columns ) |
|
| 171 | + $this->traverse_components(function($taxonomy, $component) use (&$columns) |
|
| 172 | 172 | { |
| 173 | - if( $component->table['show'] && |
|
| 173 | + if ($component->table['show'] && |
|
| 174 | 174 | $component->table['sortable'] |
| 175 | 175 | ) { |
| 176 | 176 | $columns[$component->name] = $component->name; |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | * @param type $args |
| 191 | 191 | * @return string |
| 192 | 192 | */ |
| 193 | - public function sort_custom_column( $clauses, $taxonomies, $args ) |
|
| 193 | + public function sort_custom_column($clauses, $taxonomies, $args) |
|
| 194 | 194 | { |
| 195 | - $this->traverse_components(function( $taxonomy, $component ) use ( &$clauses, $args ) |
|
| 195 | + $this->traverse_components(function($taxonomy, $component) use (&$clauses, $args) |
|
| 196 | 196 | { |
| 197 | - if( in_array($taxonomy, $args['taxonomy']) && |
|
| 197 | + if (in_array($taxonomy, $args['taxonomy']) && |
|
| 198 | 198 | $component->table['sortable'] && |
| 199 | 199 | $component->name === $args['orderby'] |
| 200 | 200 | ) |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @param collable $callback Called on each iteration |
| 236 | 236 | */ |
| 237 | - private function traverse_components( $callback ) |
|
| 237 | + private function traverse_components($callback) |
|
| 238 | 238 | { |
| 239 | - foreach( $this->forms as $taxonomy => $form ) |
|
| 239 | + foreach ($this->forms as $taxonomy => $form) |
|
| 240 | 240 | { |
| 241 | - foreach( $form->get_components() as $component ) |
|
| 241 | + foreach ($form->get_components() as $component) |
|
| 242 | 242 | { |
| 243 | - $callback( $taxonomy, $component ); |
|
| 243 | + $callback($taxonomy, $component); |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | } |
@@ -13,15 +13,15 @@ discard block |
||
| 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_TAXONOMY' ) ) return false; |
|
| 22 | -define( 'AMARKAL_TAXONOMY', true ); |
|
| 21 | +if (defined('AMARKAL_TAXONOMY')) return false; |
|
| 22 | +define('AMARKAL_TAXONOMY', true); |
|
| 23 | 23 | |
| 24 | -if(!function_exists('amarkal_taxonomy_add_field')) |
|
| 24 | +if (!function_exists('amarkal_taxonomy_add_field')) |
|
| 25 | 25 | { |
| 26 | 26 | /** |
| 27 | 27 | * Add a field to the add & edit forms of a given taxonomy. |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @param string $component The UI component arguments. One of the core |
| 31 | 31 | * amarkal-ui components or a registered custom component. |
| 32 | 32 | */ |
| 33 | - function amarkal_taxonomy_add_field( $taxonomy_name, $component ) |
|
| 33 | + function amarkal_taxonomy_add_field($taxonomy_name, $component) |
|
| 34 | 34 | { |
| 35 | 35 | $form = Amarkal\Taxonomy\Form::get_instance(); |
| 36 | - $form->add_field( $taxonomy_name, $component ); |
|
| 36 | + $form->add_field($taxonomy_name, $component); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |