Populate a block or widget picker without needing an administrator
A Gutenberg block, an Elementor widget or any other editor-side control that lets someone pick a show, tier, season or episode needs that list from somewhere. Benecaster’s admin routes need manage_options, so an Editor or Author building a page gets a 403 and the dropdown comes up empty — silently, because an empty list looks like a site with no shows.
Use the Editor Pickers routes instead. They need only edit_posts, and wp.apiFetch supplies the nonce for you:
const shows = await apiFetch( { path: '/benecaster/v1/editor/shows' } );
const tiers = await apiFetch( { path: `/benecaster/v1/editor/shows/${ showId }/tiers` } );
const seasons = await apiFetch( { path: `/benecaster/v1/editor/shows/${ showId }/seasons` } );
const episodes = await apiFetch( {
path: `/benecaster/v1/editor/shows/${ showId }/episodes?search=${ q }&per_page=20`,
} );
// shows: { shows: [ { id, title, slug } ] }
// tiers: { tiers: [ { slug, name } ] } — already in the show's tier order
// episodes: { episodes: [ { id, title, status } ], total, total_pages, page } — status is publish or future
The platform and merge-tag choices a link or share block offers do not change per show, so hand them to your editor script from PHP instead, as the example does. Pass the lists through rather than copying them into JavaScript — a copy drifts.
Offer rss in a platform-links picker. The podcast list ends with rss, and the shortcode’s platforms attribute leaves out anything it does not name — so a picker without an rss choice drops the show’s feed link as soon as anything is ticked. rss has no URL to enter; show the entries in autoPlatforms as plain checkboxes.
Do not ask the customer to grant manage_options so the admin routes work. That is the workaround this surface exists to make unnecessary, and it hands an Author subscriber counts and prices.
Rank tiers by their position in the list, never by a number fetched elsewhere. The stored tier_order is 0 for every tier created in the Memberships admin, which is why the routes and benecaster_get_show_tiers() leave it out.
An empty tier list is normal. A show on neither built-in memberships nor a membership plugin returns [] rather than an error; render an empty state.
The payloads will not grow. They carry ids, names, slugs, season numbers and an episode’s status only. For a price, a subscriber count or a feed URL, use a manage_options route or a front-end shortcode.
Code
<?php
// Hand the fixed picker lists to your block's editor script, so it needs no
// request for them. Shows, tiers, seasons and episodes come from the Editor
// Pickers REST routes at edit time.
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_script(
'my-benecaster-blocks',
plugins_url( 'build/editor.js', __FILE__ ),
[ 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-element' ],
'1.0.0',
true
);
wp_localize_script( 'my-benecaster-blocks', 'myBenecasterPickers', [
'socialPlatforms' => benecaster_get_social_platforms(), // [benecaster_social_links]
'podcastPlatforms' => benecaster_get_podcast_platforms(), // [benecaster_platform_links], ends with `rss`
'autoPlatforms' => benecaster_get_automatic_podcast_platforms(), // no URL to enter: [ 'rss' ]
'sharePlatforms' => benecaster_get_share_platforms(), // [benecaster_episode_share], also its default
'shareMergeTags' => benecaster_get_share_merge_tags(), // tags its `text` attribute resolves
] );
} );
Need this built rather than just documented? See our services →