benecaster_resolve_show_id()
benecaster_resolve_show_id( int $show_id = 0 ): int
Decides which show a show-scoped shortcode or block is for, in the order Benecaster’s own shortcodes use, so yours picks the same show theirs would on the same page:
- the ID you pass, when it is positive;
- the current page: a show page is that show, and an episode page belongs to its show;
- the site’s only active show, from benecaster_get_sole_show_id().
0 means none of them answered: a multi-show site, on a page that is not a show or an episode, with no ID given. What to print then is your shortcode’s choice.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
show_id |
int |
0 |
No | An explicit show ID, such as a shortcode's show_id attribute passed through absint(), or 0 for none. |
Return Value
Type:
int
$show_id when it is positive; otherwise the show of the current page (a show page is that show, an episode page its show); otherwise the site's only active show. 0 when none of them answers.
Example
add_shortcode( 'my_addon_box', function ( $atts ) {
$atts = shortcode_atts( [ 'show_id' => 0 ], $atts );
$show_id = benecaster_resolve_show_id( absint( $atts['show_id'] ) );
if ( ! $show_id ) {
return ''; // A multi-show site, on a page that is not a show or an episode.
}
return my_addon_render_box( $show_id );
} );
Notes
An explicit ID is returned as given, not checked against the shows on the site, the same as a Benecaster shortcode's show_id attribute. Check it yourself if a wrong ID matters.
Do not use it where 0 already means something. If 0 means "every show" or "site-wide" in your shortcode, this order would quietly narrow it to one show on a single-show site. That is why [benecaster_account], [benecaster_user_badge], [benecaster_member_since] and [benecaster_listener_support] do not use it.
Need this built rather than just documented? See our services →