PluginProbe
Countdown Timer Block – build urgency for events and launches / 1.2.4
Countdown Timer Block – build urgency for events and launches v1.2.4
1.3.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 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 32 releases
countdown-time / inc / CustomPost.php

CustomPost.php in Countdown Timer Block – build urgency for events and launches 1.2.4, at inc/CustomPost.php

114 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class CTBCustomPost{
3 public $post_type = 'ctb';
4
5 public function __construct(){
6 add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] );
7 add_action( 'init', [$this, 'onInit'] );
8 add_shortcode( 'ctb', [$this, 'onAddShortcode'] );
9 add_filter( 'manage_ctb_posts_columns', [$this, 'manageCTBPostsColumns'], 10 );
10 add_action( 'manage_ctb_posts_custom_column', [$this, 'manageCTBPostsCustomColumns'], 10, 2 );
11 add_action( 'use_block_editor_for_post', [$this, 'useBlockEditorForPost'], 999, 2 );
12 add_filter( 'custom_menu_order', [$this, 'orderSubMenu'] );
13 }
14
15 function adminEnqueueScripts( $hook ){
16 if( 'edit.php' === $hook || 'post.php' === $hook ){
17 wp_enqueue_style( 'ctb-admin-post', CTB_DIR_URL . 'dist/admin-post.css', [], CTB_VERSION );
18 wp_enqueue_script( 'ctb-admin-post', CTB_DIR_URL . 'dist/admin-post.js', [], CTB_VERSION );
19 wp_set_script_translations( 'ctb-admin-post', 'countdown-time', CTB_DIR_PATH . 'languages' );
20 }
21 }
22
23 function onInit(){
24 $menuIcon = "<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 512 512' fill='#fff'><path d='m288 48h-64a24 24 0 0 1 0-48h64a24 24 0 0 1 0 48z' /><path d='m414.392 129.608c-1.867-1.867-3.772-3.684-5.692-5.477l19.963-26.769a8 8 0 0 0 -1.63-11.195l-25.65-19.13a8 8 0 0 0 -11.2 1.631l-19.844 26.614a224.63 224.63 0 1 0 44.053 34.326zm-158.392 350.392c-105.869 0-192-86.131-192-192s86.131-192 192-192 192 86.131 192 192-86.131 192-192 192z' /><path d='m408 296h-152a8 8 0 0 1 -8-8v-152a8 8 0 0 1 8-8c88.224 0 160 71.775 160 160a8 8 0 0 1 -8 8z' /><circle cx='201.421' cy='145.912' r='8' /><circle cx='160.185' cy='169.732' r='8' /><circle cx='128.327' cy='205.129' r='8' /><circle cx='108.967' cy='248.638' r='8' /><circle cx='104' cy='296' r='8' /><circle cx='113.912' cy='342.579' r='8' /><circle cx='137.732' cy='383.815' r='8' /><circle cx='173.129' cy='415.673' r='8' /><circle cx='216.638' cy='435.033' r='8' /><circle cx='264' cy='440' r='8' /><circle cx='310.579' cy='430.088' r='8' /><circle cx='351.815' cy='406.268' r='8' /><circle cx='383.673' cy='370.871' r='8' /><circle cx='403.033' cy='327.362' r='8' /></svg>";
25
26 register_post_type( 'ctb', [
27 'labels' => [
28 'name' => __( 'Countdown Time', 'countdown-time'),
29 'singular_name' => __( 'Countdown Time', 'countdown-time' ),
30 'add_new' => __( 'Add New', 'countdown-time' ),
31 'add_new_item' => __( 'Add New', 'countdown-time' ),
32 'edit_item' => __( 'Edit', 'countdown-time' ),
33 'new_item' => __( 'New', 'countdown-time' ),
34 'view_item' => __( 'View', 'countdown-time' ),
35 'search_items' => __( 'Search', 'countdown-time'),
36 'not_found' => __( 'Sorry, we couldn\'t find the that you are looking for.', 'countdown-time' )
37 ],
38 'public' => false,
39 'show_ui' => true,
40 'show_in_rest' => true,
41 'publicly_queryable' => false,
42 'exclude_from_search' => true,
43 'menu_position' => 14,
44 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode( $menuIcon ),
45 'has_archive' => false,
46 'hierarchical' => false,
47 'capability_type' => 'page',
48 'rewrite' => [ 'slug' => 'ctb' ],
49 'supports' => [ 'title', 'editor' ],
50 'template' => [ ['ctb/countdown-time'] ],
51 'template_lock' => 'all',
52 ]); // Register Post Type
53 }
54
55 function onAddShortcode( $atts ) {
56 $post_id = $atts['id'];
57
58 $post = get_post( $post_id );
59 $blocks = parse_blocks( $post->post_content );
60
61 ob_start();
62 echo render_block($blocks[0]);
63
64 return ob_get_clean();
65 }
66
67 function manageCTBPostsColumns( $defaults ) {
68 unset( $defaults['date'] );
69 $defaults['shortcode'] = 'ShortCode';
70 $defaults['date'] = 'Date';
71 return $defaults;
72 }
73
74 function manageCTBPostsCustomColumns( $column_name, $post_ID ) {
75 if ( $column_name == 'shortcode' ) {
76 echo "<div class='ctbFrontShortcode' id='ctbFrontShortcode-$post_ID'>
77 <input value='[ctb id=$post_ID]' onclick='ctbHandleShortcode( $post_ID )'>
78 <span class='tooltip'>Copy To Clipboard</span>
79 </div>";
80 }
81 }
82
83 function useBlockEditorForPost($use, $post){
84 if ( $this->post_type === $post->post_type ) {
85 return true;
86 }
87 return $use;
88 }
89
90 function orderSubMenu( $menu_ord ){
91 global $submenu;
92
93 $sMenu = $submenu['edit.php?post_type=ctb'];
94 $arr = [];
95 if( CTB_HAS_PRO && ctbIsPremium() ){
96 if( isset( $sMenu[5] ) ){
97 $arr[] = $sMenu[5]; // Countdown Time
98 }
99 if( isset( $sMenu[10] ) ){
100 $arr[] = $sMenu[10]; // Add New
101 }
102 }
103 if( isset( $sMenu[11] ) ){
104 $arr[] = $sMenu[11]; // Help
105 }
106 if( isset( $sMenu[12] ) ){
107 $arr[] = $sMenu[12]; // Upgrade FS or Account
108 }
109 $submenu['edit.php?post_type=ctb'] = $arr;
110
111 return $menu_ord;
112 }
113 }
114 new CTBCustomPost();