This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dead-simple-countdown-widget.php
107 lines (95 loc) · 2.75 KB
/
dead-simple-countdown-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Plugin Name: Dead Simple Countdown Widget
* Plugin URI: https://github.com/DaveLak/dead-simple-countdown-widget
* Description: A dead simple plugin that adds a countdown timer widget
* Author: David Lakin
* Version: 2.0.0
* Author URI: #
* License: GPLv2 or later
* Text Domain: dead_simple_countdown
*
* @package Dead_Simple_Countdown_Widget
* @since 1.0.0
*
* @author David Lakin <[email protected]>
* @license GPLv2 or later
* @link https://github.com/DaveLak/dead-simple-countdown-widget
* @copyright Copyright (c) 2018, David Lakin
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* The absolute URL to this file **WITH trailing slash**.
* Used when requesting assets.
*/
if ( ! defined( 'DSCW_COUNTDOWN_TIMER_URL' ) ) {
define( 'DSCW_COUNTDOWN_TIMER_URL', plugin_dir_url( __FILE__ ) );
}
/**
* The absolute filesystem directory path to this file **WITH trailing slash**.
* Used when including PHP files
*/
if ( ! defined( 'DSCW_COUNTDOWN_TIMER_PATH' ) ) {
define( 'DSCW_COUNTDOWN_TIMER_PATH', plugin_dir_path( __FILE__ ) );
}
/**
* The current version of the plugin.
* Used to cache bust assets and check for available features.
*/
if ( ! defined( 'DSCW_VERSION' ) ) {
define( 'DSCW_VERSION', '2.0.0' );
}
/**
* Register CountDown widget class
*/
function dscw_countdown_register_widget() {
/**
* Require Dead_Simple_CountDown_Widget class.
*/
require_once DSCW_COUNTDOWN_TIMER_PATH . 'inc/class-dead-simple-countdown-widget.php';
register_widget( 'Dead_Simple_CountDown_Widget' );
}
add_action( 'widgets_init', 'dscw_countdown_register_widget' );
/**
* Register scripts and styles for use in the front end
*/
function dscw_countdown_register_assets() {
// Front end JS.
wp_register_script(
'dead-simple-countdown-widget-js',
DSCW_COUNTDOWN_TIMER_URL . 'built/assets/front-end/js/countdown-timer.min.js',
array( 'jquery' ),
DSCW_VERSION,
true
);
// Front end styles.
wp_register_style(
'dead-simple-countdown-widget-styles',
DSCW_COUNTDOWN_TIMER_URL . 'built/assets/front-end/css/countdown-timer.min.css',
array(),
DSCW_VERSION
);
}
add_action( 'wp_enqueue_scripts', 'dscw_countdown_register_assets' );
/**
* Register scripts and styles for use in the admin
*
* @param string $page The current admin page.
*/
function dscw_countdown_admin_scripts( $page ) {
// Admin Styles.
wp_register_style(
'dscw-jquery-base-theme-styles',
DSCW_COUNTDOWN_TIMER_URL . 'built/assets/admin/css/jquery-ui-base-theme.min.css',
array(),
'1.0.0'
);
// Enqueue only if we are on widgets admin page.
if ( 'widgets.php' === $page ) {
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style( 'dscw-jquery-base-theme-styles' );
}
}
add_action( 'admin_enqueue_scripts', 'dscw_countdown_admin_scripts' );