register_meta(); add_filter( 'wp_prepare_attachment_for_js', [ $this, 'wp_prepare_attachment_for_js' ] ); } /** * Register meta * * @since 1.16.0 */ public function register_meta(): void { register_meta( 'post', self::BLURHASH_POST_META_KEY, [ 'type' => 'string', 'description' => __( 'Attachment BlurHash', 'web-stories' ), 'show_in_rest' => [ 'schema' => [ 'type' => 'string', ], ], 'single' => true, 'object_subtype' => 'attachment', ] ); } /** * Filters the attachment data prepared for JavaScript. * * @since 1.16.0 * * @param array|mixed $response Array of prepared attachment data. * @return array|mixed Response data. * * @template T * * @phpstan-return ($response is array ? array : mixed) */ public function wp_prepare_attachment_for_js( $response ) { if ( ! \is_array( $response ) ) { return $response; } /** * Post ID. * * @var int $post_id */ $post_id = $response['id']; $response[ self::BLURHASH_POST_META_KEY ] = get_post_meta( $post_id, self::BLURHASH_POST_META_KEY, true ); return $response; } /** * Act on plugin uninstall. * * @since 1.26.0 */ public function on_plugin_uninstall(): void { delete_post_meta_by_key( self::BLURHASH_POST_META_KEY ); } }