diff --git a/inc/Framework.php b/inc/Framework.php index 8c0a6661..c435cd17 100644 --- a/inc/Framework.php +++ b/inc/Framework.php @@ -5,12 +5,10 @@ use BEA\Theme\Framework\Services\Acf; use BEA\Theme\Framework\Services\Assets; use BEA\Theme\Framework\Services\Performance; -use BEA\Theme\Framework\Services\Assets_JS_Async; use BEA\Theme\Framework\Services\Editor; use BEA\Theme\Framework\Services\Editor_Patterns; use BEA\Theme\Framework\Services\Gravity_Forms; use BEA\Theme\Framework\Services\Menu; -use BEA\Theme\Framework\Services\Sidebar; use BEA\Theme\Framework\Services\Svg; use BEA\Theme\Framework\Services\Theme; use BEA\Theme\Framework\Tools\Body_Class; @@ -35,7 +33,6 @@ class Framework { Theme::class, Assets::class, Performance::class, - Assets_JS_Async::class, Editor::class, Editor_Patterns::class, Gravity_Forms::class, diff --git a/inc/Services/Assets.php b/inc/Services/Assets.php index 2a1a3ec3..1933699b 100644 --- a/inc/Services/Assets.php +++ b/inc/Services/Assets.php @@ -68,7 +68,7 @@ public function register_assets(): void { 'dist/' . $file, array_merge( [ 'jquery' ], $asset_data['dependencies'] ), // ensure jQuery dependency is set even if not declared explicitly in the JS $asset_data['version'], - true + [ 'strategy' => 'defer' ] ); wp_add_inline_script( diff --git a/inc/Services/Assets_JS_Async.php b/inc/Services/Assets_JS_Async.php deleted file mode 100644 index 70a6fca6..00000000 --- a/inc/Services/Assets_JS_Async.php +++ /dev/null @@ -1,73 +0,0 @@ - 'async' ]; - - /** - * @param Service_Container $container - */ - public function register( Service_Container $container ): void {} - - /** - * @param Service_Container $container - */ - public function boot( Service_Container $container ): void { - if ( current_theme_supports( 'async-js' ) && ! is_admin() ) { - add_filter( 'script_loader_tag', [ $this, 'script_loader_tag' ], 20, 2 ); - } - - /** - * Example - * - * $this->add_handler( 'scripts', 'async defer' ); - */ - } - - /** - * @return string - */ - public function get_service_name(): string { - return 'assets-js-async'; - } - - /** - * @param string $handler - * @param string $type : async/defer or a combination of - */ - public function add_handler( string $handler, string $type = 'async' ): void { - $this->js_handlers[ $handler ] = $type; - } - - /** - * Replace default generated WP Link Tag - * - * @param string $html The link tag for the enqueued script. - * @param string $handle The script's registered handle. - * - * @return string - * @author Nicolas JUEN - */ - public function script_loader_tag( string $html, string $handle ): string { - if ( ! isset( $this->js_handlers[ $handle ] ) ) { - return $html; - } - - return str_replace( ' src', sprintf( ' %s src', esc_attr( $this->js_handlers[ $handle ] ) ), $html ); - } -} diff --git a/inc/Services/Theme.php b/inc/Services/Theme.php index 86958390..996e9fdc 100644 --- a/inc/Services/Theme.php +++ b/inc/Services/Theme.php @@ -55,7 +55,6 @@ private function add_theme_supports(): void { add_theme_support( 'post-thumbnails' ); add_theme_support( 'html5', [ 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'script', 'style' ] ); add_theme_support( 'title-tag' ); - add_theme_support( 'async-js' ); add_theme_support( 'yoast-seo-breadcrumbs' ); } diff --git a/inc/Tools/Assets.php b/inc/Tools/Assets.php index 81ea23d7..72f7f8e3 100644 --- a/inc/Tools/Assets.php +++ b/inc/Tools/Assets.php @@ -17,12 +17,12 @@ class Assets { * @param $src : Have to be a relative filename * @param array $deps * @param mixed $ver - * @param bool $in_footer + * @param array $strategy * * @return bool */ - public function register_script( string $handle, string $src, array $deps = [], $ver = false, bool $in_footer = false ): bool { - return \wp_register_script( $handle, \get_theme_file_uri( $src ), $deps, $ver, $in_footer ); + public function register_script( string $handle, string $src, array $deps = [], $ver = false, array $strategy = [] ): bool { + return \wp_register_script( $handle, \get_theme_file_uri( $src ), $deps, $ver, $strategy ); } /** diff --git a/style.css b/style.css index 642254fd..7b357f22 100644 --- a/style.css +++ b/style.css @@ -6,4 +6,5 @@ Version: 1.0.0 Author: BeAPI Author URI: http://www.beapi.fr Text Domain: beapi-frontend-framework +Requires at least: 6.3 */