false, 'count' => false, 'typing' => false, ); /** * Allow to load in frontend. * * @var bool */ public static $can_load_frontend = true; /** * Initialize the class */ public function init() { if ( ! defined( 'BLOCKS_ANIMATION_URL' ) ) { define( 'BLOCKS_ANIMATION_URL', OTTER_BLOCKS_URL ); define( 'BLOCKS_ANIMATION_PATH', OTTER_BLOCKS_PATH ); } add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) ); add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_frontend_assets' ) ); add_filter( 'render_block', array( $this, 'frontend_load' ), 800, 2 ); } /** * Load Gutenberg editor assets. * * @since 1.0.0 * @access public */ public function enqueue_editor_assets() { $asset_file = include BLOCKS_ANIMATION_PATH . '/build/animation/index.asset.php'; wp_enqueue_style( 'otter-animation', BLOCKS_ANIMATION_URL . 'build/animation/index.css', array(), $asset_file['version'] ); if ( defined( 'OTTER_BLOCKS_VERSION' ) ) { array_push( $asset_file['dependencies'], 'otter-blocks' ); } wp_enqueue_script( 'otter-animation', BLOCKS_ANIMATION_URL . 'build/animation/index.js', $asset_file['dependencies'], $asset_file['version'], true ); wp_localize_script( 'otter-animation', 'blocksAnimation', array( 'hasOtter' => defined( 'OTTER_BLOCKS_VERSION' ), ) ); wp_set_script_translations( 'otter-animation', 'blocks-animation' ); $asset_file = include BLOCKS_ANIMATION_PATH . '/build/animation/anim-count.asset.php'; wp_enqueue_script( 'otter-count', BLOCKS_ANIMATION_URL . 'build/animation/anim-count.js', $asset_file['dependencies'], $asset_file['version'], true ); wp_script_add_data( 'otter-count', 'defer', true ); wp_enqueue_script( 'otter-typing', BLOCKS_ANIMATION_URL . 'build/animation/anim-typing.js', $asset_file['dependencies'], $asset_file['version'], true ); wp_script_add_data( 'otter-typing', 'defer', true ); } /** * Load Gutenberg assets. * * @since 1.0.0 * @access public */ public function enqueue_block_frontend_assets() { if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { self::$can_load_frontend = false; } global $post; if ( is_singular() && strpos( get_the_content( null, false, $post ), '