Skip to content

Commit

Permalink
Add tag selection to the playlist player in block editor
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-c authored and zahardev committed Dec 27, 2024
1 parent 656722c commit 59851d8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
31 changes: 31 additions & 0 deletions php/classes/integrations/blocks/class-castos-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ protected function register_playlist_player() {
'type' => 'string',
'default' => '-1',
),
'availableTags' => array(
'type' => 'array',
'default' => $this->get_tags(),
),
'selectedTag' => array(
'type' => 'string',
'default' => '',
),
// Use string everywhere instead of number because of the WP bug.
// It doesn't show the saved value in the admin after page refresh.
'limit' => array(
Expand All @@ -440,6 +448,10 @@ protected function register_playlist_player() {
$args['series'] = $this->get_term_slug_by_id( $podcast_id );
}

if ( ! empty( $attributes['selectedTag'] ) ) {
$args['tag'] = $attributes['selectedTag'];
}

if ( ! empty( $attributes['limit'] ) ) {
$args['limit'] = $attributes['limit'];
}
Expand Down Expand Up @@ -501,4 +513,23 @@ protected function get_podcast_settings() {
);
}, ssp_get_podcasts() ) );
}

/**
* @return array
*/
protected function get_tags() {
return array_merge(
array(
array(
'label' => __( '-- All --', 'seriously-simple-podcasting' ),
'value' => '',
),
),
array_map( function ( $item ) {
return array(
'label' => $item->name,
'value' => $item->slug,
);
}, ssp_get_tags() ) );
}
}
20 changes: 20 additions & 0 deletions php/includes/ssp-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,26 @@ function ssp_get_podcasts( $hide_empty = false ) {
}
}

/**
* Gets array of tags.
*/
if ( ! function_exists( 'ssp_get_tags' ) ) {
/**
* Gets array of tags.
*
* @param bool $hide_empty
*
* @return WP_Term[]
*/
function ssp_get_tags( $hide_empty = false ) {
$tags = get_terms( 'post_tag', array(
'post_type' => ssp_post_types(),
'hide_empty' => $hide_empty,
) );
return is_array( $tags ) ? $tags : array();
}
}

/**
* Gets SSP Version.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/components/EditPlaylistPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class EditPlaylistPlayer extends Component {

const {
availablePodcasts,
availableTags,
selectedTag,
limit,
orderBy,
order,
Expand All @@ -45,6 +47,21 @@ class EditPlaylistPlayer extends Component {
}}
/>
</PanelRow>
<PanelRow>
<label htmlFor="ssp-playlist-player-tag">
{__('Select Tag', 'seriously-simple-podcasting')}
</label>
<SelectControl
id="ssp-playlist-player-tag"
value={selectedTag}
options={availableTags}
onChange={(selectedTag) => {
setAttributes({
selectedTag: selectedTag
});
}}
/>
</PanelRow>
<PanelRow>
<label htmlFor="ssp-playlist-player-episodes-limit">
{__('Episodes Limit', 'seriously-simple-podcasting')}
Expand Down

0 comments on commit 59851d8

Please sign in to comment.