diff --git a/minit.php b/minit.php index 1f1266d..c8f8ccd 100644 --- a/minit.php +++ b/minit.php @@ -4,7 +4,7 @@ Plugin URI: https://github.com/kasparsd/minit GitHub URI: https://github.com/kasparsd/minit Description: Combine JS and CSS files and serve them from the uploads folder. -Version: 1.5.0 +Version: 1.6.0 Author: Kaspars Dambis Author URI: https://kaspars.net */ diff --git a/src/minit-assets.php b/src/minit-assets.php index 35525eb..f0f4991 100644 --- a/src/minit-assets.php +++ b/src/minit-assets.php @@ -108,32 +108,19 @@ function minit() { continue; } - // Ignore pseudo packages such as jquery which return src as empty string. - if ( empty( $this->handler->registered[ $handle ]->src ) ) { - $done[ $handle ] = null; - - continue; - } - // Get the relative URL of the asset. $src = $this->get_asset_relative_path( $handle ); - // Skip if the file is not hosted locally. - if ( empty( $src ) || ! file_exists( ABSPATH . $src ) ) { - continue; - } - - $item = $this->minit_item( file_get_contents( ABSPATH . $src ), $handle, $src ); - - $item = apply_filters( - 'minit-item-' . $this->extension, - $item, - $this->handler, - $handle - ); - - if ( false !== $item ) { - $done[ $handle ] = $item; + // Ignore pseudo packages such as jquery which return src as empty string. + if ( ! empty( $src ) && is_readable( ABSPATH . $src ) ) { + $item = $this->minit_item( file_get_contents( ABSPATH . $src ), $handle, $src ); + + $done[ $handle ] = apply_filters( + 'minit-item-' . $this->extension, + $item, + $this->handler, + $handle + ); } } @@ -243,27 +230,30 @@ protected function get_asset_relative_path( $handle ) { return false; } - $item_url = $this->handler->registered[ $handle ]->src; + if ( ! empty( $this->handler->registered[ $handle ]->src ) ) { + $item_url = $this->handler->registered[ $handle ]->src; - if ( empty( $item_url ) ) { - return false; - } + // Inline block scripts are sometimes relative URLs. + if ( 0 === strpos( $item_url, '/' ) ) { + return $item_url; + } - // Remove protocol reference from the local base URL - $base_url = preg_replace( '/^(https?:)/i', '', $this->handler->base_url ); + // Remove protocol reference from the local base URL + $base_url = preg_replace( '/^(https?:)/i', '', $this->handler->base_url ); - // Check if this is a local asset which we can include - $src_parts = explode( $base_url, $item_url ); + // Check if this is a local asset which we can include + $src_parts = explode( $base_url, $item_url ); - if ( empty( $src_parts ) ) { - return false; - } - - // Get the trailing part of the local URL - $maybe_relative = array_pop( $src_parts ); + // Get the trailing part of the local URL + if ( ! empty( $src_parts ) ) { + return array_pop( $src_parts ); + } + } elseif ( ! empty( $this->handler->registered[ $handle ]->extra[ 'path' ] ) ) { + $item_path = $this->handler->registered[ $handle ]->extra[ 'path' ]; - if ( file_exists( ABSPATH . $maybe_relative ) ) { - return $maybe_relative; + if ( 0 === strpos( $item_path, ABSPATH ) ) { + return str_replace( ABSPATH, '', $item_path ); + } } return false; diff --git a/src/minit-js.php b/src/minit-js.php index 43ba114..e7e5861 100644 --- a/src/minit-js.php +++ b/src/minit-js.php @@ -31,9 +31,6 @@ public function init() { // Print our JS file add_filter( 'print_scripts_array', array( $this, 'process' ), 20 ); - // Print external scripts asynchronously in the footer - add_action( 'wp_print_footer_scripts', array( $this, 'print_async_scripts' ), 20 ); - // Load our JS files asynchronously add_filter( 'script_loader_tag', array( $this, 'script_tag_async' ), 20, 3 ); } @@ -126,66 +123,6 @@ protected function get_script_data( $handles, $keys ) { return $extra; } - - public function print_async_scripts() { - $async_queue = array(); - - $minit_exclude = (array) apply_filters( - 'minit-exclude-js', - array() - ); - - foreach ( $this->handler->queue as $handle ) { - // Skip asyncing explicitly excluded script handles - if ( in_array( $handle, $minit_exclude, true ) ) { - continue; - } - - $script_relative_path = $this->get_asset_relative_path( $handle ); - - if ( ! $script_relative_path ) { - // Add this script to our async queue - $async_queue[] = $handle; - } - } - - if ( empty( $async_queue ) ) { - return; - } - - $scripts = array(); - - foreach ( $async_queue as $handle ) { - $scripts[] = array( - 'id' => 'async-script-' . sanitize_key( $handle ), - 'src' => $this->handler->registered[ $handle ]->src, - ); - } - - ?> - - -