@@ -14,113 +14,113 @@ |
||
14 | 14 | |
15 | 15 | class Entity_Type { |
16 | 16 | |
17 | - public function __construct() { |
|
18 | - |
|
19 | - $that = $this; |
|
20 | - |
|
21 | - add_action( |
|
22 | - 'init', |
|
23 | - function () use ( $that ) { |
|
24 | - $that->init_ui_and_save_handlers(); |
|
25 | - } |
|
26 | - ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @param $term \WP_Term |
|
31 | - */ |
|
32 | - public function render_ui( $term ) { |
|
33 | - |
|
34 | - $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
35 | - |
|
36 | - /** |
|
37 | - * Thing should be the default selected entity type |
|
38 | - * when this feature is activated. |
|
39 | - */ |
|
40 | - if ( count( $selected_entity_types ) === 0 ) { |
|
41 | - $selected_entity_types[] = 'thing'; |
|
42 | - } |
|
43 | - |
|
44 | - $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME; |
|
45 | - $types = Terms_Compat::get_terms( |
|
46 | - $entity_type_taxonomy, |
|
47 | - array( |
|
48 | - 'taxonomy' => $entity_type_taxonomy, |
|
49 | - 'parent' => 0, |
|
50 | - 'hide_empty' => false, |
|
51 | - ) |
|
52 | - ); |
|
53 | - ?> |
|
17 | + public function __construct() { |
|
18 | + |
|
19 | + $that = $this; |
|
20 | + |
|
21 | + add_action( |
|
22 | + 'init', |
|
23 | + function () use ( $that ) { |
|
24 | + $that->init_ui_and_save_handlers(); |
|
25 | + } |
|
26 | + ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @param $term \WP_Term |
|
31 | + */ |
|
32 | + public function render_ui( $term ) { |
|
33 | + |
|
34 | + $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
35 | + |
|
36 | + /** |
|
37 | + * Thing should be the default selected entity type |
|
38 | + * when this feature is activated. |
|
39 | + */ |
|
40 | + if ( count( $selected_entity_types ) === 0 ) { |
|
41 | + $selected_entity_types[] = 'thing'; |
|
42 | + } |
|
43 | + |
|
44 | + $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME; |
|
45 | + $types = Terms_Compat::get_terms( |
|
46 | + $entity_type_taxonomy, |
|
47 | + array( |
|
48 | + 'taxonomy' => $entity_type_taxonomy, |
|
49 | + 'parent' => 0, |
|
50 | + 'hide_empty' => false, |
|
51 | + ) |
|
52 | + ); |
|
53 | + ?> |
|
54 | 54 | <?php wp_nonce_field( 'wordlift_vocabulary_terms_entity_type', 'wordlift_vocabulary_terms_entity_type_nonce' ); ?> |
55 | 55 | <tr class="form-field term-name-wrap"> |
56 | 56 | <th scope="row"><label for="wl-entity-type__checklist">%s</label></th> |
57 | 57 | <td> |
58 | 58 | <div id="wl-entity-type__checklist"> |
59 | 59 | <?php |
60 | - echo wp_kses( |
|
61 | - Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ), |
|
62 | - array( |
|
63 | - 'li' => array( 'id' => array() ), |
|
64 | - 'ul' => array( 'id' => array() ), |
|
65 | - 'label' => array( 'class' => array() ), |
|
66 | - 'input' => array( |
|
67 | - 'value' => array(), |
|
68 | - 'type' => array(), |
|
69 | - 'name' => array(), |
|
70 | - 'id' => array(), |
|
71 | - 'placeholder' => array(), |
|
72 | - 'checked' => array(), |
|
73 | - ), |
|
74 | - ) |
|
75 | - ); |
|
76 | - ?> |
|
60 | + echo wp_kses( |
|
61 | + Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ), |
|
62 | + array( |
|
63 | + 'li' => array( 'id' => array() ), |
|
64 | + 'ul' => array( 'id' => array() ), |
|
65 | + 'label' => array( 'class' => array() ), |
|
66 | + 'input' => array( |
|
67 | + 'value' => array(), |
|
68 | + 'type' => array(), |
|
69 | + 'name' => array(), |
|
70 | + 'id' => array(), |
|
71 | + 'placeholder' => array(), |
|
72 | + 'checked' => array(), |
|
73 | + ), |
|
74 | + ) |
|
75 | + ); |
|
76 | + ?> |
|
77 | 77 | </div> |
78 | 78 | </td> |
79 | 79 | </tr> |
80 | 80 | <?php |
81 | - $this->enqueue_script_and_style(); |
|
82 | - } |
|
83 | - |
|
84 | - public function save_field( $term_id ) { |
|
85 | - |
|
86 | - if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
87 | - return; |
|
88 | - } |
|
89 | - $entity_types = array(); |
|
90 | - if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
91 | - $entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
92 | - $entity_types = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
93 | - } |
|
94 | - if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
95 | - // Save the taxonomies. |
|
96 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
97 | - foreach ( $entity_types as $entity_type ) { |
|
98 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - public function init_ui_and_save_handlers() { |
|
104 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
105 | - foreach ( $taxonomies as $taxonomy ) { |
|
106 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
107 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - private function enqueue_script_and_style() { |
|
112 | - |
|
113 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
114 | - 'wl-vocabulary-term', |
|
115 | - plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term', |
|
116 | - array( 'wp-polyfill' ) |
|
117 | - ); |
|
118 | - wp_enqueue_style( |
|
119 | - 'wl-vocabulary-term', |
|
120 | - plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css', |
|
121 | - array(), |
|
122 | - WORDLIFT_VERSION |
|
123 | - ); |
|
124 | - } |
|
81 | + $this->enqueue_script_and_style(); |
|
82 | + } |
|
83 | + |
|
84 | + public function save_field( $term_id ) { |
|
85 | + |
|
86 | + if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
87 | + return; |
|
88 | + } |
|
89 | + $entity_types = array(); |
|
90 | + if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
91 | + $entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
92 | + $entity_types = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
93 | + } |
|
94 | + if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
95 | + // Save the taxonomies. |
|
96 | + delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
97 | + foreach ( $entity_types as $entity_type ) { |
|
98 | + add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + public function init_ui_and_save_handlers() { |
|
104 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
105 | + foreach ( $taxonomies as $taxonomy ) { |
|
106 | + add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
107 | + add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + private function enqueue_script_and_style() { |
|
112 | + |
|
113 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
114 | + 'wl-vocabulary-term', |
|
115 | + plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term', |
|
116 | + array( 'wp-polyfill' ) |
|
117 | + ); |
|
118 | + wp_enqueue_style( |
|
119 | + 'wl-vocabulary-term', |
|
120 | + plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css', |
|
121 | + array(), |
|
122 | + WORDLIFT_VERSION |
|
123 | + ); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | add_action( |
22 | 22 | 'init', |
23 | - function () use ( $that ) { |
|
23 | + function() use ($that) { |
|
24 | 24 | $that->init_ui_and_save_handlers(); |
25 | 25 | } |
26 | 26 | ); |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @param $term \WP_Term |
31 | 31 | */ |
32 | - public function render_ui( $term ) { |
|
32 | + public function render_ui($term) { |
|
33 | 33 | |
34 | - $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
34 | + $selected_entity_types = get_term_meta($term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Thing should be the default selected entity type |
38 | 38 | * when this feature is activated. |
39 | 39 | */ |
40 | - if ( count( $selected_entity_types ) === 0 ) { |
|
40 | + if (count($selected_entity_types) === 0) { |
|
41 | 41 | $selected_entity_types[] = 'thing'; |
42 | 42 | } |
43 | 43 | |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | ?> |
54 | - <?php wp_nonce_field( 'wordlift_vocabulary_terms_entity_type', 'wordlift_vocabulary_terms_entity_type_nonce' ); ?> |
|
54 | + <?php wp_nonce_field('wordlift_vocabulary_terms_entity_type', 'wordlift_vocabulary_terms_entity_type_nonce'); ?> |
|
55 | 55 | <tr class="form-field term-name-wrap"> |
56 | 56 | <th scope="row"><label for="wl-entity-type__checklist">%s</label></th> |
57 | 57 | <td> |
58 | 58 | <div id="wl-entity-type__checklist"> |
59 | 59 | <?php |
60 | 60 | echo wp_kses( |
61 | - Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ), |
|
61 | + Term_Checklist::render('tax_input[wl_entity_type]', $types, $selected_entity_types), |
|
62 | 62 | array( |
63 | - 'li' => array( 'id' => array() ), |
|
64 | - 'ul' => array( 'id' => array() ), |
|
65 | - 'label' => array( 'class' => array() ), |
|
63 | + 'li' => array('id' => array()), |
|
64 | + 'ul' => array('id' => array()), |
|
65 | + 'label' => array('class' => array()), |
|
66 | 66 | 'input' => array( |
67 | 67 | 'value' => array(), |
68 | 68 | 'type' => array(), |
@@ -81,30 +81,30 @@ discard block |
||
81 | 81 | $this->enqueue_script_and_style(); |
82 | 82 | } |
83 | 83 | |
84 | - public function save_field( $term_id ) { |
|
84 | + public function save_field($term_id) { |
|
85 | 85 | |
86 | - if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
86 | + if ( ! isset($_REQUEST['tax_input'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
87 | 87 | return; |
88 | 88 | } |
89 | 89 | $entity_types = array(); |
90 | - if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
91 | - $entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
92 | - $entity_types = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
90 | + if (isset($_REQUEST['tax_input'][Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
91 | + $entity_types_data = filter_var_array($_REQUEST, array('tax_input' => array('flags' => FILTER_REQUIRE_ARRAY))); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
92 | + $entity_types = $entity_types_data['tax_input'][Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME]; |
|
93 | 93 | } |
94 | - if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
94 | + if (isset($entity_types) && is_array($entity_types)) { |
|
95 | 95 | // Save the taxonomies. |
96 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
97 | - foreach ( $entity_types as $entity_type ) { |
|
98 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
96 | + delete_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
97 | + foreach ($entity_types as $entity_type) { |
|
98 | + add_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | 103 | public function init_ui_and_save_handlers() { |
104 | 104 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
105 | - foreach ( $taxonomies as $taxonomy ) { |
|
106 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
107 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
105 | + foreach ($taxonomies as $taxonomy) { |
|
106 | + add_action("${taxonomy}_edit_form_fields", array($this, 'render_ui'), 1); |
|
107 | + add_action("edited_${taxonomy}", array($this, 'save_field')); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | |
113 | 113 | Scripts_Helper::enqueue_based_on_wordpress_version( |
114 | 114 | 'wl-vocabulary-term', |
115 | - plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term', |
|
116 | - array( 'wp-polyfill' ) |
|
115 | + plugin_dir_url(dirname(__DIR__)).'/js/dist/vocabulary-term', |
|
116 | + array('wp-polyfill') |
|
117 | 117 | ); |
118 | 118 | wp_enqueue_style( |
119 | 119 | 'wl-vocabulary-term', |
120 | - plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css', |
|
120 | + plugin_dir_url(dirname(__DIR__)).'/js/dist/vocabulary-term.css', |
|
121 | 121 | array(), |
122 | 122 | WORDLIFT_VERSION |
123 | 123 | ); |