| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
add_shortcode('player', function ($atts) { |
| 7 |
extract(shortcode_atts(array( |
| 8 |
'id' => null, |
| 9 |
), $atts)); |
| 10 |
|
| 11 |
|
| 12 |
$post_id = esc_html($atts['id']); |
| 13 |
$post = get_post($id); |
| 14 |
if (!$post) { |
| 15 |
return ''; |
| 16 |
} |
| 17 |
|
| 18 |
// Enqueue necessary assets for the player to function |
| 19 |
wp_enqueue_style('h5ap-public'); |
| 20 |
wp_enqueue_style('bplugins-plyrio'); |
| 21 |
wp_enqueue_script('bplugins-plyrio'); |
| 22 |
|
| 23 |
// Enqueue block assets manually as render_block doesn't handle it for shortcodes |
| 24 |
wp_enqueue_script('h5ap-audioplayer-view-script'); |
| 25 |
wp_enqueue_style('h5ap-audioplayer-style'); |
| 26 |
wp_enqueue_script('h5ap-radio-player-view-script'); |
| 27 |
wp_enqueue_style('h5ap-radio-player-style'); |
| 28 |
|
| 29 |
if (post_password_required($post)) { |
| 30 |
return get_the_password_form($post); |
| 31 |
} |
| 32 |
switch ($post->post_status) { |
| 33 |
case 'publish': |
| 34 |
return h5ap_player_shortcode_content($post_id); |
| 35 |
case 'private': |
| 36 |
if (current_user_can('read_private_posts')) { |
| 37 |
return h5ap_player_shortcode_content($post_id); |
| 38 |
} |
| 39 |
return ''; |
| 40 |
case 'draft': |
| 41 |
case 'pending': |
| 42 |
case 'future': |
| 43 |
if (current_user_can('edit_post', $post_id)) { |
| 44 |
return h5ap_player_shortcode_content($post_id); |
| 45 |
} |
| 46 |
return ''; |
| 47 |
default: |
| 48 |
return ''; |
| 49 |
} |
| 50 |
}); |
| 51 |
|
| 52 |
if (!function_exists('h5ap_player_shortcode_content')) { |
| 53 |
function h5ap_player_shortcode_content($post_id) |
| 54 |
{ |
| 55 |
|
| 56 |
$meta = h5ap_get_post_meta($post_id, '_h5ap_plyr'); |
| 57 |
$type = $meta('h5ap_player_type', 'opt-1'); |
| 58 |
$player_theme = $meta('player_theme'); |
| 59 |
$player_skin = $meta('player_skin'); |
| 60 |
$h5vp_default_audio = $meta('h5vp_default_audio'); |
| 61 |
$width = $meta('width', ['width' => '100', 'unit' => '%']); |
| 62 |
$playlist_type = $meta('playlist_type'); |
| 63 |
$playlist_in_metabox = $meta('playlist_in_metabox', []); |
| 64 |
|
| 65 |
$sticky_simple_background = $meta('sticky_simple_background'); |
| 66 |
$forward_rewind_change_audio = $meta('forward_rewind_change_audio'); |
| 67 |
$plp_width = $meta('plp_width', ['width' => '100', 'unit' => '%']); |
| 68 |
$plp_align = $meta('plp_align'); |
| 69 |
$plp_volume = $meta('plp_volume'); |
| 70 |
$sticky_download = $meta('sticky_download'); |
| 71 |
$sticky_volume = $meta('sticky_volume'); |
| 72 |
$selected_audio = $meta('selected_audio'); |
| 73 |
|
| 74 |
$tracks = []; |
| 75 |
|
| 76 |
|
| 77 |
if ($playlist_type !== 'create' && is_array($selected_audio)) { |
| 78 |
foreach ($selected_audio as $id) { |
| 79 |
$playlist_ids = get_post_meta($id, '_h5applaylist'); |
| 80 |
|
| 81 |
foreach ($playlist_ids as $audios) { |
| 82 |
foreach ($audios as $audio) { |
| 83 |
if ($audio['audio'] !== '') { |
| 84 |
$tracks[] = wp_parse_args(['source' => h5ap_resolve_gdrive_url(h5ap_resolve_soundcloud_url($audio['audio']))], $audio); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
} else { |
| 90 |
if (is_array($playlist_in_metabox) && !empty($playlist_in_metabox)) { |
| 91 |
foreach ($playlist_in_metabox as $audio) { |
| 92 |
$tracks[] = [ |
| 93 |
'title' => $audio['pl_audio_title'], |
| 94 |
'source' => h5ap_resolve_gdrive_url(h5ap_resolve_soundcloud_url($audio['pl_audio_file'])), |
| 95 |
'poster' => $audio['pl_audio_poster'], |
| 96 |
'artist' => $audio['pl_audio_artist'] |
| 97 |
]; |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
$block_types = [ |
| 105 |
'opt-1' => 'audioplayer', |
| 106 |
'opt-2' => 'playlist' . $player_skin, |
| 107 |
'opt-3' => 'audioplayer', |
| 108 |
]; |
| 109 |
|
| 110 |
if (file_exists(__DIR__ . '/blocks/' . $block_types[$type] . '.php')) { |
| 111 |
$block = []; |
| 112 |
include __DIR__ . '/blocks/' . $block_types[$type] . '.php'; |
| 113 |
return render_block($block); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|