Skip to content

Commit

Permalink
Use require over require_once for assets
Browse files Browse the repository at this point in the history
require_once is unsafe for a require that should return a value on each
function call.

See WordPress/gutenberg#18599
  • Loading branch information
sirreal committed May 27, 2020
1 parent 5ad41d9 commit 3a75e27
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function enqueue_script( $filename, $in_footer = false ) {
);
}

$asset = require_once $asset_path;
$asset = require $asset_path;

wp_enqueue_script(
$filename,
Expand All @@ -42,7 +42,7 @@ function enqueue_script( $filename, $in_footer = false ) {
/**
* Enqueues a submodule style by its filename.
*
* @param string $filename Name of the style file w/o extension.
* @param string $filename Name of the style file w/o extension.
*/
function enqueue_style( $filename ) {
$style_file = is_rtl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
function() {

$asset_file = __DIR__ . '/dist/event-countdown-block.asset.php';
$asset = file_exists( $asset_file ) ? require_once $asset_file : null;
$asset = file_exists( $asset_file ) ? require $asset_file : null;
$dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
$version = isset( $asset['version'] ) ? $asset['version'] : filemtime( __DIR__ . '/dist/event-countdown-block.js' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function block_editor_settings( $settings ) {
public function enqueue_block_editor_assets() {
$asset_file = plugin_dir_path( __FILE__ ) . 'dist/global-styles.asset.php';
$asset = file_exists( $asset_file )
? require_once $asset_file
? require $asset_file
: null;
$dependencies = isset( $asset['dependencies'] ) ?
$asset['dependencies'] :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'init',
function() {
$asset_file = __DIR__ . '/dist/jetpack-timleine.asset.php';
$asset = file_exists( $asset_file ) ? require_once $asset_file : null;
$asset = file_exists( $asset_file ) ? require $asset_file : null;
$dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();
$version = isset( $asset['version'] ) ? $asset['version'] : filemtime( __DIR__ . '/index.js' );

Expand Down

0 comments on commit 3a75e27

Please sign in to comment.