Skip to content

Commit

Permalink
Removed changes by #77. Code format
Browse files Browse the repository at this point in the history
  • Loading branch information
netlas committed Jun 13, 2024
1 parent d4557f8 commit fd817cf
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions vite-for-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,14 @@ function filter_script_tag( string $handle ): void {
*
* @return string Script tag with attribute `type="module"` added.
*/
function set_script_type_attribute( string $target_handle, string $tag, string $handle, string $src ): string {
function set_script_type_attribute( string $target_handle, string $tag, string $handle ): string {
if ( $target_handle !== $handle ) {
return $tag;
}

$processor = new WP_HTML_Tag_Processor( $tag );

$script_fount = false;

do {
$script_fount = $processor->next_tag( 'script' );
} while ($processor->get_attribute( 'src' ) !== $src );

if ( $script_fount ) {
if ( $processor->next_tag( 'script' ) ) {
$processor->set_attribute( 'type', 'module' );
}

Expand Down Expand Up @@ -297,7 +291,7 @@ function load_production_asset( object $manifest, string $entry, array $options

if ( ! empty( $item->imports ) ) {
// Recursive inline function to deeply check for .css files.
$check_imports = function( array $imports ) use ( &$check_imports, &$assets, $manifest, $url, $options ) : void {
$check_imports = function ( array $imports ) use ( &$check_imports, &$assets, $manifest, $url, $options ): void {

foreach ( $imports as $import ) {
$import_item = $manifest->data->{$import};
Expand All @@ -307,15 +301,15 @@ function load_production_asset( object $manifest, string $entry, array $options
}

if ( ! empty( $import_item->css ) ) {
register_stylesheets($assets, $import_item->css, $url, $options);
register_stylesheets( $assets, $import_item->css, $url, $options );
}
}
};
$check_imports( $item->imports );
}

if ( ! empty( $item->css ) ) {
register_stylesheets($assets, $item->css, $url, $options);
register_stylesheets( $assets, $item->css, $url, $options );
}

/**
Expand All @@ -332,17 +326,17 @@ function load_production_asset( object $manifest, string $entry, array $options
}

/**
* Register stylesheet assets to wordpress and saves stylesheet handles for later enqueuing
* Register stylesheet assets to WordPress and saves stylesheet handles for later enqueuing
*
* @param array &$assets Reference to registered assets.
* @param array $styelsheets List of stylesheets to register.
* @param string $url Base URL to asset.
* @param array $options Array of options.
* @param array $assets Reference to registered assets.
* @param array $stylesheets List of stylesheets to register.
* @param string $url Base URL to asset.
* @param array $options Array of options.
*/
function register_stylesheets(array &$assets, array $stylesheets, string $url, array $options): void {
function register_stylesheets( array &$assets, array $stylesheets, string $url, array $options ): void {
foreach ( $stylesheets as $css_file_path ) {

$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', pathinfo($css_file_path, PATHINFO_FILENAME)), '-'));
$slug = strtolower( trim( preg_replace( '/[^A-Za-z0-9-]+/', '-', pathinfo( $css_file_path, PATHINFO_FILENAME ) ), '-' ) );
// Including a slug based on the actual css file in the handle ensures it wont be registered more than once.
$style_handle = "{$options['handle']}-{$slug}";

Expand Down Expand Up @@ -470,4 +464,3 @@ function enqueue_asset( string $manifest_dir, string $entry, array $options ): b

return true;
}

0 comments on commit fd817cf

Please sign in to comment.