@@ -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,22 +39,22 @@ 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 | $this->fields[$taxonomy_name] = array(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if( !isset($this->fields[$taxonomy_name][$field_name])) |
|
| 57 | + if (!isset($this->fields[$taxonomy_name][$field_name])) |
|
| 58 | 58 | { |
| 59 | 59 | $this->fields[$taxonomy_name][$field_name] = $field_props; |
| 60 | 60 | } |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @param object $term Taxonomy term |
| 68 | 68 | */ |
| 69 | - public function render_edit_form( $term ) |
|
| 69 | + public function render_edit_form($term) |
|
| 70 | 70 | { |
| 71 | 71 | $fields = $this->fields[$term->taxonomy]; |
| 72 | 72 | |
| 73 | - foreach( $fields as $name => $props ) |
|
| 73 | + foreach ($fields as $name => $props) |
|
| 74 | 74 | { |
| 75 | 75 | $props['name'] = $name; |
| 76 | 76 | $props['term_id'] = $term->term_id; |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @param string $taxonomy Taxonomy name |
| 86 | 86 | */ |
| 87 | - public function render_add_form( $taxonomy ) |
|
| 87 | + public function render_add_form($taxonomy) |
|
| 88 | 88 | { |
| 89 | 89 | $fields = $this->fields[$taxonomy]; |
| 90 | 90 | |
| 91 | - foreach( $fields as $name => $props ) |
|
| 91 | + foreach ($fields as $name => $props) |
|
| 92 | 92 | { |
| 93 | 93 | $props['name'] = $name; |
| 94 | 94 | $field = new AddField($props); |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @param type $term_id |
| 104 | 104 | */ |
| 105 | - function update_term( $term_id ) |
|
| 105 | + function update_term($term_id) |
|
| 106 | 106 | { |
| 107 | - $term = \get_term( $term_id ); |
|
| 107 | + $term = \get_term($term_id); |
|
| 108 | 108 | |
| 109 | - foreach( $this->fields[$term->taxonomy] as $name => $props ) |
|
| 109 | + foreach ($this->fields[$term->taxonomy] as $name => $props) |
|
| 110 | 110 | { |
| 111 | - if( isset($_POST[$name]) ) |
|
| 111 | + if (isset($_POST[$name])) |
|
| 112 | 112 | { |
| 113 | 113 | update_term_meta($term_id, $name, filter_input(INPUT_POST, $name)); |
| 114 | 114 | } |
@@ -57,8 +57,9 @@ |
||
| 57 | 57 | if( !isset($this->fields[$taxonomy_name][$field_name])) |
| 58 | 58 | { |
| 59 | 59 | $this->fields[$taxonomy_name][$field_name] = $field_props; |
| 60 | + } else { |
|
| 61 | + throw new \RuntimeException("A field named '$field_name' has already been registered in '$taxonomy_name'"); |
|
| 60 | 62 | } |
| 61 | - else throw new \RuntimeException("A field named '$field_name' has already been registered in '$taxonomy_name'"); |
|
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | /** |
@@ -11,13 +11,13 @@ discard block |
||
| 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 |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | require_once 'add-field.php'; |
| 27 | 27 | require_once 'edit-field.php'; |
| 28 | 28 | |
| 29 | -if(!function_exists('amarkal_taxonomy_add_field')) |
|
| 29 | +if (!function_exists('amarkal_taxonomy_add_field')) |
|
| 30 | 30 | { |
| 31 | 31 | /** |
| 32 | 32 | * Add a field to the add & edit forms of a given taxonomy. |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * amarkal-ui components or a registered custom component. |
| 37 | 37 | * @param array $field_props The field's properties |
| 38 | 38 | */ |
| 39 | - function amarkal_taxonomy_add_field( $taxonomy_name, $field_type, $field_props ) |
|
| 39 | + function amarkal_taxonomy_add_field($taxonomy_name, $field_type, $field_props) |
|
| 40 | 40 | { |
| 41 | 41 | $form = Amarkal\Taxonomy\Form::get_instance(); |
| 42 | - $form->add_field( $taxonomy_name, $field_type, $field_props ); |
|
| 42 | + $form->add_field($taxonomy_name, $field_type, $field_props); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | \ No newline at end of file |
@@ -16,7 +16,9 @@ |
||
| 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 | /** |