From 9843067b2b2452f928ae3dca317180dc5a9669dc Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Thu, 6 Feb 2020 10:22:46 -0300 Subject: [PATCH] organize the execution order of the action and add filter_type_helper in aggrs #349 --- src/classes/tainacan-creator.php | 17 --------- .../class-tainacan-filter-type-helper.php | 37 ++++++++++--------- src/views/class-tainacan-admin.php | 1 - 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/classes/tainacan-creator.php b/src/classes/tainacan-creator.php index 1148b3e29..7292d9171 100644 --- a/src/classes/tainacan-creator.php +++ b/src/classes/tainacan-creator.php @@ -143,24 +143,7 @@ $Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Relationship $Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Taxonomy'); //$Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Compound'); -//$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); $Filter_Type_Helper = \Tainacan\Filter_Types\Filter_Type_Helper::get_instance(); -do_action('tainacan-register-filter-type', 'register-type'); - -//register filter type -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Date'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Selectbox'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Autocomplete'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Taginput'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Checkbox'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyTaginput'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyCheckbox'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Date_Interval'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_Interval'); -// $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_List_Interval'); -//do_action('tainacan-register-filter-type', $Tainacan_Filters); - $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); diff --git a/src/views/admin/components/filter-types/filter-type-helper/class-tainacan-filter-type-helper.php b/src/views/admin/components/filter-types/filter-type-helper/class-tainacan-filter-type-helper.php index 773e75583..be231733d 100644 --- a/src/views/admin/components/filter-types/filter-type-helper/class-tainacan-filter-type-helper.php +++ b/src/views/admin/components/filter-types/filter-type-helper/class-tainacan-filter-type-helper.php @@ -42,6 +42,11 @@ class Filter_Type_Helper { $this->Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyTaginput'); $this->Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyCheckbox'); $this->Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_List_Interval'); + do_action('tainacan-register-filter-type', $this); + } + + public function register_filter_type_compoment() { + wp_enqueue_script($this->handle, $this->script_path); } /** @@ -51,27 +56,25 @@ class Filter_Type_Helper { * @param string $class a class name of the filter type * @param array|string $args */ - public function register_filter_type($handle, $class_name, $script_path, $type='register-type', $args = []) { + public function register_filter_type($handle, $class_name, $script_path, $args = []) { global $TAINACAN_EXTRA_FILTER_SCRIPTS; - if($type == 'register-type') { - $this->Tainacan_Filters->register_filter_type($class_name); - return; + $this->handle = $handle; + $this->script_path = $script_path; + + $this->Tainacan_Filters->register_filter_type($class_name); + if ( ! in_array( $handle, $this->registered_filter_type ) ) { + $TAINACAN_EXTRA_FILTER_SCRIPTS[] = $handle; + add_action( 'admin_enqueue_scripts', array( &$this, 'register_filter_type_compoment' ), 80 ); + + $this->registered_filter_type[$handle] = [ + 'handle' => $handle, + 'class_name' => $class_name, + 'script_path' => $script_path, + 'args' => $args + ]; } - if($type == 'register-script') { - if ( ! in_array( $handle, $this->registered_filter_type ) ) { - $TAINACAN_EXTRA_FILTER_SCRIPTS[] = $handle; - wp_enqueue_script($handle, $script_path); - - $this->registered_filter_type[$handle] = [ - 'handle' => $handle, - 'class_name' => $class_name, - 'script_path' => $script_path, - 'args' => $args - ]; - } - } } /** diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php index 7ccfb347a..2d3dcd55a 100644 --- a/src/views/class-tainacan-admin.php +++ b/src/views/class-tainacan-admin.php @@ -164,7 +164,6 @@ class Admin { global $TAINACAN_BASE_URL; global $TAINACAN_EXTRA_FILTER_SCRIPTS; - do_action('tainacan-register-filter-type', 'register-script'); $deps = ['underscore', 'media-editor', 'media-views', 'customize-controls']; if ( !empty($TAINACAN_EXTRA_FILTER_SCRIPTS) ) { foreach($TAINACAN_EXTRA_FILTER_SCRIPTS as $dep) {