use only one location to add `action`#349

This commit is contained in:
vnmedeiros 2020-02-07 16:36:09 -03:00
parent 9ce2b7c4e3
commit 71e0d4c841
3 changed files with 19 additions and 22 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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
];
}
}
/**