| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Countdown Timer |
| 5 |
* Description: Display your events date into a timer to your visitor with countdown time block |
| 6 |
* Version: 1.3.0 |
| 7 |
* Author: bPlugins |
| 8 |
* Author URI: https://bplugins.com |
| 9 |
* License: GPLv3 |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 11 |
* Text Domain: countdown-time |
| 12 |
*/ |
| 13 |
// ABS PATH |
| 14 |
if ( !defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
if ( function_exists( 'ctb_fs' ) ) { |
| 18 |
ctb_fs()->set_basename( false, __FILE__ ); |
| 19 |
} else { |
| 20 |
define( 'CTB_VERSION', ( isset( $_SERVER['HTTP_HOST'] ) && 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '1.3.0' ) ); |
| 21 |
define( 'CTB_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 22 |
define( 'CTB_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 23 |
define( 'CTB_HAS_PRO', file_exists( dirname( __FILE__ ) . '/vendor/freemius/start.php' ) ); |
| 24 |
function ctb_fs() { |
| 25 |
global $ctb_fs; |
| 26 |
if ( !isset( $ctb_fs ) ) { |
| 27 |
if ( CTB_HAS_PRO ) { |
| 28 |
require_once dirname( __FILE__ ) . '/vendor/freemius/start.php'; |
| 29 |
} else { |
| 30 |
require_once dirname( __FILE__ ) . '/vendor/freemius-lite/start.php'; |
| 31 |
} |
| 32 |
$ctbConfig = [ |
| 33 |
'id' => '14562', |
| 34 |
'slug' => 'countdown-time', |
| 35 |
'premium_slug' => 'countdown-time-pro', |
| 36 |
'type' => 'plugin', |
| 37 |
'public_key' => 'pk_7f62446a2a53154c56c36346db2fa', |
| 38 |
'is_premium' => false, |
| 39 |
'premium_suffix' => 'Pro', |
| 40 |
'has_premium_version' => true, |
| 41 |
'has_addons' => false, |
| 42 |
'has_paid_plans' => true, |
| 43 |
'trial' => [ |
| 44 |
'days' => 7, |
| 45 |
'is_require_payment' => false, |
| 46 |
], |
| 47 |
'menu' => ( CTB_HAS_PRO ? [ |
| 48 |
'slug' => 'countdown-time', |
| 49 |
'first-path' => 'admin.php?page=countdown-time', |
| 50 |
'contact' => false, |
| 51 |
'support' => false, |
| 52 |
] : [ |
| 53 |
'slug' => 'countdown-time', |
| 54 |
'override_exact' => true, |
| 55 |
'first-path' => 'tools.php?page=countdown-time', |
| 56 |
'contact' => false, |
| 57 |
'support' => false, |
| 58 |
'parent' => [ |
| 59 |
'slug' => 'tools.php', |
| 60 |
], |
| 61 |
] ), |
| 62 |
]; |
| 63 |
$ctb_fs = ( CTB_HAS_PRO ? fs_dynamic_init( $ctbConfig ) : fs_lite_dynamic_init( $ctbConfig ) ); |
| 64 |
} |
| 65 |
return $ctb_fs; |
| 66 |
} |
| 67 |
|
| 68 |
ctb_fs(); |
| 69 |
do_action( 'ctb_fs_loaded' ); |
| 70 |
function ctbIsPremium() { |
| 71 |
return ( CTB_HAS_PRO ? ctb_fs()->can_use_premium_code() : false ); |
| 72 |
} |
| 73 |
|
| 74 |
// Require Files |
| 75 |
require_once CTB_DIR_PATH . '/includes/pattern.php'; |
| 76 |
if ( CTB_HAS_PRO ) { |
| 77 |
require_once CTB_DIR_PATH . 'includes/admin/Menu.php'; |
| 78 |
} else { |
| 79 |
require_once CTB_DIR_PATH . 'includes/admin/SubMenu.php'; |
| 80 |
} |
| 81 |
if ( CTB_HAS_PRO && ctbIsPremium() ) { |
| 82 |
require_once CTB_DIR_PATH . 'includes/admin/CPT.php'; |
| 83 |
} |
| 84 |
class CTBPlugin { |
| 85 |
function __construct() { |
| 86 |
add_filter( 'block_categories_all', [$this, 'blockCategories'] ); |
| 87 |
add_action( 'init', [$this, 'onInit'] ); |
| 88 |
add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] ); |
| 89 |
add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockEditorAssets'] ); |
| 90 |
} |
| 91 |
|
| 92 |
function blockCategories( $categories ) { |
| 93 |
return array_merge( [[ |
| 94 |
'slug' => 'CTBlock', |
| 95 |
'title' => 'Countdown Time', |
| 96 |
]], $categories ); |
| 97 |
} |
| 98 |
|
| 99 |
function onInit() { |
| 100 |
register_block_type( __DIR__ . '/build' ); |
| 101 |
} |
| 102 |
|
| 103 |
function adminEnqueueScripts( $hook ) { |
| 104 |
if ( strpos( $hook, 'countdown-time' ) ) { |
| 105 |
wp_enqueue_style( |
| 106 |
'ctb-admin-dashboard', |
| 107 |
CTB_DIR_URL . 'build/admin-dashboard.css', |
| 108 |
[], |
| 109 |
CTB_VERSION |
| 110 |
); |
| 111 |
wp_enqueue_script( |
| 112 |
'ctb-admin-dashboard', |
| 113 |
CTB_DIR_URL . 'build/admin-dashboard.js', |
| 114 |
['react', 'react-dom'], |
| 115 |
CTB_VERSION, |
| 116 |
true |
| 117 |
); |
| 118 |
wp_set_script_translations( 'ctb-admin-dashboard', 'countdown-time', CTB_DIR_PATH . 'languages' ); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
function enqueueBlockEditorAssets() { |
| 123 |
wp_add_inline_script( 'ctb-countdown-time-editor-script', 'const ctppipecheck = ' . wp_json_encode( ctbIsPremium() ) . ';', 'before' ); |
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
new CTBPlugin(); |
| 129 |
} |