/** * Display a meta box to choose which theme-registered players to connect a * playlist with. * * @since 1.1.0 * * @param WP_Post $post Post object. */ public function display_playlist_players_meta_box($post) { wp_nonce_field('save-playlist-players_' . $post->ID, 'cue_playlist_players_nonce'); printf('<p>%s</p>', __('Choose which players should use this playlist:', 'cue')); $players = get_cue_players(); echo '<ul style="margin-bottom: 0">'; foreach ($players as $id => $player) { printf('<li><label><input type="checkbox" name="cue_players[]" value="%2$s"%3$s> %1$s</label></li>', esc_html($player['name']), esc_attr($player['id']), checked($player['playlist_id'], $post->ID, false)); } echo '</ul>'; }
/** * Add a Customizer section for selecting playlists for registered players. * * @since 1.1.1 * * @param WP_Customize_Manager $wp_customize Customizer instance. */ public function customize_register($wp_customize) { $description = ''; $players = get_cue_players(); if (empty($players)) { return; } $playlists = get_posts(array('post_type' => 'cue_playlist', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'asc')); $wp_customize->add_section('cue', array('title' => __('Cue Players', 'cue'), 'description' => __('Choose a playlist for each registered player.', 'cue'), 'priority' => 115)); if (empty($playlists)) { $playlists = array(); $description = sprintf(__('<a href="%s">Create a playlist</a> for this player.', 'cue'), admin_url('post-new.php?post_type=cue_playlist')); } else { // Create an array: ID => post_title $playlists = array_combine(wp_list_pluck($playlists, 'ID'), wp_list_pluck($playlists, 'post_title')); } $playlists = array(0 => '') + $playlists; foreach ($players as $id => $player) { $id = sanitize_key($id); $wp_customize->add_setting('cue_players[' . $id . ']', array('capability' => 'edit_theme_options', 'sanitize_callback' => 'absint')); $wp_customize->add_control('cue_player_' . $id, array('choices' => $playlists, 'description' => $description, 'label' => $player['name'], 'section' => 'cue', 'settings' => 'cue_players[' . $id . ']', 'type' => 'select')); } }