diff --git a/mu-plugins/10up-plugin/src/Assets.php b/mu-plugins/10up-plugin/src/Assets.php index a3c8359..b9fa824 100644 --- a/mu-plugins/10up-plugin/src/Assets.php +++ b/mu-plugins/10up-plugin/src/Assets.php @@ -7,9 +7,9 @@ namespace TenUpPlugin; +use TenupFramework\Assets\GetAssetInfo; use TenupFramework\Module; use TenupFramework\ModuleInterface; -use TenUpPlugin\Traits\GetAssetInfo; /** * Assets module. @@ -36,6 +36,11 @@ public function can_register() { * @return void */ public function register() { + $this->setup_asset_vars( + dist_path: TENUP_PLUGIN_PATH . 'dist/', + fallback_version: TENUP_PLUGIN_VERSION + ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'admin_styles' ] ); } diff --git a/mu-plugins/10up-plugin/src/Traits/GetAssetInfo.php b/mu-plugins/10up-plugin/src/Traits/GetAssetInfo.php deleted file mode 100644 index 6993d71..0000000 --- a/mu-plugins/10up-plugin/src/Traits/GetAssetInfo.php +++ /dev/null @@ -1,45 +0,0 @@ -} : $attribute is 'dependencies' ? array : string) - */ - public function get_asset_info( $slug, $attribute = null ) { - if ( file_exists( TENUP_PLUGIN_PATH . 'dist/js/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_PLUGIN_PATH . 'dist/js/' . $slug . '.asset.php'; - } elseif ( file_exists( TENUP_PLUGIN_PATH . 'dist/css/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_PLUGIN_PATH . 'dist/css/' . $slug . '.asset.php'; - } else { - $asset = [ - 'version' => TENUP_PLUGIN_VERSION, - 'dependencies' => [], - ]; - } - - // @var }> $asset - - if ( ! empty( $attribute ) && isset( $asset[ $attribute ] ) ) { - return $asset[ $attribute ]; - } - - return $asset; - } -} diff --git a/themes/10up-block-theme/src/Assets.php b/themes/10up-block-theme/src/Assets.php index a8d0ced..f024b00 100644 --- a/themes/10up-block-theme/src/Assets.php +++ b/themes/10up-block-theme/src/Assets.php @@ -7,9 +7,9 @@ namespace TenupBlockTheme; +use TenupFramework\Assets\GetAssetInfo; use TenupFramework\Module; use TenupFramework\ModuleInterface; -use TenupBlockTheme\Traits\GetAssetInfo; /** * Assets module. @@ -36,6 +36,10 @@ public function can_register() { * @return void */ public function register() { + $this->setup_asset_vars( + dist_path: TENUP_BLOCK_THEME_DIST_PATH, + fallback_version: TENUP_BLOCK_THEME_VERSION + ); add_action( 'init', [ $this, 'scripts' ] ); add_action( 'init', [ $this, 'register_all_icons' ], 10 ); add_action( 'wp_enqueue_scripts', [ $this, 'styles' ] ); diff --git a/themes/10up-block-theme/src/Blocks.php b/themes/10up-block-theme/src/Blocks.php index dc7b38c..8537a10 100644 --- a/themes/10up-block-theme/src/Blocks.php +++ b/themes/10up-block-theme/src/Blocks.php @@ -7,9 +7,9 @@ namespace TenupBlockTheme; +use TenupFramework\Assets\GetAssetInfo; use TenupFramework\Module; use TenupFramework\ModuleInterface; -use TenupBlockTheme\Traits\GetAssetInfo; /** * Blocks module. @@ -36,6 +36,10 @@ public function can_register() { * @return void */ public function register() { + $this->setup_asset_vars( + dist_path: TENUP_BLOCK_THEME_DIST_PATH, + fallback_version: TENUP_BLOCK_THEME_VERSION + ); add_action( 'init', [ $this, 'register_theme_blocks' ], 10, 0 ); add_action( 'init', [ $this, 'enqueue_theme_block_styles' ], 10, 0 ); } diff --git a/themes/10up-block-theme/src/Traits/GetAssetInfo.php b/themes/10up-block-theme/src/Traits/GetAssetInfo.php deleted file mode 100644 index 5126a0f..0000000 --- a/themes/10up-block-theme/src/Traits/GetAssetInfo.php +++ /dev/null @@ -1,45 +0,0 @@ -} : $attribute is 'dependencies' ? array : string) - */ - protected function get_asset_info( $slug, $attribute = null ) { - if ( file_exists( TENUP_BLOCK_THEME_PATH . 'dist/js/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_BLOCK_THEME_PATH . 'dist/js/' . $slug . '.asset.php'; - } elseif ( file_exists( TENUP_BLOCK_THEME_PATH . 'dist/css/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_BLOCK_THEME_PATH . 'dist/css/' . $slug . '.asset.php'; - } elseif ( file_exists( TENUP_BLOCK_THEME_PATH . 'dist/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_BLOCK_THEME_PATH . 'dist/' . $slug . '.asset.php'; - } else { - $asset = [ - 'version' => TENUP_BLOCK_THEME_VERSION, - 'dependencies' => [], - ]; - } - - if ( ! empty( $attribute ) && isset( $asset[ $attribute ] ) ) { - return $asset[ $attribute ]; - } - - return $asset; - } -} diff --git a/themes/10up-theme/src/Assets.php b/themes/10up-theme/src/Assets.php index debaad9..576b962 100644 --- a/themes/10up-theme/src/Assets.php +++ b/themes/10up-theme/src/Assets.php @@ -7,9 +7,9 @@ namespace TenUpTheme; +use TenupFramework\Assets\GetAssetInfo; use TenupFramework\Module; use TenupFramework\ModuleInterface; -use TenUpTheme\Traits\GetAssetInfo; /** * Assets module. @@ -36,6 +36,10 @@ public function can_register() { * @return void */ public function register() { + $this->setup_asset_vars( + dist_path: TENUP_THEME_DIST_PATH, + fallback_version: TENUP_THEME_VERSION + ); add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] ); add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_scripts' ] ); add_action( 'wp_enqueue_scripts', [ $this, 'styles' ] ); diff --git a/themes/10up-theme/src/Blocks.php b/themes/10up-theme/src/Blocks.php index 89423a9..85a9589 100644 --- a/themes/10up-theme/src/Blocks.php +++ b/themes/10up-theme/src/Blocks.php @@ -7,9 +7,9 @@ namespace TenUpTheme; +use TenupFramework\Assets\GetAssetInfo; use TenupFramework\Module; use TenupFramework\ModuleInterface; -use TenUpTheme\Traits\GetAssetInfo; /** * Blocks module. @@ -36,6 +36,10 @@ public function can_register() { * @return void */ public function register() { + $this->setup_asset_vars( + dist_path: TENUP_THEME_DIST_PATH, + fallback_version: TENUP_THEME_VERSION + ); add_action( 'enqueue_block_editor_assets', [ $this, 'blocks_editor_styles' ] ); add_action( 'init', [ $this, 'enqueue_block_specific_styles' ] ); add_action( 'init', [ $this, 'register_theme_blocks' ] ); diff --git a/themes/10up-theme/src/Traits/GetAssetInfo.php b/themes/10up-theme/src/Traits/GetAssetInfo.php deleted file mode 100644 index d41d8ab..0000000 --- a/themes/10up-theme/src/Traits/GetAssetInfo.php +++ /dev/null @@ -1,43 +0,0 @@ -} : $attribute is 'dependencies' ? array : string) - */ - protected function get_asset_info( $slug, $attribute = null ) { - if ( file_exists( TENUP_THEME_PATH . 'dist/js/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_THEME_PATH . 'dist/js/' . $slug . '.asset.php'; - } elseif ( file_exists( TENUP_THEME_PATH . 'dist/css/' . $slug . '.asset.php' ) ) { - $asset = require TENUP_THEME_PATH . 'dist/css/' . $slug . '.asset.php'; - } else { - $asset = [ - 'version' => TENUP_THEME_VERSION, - 'dependencies' => [], - ]; - } - - if ( ! empty( $attribute ) && isset( $asset[ $attribute ] ) ) { - return $asset[ $attribute ]; - } - - return $asset; - } -}