Skip to main content

ShowCreditsController

\Benecaster\REST\ShowCreditsController

Class Free

Admin REST controller for per-show episode credit templates. Provides CRUD access to the show’s list of credit templates. Auth: permission_callback_admin on both endpoints. A thin boundary layer — validation (unique name, single default, non-empty name, UUID generation, wp_kses_post on body) happens where the list is saved, not here; this class only maps a rejected save to a 400.

GET /shows/{id}/credits accepts an optional episode_id query parameter. When present, the stored list is passed through the benecaster_credit_options filter before returning — this is how the episode editor’s credit-picker dropdown gets rewritten per-episode (e.g. an add-on pre-selecting a guest-interview template). Show Settings CRUD callers omit episode_id and always see the raw stored list untouched by the filter. PUT /shows/{id}/credits replaces the entire list in one atomic write — there is no per-item PATCH.

Methods

Method Visibility Since Description
register_routes(): void Public — Registers GET and PUT /shows/{id}/credits on the same route, both permission_callback_admin with a numeric-id validate_callback.
get_credits( WP_REST_Request $request ): WP_REST_Response|WP_Error Public — 404 for a missing or non-show {id}. Reads the show's stored credit list. When episode_id (query param) is a positive int, applies the benecaster_credit_options filter with the credits list, show_id, and episode_id before returning; the filter is skipped entirely — not called with a 0 — when episode_id is absent.
update_credits( WP_REST_Request $request ): WP_REST_Response|WP_Error Public — 404 for a missing or non-show {id}. 400 invalid_param when the credits body param isn't an array. A save that fails validation returns 400 invalid_credit carrying the validation message. Returns the freshly re-read stored list (post-validation, post-UUID-generation) on success, not an echo of the request body.
resolve_show( int $show_id ): WP_Post|WP_Error — — Loads the post and returns not_found() unless it exists and is a show CPT post.

Hooks Fired

Notes

Extends the plugin's internal RestController base — not part of the public API; its own docblock tells add-on developers not to extend it, and to register independent routes on rest_api_init with the public benecaster_rest_permission_admin() function instead. Inherits register() (hooks register_routes() onto rest_api_init), the permission_callback_admin / permission_callback_editor / permission_callback_subscriber callbacks, rest_error(), and not_found().