@@ -494,20 +494,25 @@ function stackable_init_animations() {
494494
495495if ( ! function_exists ( 'stackable_check_block_animation ' ) ) {
496496
497+ function stackable_css_has_hover_effects_or_animation ( $ css_string ) {
498+ if ( strpos ( $ css_string , ':hover ' ) !== false || // Hover effects
499+ strpos ( $ css_string , '--entrance- ' ) !== false || // Entrance animations
500+ strpos ( $ css_string , 'stk-anim ' ) !== false || // Scroll animations
501+ strpos ( $ css_string , '--stk-tran ' ) !== false || // Transition duration
502+ strpos ( $ css_string , 'stk-entrance ' ) !== false || // Entrance class
503+ strpos ( $ css_string , '-hover ' ) !== false // has CSS custom property for hover effects
504+ ) {
505+ return true ;
506+ }
507+ return false ;
508+ }
509+
497510 function stackable_check_block_animation ( $ block_content , $ block ) {
498511 if ( ! isset ( $ block ['blockName ' ] ) || strpos ( $ block ['blockName ' ], 'stackable/ ' ) === false ) {
499512 return $ block_content ;
500513 }
501514
502- $ has_global_animations = apply_filters ( 'stackable_has_global_animations ' , false );
503-
504- if ( strpos ( $ block_content , ':hover ' ) !== false || // Hover effects
505- strpos ( $ block_content , '--entrance- ' ) !== false || // Entrance animations
506- strpos ( $ block_content , 'stk-anim ' ) !== false || // Scroll animations
507- strpos ( $ block_content , '--stk-tran ' ) !== false || // Transition duration
508- strpos ( $ block_content , 'stk-entrance ' ) !== false || // Entrance class
509- $ has_global_animations !== false // Global block layouts has hover effects
510- ) {
515+ if ( stackable_css_has_hover_effects_or_animation ( $ block_content ) ) {
511516 // Adds a special class to the body tag, to indicate we can now run animations.
512517 add_action ( 'wp_footer ' , 'stackable_init_animations ' );
513518 remove_filter ( 'render_block ' , 'stackable_check_block_animation ' , 10 , 2 );
@@ -516,7 +521,17 @@ function stackable_check_block_animation( $block_content, $block ) {
516521 return $ block_content ;
517522 }
518523
524+ function stackable_check_block_animation_on_global_styles ( $ css ) {
525+ if ( stackable_css_has_hover_effects_or_animation ( $ css ) ) {
526+ // Adds a special class to the body tag, to indicate we can now run animations.
527+ add_action ( 'wp_footer ' , 'stackable_init_animations ' );
528+ }
529+
530+ return $ css ;
531+ }
532+
519533 if ( is_frontend () ) {
520534 add_filter ( 'render_block ' , 'stackable_check_block_animation ' , 1 , 2 );
535+ add_filter ( 'stackable_frontend_css ' , 'stackable_check_block_animation_on_global_styles ' , 999 );
521536 }
522537}
0 commit comments