PluginProbe
Audio Player Block – Play Audio Beautifully on Any Page / trunk
Audio Player Block – Play Audio Beautifully on Any Page vtrunk
1.6.2 1.6.1 1.6.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 37 releases
audio-player-block / includes / ShortCode.php

ShortCode.php in Audio Player Block – Play Audio Beautifully on Any Page trunk, at includes/ShortCode.php

62 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BPMP;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Shortcode {
10 function __construct() {
11 add_shortcode('audio_player', [$this, 'bpmp_audio_player_block_shortcode']);
12 }
13
14 function bpmp_audio_player_block_shortcode($atts){
15
16 if (!isset($atts['id'])) {
17 return esc_html__( 'Error: Missing Audio Player ID.', 'audio-player-block' );
18 }
19
20 $post_id = $atts['id'];
21 $post = get_post( $post_id );
22
23 if ( !$post ) {
24 return '';
25 }
26
27 if ( post_password_required( $post ) ) {
28 return get_the_password_form( $post );
29 }
30
31 switch ( $post->post_status ) {
32 case 'publish':
33 return $this->displayContent( $post );
34
35 case 'private':
36 if (current_user_can('read_private_posts')) {
37 return $this->displayContent( $post );
38 }
39 return '';
40
41 case 'draft':
42 case 'pending':
43 case 'future':
44 if ( current_user_can( 'edit_post', $post_id ) ) {
45 return $this->displayContent( $post );
46 }
47 return '';
48
49 default:
50 return '';
51 }
52 }
53
54 function displayContent( $post ){
55 $blocks = parse_blocks( $post->post_content );
56 if ( ! empty( $blocks ) && isset( $blocks[0] ) ) {
57 return render_block( $blocks[0] );
58 }
59 return '';
60 }
61 }
62