Skip to content

Commit

Permalink
Merge pull request #4 from Eleven-Miles/release/v1.3.0
Browse files Browse the repository at this point in the history
Move editor assets to admin only enqueue & add fallback for full theme file path
  • Loading branch information
harryfinn committed Mar 11, 2024
2 parents f941205 + 58e4894 commit 4064d41
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea
vendor/*
bin/*
composer.lock
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "eleven-miles/zeus",
"description": "Zeus Bundle",
"require": {
"php": ">=7.2"
"php": ">=8.2"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3",
Expand Down
208 changes: 208 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src/Wordpress/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($moduleConfig)
add_action('wp_enqueue_scripts', [$this, 'preload'], 20);
}

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

/**
Expand All @@ -58,13 +58,18 @@ public function preload()
return;
}

$theme_public_path = get_template_directory_uri() . "/public/dist/";

foreach ($this->manifestFiles as $name => $file) {
// Skip editor styles from preload
if (strpos($name, 'editor') !== false || strpos($name, '.map')) {
continue;
}

$filename = $file;
// Check to see if file contains $theme_public_path, if not add it
$filename = (strpos($file, $theme_public_path) !== false) ?
$file :
$theme_public_path . $file;

if (strpos($name, 'app.js') !== false) {
wp_enqueue_script($name, $filename, [], null, true);
Expand Down

0 comments on commit 4064d41

Please sign in to comment.