array( __CLASS__, 'render_block' ), ) ); } /** * Handle the [airygen_breadcrumbs] shortcode. * * @param array $atts Shortcode attributes. * @return string */ public static function render_shortcode( array $atts ): string { return TrailRenderer::render_current( self::build_overrides( $atts ) ); } /** * Render callback for the airygen/breadcrumb block. * * @param array $attributes Block attributes. * @return string */ public static function render_block( array $attributes = array() ): string { return TrailRenderer::render_current( self::build_overrides( $attributes ) ); } /** * Reduce shortcode/block attributes to non-empty override values. * * @param array $raw Raw attributes. * * @return array */ private static function build_overrides( array $raw ): array { $args = shortcode_atts( array( 'separator' => null, 'wrap_before' => null, 'wrap_after' => null, 'before' => null, 'after' => null, 'prefix' => null, 'link_last' => null, ), $raw ); $overrides = array(); foreach ( $args as $key => $value ) { if ( null !== $value && '' !== $value ) { $overrides[ $key ] = $value; } } return $overrides; } /** * Inject breadcrumbs before or after main content. * * @param string $content Post content. * * @return string */ public static function inject_to_content( string $content ): string { if ( ! is_singular() || ! in_the_loop() || ! is_main_query() ) { return $content; } if ( has_shortcode( $content, 'airygen_breadcrumbs' ) ) { return $content; } $post_id = get_the_ID(); if ( ! is_int( $post_id ) || $post_id <= 0 ) { return $content; } $queried_object_id = get_queried_object_id(); if ( ! is_int( $queried_object_id ) || $queried_object_id <= 0 || $queried_object_id !== $post_id ) { return $content; } $settings = Settings::get(); if ( empty( $settings['auto_injection_enabled'] ) ) { return $content; } $html = TrailRenderer::render_current( array(), false ); if ( '' === $html ) { return $content; } $position = isset( $settings['injection_position'] ) ? (string) $settings['injection_position'] : 'before_content'; if ( 'after_content' === $position ) { return $content . $html; } return $html . $content; } }