From 52f7203992e1c8662d421e7287e1e1e5f1c2b7cd Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 10 Mar 2021 16:03:23 +0100 Subject: Initial commit --- src/UsesWordPressScripts.php | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/UsesWordPressScripts.php (limited to 'src') diff --git a/src/UsesWordPressScripts.php b/src/UsesWordPressScripts.php new file mode 100644 index 0000000..e93a01e --- /dev/null +++ b/src/UsesWordPressScripts.php @@ -0,0 +1,71 @@ +assetsMeta($assetBaseName); + + wp_enqueue_script( + $handle, + $this->assetsUrl($asset), + array_replace($meta['dependencies'] ?? [], $deps), + $meta['version'] ?? false, + $inFooter + ); + } + + /** + * @param string $handle + * @param string $asset + * @param array $deps + * @param string $media + */ + public function enqueueStyle($handle, $asset, $deps = [], $media = 'all') + { + $assetBaseName = pathinfo($asset, PATHINFO_FILENAME); + $meta = $this->assetsMeta($assetBaseName); + + wp_enqueue_style( + $handle, + $this->assetsUrl($asset), + $deps, + $meta['version'] ?? false, + $media + ); + } + + /** + * @param string $asset + * + * @return string + */ + public function assetsUrl($asset) + { + return get_stylesheet_directory_uri() . "/{$this->buildDir}/$asset"; + } + + /** + * @param string $asset + * + * @return mixed + */ + public function assetsMeta($asset) + { + return include get_stylesheet_directory() . "/{$this->buildDir}/$asset.asset.php"; + } +} -- cgit v1.2.3