PluginProbe
PDF Embed Block – share documents right inside your posts / trunk
PDF Embed Block – share documents right inside your posts vtrunk
1.3.3 1.3.2 1.3.1 1.3.0 trunk 1.0.0 1.0.1 1.0.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5
pdf-embed-block / includes / ShortCode.php

ShortCode.php in PDF Embed Block – share documents right inside your posts trunk, at includes/ShortCode.php

53 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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