PluginProbe
Team Section Block – Showcase Team Members with Layout Options / 2.0.0
Team Section Block – Showcase Team Members with Layout Options v2.0.0
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 / ShortCode.php

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

119 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( !defined( 'ABSPATH' ) ) { exit; }
4 class TSB_Shortcode {
5 private $post_type = 'tsb';
6 public function __construct() {
7 add_shortcode( 'tsb', [$this, 'onAddShortcode'] );
8 add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] );
9 add_action( 'init', [$this, 'onInit'] );
10 add_filter( 'manage_tsb_posts_columns', [$this, 'manageTSBPostsColumns'], 10 );
11 add_action( 'manage_tsb_posts_custom_column', [$this, 'manageTSBPostsCustomColumns'], 10, 2 );
12
13 add_action( 'use_block_editor_for_post', [$this, 'useBlockEditorForPost'], 999, 2 );
14 }
15
16 function onInit(){
17
18
19 register_post_type( 'tsb', [
20 'labels' => [
21 'name' => __( 'Team Section', 'team-section' ),
22 'singular_name' => __( 'ShortCode', 'team-section' ),
23 'add_new_item' => __( 'Add New ShortCode', 'team-section' ),
24 'edit_item' => __( 'Edit ShortCode', 'team-section' ),
25 'new_item' => __( 'New ShortCode', 'team-section' ),
26 'view_item' => __( 'View ShortCode', 'team-section' ),
27 'search_items' => __( 'Search ShortCodes', 'team-section' ),
28 'not_found' => __( 'Sorry, we couldn\'t find the ShortCode you are looking for.', 'team-section' )
29 ],
30 'public' => false,
31 'show_ui' => true,
32 'show_in_rest' => true,
33 'publicly_queryable' => false,
34 'show_in_menu' => true,
35 'exclude_from_search' => true,
36 'menu_position' => 14,
37 'menu_icon' => 'dashicons-groups',
38 'has_archive' => false,
39 'hierarchical' => false,
40 'capability_type' => 'page',
41 'rewrite' => [ 'slug' => 'apb' ],
42 'supports' => [ 'title', 'editor' ],
43 'template' => [ [ 'tsb/team' ] ],
44 'template_lock' => "all",
45 ] );
46 }
47
48 function onAddShortcode( $atts ) {
49 $post_id = $atts['id'];
50 $post = get_post( $post_id );
51
52 if ( !$post ) {
53 return '';
54 }
55
56 if ( post_password_required( $post ) ) {
57 return get_the_password_form( $post );
58 }
59
60 switch ( $post->post_status ) {
61 case 'publish':
62 return $this->displayContent( $post );
63
64 case 'private':
65 if ( current_user_can( 'read_private_posts' ) ) {
66 return $this->displayContent( $post );
67 }
68 return '';
69
70 case 'draft':
71 case 'pending':
72 case 'future':
73 if ( current_user_can( 'edit_post', $post_id ) ) {
74 return $this->displayContent( $post );
75 }
76 return '';
77
78 default:
79 return '';
80 }
81 }
82
83 function displayContent( $post ) {
84 $content = apply_filters( 'the_content', $post->post_content );
85 return $content;
86 }
87
88 function manageTSBPostsColumns( $defaults ) {
89 unset( $defaults['date'] );
90 $defaults['shortcode'] = 'ShortCode';
91 $defaults['date'] = 'Date';
92 return $defaults;
93 }
94
95 function manageTSBPostsCustomColumns( $column_name, $post_ID ) {
96 if ( $column_name == 'shortcode' ) {
97 echo '<div class="bPlAdminShortcode" id="bPlAdminShortcode-' . esc_attr( $post_ID ) . '">
98 <input value="[tsb id=' . esc_attr( $post_ID ) . ']" onclick="copyBPlAdminShortcode(\'' . esc_attr( $post_ID ) . '\')">
99 <span class="tooltip">' . esc_html__( 'Copy To Clipboard', 'team-section' ) . '</span>
100 </div>';
101 }
102 }
103
104 function useBlockEditorForPost( $use, $post ){
105 if ( is_object( $post ) && isset( $post->post_type ) && $this->post_type === $post->post_type ) {
106 return true;
107 }
108 return $use;
109 }
110 function adminEnqueueScripts( $hook ){
111 if( 'edit.php' === $hook || 'post.php' === $hook ){
112 wp_enqueue_style( 'tsb-admin-post', TSB_DIR_URL . 'build/admin-post.css', [], TSB_VERSION );
113 wp_enqueue_script( 'tsb-admin-post', TSB_DIR_URL . 'build/admin-post.js', [], TSB_VERSION, true );
114 wp_set_script_translations( 'tsb-admin-post', 'team-section', TSB_DIR_PATH . 'languages' );
115 }
116 }
117
118 }
119 new TSB_Shortcode();