From 7c2a1458a7492c2e71360e6d374bc37befb4f014 Mon Sep 17 00:00:00 2001 From: Lauren V Caple Date: Thu, 14 Oct 2021 13:59:16 -0700 Subject: [PATCH] fix: standardizing js enqueue + bug with enqueing mega menu on single sites --- inc/2014/class.uw.php | 5 ++++- inc/customizer.php | 9 ++++----- inc/nav/megamenu.php | 9 ++++----- inc/shortcodes/class.accordion-shortcode.php | 9 ++++----- inc/shortcodes/class.button-shortcode.php | 9 ++++----- inc/shortcodes/class.modal-shortcode.php | 9 ++++----- inc/shortcodes/class.tabs-tours-shortcode.php | 9 ++++----- inc/shortcodes/shortcodes.php | 9 ++++----- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/inc/2014/class.uw.php b/inc/2014/class.uw.php index f8a9271..352e3a4 100755 --- a/inc/2014/class.uw.php +++ b/inc/2014/class.uw.php @@ -46,7 +46,10 @@ function uw_wp_theme_2014() { * Enqueue and defer 2014 script. */ function uw_wp_theme_enqueue_2014_carryover() { - wp_enqueue_script( 'uw_wp_theme-2014-script', get_template_directory_uri() . '/js/2014.min.js', array( 'underscore', 'backbone' ), '20190708', true ); + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_enqueue_script( 'uw_wp_theme-2014-script', $template_directory . '/js/2014.min.js', array( 'underscore', 'backbone' ), $theme_version, true ); $site_parameters = array( 'style_dir' => site_url(), diff --git a/inc/customizer.php b/inc/customizer.php index 82eb126..e26f71e 100755 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -64,10 +64,9 @@ function uw_wp_theme_customize_partial_blogdescription() { * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function uw_wp_theme_customize_preview_js() { - if ( is_multisite() ) { - wp_enqueue_script( 'uw_wp_theme-customizer', network_site_url( '/wp-content/themes/uw_wp_theme/js/customizer.js' ), array( 'customize-preview' ), '20151215', true ); - } else { - wp_enqueue_script( 'uw_wp_theme-customizer', get_theme_file_uri( '/js/customizer.js' ), array( 'customize-preview' ), '20151215', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_enqueue_script( 'uw_wp_theme-customizer', $template_directory. '/js/customizer.js', array( 'customize-preview' ), $theme_version, true ); } add_action( 'customize_preview_init', 'uw_wp_theme_customize_preview_js' ); diff --git a/inc/nav/megamenu.php b/inc/nav/megamenu.php index 5a0b23e..3e009f2 100644 --- a/inc/nav/megamenu.php +++ b/inc/nav/megamenu.php @@ -31,10 +31,9 @@ public function register_mega_menu() { * @return void */ public function uw_wp_theme_enqueue_megamenu_script() { - if ( is_multisite() ) { - wp_register_script( 'uw_wp_theme-megamenu-script', network_site_url( '/wp-content/themes/uw_wp_theme/js/megamenu.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210713', true ); - } else { - wp_register_script( 'uw_wp_theme-megamenu-script', get_theme_file_uri( '/js/js/megamenu.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210713', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_register_script( 'uw_wp_theme-megamenu-script', $template_directory . '/js/megamenu.js', array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210713', true ); } } diff --git a/inc/shortcodes/class.accordion-shortcode.php b/inc/shortcodes/class.accordion-shortcode.php index 1870714..0046e72 100644 --- a/inc/shortcodes/class.accordion-shortcode.php +++ b/inc/shortcodes/class.accordion-shortcode.php @@ -35,11 +35,10 @@ public function __construct() { * @return void */ public function uw_wp_theme_enqueue_accordion_script() { - if ( is_multisite() ) { - wp_register_script( 'uw_wp_theme-accordion-script', network_site_url( '/wp-content/themes/uw_wp_theme/js/shortcodes/accordion.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210303', true ); - } else { - wp_register_script( 'uw_wp_theme-accordion-script', get_theme_file_uri( '/js/shortcodes/accordion.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210303', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_register_script( 'uw_wp_theme-accordion-script', $template_directory . '/js/shortcodes/accordion.js', array( 'jquery', 'uw_wp_theme-bootstrap' ), $theme_version, true ); } /** diff --git a/inc/shortcodes/class.button-shortcode.php b/inc/shortcodes/class.button-shortcode.php index c165163..fdc0856 100644 --- a/inc/shortcodes/class.button-shortcode.php +++ b/inc/shortcodes/class.button-shortcode.php @@ -22,11 +22,10 @@ function __construct() * @return void */ public function uw_wp_theme_enqueue_button_script() { - if ( is_multisite() ) { - wp_register_script( 'uw_wp_theme-button-script', network_site_url( '/wp-content/themes/uw_wp_theme/js/shortcodes/button.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210921', true ); - } else { - wp_register_script( 'uw_wp_theme-button-script', get_theme_file_uri( '/js/shortcodes/button.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210921', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_register_script( 'uw_wp_theme-button-script', $template_directory . '/js/shortcodes/button.js', array( 'jquery', 'uw_wp_theme-bootstrap' ), $theme_version, true ); } function button_handler( $atts, $content = null ) { diff --git a/inc/shortcodes/class.modal-shortcode.php b/inc/shortcodes/class.modal-shortcode.php index 4d35693..44b7d60 100644 --- a/inc/shortcodes/class.modal-shortcode.php +++ b/inc/shortcodes/class.modal-shortcode.php @@ -23,11 +23,10 @@ public function __construct() { * @return void */ public function uw_wp_theme_enqueue_modal_script() { - if ( is_multisite() ) { - wp_register_script( 'uw_wp_theme-modal-script', network_site_url( '/wp-content/themes/uw_wp_theme/js/shortcodes/modal.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210514', true ); - } else { - wp_register_script( 'uw_wp_theme-modal-script', get_theme_file_uri( '/js/shortcodes/modal.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210514', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_register_script( 'uw_wp_theme-modal-script', $template_directory . '/js/shortcodes/modal.js', array( 'jquery', 'uw_wp_theme-bootstrap' ), $theme_version, true ); } /** diff --git a/inc/shortcodes/class.tabs-tours-shortcode.php b/inc/shortcodes/class.tabs-tours-shortcode.php index 9bd16b2..68a5f43 100644 --- a/inc/shortcodes/class.tabs-tours-shortcode.php +++ b/inc/shortcodes/class.tabs-tours-shortcode.php @@ -31,11 +31,10 @@ public function __construct() { * @return void */ public function uw_wp_theme_register_tabs_script() { - if ( is_multisite() ) { - wp_register_script( 'uw_wp_theme-tabs-script', network_site_url( '/wp-content/themes/uw_wp_theme/js/shortcodes/tabs-tours.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210315', true ); - } else { - wp_register_script( 'uw_wp_theme-tabs-script', get_theme_file_uri( '/js/shortcodes/tabs-tours.js' ), array( 'jquery', 'uw_wp_theme-bootstrap' ), '20210315', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_register_script( 'uw_wp_theme-tabs-script', $template_directory . '/js/shortcodes/tabs-tours.js', array( 'jquery', 'uw_wp_theme-bootstrap' ), $theme_version, true ); } /** diff --git a/inc/shortcodes/shortcodes.php b/inc/shortcodes/shortcodes.php index 5f761c1..66e6459 100755 --- a/inc/shortcodes/shortcodes.php +++ b/inc/shortcodes/shortcodes.php @@ -65,9 +65,8 @@ function uw_wp_theme_shortcodes() { * Enqueue and defer shortcode scripts. */ function uw_wp_theme_enqueue_shortcodes() { - if ( is_multisite() ) { - wp_enqueue_script( 'uw_wp_theme-custom-link-script', network_site_url( '/wp-content/themes/uw_wp_theme/js/shortcodes/custom-link.js' ), array( 'jquery', 'uw_wp_theme-popper' ), '20200116', true ); - } else { - wp_enqueue_script( 'uw_wp_theme-custom-link-script', get_theme_file_uri( '/js/shortcodes/custom-link.js' ), array( 'jquery', 'uw_wp_theme-popper' ), '20200116', true ); - } + $template_directory = get_bloginfo( 'template_directory' ); + $theme_version = wp_get_theme( get_template( ) )->get( 'Version' ); + + wp_enqueue_script( 'uw_wp_theme-custom-link-script', $template_directory. '/js/shortcodes/custom-link.js', array( 'jquery', 'uw_wp_theme-popper' ), $theme_version, true ); }