| 1 |
<?php |
| 2 |
namespace PEB; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Shortcode { |
| 9 |
function __construct() { |
| 10 |
add_shortcode('pdf_embed', [$this, 'peb_shortcode']); |
| 11 |
} |
| 12 |
|
| 13 |
function peb_shortcode($atts){ |
| 14 |
$post_id = $atts['id']; |
| 15 |
$post = get_post( $post_id ); |
| 16 |
|
| 17 |
if ( !$post ) { |
| 18 |
return ''; |
| 19 |
} |
| 20 |
|
| 21 |
if ( post_password_required( $post ) ) { |
| 22 |
return get_the_password_form( $post ); |
| 23 |
} |
| 24 |
|
| 25 |
switch ( $post->post_status ) { |
| 26 |
case 'publish': |
| 27 |
return $this->displayContent( $post ); |
| 28 |
|
| 29 |
case 'private': |
| 30 |
if (current_user_can('read_private_posts')) { |
| 31 |
return $this->displayContent( $post ); |
| 32 |
} |
| 33 |
return ''; |
| 34 |
|
| 35 |
case 'draft': |
| 36 |
case 'pending': |
| 37 |
case 'future': |
| 38 |
if ( current_user_can( 'edit_post', $post_id ) ) { |
| 39 |
return $this->displayContent( $post ); |
| 40 |
} |
| 41 |
return ''; |
| 42 |
|
| 43 |
default: |
| 44 |
return ''; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
function displayContent( $post ){ |
| 49 |
$blocks = parse_blocks( $post->post_content ); |
| 50 |
return render_block( $blocks[0] ); |
| 51 |
} |
| 52 |
} |
| 53 |
|