PluginProbe
Team Section Block – Showcase Team Members with Layout Options / trunk
Team Section Block – Showcase Team Members with Layout Options vtrunk
2.0.4 2.0.3 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 2.0.0 2.0.1 2.0.2
team-section / includes / rootPlugin / ShortCode.php

ShortCode.php in Team Section Block – Showcase Team Members with Layout Options trunk, at includes/rootPlugin/ShortCode.php

60 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 TSB;
3
4 class ShortCode {
5 private $post_type = 'tsb';
6
7 function __construct() {
8 add_shortcode( 'tsb', [$this, 'onAddShortcode'] );
9 add_action( 'use_block_editor_for_post', [$this, 'useBlockEditorForPost'], 999, 2 );
10 }
11
12 function onAddShortcode( $atts ) {
13 $post_id = $atts['id'];
14 $post = get_post( $post_id );
15
16 if ( !$post ) {
17 return '';
18 }
19
20 if ( post_password_required( $post ) ) {
21 return get_the_password_form( $post );
22 }
23
24 switch ( $post->post_status ) {
25 case 'publish':
26 return $this->displayContent( $post );
27
28 case 'private':
29 if ( current_user_can( 'read_private_posts' ) ) {
30 return $this->displayContent( $post );
31 }
32 return '';
33
34 case 'draft':
35 case 'pending':
36 case 'future':
37 if ( current_user_can( 'edit_post', $post_id ) ) {
38 return $this->displayContent( $post );
39 }
40 return '';
41
42 default:
43 return '';
44 }
45 }
46
47 function displayContent( $post ) {
48 $content = apply_filters( 'the_content', $post->post_content );
49 return $content;
50 }
51
52 function useBlockEditorForPost( $use, $post ){
53 if ( is_object( $post ) && isset( $post->post_type ) && $this->post_type === $post->post_type ) {
54 return true;
55 }
56 return $use;
57 }
58
59 }
60