PluginProbe
Countdown Timer Block – build urgency for events and launches / trunk
Countdown Timer Block – build urgency for events and launches vtrunk
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 / plugin.php

plugin.php in Countdown Timer Block – build urgency for events and launches trunk, at plugin.php

170 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Countdown Timer
4 * Description: Display your events date into a timer to your visitor with countdown time block
5 * Version: 1.3.3
6 * Author: bPlugins
7 * Author URI: https://bplugins.com
8 * Plugin URI: https://bplugins.com/products/countdown-time
9 * License: GPLv3
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
11 * Text Domain: countdown-time
12 * Requires at least: 6.5
13 * Tested up to: 7.1
14 * Requires PHP: 7.4
15 */
16
17 // ABS PATH
18 if ( !defined( 'ABSPATH' ) ) { exit; }
19
20 if ( function_exists( 'ctb_fs' ) ) {
21 ctb_fs()->set_basename( true, __FILE__ );
22 }else{
23 define( 'CTB_VERSION', ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : '1.3.3' );
24 define( 'CTB_DIR_URL', plugin_dir_url( __FILE__ ) );
25 define( 'CTB_DIR_PATH', plugin_dir_path( __FILE__ ) );
26
27 require_once CTB_DIR_PATH . 'includes/fs-lite.php';
28 require_once CTB_DIR_PATH . 'includes/admin/SubMenu.php';
29 require_once CTB_DIR_PATH . 'includes/Patterns.php';
30
31 if( !class_exists( 'CTBPlugin' ) ){
32 /**
33 * Main plugin class for Countdown Timer.
34 */
35 class CTBPlugin{
36 /**
37 * Constructor. Sets up action and filter hooks.
38 */
39 public function __construct(){
40 add_action( 'init', [ $this, 'onInit' ] );
41 add_filter( 'block_categories_all', [$this, 'blockCategories'] );
42 add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] );
43 add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockEditorAssets'] );
44
45 add_filter( 'plugin_action_links', [$this, 'pluginActionLinks'], 10, 2 );
46 add_filter( 'default_title', [$this, 'defaultTitle'], 10, 2 );
47 add_filter( 'default_content', [$this, 'defaultContent'], 10, 2 );
48 }
49
50 /**
51 * Filter the default title for newly created pages.
52 *
53 * @param string $title Default page title.
54 * @param \WP_Post $post Post object.
55 * @return string Filtered page title.
56 */
57 public function defaultTitle( $title, $post ) {
58 if ( 'page' === $post->post_type && isset( $_GET['title'] ) ) {
59 $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
60
61 if ( wp_verify_nonce( $nonce, 'ctbCreatePage' ) ) {
62 return sanitize_text_field( wp_unslash( $_GET['title'] ) );
63 }
64 }
65 return $title;
66 }
67
68 /**
69 * Filter the default content for newly created pages.
70 *
71 * @param string $content Default page content.
72 * @param \WP_Post $post Post object.
73 * @return string Filtered page content.
74 */
75 public function defaultContent( $content, $post ) {
76 if ( 'page' === $post->post_type && isset( $_GET['content'] ) ) {
77 $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
78
79 if ( wp_verify_nonce( $nonce, 'ctbCreatePage' ) ) {
80 return wp_kses_post( wp_unslash( $_GET['content'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
81 }
82 }
83 return $content;
84 }
85
86 /**
87 * Add custom links to the plugin action links on the plugins page.
88 *
89 * @param array $links Action links array.
90 * @param string $file Plugin filename relative to plugins directory.
91 * @return array Modified action links.
92 */
93 public function pluginActionLinks( $links, $file ) {
94 if( plugin_basename( __FILE__ ) === $file ) {
95 $helpDemosLink = admin_url( 'tools.php?page=countdown-time#/welcome' );
96
97 $links['help-and-demos'] = sprintf( '<a href="%s" style="%s">%s</a>', $helpDemosLink, 'color:#FF7A00;font-weight:bold', __( 'Help & Demos', 'countdown-time' ) );
98 }
99
100 return $links;
101 }
102
103 /**
104 * Initialize the block and register block type.
105 *
106 * @return void
107 */
108 public function onInit(){
109 register_block_type( __DIR__ . '/build' );
110 }
111
112 /**
113 * Add custom block category for Countdown Time.
114 *
115 * @param array $categories Current block categories.
116 * @return array Modified block categories.
117 */
118 public function blockCategories( $categories ){
119 return array_merge( [ [
120 'slug' => 'CTBlock',
121 'title' => 'Countdown Time'
122 ] ], $categories );
123 }
124
125 /**
126 * Enqueue stylesheets and scripts in the admin dashboard page.
127 *
128 * @param string $hook The current admin page hook.
129 * @return void
130 */
131 public function adminEnqueueScripts( $hook ) {
132 if( strpos( $hook, 'countdown-time' ) ){
133 wp_enqueue_style( 'ctb-admin-dashboard', CTB_DIR_URL . 'build/admin/dashboard.css', [], CTB_VERSION );
134
135 $asset_file = include CTB_DIR_PATH . 'build/admin/dashboard.asset.php';
136 wp_enqueue_script( 'ctb-admin-dashboard', CTB_DIR_URL . 'build/admin/dashboard.js', array_merge( $asset_file['dependencies'], [ 'wp-util' ] ), CTB_VERSION, true );
137 wp_set_script_translations( 'ctb-admin-dashboard', 'countdown-time', CTB_DIR_PATH . 'languages' );
138 }
139 }
140
141 /**
142 * Add inline script for the block editor.
143 *
144 * @return void
145 */
146 public function enqueueBlockEditorAssets(){
147 wp_add_inline_script( 'ctb-countdown-time-editor-script', 'const ctbpricingurl = "'. admin_url( 'tools.php?page=countdown-time#/pricing' ) .'";', 'before' );
148 }
149
150 /**
151 * Render the admin dashboard wrapper div.
152 *
153 * @return void
154 */
155 public static function renderDashboard(){ ?>
156 <div
157 id='ctbDashboard'
158 data-info='<?php echo esc_attr( wp_json_encode( [
159 'version' => CTB_VERSION,
160 'isPremium' => false,
161 'hasPro' => false,
162 'adminUrl' => admin_url(),
163 'startUrl' => admin_url( 'post-new.php?post_type=page&title=Countdown&content=' . rawurlencode( '<!-- wp:ctb/countdown-time /-->' ) . '&nonce=' . wp_create_nonce( 'ctbCreatePage' ) )
164 ] ) ); ?>'
165 ></div>
166 <?php }
167 }
168 new CTBPlugin;
169 }
170 }