Skip to content

Commit

Permalink
Merge pull request #5 from Eleven-Miles/feature/block-previews
Browse files Browse the repository at this point in the history
Added style and script enqueues for block previews
  • Loading branch information
harryfinn authored Jul 10, 2024
2 parents 4064d41 + d3f7ee1 commit 8075860
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Wordpress/ACF.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function __construct($moduleConfig)
}

add_action('acf/init', [$this, 'registerGoogleMapsKey']);

add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockStyles'] );
}

/**
Expand Down Expand Up @@ -121,4 +123,52 @@ public function allowedBlocks($allowed_block_types)

return $allowed;
}

/**
* Enqueue app and editor styles in admin area
*/
public function enqueueBlockStyles() {

$manifest_path = get_template_directory() . '/public/dist/manifest.json';

if (file_exists($manifest_path)) {
$manifest_files = json_decode(file_get_contents($manifest_path), true);

foreach ($manifest_files as $name => $file) {
// Skip editor styles from preload

if ( ($name === 'editor.css' ) || ($name === 'app.css' ) ) {

$filename = "/public/dist/$file";

wp_enqueue_style(
'block-' . $name ,
get_theme_file_uri( $filename ),
array(),
filemtime( get_theme_file_path( $filename ) ),
'all'
);

}

if ( ($name == 'editor.js') ) {

$filename = "/public/dist/$file";

wp_enqueue_script(
'block-' . $name ,
get_theme_file_uri( $filename ),
array(),
filemtime( get_theme_file_path( $filename ) ),
'all'
);

}

}

}

}

}

0 comments on commit 8075860

Please sign in to comment.