PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 1.1.3
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v1.1.3
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / admin / class-hurrytimer-admin.php

class-hurrytimer-admin.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 1.1.3, at admin/class-hurrytimer-admin.php

323 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Hurrytimer;
3
4 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/includes/class-hurrytimer-ct-settings.php';
5 /**
6 * The admin-specific functionality of the plugin.
7 *
8 * @link http://nabillemsieh.com
9 * @since 1.0.0
10 *
11 * @package Hurrytimer
12 * @subpackage Hurrytimer/admin
13 */
14
15 /**
16 * The admin-specific functionality of the plugin.
17 *
18 * Defines the plugin name, version, and two examples hooks for how to
19 * enqueue the admin-specific stylesheet and JavaScript.
20 *
21 * @package Hurrytimer
22 * @subpackage Hurrytimer/admin
23 * @author Nabil Lemsieh <contact@nabillemsieh.com>
24 */
25 class Hurrytimer_Admin
26 {
27
28 /**
29 * The ID of this plugin.
30 *
31 * @since 1.0.0
32 * @access private
33 * @var string $plugin_name The ID of this plugin.
34 */
35 private $plugin_name;
36
37 /**
38 * The version of this plugin.
39 *
40 * @since 1.0.0
41 * @access private
42 * @var string $version The current version of this plugin.
43 */
44 private $version;
45
46 /**
47 * Initialize the class and set its properties.
48 *
49 * @since 1.0.0
50 *
51 * @param string $plugin_name The name of this plugin.
52 * @param string $version The version of this plugin.
53 */
54 public function __construct($plugin_name, $version)
55 {
56
57 $this->plugin_name = $plugin_name;
58 $this->version = $version;
59 add_action('wp_ajax_search_products', [$this, 'search_products']);
60 add_action('admin_init', [$this, 'maybe_activate_countdown']);
61 add_action('admin_init', [$this, 'maybe_deactivate_countdown']);
62 add_filter('post_row_actions', [$this, 'countdown_list_row_actions']);
63 add_filter('bulk_actions-edit-' . HURRYTIMER_COUNTDOWN_PT, [$this, 'countdown_list_bulk_actions']);
64 add_filter('manage_' . HURRYTIMER_COUNTDOWN_PT . '_posts_columns', [$this, 'countdown_list_columns']);
65 add_action('manage_' . HURRYTIMER_COUNTDOWN_PT . '_posts_custom_column', [$this, 'countdown_list_columns_content'], 10, 2);
66 add_action('views_edit-' . HURRYTIMER_COUNTDOWN_PT, [$this, 'countdown_list_header_links'], 10);
67 add_filter('bulk_post_updated_messages', [$this, 'custom_bulk_post_updated_messages'], 10, 2);
68 add_action('admin_menu', [$this, 'help_tabs']);
69 add_action('admin_notices', [$this, 'countdown_activation_notice']);
70 add_filter('admin_footer_text', [$this, 'admin_footer_text']);
71
72 }
73
74 public function admin_footer_text()
75 {
76 $screen = get_current_screen();
77 if ($screen->post_type === HURRYTIMER_COUNTDOWN_PT) {
78 echo '<strong>HurryTimer</strong> is made by <a href="http://nabillemsieh.com" target="_blank" style="font-weight: 500;">Nabil Lemsieh</a> | <a href="https://wordpress.org/support/plugin/hurrytimer/reviews/" target="_blank" style="font-weight: 500;">Leave a Review</a>';
79 }
80 }
81 public function countdown_activation_notice()
82 {
83 $post_id = filter_input(INPUT_GET, 'post', \FILTER_VALIDATE_INT);
84 $status = \filter_input(INPUT_GET, 'hrytmr_action');
85 if (!$post_id || !$status || !($post = get_post($post_id))) {
86 return;
87 }
88 if ($status === "hrytmr-ct-deactivate" && !Hurrytimer_CT_Settings::is_active($post_id)) {
89 ?>
90 <div class="notice notice-success is-dismissible">
91 <p><?php _e('Countdown timer deactivated.', "hurrytimer");?></p>
92 </div>
93 <?php
94 } else {
95 ?>
96 <div class="notice notice-success is-dismissible">
97 <p><?php _e('Countdown timer activated.', "hurrytimer");?></p>
98 </div>
99 <?php
100 }
101 }
102 public function help_tabs()
103 {
104 add_action('load-edit.php', [$this, 'edit_help_tabs']);
105 add_action('load-post-new.php', [$this, 'edit_help_tabs']);
106 add_action('load-post.php', [$this, 'edit_help_tabs']);
107 }
108
109 public function edit_help_tabs()
110 {
111 $screen = get_current_screen();
112 if (strpos($screen->id, 'hurrytimer_countdown') === false) {
113 return;
114 }
115 $screen->remove_help_tabs();
116 }
117 public function custom_bulk_post_updated_messages($bulk_messages, $bulk_counts)
118 {
119 $bulk_messages[HURRYTIMER_COUNTDOWN_PT] = [
120 'updated' => _n('%s countdown timer updated.', '%s countdown timers updated.', $bulk_counts['updated']),
121 'locked' => _n('%s countdown timer not updated, somebody is editing it.', '%s countdown timers not updated, somebody is editing them.', $bulk_counts['locked']),
122 'deleted' => _n('%s countdown timer permanently deleted.', '%s countdown timers permanently deleted.', $bulk_counts['deleted']),
123 'trashed' => _n('%s countdown timer deleted.', '%s countdown timers deleted.', $bulk_counts['trashed']),
124 'untrashed' => _n('%s countdown timer restored from the Trash.', '%s countdown timers restored from the Trash.', $bulk_counts['untrashed']),
125 ];
126
127 return $bulk_messages;
128 }
129 public function countdown_list_header_links($views)
130 {
131 unset($views['trash']);
132 return $views;
133 }
134 public function countdown_list_columns_content($column, $post_id)
135 {
136 global $post;
137 $ct_instance = new Hurrytimer_Countdown($post_id);
138 switch ($column) {
139 case 'status':
140 echo $post->post_status === "publish" ? __('Active', "hurrytimer") : __('Inactive', "hurrytimer");
141 break;
142 case 'mode':
143 echo $ct_instance->get_mode() === CDT_MODE::EVERGREEN ? __('Evergreen', "hurrytimer") : __('Normal', "hurrytimer");
144 break;
145 case 'shortcode':
146 echo '<pre class="htmr-list-shortcode">[hurrytimer id="' . $post_id . '"]</pre>';
147 break;
148
149 }
150 }
151 public function countdown_list_bulk_actions($actions)
152 {
153 unset($actions['edit']);
154 return $actions;
155 }
156 public function countdown_list_columns($columns)
157 {
158 $allowed_columns = [];
159 foreach ($columns as $column_name => $value) {
160 if (in_array($column_name, ['cb', 'title', 'date'])) {
161 $allowed_columns[$column_name] = $value;
162 }
163 }
164
165 $columns = $allowed_columns;
166 $date = $columns['date'];
167 unset($columns['date']);
168 $columns = array_merge($columns, [
169 'status' => __('Status', "hurrytimer"),
170 'mode' => __('Mode', "hurrytimer"),
171 'shortcode' => __('Shortcode', "hurrytimer"),
172 ]);
173 $columns['date'] = $date;
174 return $columns;
175 }
176 /**
177 * Register the stylesheets for the admin area.
178 *
179 * @since 1.0.0
180 */
181 public function enqueue_styles()
182 {
183 wp_enqueue_style('wp-color-picker');
184 wp_enqueue_style($this->plugin_name, HURRYTIMER_PLUGIN_URL . '/admin/css/admin.css', [], filemtime(HURRYTIMER_PLUGIN_DIR . '/admin/css/admin.css'), 'all');
185 }
186
187 public function countdown_list_row_actions($actions)
188 {
189 global $post;
190 if ($post->post_type === HURRYTIMER_COUNTDOWN_PT) {
191 unset($actions['inline hide-if-no-js']);
192 unset($actions['trash']);
193 }
194 $actions['delete'] = '<a href="' . get_delete_post_link($post->ID) . '">' . __('Delete', "hurrytimer") . '</a>';
195 return $actions;
196 }
197 /**
198 * Register the JavaScript for the admin area.
199 *
200 * @since 1.0.0
201 */
202 public function enqueue_scripts()
203 {
204 wp_enqueue_script('wp-color-picker');
205
206 wp_enqueue_script(
207 $this->plugin_name,
208 HURRYTIMER_PLUGIN_URL . '/admin/js/admin.js',
209 array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'),
210 time(),
211 true);
212
213 wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
214
215 }
216
217 public function menu()
218 {
219 add_menu_page('HurryTimer', 'HurryTimer', 'manage_options', 'hurrytimer', [ & $this, 'welcome_page_tpl']);
220
221 add_submenu_page('hurrytimer',
222 __('Add New Timer', 'hurrytimer'),
223 __('Add New Timer', 'hurrytimer'),
224 'manage_options',
225 'post-new.php?post_type=hurrytimer_countdown'
226 );
227
228 // add_submenu_page('hurrytimer',
229 // __('Settings',"hurrytimer"),
230 // __('Settings', "hurrytimer"),
231 // 'manage_options',
232 // 'hurrytimer_settings',
233 // array(&$this, 'settings_page_tpl')
234 // );
235 }
236
237 public function maybe_activate_countdown()
238 {
239 if (
240 isset($_GET['hrytmr_action'])
241 && $_GET['hrytmr_action'] === "hrytmr-ct-activate"
242 && isset($_GET['_wpnonce'])
243 && wp_verify_nonce($_GET['_wpnonce'], 'hrytmr-ct-activate')
244 ) {
245 $post_id = filter_input(INPUT_GET, 'post');
246 wp_update_post(['ID' => $post_id, 'post_status' => 'publish']);
247 }
248 }
249
250 public function maybe_deactivate_countdown()
251 {
252 if (
253 isset($_GET['hrytmr_action'])
254 && $_GET['hrytmr_action'] === "hrytmr-ct-deactivate"
255 && isset($_GET['_wpnonce'])
256 && wp_verify_nonce($_GET['_wpnonce'], 'hrytmr-ct-deactivate')
257 ) {
258 $post_id = filter_input(INPUT_GET, 'post');
259 wp_update_post(['ID' => $post_id, 'post_status' => 'draft']);
260 }
261 }
262
263 public function welcome_page_tpl()
264 {
265 include plugin_dir_path(dirname(__FILE__)) . 'admin/templates/welcome.php';
266 }
267
268 public function new_countdown_page_tpl()
269 {
270 include plugin_dir_path(dirname(__FILE__)) . 'admin/templates/new-countdown.php';
271 }
272
273 public function meta_boxes()
274 {
275 require plugin_dir_path(dirname(__FILE__)) . 'admin/class-hurrytimer-metaboxes.php';
276
277 new Hurrytimer_MetaBoxes();
278 }
279
280 /**
281 * Search products
282 *
283 * @return void
284 */
285 public function search_products()
286 {
287 $search = sanitize_text_field($_GET['search']);
288 $products_selection = sanitize_text_field($_GET['productsSelection']);
289 $results = [];
290 $exclude = array_map('intval', $_GET['exclude']);
291
292 if (in_array($products_selection, [WC_Product_Selection::SPECIFIC_CATEGORIES, WC_Product_Selection::ALL_CATEGORIES_EXCEPT])) {
293 $args = [
294 "hide_empty" => false,
295 "taxonomy" => "product_cat",
296 "name__like" => $search,
297 'exclude' => $exclude,
298 ];
299
300 $items = get_terms($args);
301 $results = array_map(function ($item) {
302 return [
303 "id" => $item->term_id,
304 "text" => $item->name,
305 ];
306 }, $items);
307 } else {
308 $args = ['s' => $search, 'post_type' => 'product',
309 'post__not_in' => $exclude,
310 ];
311 $items = get_posts($args);
312 $results = array_map(function ($item) {
313 return [
314 "id" => $item->ID,
315 "text" => $item->post_title,
316 ];
317 }, $items);
318 }
319 exit(json_encode(["results" => $results, "pagination" => true]));
320
321 }
322 }
323