Skip to content

Commit

Permalink
fix: standardizing js enqueue + bug with enqueing mega menu on single…
Browse files Browse the repository at this point in the history
… sites
  • Loading branch information
lcaple committed Oct 14, 2021
1 parent 4489275 commit 7c2a145
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 36 deletions.
5 changes: 4 additions & 1 deletion inc/2014/class.uw.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 4 additions & 5 deletions inc/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
9 changes: 4 additions & 5 deletions inc/nav/megamenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
9 changes: 4 additions & 5 deletions inc/shortcodes/class.accordion-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
9 changes: 4 additions & 5 deletions inc/shortcodes/class.button-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
9 changes: 4 additions & 5 deletions inc/shortcodes/class.modal-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
9 changes: 4 additions & 5 deletions inc/shortcodes/class.tabs-tours-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
9 changes: 4 additions & 5 deletions inc/shortcodes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

0 comments on commit 7c2a145

Please sign in to comment.