Skip to content

Commit 9daee05

Browse files
committed
Simplify environment checker.
1 parent 7b17373 commit 9daee05

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/ableplayer.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,38 @@ function ableplayer_enqueue_scripts() {
4949
wp_enqueue_script( 'js-cookie', plugins_url( 'thirdparty', __FILE__ ) . '/js.cookie.js', array( 'jquery' ) );
5050
wp_enqueue_script( 'vimeo', 'https://player.vimeo.com/api/player.js' );
5151

52+
// if the environment is production, use minified files. Otherwise, inherit the value of SCRIPT_DEBUG.
53+
$is_production = ( function_exists( 'wp_get_environment_type' ) && wp_get_environment_type() === 'production' ) ? true : SCRIPT_DEBUG;
54+
55+
$js_file = ( $is_production ) ? 'ableplayer.min.js' : 'ableplayer.js';
56+
$css_file = ( $is_production ) ? 'ableplayer.min.css' : 'ableplayer.css';
5257
/**
53-
* Filter the Able Player build directory JS.
58+
* Filter the Able Player JS URL.
5459
*
5560
* @hook able_player_js
5661
*
5762
* @param {string} $url URL to Able Player root directory.
63+
* @param {bool} $is_production True if environment is designated as production.
5864
*
5965
* @return string
6066
*/
61-
$js_dir = apply_filters( 'able_player_js', plugins_url( 'build', __FILE__ ) );
67+
$js_dir = apply_filters( 'able_player_js', plugins_url( 'build', __FILE__ ) . '/' . $js_file, $is_production );
6268
/**
63-
* Filter the Able Player build directory CSS.
69+
* Filter the Able Player CSS URL.
6470
*
6571
* @hook able_player_css
6672
*
6773
* @param {string} $url URL to Able Player root directory.
74+
* @param {bool} $is_production True if environment is designated as production.
6875
*
6976
* @return string
7077
*/
71-
$css_dir = apply_filters( 'able_player_css', plugins_url( 'build', __FILE__ ) );
72-
73-
$is_production_environment = ( function_exists( 'wp_get_environment_type' ) && wp_get_environment_type() === 'production' ) ? true : SCRIPT_DEBUG;
78+
$css_dir = apply_filters( 'able_player_css', plugins_url( 'build', __FILE__ ) . '/' . $css_file, $is_production );
7479

75-
if ( SCRIPT_DEBUG === true || ! $is_production_environment ) {
76-
// JS Option 2: human-readable, for debugging.
77-
wp_enqueue_script( 'ableplayer', $js_dir . '/ableplayer.js', array( 'jquery' ), ABLEPLAYER_VERSION );
80+
// Enqueue Able Player script and CSS.
81+
wp_enqueue_script( 'ableplayer', $js_dir, array( 'jquery' ), ABLEPLAYER_VERSION );
82+
wp_enqueue_style( 'ableplayer', $css_dir, array(), ABLEPLAYER_VERSION );
7883

79-
// CSS Option 2: human-readable; use this if you intend to change the styles and customize the player.
80-
wp_enqueue_style( 'ableplayer', $css_dir . '/ableplayer.css', array(), ABLEPLAYER_VERSION );
81-
} else {
82-
// JS Option 1: minified, for production.
83-
wp_enqueue_script( 'ableplayer', $js_dir . '/ableplayer.min.js', array( 'jquery' ), ABLEPLAYER_VERSION );
84-
85-
// CSS Option 1: minified, for production.
86-
wp_enqueue_style( 'ableplayer', $css_dir . '/ableplayer.min.css', array(), ABLEPLAYER_VERSION );
87-
}
8884
}
8985
add_action( 'wp_enqueue_scripts', 'ableplayer_enqueue_scripts' );
9086

0 commit comments

Comments
 (0)