admin-bar-menu.php
4 years ago
ajax-pagination.php
1 week ago
class-ecs-core.php
4 months ago
class-ecs-module-base.php
1 week ago
class-ecs-modules-manager.php
3 months ago
dynamic-style.php
4 years ago
ecs-assets.php
1 week ago
ecs-dependencies.php
6 years ago
ecs-notices.php
6 years ago
enqueue-styles.php
1 week ago
pro-features.php
3 months ago
pro-preview.php
6 years ago
ecs-assets.php
35 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Minified asset URL helper. |
| 4 | * |
| 5 | * .min.css / .min.js files are generated at release time (see |
| 6 | * release-ecs-free.py / release-ecs-pro.py) and are not committed to the |
| 7 | * plugin's git repository — only the SVN/zip release build ships them. |
| 8 | * Falls back to the unminified file when SCRIPT_DEBUG is on, or when the |
| 9 | * .min file doesn't exist yet (e.g. running straight from git checkout). |
| 10 | */ |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 13 | |
| 14 | /** |
| 15 | * @param string $url Full enqueue URL for a .css or .js file. |
| 16 | * @param string $path Filesystem path to the same file (to check the .min |
| 17 | * file actually exists before pointing at it). |
| 18 | */ |
| 19 | function ecs_asset_url( string $url, string $path ): string { |
| 20 | if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { |
| 21 | return $url; |
| 22 | } |
| 23 | |
| 24 | if ( ! preg_match( '/\.(css|js)$/', $path ) || str_ends_with( $path, '.min.css' ) || str_ends_with( $path, '.min.js' ) ) { |
| 25 | return $url; |
| 26 | } |
| 27 | |
| 28 | $min_path = preg_replace( '/\.(css|js)$/', '.min.$1', $path ); |
| 29 | if ( ! file_exists( $min_path ) ) { |
| 30 | return $url; |
| 31 | } |
| 32 | |
| 33 | return preg_replace( '/\.(css|js)$/', '.min.$1', $url ); |
| 34 | } |
| 35 |