'string', 'single' => true, 'sanitize_callback' => [ __CLASS__, 'sanitize_json_meta' ], 'show_in_rest' => true, 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ] ); // Rendering engine for this item: 'native' (default — TruePlayer's own // player) or another engine an add-on registers (see the // `trueplayer/render_engine` filter). A dedicated, queryable meta so the // library and the frontend router can branch without decoding the whole // JSON blob. Absent meta reads as 'native'. register_post_meta( TRUEPLAYER_VIDEO_POST_TYPE, '_trueplayer_engine', [ 'type' => 'string', 'single' => true, 'default' => 'native', 'show_in_rest' => true, 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ] ); register_post_meta( TRUEPLAYER_PRESET_POST_TYPE, '_trueplayer_preset', [ 'type' => 'string', 'single' => true, 'sanitize_callback' => [ __CLASS__, 'sanitize_json_meta' ], 'show_in_rest' => true, 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ] ); /** * Whether a preset styles the video player or the audio one. * * A dedicated meta rather than a key inside `_trueplayer_preset` for two * reasons. Everything in that blob is merge payload — Helper::apply_preset * folds it onto a video — and a preset's own classification must never be * something a video can inherit. And it is queryable without decoding * JSON, the same reasoning ENGINE_META documents above. * * The registered default is what makes this free of any migration: every * preset that existed before audio reads as 'video' with no rows written. */ register_post_meta( TRUEPLAYER_PRESET_POST_TYPE, '_trueplayer_preset_type', [ 'type' => 'string', 'single' => true, 'default' => 'video', 'show_in_rest' => true, 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ] ); } /** * Validate style values in a JSON config written through the REST meta API. * * @param mixed $value Raw (JSON string) meta value. * @return mixed */ public static function sanitize_json_meta( $value ) { if ( ! is_string( $value ) || '' === $value ) { return $value; } $data = json_decode( $value, true ); if ( ! is_array( $data ) ) { return $value; } return wp_json_encode( \TruePlayer\Helper::sanitize_style_values( $data ) ); } }