repository = $repository; } /** * Hangt zichzelf op. */ public function register(): void { add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_data' ), 10, 2 ); } /** * Hangt een compact `yingaFocus`-object aan het model. * * Bewust compact: dit draait voor elke thumbnail in de bibliotheek, dus * veertig keer per schermvulling. De volledige data komt pas als de editor * daadwerkelijk opengaat, via één REST-call. * * @param array $response Het antwoord. * @param WP_Post $attachment De attachment. * @return array Het aangevulde antwoord. */ public function add_data( $response, $attachment ) { if ( ! is_array( $response ) || ! $attachment instanceof WP_Post ) { return $response; } if ( ! wp_attachment_is_image( $attachment->ID ) ) { return $response; } $position = $this->repository->css_position( $attachment->ID ); $response['yingaFocus'] = array( 'hasFocus' => null !== $position, 'cssPosition' => $position, ); return $response; } }