From 509cb6170a3d078541bcd5031f173fb4210fdb50 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 15 Jan 2021 12:06:31 -0300 Subject: [PATCH] Alters priority of some scripts enqueueing #473 --- .../theme-helper/class-tainacan-theme-helper.php | 10 ++++------ src/views/class-tainacan-admin.php | 2 +- src/views/class-tainacan-component-hooks.php | 1 + .../class-tainacan-gutenberg-block.php | 11 +++++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/classes/theme-helper/class-tainacan-theme-helper.php b/src/classes/theme-helper/class-tainacan-theme-helper.php index 509978537..c018a5e99 100644 --- a/src/classes/theme-helper/class-tainacan-theme-helper.php +++ b/src/classes/theme-helper/class-tainacan-theme-helper.php @@ -35,7 +35,7 @@ class Theme_Helper { // Redirect to post type archive if no cover page is set add_action('wp', array($this, 'collection_single_redirect')); - add_action('wp_print_scripts', array($this, 'enqueue_scripts')); + add_action('wp_print_scripts', array($this, 'enqueue_scripts'), 90); // make archive for terms work with items add_action('pre_get_posts', array($this, 'tax_archive_pre_get_posts')); @@ -62,11 +62,7 @@ class Theme_Helper { $this->register_view_mode('table', [ 'label' => __('Table', 'tainacan'), - 'dynamic_metadata' => true, - 'icon' => '', - 'type' => 'component', - 'implements_skeleton' => true, - 'requires_thumbnail' => false + 'dynamic_metadata' => true ]); $this->register_view_mode('cards', [ 'label' => __('Cards', 'tainacan'), @@ -120,6 +116,8 @@ class Theme_Helper { wp_register_script('tainacan-search', $TAINACAN_BASE_URL . '/assets/js/theme_search.js' , ['underscore'] , TAINACAN_VERSION); wp_localize_script('tainacan-search', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params()); } + + error_log('enqueue_scripts'); } public function is_post_an_item(\WP_Post $post) { diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php index 67f388259..e8467eb7c 100644 --- a/src/views/class-tainacan-admin.php +++ b/src/views/class-tainacan-admin.php @@ -254,7 +254,7 @@ class Admin { 'wp_elasticpress' => \Tainacan\Elastic_Press::get_instance()->is_active(), 'item_submission_captcha_site_key' => get_option("tnc_option_recaptch_site_key") ]; - + $maps = [ 'collections' => $Tainacan_Collections->get_map(), 'metadata' => $Tainacan_Metadata->get_map(), diff --git a/src/views/class-tainacan-component-hooks.php b/src/views/class-tainacan-component-hooks.php index e6a9bd567..3e099bcf2 100644 --- a/src/views/class-tainacan-component-hooks.php +++ b/src/views/class-tainacan-component-hooks.php @@ -32,6 +32,7 @@ class Component_Hooks { // the priority should see less than on function // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php add_action( 'wp_enqueue_scripts', array( &$this, 'register_component' ), 80 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'register_component' ), 80 ); } public function register_component() { diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index e23c49263..81c6ea74b 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -28,7 +28,8 @@ function tainacan_blocks_add_gutenberg_blocks_actions() { add_action('init', 'tainacan_blocks_register_tainacan_facets_list'); add_action('init', 'tainacan_blocks_register_tainacan_item_submission_form'); - add_action('init', 'tainacan_blocks_add_plugin_settings'); + add_action('init', 'tainacan_blocks_add_plugin_settings', 90); + add_action('wp_enqueue_scripts', 'tainacan_blocks_add_plugin_admin_settings', 90); add_filter('block_categories', 'tainacan_blocks_register_categories', 10, 2); add_action('init', 'tainacan_blocks_register_category_icon'); @@ -403,14 +404,13 @@ function tainacan_blocks_get_plugin_js_settings(){ 'base_url' => $TAINACAN_BASE_URL, 'admin_url' => admin_url(), 'site_url' => site_url(), - 'theme_items_list_url' => esc_url_raw( get_site_url() ) . '/' . \Tainacan\Theme_Helper::get_instance()->get_items_list_slug(), + 'theme_items_list_url' => esc_url_raw( get_site_url() ) . '/' . \Tainacan\Theme_Helper::get_instance()->get_items_list_slug() ]; - + return $settings; } function tainacan_blocks_add_plugin_settings() { - $settings = tainacan_blocks_get_plugin_js_settings(); wp_localize_script( 'terms-list', 'tainacan_blocks', $settings ); @@ -423,6 +423,9 @@ function tainacan_blocks_add_plugin_settings() { wp_localize_script( 'collections-list', 'tainacan_blocks', $settings ); wp_localize_script( 'carousel-collections-list', 'tainacan_blocks', $settings ); wp_localize_script( 'facets-list', 'tainacan_blocks', $settings ); +} + +function tainacan_blocks_add_plugin_admin_settings() { // The faceded search block uses a different settings object, the same used on the theme items list wp_localize_script( 'tainacan-search', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params() );