";
register_post_type( 'ctb', [
'labels' => [
'name' => __( 'Countdown Time', 'countdown-time'),
'singular_name' => __( 'Countdown Time', 'countdown-time' ),
'add_new' => __( 'Add New', 'countdown-time' ),
'add_new_item' => __( 'Add New', 'countdown-time' ),
'edit_item' => __( 'Edit', 'countdown-time' ),
'new_item' => __( 'New', 'countdown-time' ),
'view_item' => __( 'View', 'countdown-time' ),
'search_items' => __( 'Search', 'countdown-time'),
'not_found' => __( 'Sorry, we couldn\'t find the that you are looking for.', 'countdown-time' )
],
'public' => false,
'show_ui' => true,
'show_in_rest' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'menu_position' => 14,
'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode( $menuIcon ),
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => [ 'slug' => 'ctb' ],
'supports' => [ 'title', 'editor' ],
'template' => [ ['ctb/countdown-time'] ],
'template_lock' => 'all',
]); // Register Post Type
}
function onAddShortcode( $atts ) {
$post_id = $atts['id'];
$post = get_post( $post_id );
if ( !$post ) {
return '';
}
if ( post_password_required( $post ) ) {
return get_the_password_form( $post );
}
switch ( $post->post_status ) {
case 'publish':
return $this->displayContent( $post );
case 'private':
if (current_user_can('read_private_posts')) {
return $this->displayContent( $post );
}
return '';
case 'draft':
case 'pending':
case 'future':
if ( current_user_can( 'edit_post', $post_id ) ) {
return $this->displayContent( $post );
}
return '';
default:
return '';
}
}
function displayContent( $post ){
$blocks = parse_blocks( $post->post_content );
global $allowedposttags;
$allowed_html = wp_parse_args( ['style' => [] ], $allowedposttags );
return wp_kses( render_block( $blocks[0] ), $allowed_html );
}
function manageCTBPostsColumns( $defaults ) {
unset( $defaults['date'] );
$defaults['shortcode'] = 'ShortCode';
$defaults['date'] = 'Date';
return $defaults;
}
function manageCTBPostsCustomColumns( $column_name, $post_ID ) {
if ( $column_name == 'shortcode' ) {
echo "
Copy To Clipboard
";
}
}
function useBlockEditorForPost( $use, $post ){
if ( $this->post_type === $post->post_type ) {
return true;
}
return $use;
}
function orderSubMenu( $menu_ord ){
global $submenu;
$sMenu = $submenu['edit.php?post_type=ctb'] ?? [];
$arr = [];
if( CTB_HAS_PRO && ctbIsPremium() ){
if( isset( $sMenu[5] ) ){
$arr[] = $sMenu[5]; // Countdown Time
}
if( isset( $sMenu[10] ) ){
$arr[] = $sMenu[10]; // Add New
}
}
if( isset( $sMenu[11] ) ){
$arr[] = $sMenu[11]; // Help
}
if( isset( $sMenu[12] ) ){
$arr[] = $sMenu[12]; // Upgrade FS or Account
}
$submenu['edit.php?post_type=ctb'] = $arr;
return $menu_ord;
}
}
new CTBCustomPost();