From 71e0d4c841b7c35f4270e512032f182865fee611 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 7 Feb 2020 16:36:09 -0300 Subject: [PATCH] use only one location to add `action`#349 --- .../class-tainacan-filter-type-helper.php | 14 +++++++------- .../class-tainacan-metadata-type-helper.php | 13 ++++++------- src/views/class-tainacan-component-hooks.php | 14 ++++++-------- 3 files changed, 19 insertions(+), 22 deletions(-) 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 6710b9b54..594589ec6 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,11 +42,17 @@ 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'); + + // the priority should see less than on function + // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php + add_action( 'admin_enqueue_scripts', array( &$this, 'register_filter_type_compoment' ), 80 ); do_action('tainacan-register-filter-type', $this); } public function register_filter_type_compoment() { - wp_enqueue_script($this->handle, $this->script_path); + foreach($this->registered_filter_type as $handle => $component) { + wp_enqueue_script($handle, $component['script_path']); + } } /** @@ -59,15 +65,9 @@ class Filter_Type_Helper { public function register_filter_type($handle, $class_name, $script_path, $args = []) { global $TAINACAN_EXTRA_SCRIPTS; - $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_SCRIPTS[] = $handle; - // the priority should see less than on function - // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php - add_action( 'admin_enqueue_scripts', array( &$this, 'register_filter_type_compoment' ), 80 ); $this->registered_filter_type[$handle] = [ 'handle' => $handle, diff --git a/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php b/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php index 3b881a171..e3f3fb71f 100644 --- a/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php +++ b/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php @@ -41,11 +41,16 @@ class Metadata_Type_Helper { $this->Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Taxonomy'); //$Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Compound'); + // the priority should see less than on function + // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php + add_action( 'admin_enqueue_scripts', array( &$this, 'register_metadata_type_compoment' ), 80 ); do_action('tainacan-register-metadata-type', $this); } public function register_metadata_type_compoment() { - wp_enqueue_script($this->handle, $this->script_path); + foreach($this->registered_metadata_type as $handle => $component) { + wp_enqueue_script($handle, $component['script_path']); + } } /** @@ -58,15 +63,9 @@ class Metadata_Type_Helper { public function register_metadata_type($handle, $class_name, $script_path, $args = []) { global $TAINACAN_EXTRA_SCRIPTS; - $this->handle = $handle; - $this->script_path = $script_path; - $this->Tainacan_Metadata->register_metadata_type($class_name); if ( ! in_array( $handle, $this->registered_metadata_type ) ) { $TAINACAN_EXTRA_SCRIPTS[] = $handle; - // the priority should see less than on function - // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php - add_action( 'admin_enqueue_scripts', array( &$this, 'register_metadata_type_compoment' ), 80 ); $this->registered_metadata_type[$handle] = [ 'handle' => $handle, diff --git a/src/views/class-tainacan-component-hooks.php b/src/views/class-tainacan-component-hooks.php index 6c38a6a57..125a08136 100644 --- a/src/views/class-tainacan-component-hooks.php +++ b/src/views/class-tainacan-component-hooks.php @@ -29,11 +29,16 @@ class Component_Hooks { } private function init() { + // the priority should see less than on function + // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php + add_action( 'admin_enqueue_scripts', array( &$this, 'register_component' ), 80 ); do_action('tainacan-register-vuejs-component', $this); } public function register_component() { - wp_enqueue_script($this->handle, $this->script_path); + foreach($this->registered_component as $handle => $component) { + wp_enqueue_script($handle, $component['script_path']); + } } /** @@ -46,21 +51,14 @@ class Component_Hooks { public function register_vuejs_component($handle, $script_path, $args = []) { global $TAINACAN_EXTRA_SCRIPTS; - $this->handle = $handle; - $this->script_path = $script_path; if ( ! in_array( $handle, $this->registered_component ) ) { $TAINACAN_EXTRA_SCRIPTS[] = $handle; - // the priority should see less than on function - // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php - add_action( 'admin_enqueue_scripts', array( &$this, 'register_component' ), 80 ); - $this->registered_component[$handle] = [ 'handle' => $handle, 'script_path' => $script_path, 'args' => $args ]; } - } /**