Skip to content

Commit

Permalink
Defer script loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Nov 20, 2024
1 parent 771f067 commit 2fb7848
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ a.button.wc-stc-shipment-action-button {

.wc-shiptastic-settings {
.nav-tab-wrapper {
a.nav-tab[href*="tab=shipments"] {
a.nav-tab[href*="tab=shiptastic"] {
border-bottom: 1px solid #f1f1f1;
background: #f1f1f1;
color: #000;
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Tabs/Packaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function get_pointers() {
),
);

if ( strstr( $last_url, 'tab=shipments' ) ) {
if ( strstr( $last_url, 'tab=shiptastic' ) ) {
$pointers['pointers']['auto']['last_step'] = true;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,24 @@ public static function load_blocks() {
return version_compare( $woo_version, '8.2.0', '>=' );
}

public static function register_script( $handle, $path, $dep = array(), $ver = '', $in_footer = array( 'strategy' => 'defer' ) ) {
global $wp_version;

if ( version_compare( $wp_version, '6.3', '<' ) ) {
$in_footer = true;
}

$ver = empty( $ver ) ? self::get_version() : $ver;

wp_register_script(
$handle,
self::get_assets_url( $path ),
$dep,
$ver,
$in_footer
);
}

public static function get_assets_url( $script_or_style ) {
$assets_url = self::get_url() . '/build';
$is_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
Expand Down
4 changes: 2 additions & 2 deletions src/PickupDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ public static function register_assets() {
return;
}

wp_register_script( 'wc-shiptastic-modal', Package::get_assets_url( 'static/modal.js' ), array( 'jquery' ), Package::get_version() ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
wp_register_script( 'wc-shiptastic-pickup-locations', Package::get_assets_url( 'static/pickup-locations.js' ), array( 'jquery', 'woocommerce', 'selectWoo', 'wc-shiptastic-modal' ), Package::get_version() ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
Package::register_script( 'wc-shiptastic-modal', 'static/modal.js', array( 'jquery' ) );
Package::register_script( 'wc-shiptastic-pickup-locations', 'static/pickup-locations.js', array( 'jquery', 'woocommerce', 'selectWoo', 'wc-shiptastic-modal' ) );

// Register admin styles.
wp_register_style( 'woocommerce_shiptastic_pickup_locations', Package::get_assets_url( 'static/pickup-locations-styles.css' ), array(), Package::get_version() );
Expand Down
6 changes: 3 additions & 3 deletions src/ShippingProvider/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public function hide_return_address() {
}

public function get_edit_link( $section = '' ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=shipments-shipping_provider&provider=' . esc_attr( $this->get_name() ) );
$url = add_query_arg( array( 'section' => $section ), $url );
$base_url = Settings::get_settings_url( 'shipping_provider', $section );
$base_url = add_query_arg( array( 'provider' => $this->get_name() ), $base_url );

return esc_url_raw( $url );
return esc_url_raw( $base_url );
}

/**
Expand Down

0 comments on commit 2fb7848

Please sign in to comment.