register_meta(); } /** * Register post meta * * @since 1.23.0 */ public function register_meta(): void { register_post_meta( 'attachment', self::IS_GIF_POST_META_KEY, [ 'sanitize_callback' => 'rest_sanitize_boolean', 'type' => 'boolean', 'description' => __( 'Whether the video is to be considered a GIF', 'web-stories' ), 'show_in_rest' => true, 'default' => false, 'single' => true, 'object_subtype' => 'attachment', ] ); } /** * Filters the attachment data prepared for JavaScript. * * @since 1.23.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::IS_GIF_POST_META_KEY ] = get_post_meta( $post_id, self::IS_GIF_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::IS_GIF_POST_META_KEY ); } }