` die WordPress zelf bouwt. * * `wp_get_attachment_image_attributes` is het breedste aangrijppunt dat er * bestaat. Alles wat onder water `wp_get_attachment_image()` aanroept komt * hierlangs: `the_post_thumbnail()`, `post_thumbnail` in blokthema's, * `core/post-featured-image`, galerijen, en elk thema dat de functie netjes * gebruikt. Eén filter, en het grootste deel van de dekking is binnen. * * Het formaat komt hier als derde argument binnen, dus dit is óók de enige * route waar we met zekerheid weten of er een hard gecropt bestand geserveerd * wordt. Zie ApplyPolicy voor waarom dat uitmaakt. * * @package Yinga\Focus */ declare( strict_types = 1 ); namespace Yinga\Focus\Frontend; defined( 'ABSPATH' ) || exit; final class ImageFilters { private ApplyPolicy $policy; /** * @param ApplyPolicy $policy De policy. */ public function __construct( ApplyPolicy $policy ) { $this->policy = $policy; } /** * Haakt aan. */ public function register(): void { // Prioriteit 20: na de thema's, zodat een style die zíj zetten blijft // staan en de onze erachter komt. add_filter( 'wp_get_attachment_image_attributes', array( $this, 'attributes' ), 20, 3 ); } /** * Vult class en style aan. * * @param mixed $attr Attributen van de ``. * @param mixed $attachment Het attachment-object. * @param mixed $size Het opgevraagde beeldformaat. * @return mixed De attributen, ongewijzigd als er niets toe te passen viel. */ public function attributes( $attr, $attachment = null, $size = null ) { if ( ! is_array( $attr ) ) { return $attr; } $id = ( is_object( $attachment ) && isset( $attachment->ID ) ) ? (int) $attachment->ID : 0; if ( $id <= 0 ) { return $attr; } // In de bewerkmodus is elk herleidbaar element klikbaar — óók zonder // focuspunt, want juist die wil je kunnen instellen. if ( $this->policy->edit_mode() && ! isset( $attr['data-yf-id'] ) ) { $attr['data-yf-id'] = (string) $id; } $state = Markup::inspect( isset( $attr['class'] ) ? (string) $attr['class'] : '', isset( $attr['style'] ) ? (string) $attr['style'] : '' ); if ( $state['done'] ) { return $attr; } if ( ! $this->policy->should_apply( $id, is_string( $size ) || is_array( $size ) ? $size : null ) ) { return $attr; } return Markup::merge_attributes( $attr, $this->policy->attributes( $id, ! $state['positioned'] ) ); } }