@@ -12,47 +12,47 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Term_Metabox extends Wl_Abstract_Metabox { |
| 14 | 14 | |
| 15 | - public function __construct() { |
|
| 16 | - parent::__construct(); |
|
| 17 | - add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @param $term \WP_Term |
|
| 22 | - */ |
|
| 23 | - public function render_ui( $term ) { |
|
| 24 | - $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 25 | - $this->html(); |
|
| 26 | - $this->enqueue_scripts_and_styles(); |
|
| 27 | - $plugin = \Wordlift::get_instance(); |
|
| 28 | - |
|
| 29 | - // Enqueue this scripts for sameas fields. |
|
| 30 | - wp_enqueue_script( |
|
| 31 | - 'wl-autocomplete-select', |
|
| 32 | - plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'js/dist/autocomplete-select.js', |
|
| 33 | - array(), |
|
| 34 | - $plugin->get_version(), |
|
| 35 | - true |
|
| 36 | - ); |
|
| 37 | - |
|
| 38 | - wp_enqueue_style( |
|
| 39 | - 'wl-autocomplete-select', |
|
| 40 | - plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'js/dist/autocomplete-select.css', |
|
| 41 | - array(), |
|
| 42 | - $plugin->get_version() |
|
| 43 | - ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function save_field( $term_id ) { |
|
| 47 | - $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function init_all_custom_fields() { |
|
| 51 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 52 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 53 | - add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 54 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 55 | - } |
|
| 56 | - } |
|
| 15 | + public function __construct() { |
|
| 16 | + parent::__construct(); |
|
| 17 | + add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @param $term \WP_Term |
|
| 22 | + */ |
|
| 23 | + public function render_ui( $term ) { |
|
| 24 | + $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 25 | + $this->html(); |
|
| 26 | + $this->enqueue_scripts_and_styles(); |
|
| 27 | + $plugin = \Wordlift::get_instance(); |
|
| 28 | + |
|
| 29 | + // Enqueue this scripts for sameas fields. |
|
| 30 | + wp_enqueue_script( |
|
| 31 | + 'wl-autocomplete-select', |
|
| 32 | + plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'js/dist/autocomplete-select.js', |
|
| 33 | + array(), |
|
| 34 | + $plugin->get_version(), |
|
| 35 | + true |
|
| 36 | + ); |
|
| 37 | + |
|
| 38 | + wp_enqueue_style( |
|
| 39 | + 'wl-autocomplete-select', |
|
| 40 | + plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'js/dist/autocomplete-select.css', |
|
| 41 | + array(), |
|
| 42 | + $plugin->get_version() |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function save_field( $term_id ) { |
|
| 47 | + $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function init_all_custom_fields() { |
|
| 51 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 52 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 53 | + add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 54 | + add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | } |
| 59 | 59 | \ No newline at end of file |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | - add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 17 | + add_action('init', array($this, 'init_all_custom_fields')); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @param $term \WP_Term |
| 22 | 22 | */ |
| 23 | - public function render_ui( $term ) { |
|
| 24 | - $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 23 | + public function render_ui($term) { |
|
| 24 | + $this->instantiate_fields($term->term_id, Object_Type_Enum::TERM); |
|
| 25 | 25 | $this->html(); |
| 26 | 26 | $this->enqueue_scripts_and_styles(); |
| 27 | 27 | $plugin = \Wordlift::get_instance(); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | // Enqueue this scripts for sameas fields. |
| 30 | 30 | wp_enqueue_script( |
| 31 | 31 | 'wl-autocomplete-select', |
| 32 | - plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'js/dist/autocomplete-select.js', |
|
| 32 | + plugin_dir_url(dirname(dirname(__FILE__))).'js/dist/autocomplete-select.js', |
|
| 33 | 33 | array(), |
| 34 | 34 | $plugin->get_version(), |
| 35 | 35 | true |
@@ -37,21 +37,21 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | wp_enqueue_style( |
| 39 | 39 | 'wl-autocomplete-select', |
| 40 | - plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'js/dist/autocomplete-select.css', |
|
| 40 | + plugin_dir_url(dirname(dirname(__FILE__))).'js/dist/autocomplete-select.css', |
|
| 41 | 41 | array(), |
| 42 | 42 | $plugin->get_version() |
| 43 | 43 | ); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function save_field( $term_id ) { |
|
| 47 | - $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 46 | + public function save_field($term_id) { |
|
| 47 | + $this->save_form_data($term_id, Object_Type_Enum::TERM); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function init_all_custom_fields() { |
| 51 | 51 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
| 52 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 53 | - add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 54 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 52 | + foreach ($taxonomies as $taxonomy) { |
|
| 53 | + add_action("${taxonomy}_edit_form", array($this, 'render_ui'), 1); |
|
| 54 | + add_action("edited_${taxonomy}", array($this, 'save_field')); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
@@ -14,48 +14,48 @@ discard block |
||
| 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 | - /** |
|
| 31 | - * @param $term \WP_Term |
|
| 32 | - */ |
|
| 33 | - public function render_ui( $term ) { |
|
| 34 | - |
|
| 35 | - $entity_types_text = __( 'Entity Types', 'wordlift' ); |
|
| 36 | - $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Thing should be the default selected entity type |
|
| 40 | - * when this feature is activated. |
|
| 41 | - */ |
|
| 42 | - if ( count( $selected_entity_types ) === 0 ) { |
|
| 43 | - $selected_entity_types[] = 'thing'; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME; |
|
| 47 | - $types = Terms_Compat::get_terms( |
|
| 48 | - $entity_type_taxonomy, |
|
| 49 | - array( |
|
| 50 | - 'taxonomy' => $entity_type_taxonomy, |
|
| 51 | - 'parent' => 0, |
|
| 52 | - 'hide_empty' => false, |
|
| 53 | - ) |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - $terms_html = Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ); |
|
| 57 | - |
|
| 58 | - $template = <<<EOF |
|
| 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 | + /** |
|
| 31 | + * @param $term \WP_Term |
|
| 32 | + */ |
|
| 33 | + public function render_ui( $term ) { |
|
| 34 | + |
|
| 35 | + $entity_types_text = __( 'Entity Types', 'wordlift' ); |
|
| 36 | + $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Thing should be the default selected entity type |
|
| 40 | + * when this feature is activated. |
|
| 41 | + */ |
|
| 42 | + if ( count( $selected_entity_types ) === 0 ) { |
|
| 43 | + $selected_entity_types[] = 'thing'; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME; |
|
| 47 | + $types = Terms_Compat::get_terms( |
|
| 48 | + $entity_type_taxonomy, |
|
| 49 | + array( |
|
| 50 | + 'taxonomy' => $entity_type_taxonomy, |
|
| 51 | + 'parent' => 0, |
|
| 52 | + 'hide_empty' => false, |
|
| 53 | + ) |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + $terms_html = Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ); |
|
| 57 | + |
|
| 58 | + $template = <<<EOF |
|
| 59 | 59 | <tr class="form-field term-name-wrap"> |
| 60 | 60 | <th scope="row"><label for="wl-entity-type__checklist">%s</label></th> |
| 61 | 61 | <td> |
@@ -64,29 +64,29 @@ discard block |
||
| 64 | 64 | </tr> |
| 65 | 65 | EOF; |
| 66 | 66 | |
| 67 | - echo sprintf( $template, $entity_types_text, $terms_html ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function save_field( $term_id ) { |
|
| 71 | - if ( ! isset( $_REQUEST['tax_input'] ) ) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - $entity_types = $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
| 75 | - if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
| 76 | - // Save the taxonomies. |
|
| 77 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 78 | - foreach ( $entity_types as $entity_type ) { |
|
| 79 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function init_ui_and_save_handlers() { |
|
| 85 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 86 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 87 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
| 88 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 89 | - } |
|
| 90 | - } |
|
| 67 | + echo sprintf( $template, $entity_types_text, $terms_html ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function save_field( $term_id ) { |
|
| 71 | + if ( ! isset( $_REQUEST['tax_input'] ) ) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + $entity_types = $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
| 75 | + if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
| 76 | + // Save the taxonomies. |
|
| 77 | + delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 78 | + foreach ( $entity_types as $entity_type ) { |
|
| 79 | + add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function init_ui_and_save_handlers() { |
|
| 85 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 86 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 87 | + add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
| 88 | + add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | } |
@@ -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 | ); |
@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * @param $term \WP_Term |
| 32 | 32 | */ |
| 33 | - public function render_ui( $term ) { |
|
| 33 | + public function render_ui($term) { |
|
| 34 | 34 | |
| 35 | - $entity_types_text = __( 'Entity Types', 'wordlift' ); |
|
| 36 | - $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 35 | + $entity_types_text = __('Entity Types', 'wordlift'); |
|
| 36 | + $selected_entity_types = get_term_meta($term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Thing should be the default selected entity type |
| 40 | 40 | * when this feature is activated. |
| 41 | 41 | */ |
| 42 | - if ( count( $selected_entity_types ) === 0 ) { |
|
| 42 | + if (count($selected_entity_types) === 0) { |
|
| 43 | 43 | $selected_entity_types[] = 'thing'; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | ) |
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - $terms_html = Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ); |
|
| 56 | + $terms_html = Term_Checklist::render('tax_input[wl_entity_type]', $types, $selected_entity_types); |
|
| 57 | 57 | |
| 58 | 58 | $template = <<<EOF |
| 59 | 59 | <tr class="form-field term-name-wrap"> |
@@ -64,28 +64,28 @@ discard block |
||
| 64 | 64 | </tr> |
| 65 | 65 | EOF; |
| 66 | 66 | |
| 67 | - echo sprintf( $template, $entity_types_text, $terms_html ); |
|
| 67 | + echo sprintf($template, $entity_types_text, $terms_html); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function save_field( $term_id ) { |
|
| 71 | - if ( ! isset( $_REQUEST['tax_input'] ) ) { |
|
| 70 | + public function save_field($term_id) { |
|
| 71 | + if ( ! isset($_REQUEST['tax_input'])) { |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | - $entity_types = $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
| 75 | - if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
| 74 | + $entity_types = $_REQUEST['tax_input'][Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME]; |
|
| 75 | + if (isset($entity_types) && is_array($entity_types)) { |
|
| 76 | 76 | // Save the taxonomies. |
| 77 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 78 | - foreach ( $entity_types as $entity_type ) { |
|
| 79 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
| 77 | + delete_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 78 | + foreach ($entity_types as $entity_type) { |
|
| 79 | + add_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public function init_ui_and_save_handlers() { |
| 85 | 85 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
| 86 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 87 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
| 88 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 86 | + foreach ($taxonomies as $taxonomy) { |
|
| 87 | + add_action("${taxonomy}_edit_form_fields", array($this, 'render_ui'), 1); |
|
| 88 | + add_action("edited_${taxonomy}", array($this, 'save_field')); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |