[ $id, $alt, $caption ] ) { $alt = '' !== $alt ? $alt : trim( (string) get_post_meta( $id, '_wp_attachment_image_alt', true ) ); $first = 0 === $n; $img = (string) wp_get_attachment_image( $id, 'full', false, [ 'class' => 'rooster-track__image', 'alt' => $alt, 'sizes' => $sizes, 'loading' => $first ? 'eager' : 'lazy', 'decoding' => $first ? 'auto' : 'async', 'fetchpriority' => false, ] ); $inner .= '
' . $img . ( '' !== $caption ? '
' . AIEO_Engine_Blocks::inline( $caption ) . '
' : '' ) . '
'; } $count = count( $slides ); $nav = ''; if ( $count > 1 ) { $button = static fn ( string $which, string $name, string $icon, bool $end ): string => sprintf( '', $which, esc_attr( $strip ), esc_attr( $name ), $end ? ' aria-disabled="true"' : '', function_exists( 'rooster_icon' ) ? rooster_icon( $icon, [ 'width' => 18, 'height' => 18, 'class' => 'rooster-track__arrow' ] ) : '' ); $nav = '
' . $button( 'prev', __( 'Previous picture', 'ai-eshop-optimizer' ), 'arrow-left', true ) . '1 / ' . (int) $count . '' . $button( 'next', __( 'Next picture', 'ai-eshop-optimizer' ), 'arrow-right', false ) . '
'; if ( function_exists( 'wp_register_script_module' ) ) { $file = __DIR__ . '/track.min.js'; wp_register_script_module( AIEO_Engine_Blocks::handle( 'media', 'track' ), AIEO_ENGINE_URL . '/blocks/media/variants/track.min.js', [], is_file( $file ) ? (string) filemtime( $file ) : false ); wp_enqueue_script_module( AIEO_Engine_Blocks::handle( 'media', 'track' ) ); } } $allows = function_exists( 'wp_get_global_settings' ) ? wp_get_global_settings( [ 'custom', 'track', 'sideways' ] ) : null; $sideways = $count > 1 && function_exists( 'wp_register_script_module' ) && ( true === $allows || 1 === $allows || '1' === $allows ); $extra = [ 'class' => 'rooster-track', 'data-rooster-ui' => 'rooster-one/media' ]; if ( $sideways ) { $extra = [ 'class' => 'rooster-track is-sideways', 'data-rooster-ui' => 'rooster-one/media', 'data-count' => (string) $count, 'data-wp-interactive' => 'rooster/track', 'data-wp-init' => 'callbacks.init', 'data-wp-on--focusin' => 'actions.focus', 'data-wp-on--keydown' => 'actions.key', 'data-wp-on--click' => 'actions.press', 'data-wp-on-document--click' => 'actions.link', 'data-wp-on-window--hashchange' => 'callbacks.hash', ]; $handle = AIEO_Engine_Blocks::handle( 'media', 'track-sideways' ); $sheet = __DIR__ . '/track-sideways.css'; $module = __DIR__ . '/track-sideways.min.js'; if ( ! wp_style_is( $handle, 'registered' ) ) { wp_register_style( $handle, AIEO_ENGINE_URL . '/blocks/media/variants/track-sideways.css', [], is_file( $sheet ) ? (string) filemtime( $sheet ) : false ); wp_style_add_data( $handle, 'path', wp_normalize_path( $sheet ) ); } wp_enqueue_style( $handle ); $room = '.rooster-track[data-count="' . (int) $count . '"]{--rooster-track-n:' . (int) $count . '}'; if ( ! in_array( $room, (array) wp_styles()->get_data( $handle, 'after' ), true ) ) { wp_add_inline_style( $handle, $room ); } wp_register_script_module( $handle, AIEO_ENGINE_URL . '/blocks/media/variants/track-sideways.min.js', [ '@wordpress/interactivity' ], is_file( $module ) ? (string) filemtime( $module ) : false ); wp_enqueue_script_module( $handle ); } $wrapper = AIEO_Engine_Blocks::wrapper( $library, $extra ); $body = sprintf( '
%3$s
%4$s', esc_attr( $strip ), esc_attr( $label ), $inner, $nav ); AIEO_Engine_Blocks::out( sprintf( '
%2$s
', $wrapper, $sideways ? '
' . $body . '
' : $body ) );