@@ -186,6 +186,12 @@ class Asset {
186
186
* 2. If a path group is set, that will be used.
187
187
* 3. Otherwise, the root path will be used.
188
188
*
189
+ * In the case where the `$group_path_over_root_path` property is true, the order of priority will change to this:
190
+ *
191
+ * 1. If a path group is set, that will be used.
192
+ * 2. If a specific root path is set, that will be used.
193
+ * 3. Otherwise, the root path will be used.
194
+ *
189
195
* @var string
190
196
*/
191
197
protected string $ group_path_name = '' ;
@@ -276,6 +282,17 @@ class Asset {
276
282
*/
277
283
protected ?string $ version = null ;
278
284
285
+ /**
286
+ * Whether to use the group path over the root path.
287
+ * This flag will be raised when the asset is added to a group path
288
+ * and lowered when it's removed from it.
289
+ *
290
+ * @since TBD
291
+ *
292
+ * @var bool
293
+ */
294
+ private $ group_path_over_root_path = false ;
295
+
279
296
/**
280
297
* Constructor.
281
298
*
@@ -313,6 +330,8 @@ public function add_to_group_path( string $group_path_name ) {
313
330
314
331
$ this ->prefix_asset_directory ( Config::is_group_path_using_asset_directory_prefix ( $ this ->group_path_name ) );
315
332
333
+ $ this ->group_path_over_root_path = true ;
334
+
316
335
return $ this ;
317
336
}
318
337
@@ -480,6 +499,20 @@ protected function build_resource_path_data(): array {
480
499
return (array ) apply_filters ( "stellarwp/assets/ {$ hook_prefix }/resource_path_data " , $ data , $ this ->get_slug (), $ this );
481
500
}
482
501
502
+ /**
503
+ * Removes the asset from a group.
504
+ *
505
+ * This method is the inverse of the `add_to_group_path` method.
506
+ *
507
+ * @param string $group_path_name The name of the group path to remove the asset from.
508
+ *
509
+ * @return void The asset is removed from the specified group path.
510
+ */
511
+ public function remove_from_group_path ( string $ group_path_name ): void {
512
+ $ this ->group_path_over_root_path = false ;
513
+ $ this ->group_path_name = '' ;
514
+ }
515
+
483
516
/**
484
517
* Builds the base asset URL.
485
518
*
@@ -589,13 +622,13 @@ protected function build_min_asset_url( $original_url ): string {
589
622
590
623
$ script_debug = defined ( 'SCRIPT_DEBUG ' ) && Utils::is_truthy ( SCRIPT_DEBUG );
591
624
592
- if ( $ script_debug && file_exists ( wp_normalize_path ( $ root_path . $ resource_path . $ resource ) ) ) {
625
+ if ( $ script_debug && is_file ( wp_normalize_path ( $ root_path . $ resource_path . $ resource ) ) ) {
593
626
return $ original_url ;
594
627
}
595
628
596
629
$ minified_abs_file_path = wp_normalize_path ( $ root_path . $ minified_file_path );
597
630
598
- if ( ! file_exists ( $ minified_abs_file_path ) ) {
631
+ if ( ! is_file ( $ minified_abs_file_path ) ) {
599
632
return $ original_url ;
600
633
}
601
634
@@ -958,13 +991,19 @@ public function get_root_path(): ?string {
958
991
return $ this ->root_path ;
959
992
}
960
993
994
+ if ( $ this ->group_path_over_root_path ) {
995
+ $ group_path = Config::get_path_of_group_path ( $ this ->group_path_name );
996
+
997
+ return $ group_path ?: $ this ->root_path ;
998
+ }
999
+
961
1000
if ( $ this ->root_path !== Config::get_path () ) {
962
1001
return $ this ->root_path ;
963
1002
}
964
1003
965
1004
$ group_path = Config::get_path_of_group_path ( $ this ->group_path_name );
966
1005
967
- return $ group_path ? $ group_path : $ this ->root_path ;
1006
+ return $ group_path ?: $ this ->root_path ;
968
1007
}
969
1008
970
1009
/**
@@ -1101,7 +1140,7 @@ public function has_asset_file(): bool {
1101
1140
return false ;
1102
1141
}
1103
1142
1104
- return file_exists ( $ asset_file_path );
1143
+ return is_file ( $ asset_file_path );
1105
1144
}
1106
1145
1107
1146
/**
@@ -1342,7 +1381,7 @@ public function maybe_get_min_file( $url ) {
1342
1381
$ file_path = wp_normalize_path ( "{$ base_dir }/ {$ partial_path }" );
1343
1382
$ file_url = "{$ base_url }/ {$ partial_path }" ;
1344
1383
1345
- if ( file_exists ( $ file_path ) ) {
1384
+ if ( is_file ( $ file_path ) ) {
1346
1385
return $ file_url ;
1347
1386
}
1348
1387
}
0 commit comments