Skip to content

Commit 43eb4ac

Browse files
optimized action calling to remove one class property
1 parent 116bf36 commit 43eb4ac

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/init.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
if ( ! class_exists( 'Stackable_Init' ) ) {
1717
class Stackable_Init {
1818

19-
/**
20-
* Holds the scripts which are already enqueued, to ensure we only do it once per script.
21-
* @var Array
22-
*/
23-
public $scripts_loaded = array();
24-
2519
/**
2620
* Enqueue the frontend scripts, ensures we only do it once.
2721
*
@@ -243,15 +237,15 @@ public function load_frontend_scripts_conditionally( $block_content, $block ) {
243237
}
244238

245239
// Enqueue the block script once.
246-
if ( ! isset( $this->scripts_loaded[ $block['blockName'] ] ) ) {
247-
$stackable_block = substr( $block['blockName'], 10 );
248-
do_action( 'stackable/' . $stackable_block . '/enqueue_scripts' );
249-
$this->scripts_loaded[ $block['blockName'] ] = true;
240+
if ( did_action( 'stackable/' . $block['blockName'] . '/enqueue_scripts' ) === 0 ) {
241+
do_action( 'stackable/' . $block['blockName'] . '/enqueue_scripts' );
250242
}
251243

252244
// Check whether the current block needs to enqueue some scripts.
253245
// This gets called across all the blocks.
254-
do_action( 'stackable/enqueue_scripts', $block_content, $block );
246+
if ( did_action( 'stackable/enqueue_scripts' ) === 0 ) {
247+
do_action( 'stackable/enqueue_scripts', $block_content, $block );
248+
}
255249

256250
return $block_content;
257251
}

0 commit comments

Comments
 (0)