1111 */
1212final class ScriptManager
1313{
14- public function __construct (
14+ private $ scripts = [];
15+ public function __construct ($ scripts = [])
16+ {
1517 /** @var Script[] */
16- private $ scripts = []
17- ) {
18+ $ this ->scripts = $ scripts ;
1819 }
1920
2021 public function add (Script $ script ): void
@@ -45,7 +46,7 @@ protected function enqueueScripts(): void
4546 */
4647 protected function addAttributes (): void
4748 {
48- add_filter ('wp_script_attributes ' , $ this -> addAttributesFilter (... ), 10 , 2 );
49+ add_filter ('wp_script_attributes ' , \Closure:: fromCallable ([ $ this , ' addAttributesFilter ' ] ), 10 , 2 );
4950 }
5051
5152 protected function addAttributesFilter ($ attributes )
@@ -55,7 +56,7 @@ protected function addAttributesFilter($attributes)
5556 $ script instanceof HasAttributes &&
5657 $ script ->handle () . '-js ' === $ attributes ['id ' ]
5758 ) {
58- return [... $ attributes, ... $ script ->attributes ()] ;
59+ return array_merge ( is_array ( $ attributes) ? $ attributes : iterator_to_array ( $ attributes ), $ script ->attributes ()) ;
5960 }
6061 }
6162
@@ -64,7 +65,7 @@ protected function addAttributesFilter($attributes)
6465
6566 protected function removeIds (): void
6667 {
67- add_filter ('script_loader_tag ' , $ this -> removeIdsFilter (... ), 10 , 2 );
68+ add_filter ('script_loader_tag ' , \Closure:: fromCallable ([ $ this , ' removeIdsFilter ' ] ), 10 , 2 );
6869 }
6970
7071 protected function removeIdsFilter ($ tag , $ handle ): string
0 commit comments