PluginProbe
Simple Digital Clock 🕒 / trunk
Simple Digital Clock 🕒 vtrunk
1.1.0 1.1.1 trunk 0.1.0 0.1.1 0.2.0 0.2.1 1.0.0 1.0.1 1.0.3 1.0.4 1.0.5
simple-digital-clock / widget_init.php

widget_init.php in Simple Digital Clock 🕒 trunk, at widget_init.php

195 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @version 1.1.1
5 */
6
7 /*
8 Plugin Name: Simple Digital Clock 🕒
9 Plugin URI: https://utctime.info/
10 Description: It is 🪄 a magical and easy-to-use digital clock with a beautiful UI, supporting multiple languages, locales, dates, captions, and time zones.
11 Version: 1.1.1
12 Author: UTCTime.info
13 Author URI: https://utctime.info/
14 License: GPLv2 or later
15 Text Domain: simple-digital-clock
16 Domain Path: /languages
17 */
18
19 // Exit if accessed directly.
20 if (!defined('ABSPATH')) {
21 exit;
22 }
23 // Exit if accessed directly
24
25 define('SDCW_PATH', plugin_dir_path(__FILE__));
26 define('SDCW_URL', plugin_dir_url(__FILE__));
27 define('SDCW_NAME', 'Simple Digital Clock 🕒');
28 define('SDCW_PLUGIN_SLUG', 'simple-digital-clock');
29
30 class SDCW_digital_clock_widget
31 {
32 protected static $_instance = null;
33
34 public static function get_instance()
35 {
36 if (!self::$_instance) {
37 self::$_instance = new self();
38 }
39
40 return self::$_instance;
41 }
42
43 public function __construct()
44 {
45 add_action('admin_menu', [$this, 'SDCW_add_plugin_page']);
46 add_filter('plugin_action_links', [$this, 'SDCW_plugin_action_links'], 10, 2);
47 if(file_exists(plugin_dir_path(__FILE__) . 'includes/simple-digital-clock-admin-notices.php')) {
48 require_once(plugin_dir_path(__FILE__) . 'includes/simple-digital-clock-admin-notices.php');
49
50 $admin_notice = SDCW_Admin_Notices::get_instance();
51 }
52 }
53
54 public function SDCW_plugin_action_links($links, $file)
55 {
56 if ($file == plugin_basename(SDCW_PATH.'/widget_init.php')) {
57 $links[] = '<a href="'.admin_url('admin.php?page='.SDCW_PLUGIN_SLUG).'">'.esc_html__('Settings', 'simple-digital-clock').'</a>';
58 }
59
60 return $links;
61 }
62
63 /**
64 * Add options page.
65 */
66 public function SDCW_add_plugin_page()
67 {
68 add_options_page(
69 'Settings Admin',
70 'Simple Digital Clock',
71 'manage_options',
72 SDCW_PLUGIN_SLUG,
73 [$this, 'SDCW_admin_settings_page']
74 );
75 }
76
77 public function SDCW_admin_settings_page()
78 {
79 require_once SDCW_PATH.'includes/simple-digital-clock-admin-settings.php';
80 }
81 }
82
83 function SDCW_block_register_block() {
84 wp_register_script(
85 'simple-digital-clock-block-editor-script',
86 plugins_url('block.js', __FILE__),
87 ['wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor'],
88 filemtime(plugin_dir_path(__FILE__) . 'block.js'),
89 true
90 );
91
92 // Localize the script with necessary data
93 wp_localize_script('simple-digital-clock-block-editor-script', 'blockData', [
94 'locale' => get_locale(),
95 'i18n' => [
96 'title' => esc_html__('Simple Digital Clock', 'simple-digital-clock'),
97 'description' => esc_html__('A simple block for displaying Digital Clock.', 'simple-digital-clock'),
98 'container' => esc_html__('Container', 'simple-digital-clock'),
99 'caption' => esc_html__('Caption', 'simple-digital-clock'),
100 'width' => esc_html__('Width', 'simple-digital-clock'),
101 'fullSize' => esc_html__('Full Size', 'simple-digital-clock'),
102 'rounded' => esc_html__('Rounded', 'simple-digital-clock'),
103 'border' => esc_html__('Border', 'simple-digital-clock'),
104 'textAlign' => esc_html__('Text Align', 'simple-digital-clock'),
105 'textAlignHelp' => esc_html__('Select the alignment of the text within the container.', 'simple-digital-clock'),
106 'shadow' => esc_html__('Shadow', 'simple-digital-clock'),
107 'backgroundColor' => esc_html__('Background Color', 'simple-digital-clock'),
108 'color' => esc_html__('Color', 'simple-digital-clock'),
109 'gradient' => esc_html__('Gradient', 'simple-digital-clock'),
110 'options' => esc_html__('Options', 'simple-digital-clock'),
111 'timeZone' => esc_html__('Time Zone', 'simple-digital-clock'),
112 'display' => esc_html__('Display', 'simple-digital-clock'),
113 'googleFonts' => esc_html__('Google Fonts', 'simple-digital-clock'),
114 'googleFontsHelp' => esc_html__('Google fonts are loading from the CDN, they are not included in the plugin.', 'simple-digital-clock'),
115 'locale' => esc_html__('Locale', 'simple-digital-clock'),
116 'localeHelp' => esc_html__('Language of date and including the time display format.', 'simple-digital-clock'),
117 'about' => esc_html__('About', 'simple-digital-clock'),
118 'ratePlugin' => esc_html__('❤️ Rate plugin �
119
120
121
122
123 ', 'simple-digital-clock'),
124 'second' => esc_html__('Second', 'simple-digital-clock'),
125 'hundredths' => esc_html__('Hundredths of a second', 'simple-digital-clock'),
126 'hundredthsHelp' => esc_html__('Show two digits after seconds.', 'simple-digital-clock'),
127 'date' => esc_html__('Date', 'simple-digital-clock'),
128 'amPm' => esc_html__('24-Hour', 'simple-digital-clock'),
129 'timeNow' => esc_html__('Time Now', 'simple-digital-clock'),
130 'todaysDateNow' => esc_html__('Todays Date', 'simple-digital-clock'),
131 'left' => esc_html__('Left', 'simple-digital-clock'),
132 'center' => esc_html__('Center', 'simple-digital-clock'),
133 'right' => esc_html__('Right', 'simple-digital-clock'),
134 'shadowHelp' => esc_html__('Select the Shadow of the text within the container.', 'simple-digital-clock'),
135 'gradientHelp' => esc_html__('Select a gradient (font color is automatically inverted based on background color). Note: the gradient is used on top of the background color.', 'simple-digital-clock'),
136 'time' => esc_html__('Time', 'simple-digital-clock'),
137 'clock' => esc_html__('Clock', 'simple-digital-clock'),
138 'digital' => esc_html__('Digital', 'simple-digital-clock'),
139 'simple' => esc_html__('Simple', 'simple-digital-clock'),
140 'widget' => esc_html__('Widget', 'simple-digital-clock'),
141 'demoPlugin' => esc_html__('DEMO 👀', 'simple-digital-clock'),
142 'none' => esc_html__('None', 'simple-digital-clock'),
143 'clearColors' => esc_html__('Clear All Colors', 'simple-digital-clock'),
144 'clearGradient' => esc_html__('Clear Gradient', 'simple-digital-clock'),
145 'timeZoneHelp' => esc_html__('Select the time zone for the clock display.', 'simple-digital-clock'),
146 ],
147 ]);
148
149 wp_register_style(
150 'simple-digital-clock-block-style',
151 plugins_url('assets/public/css/simple-digital-clock.css', __FILE__),
152 [],
153 filemtime(plugin_dir_path(__FILE__) . 'assets/public/css/simple-digital-clock.css')
154 );
155
156 register_block_type('simple-digital-clock-block/widget-block', [
157 'api_version' => 3,
158 'editor_script' => 'simple-digital-clock-block-editor-script',
159 'script' => 'simple-digital-clock',
160 'style' => 'simple-digital-clock-block-style',
161 ]);
162 }
163
164 function SDCW_admin_scripts() {
165 $script_path = plugin_dir_path(__FILE__) . 'assets/admin/js/simple-digital-clock-notify.js';
166 $version = filemtime($script_path); // Gets the file modification time for cache-busting
167
168 wp_enqueue_script('simple-digital-clock-script', plugin_dir_url(__FILE__) . 'assets/admin/js/simple-digital-clock-notify.js', array('jquery'), $version, true);
169 wp_localize_script('simple-digital-clock-script', 'simpleDigitalClockAjax', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('simple-digital-clock-nonce')));
170 }
171
172 function SDCW_enqueue_scripts() {
173 wp_register_script(
174 'simple-digital-clock',
175 plugins_url('assets/public/js/simple-digital-clock.min.js', __FILE__),
176 [],
177 '0.7.0',
178 [
179 'strategy' => 'async',
180 'in_footer' => true,
181 ]
182 );
183 wp_enqueue_script('simple-digital-clock');
184 }
185
186 add_action('wp_enqueue_scripts', 'SDCW_enqueue_scripts');
187 add_action('admin_enqueue_scripts', 'SDCW_enqueue_scripts');
188 // Load the clock runtime inside the iframed block editor canvas as well:
189 // the iframe collects frontend-context assets via the `enqueue_block_assets` hook.
190 add_action('enqueue_block_assets', 'SDCW_enqueue_scripts');
191 add_action('admin_enqueue_scripts', 'SDCW_admin_scripts');
192 add_action('init', 'SDCW_block_register_block');
193
194 $GLOBALS['SDCW_digital_clock_widget'] = SDCW_digital_clock_widget::get_instance();
195