PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.16
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.16
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
← All changes | admin/CampaignSettings.php +65 -141 trunk2.2.16 View file →
@@ -30,17 +30,15 @@
30 30 }
31 31
32 32 private function intializeHooks()
33 33 {
34 - // Save campaign settings.
34 +
35 + // Save compaign settings.
35 36 add_action('save_post_hurrytimer_countdown', [$this, 'save_settings'], 10, 3);
36 37
37 38 // Custom publish metabox.
38 39 add_action('post_submitbox_misc_actions', [$this, 'post_publish_metabox']);
39 40
40 - // Handle campaign duplication.
41 - add_action('admin_init', [$this, 'handle_duplicate_campaign']);
42 -
43 41 // Edit placeholder for headline.
44 42 add_filter('enter_title_here', [$this, 'change_countdown_title'], 10);
45 43
46 44 // Edit messages.
@@ -49,42 +47,11 @@
49 47 // Campaign settings metabox.
50 48 add_filter('add_meta_boxes', [$this, 'add_settings_metabox_template'], 10);
51 49
52 50 add_action("updated_post_meta", [$this, 'maybe_reset_running_countdown'], 10, 4);
53 - add_action('edit_form_before_permalink', [$this, 'show_headline_moved_notice']);
54 51 }
55 52
56 - function show_headline_moved_notice( $post )
57 - {
58 - if ( !$post || $post->post_type !== HURRYT_POST_TYPE ) {
59 - return;
60 - }
61 53
62 - if( get_option('hurryt_headline_moved_notice_dismissed') ){
63 - return;
64 - }
65 -
66 - if(isset($_COOKIE['hurryt_headline_moved_notice_dismissed'])){
67 - return;
68 - }
69 - if ( !filter_var( apply_filters( 'hurryt_show_headline_moved_notice', true ), FILTER_VALIDATE_BOOLEAN ) ) {
70 - return;
71 - }
72 -
73 - if ( !Installer::get_instance()->has_upgraded_from_2_2_28_or_prior() ) {
74 - return;
75 - }
76 -
77 - ?>
78 - <p class="description" style="margin-top:5px;font-style:normal; background:white; border: 1px solid #ccd0d4;;padding:10px;border-left: 1px solid #00a0d2;border-left-width: 4px;box-shadow: 0 1px 1px rgb(0 0 0 / 4%);">
79 - The headline can now be edited under <a href="#" class="hurryt-open-hl-tab">Appearance → Elements → Headline</a>. Use the input box above to add the name of the campaign instead.
80 - <br>
81 - <button type="button" class="button-primary" style="margin-top:5px;" id="hurryt-dismiss-headline-moved-notice">OK, got it</button>
82 - </p>
83 - <?php
84 - }
85 -
86 -
87 54 /**
88 55 * Edit notices messages.
89 56 *
90 57 * @param array $messages
@@ -90,29 +57,33 @@
90 57 * @param array $messages
91 58 *
92 59 * @return array
93 60 */
94 - public function custom_updated_messages( $messages )
61 + public function custom_updated_messages($messages)
95 62 {
96 63 global $post;
97 - $messages[ HURRYT_POST_TYPE ] = array(
64 + global $post_id;
65 + $messages[HURRYT_POST_TYPE] = array(
98 66 0 => '',
99 - 1 => __( 'Campaign updated.', 'hurrytimer' ),
67 + 1 => __('Campaign updated', "hurrytimer"),
100 68 2 => '',
101 69 3 => '',
102 - 4 => __( 'Campaign updated.', 'hurrytimer' ),
70 + 4 => __('Campaign updated.', "hurrytimer"),
103 71 5 => '',
104 - 6 => __( 'Campaign published.', 'hurrytimer' ),
105 - 7 => __( 'Campaign saved.', 'hurrytimer' ),
106 - 8 => __( 'Campaign submitted.', 'hurrytimer' ),
72 + 6 => __('Campaign published', "hurrytimer"),
73 + 7 => __('Campaign saved.', "hurrytimer"),
74 + 8 => __('Campaign submitted.', "hurrytimer"),
107 75 9 => sprintf(
108 76 __(
109 77 'Campaign scheduled for: <strong>%1$s</strong>.',
110 - 'hurrytimer'
78 + "hurrytimer"
111 79 ),
112 - date_i18n(__( 'M j, Y @ G:i', 'hurrytimer' ),strtotime( $post->post_date ))
80 + date_i18n(
81 + __('M j, Y @ G:i', "hurrytimer"),
82 + strtotime($post->post_date)
83 + )
113 84 ),
114 - 10 => __( 'Campaign draft updated.', 'hurrytimer' ),
85 + 10 => __('Campaign draft updated.', "hurrytimer"),
115 86 );
116 87
117 88 return $messages;
118 89 }
@@ -119,10 +90,10 @@
119 90
120 91 /**
121 92 * If time is edited, reset compaign.
122 93 *
123 - * @param int $meta_id
124 - * @param int $object_id
94 + * @param int $meta_id
95 + * @param int $object_id
125 96 * @param string $meta_key
126 97 * @param string $meta_value
127 98 *
128 99 * @return void
@@ -132,9 +103,9 @@
132 103 $object_id,
133 104 $meta_key,
134 105 $meta_value
135 106 ) {
136 - if ( !in_array( $meta_key, [ 'duration' ] ) ) {
107 + if (!in_array($meta_key, ['duration'])) {
137 108 return;
138 109 }
139 110
140 111 // (new EvergreenCampaign($object_id))->reset();
@@ -139,9 +110,9 @@
139 110
140 111 // (new EvergreenCampaign($object_id))->reset();
141 112 }
142 113
143 - public function maybe_delete_running_countdown( $post_id )
114 + public function maybe_delete_running_countdown($post_id)
144 115 {
145 116 //Evergreen_Countdown::reset($post_id);
146 117 }
147 118
@@ -151,14 +122,14 @@
151 122 * @param string $title
152 123 *
153 124 * @return string
154 125 */
155 - public function change_countdown_title( $title )
126 + public function change_countdown_title($title)
156 127 {
157 128 global $post;
158 - if ( $post && $post->post_type === HURRYT_POST_TYPE ) {
129 + if ($post->post_type === HURRYT_POST_TYPE) {
159 130 return __(
160 - 'Campaign name (optional)',
131 + 'Headline (optional)',
161 132 "hurrytimer"
162 133 );
163 134 }
164 135
@@ -172,29 +143,20 @@
172 143 */
173 144 public function post_publish_metabox()
174 145 {
175 146 global $post_id, $post;
176 - if ( $post->post_type !== HURRYT_POST_TYPE ) {
147 + if ($post->post_type !== HURRYT_POST_TYPE) {
177 148 return;
178 149 }
179 150
180 - if ( Utils\Helpers::isNewPost( $post_id ) ) {
151 + if (Utils\Helpers::isNewPost($post_id)) {
181 152 return;
182 153 }
183 - $isActive = Utils\Helpers::isPostActive( $post_id );
184 - $publich_date = Utils\Helpers::format_date( $post->post_date );
185 - $deactivateUrl = Utils\Helpers::deactivateUrl( $post_id );
186 - $activateUrl = Utils\Helpers::activateUrl( $post_id );
154 + $isActive = Utils\Helpers::isPostActive($post_id);
155 + $publich_date = Utils\Helpers::format_date($post->post_date);
156 + $deactivateUrl = Utils\Helpers::deactivateUrl($post_id);
157 + $activateUrl = Utils\Helpers::activateUrl($post_id);
187 158
188 - $duplicateUrl = add_query_arg(
189 - [
190 - 'action' => 'duplicate_campaign',
191 - 'post' => $post_id,
192 - '_wpnonce' => wp_create_nonce('duplicate_campaign_' . $post_id)
193 - ],
194 - admin_url('admin.php')
195 - );
196 -
197 159 include HURRYT_DIR . '/admin/templates/post-publish-metabox.php';
198 160
199 161 }
200 162
@@ -207,49 +169,43 @@
207 169 */
208 170
209 171 public function save_settings($post_id)
210 172 {
211 - // Check for CSRF protection
212 - if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-post_' . $post_id)) {
173 + if (wp_is_post_revision($post_id)) {
213 174 return;
214 175 }
215 -
216 - if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
217 - || (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID'])
218 - || (!current_user_can('publish_posts') || !current_user_can('edit_post', $post_id))
219 - ) {
176 + if (!current_user_can('edit_post', $post_id)) {
220 177 return;
221 178 }
222 - // var_dump($_POST);exit;
223 179 $countdown = new Campaign($post_id);
224 - $countdown->storeSettings(wp_unslash($_POST));
180 + $countdown->storeSettings($_POST);
225 181 }
226 182
227 - public function add_settings_metabox_template( $post_type )
183 + public function add_settings_metabox_template($post_type)
228 184 {
229 185 global $post_id;
230 - if ( $post_type != HURRYT_POST_TYPE ) {
186 + if ($post_type != HURRYT_POST_TYPE) {
231 187 return;
232 188 }
233 - remove_meta_box( 'wpseo_meta', HURRYT_POST_TYPE, 'normal' );
234 - remove_meta_box( 'slugdiv', HURRYT_POST_TYPE, 'normal' );
235 - remove_meta_box( 'eg-meta-box', HURRYT_POST_TYPE, 'normal' );
189 + remove_meta_box('wpseo_meta', HURRYT_POST_TYPE, 'normal');
190 + remove_meta_box('slugdiv', HURRYT_POST_TYPE, 'normal');
191 + remove_meta_box('eg-meta-box', HURRYT_POST_TYPE, 'normal');
236 192
237 193 add_meta_box(
238 194 'hurrytimer-settings',
239 - __( 'Settings <a href="#" class="hurryt-fullscreen hidden"></a>',
240 - 'hurrytimer' ),
241 - array( $this, 'settingsMetaboxTemplate' ),
195 + __('Settings <a href="#" class="hurryt-fullscreen hidden"></a>',
196 + 'hurrytimer'),
197 + array($this, 'settingsMetaboxTemplate'),
242 198 $post_type,
243 199 'normal',
244 200 'high'
245 201 );
246 202
247 - if ( $post_id ) {
203 + if ($post_id) {
248 204 add_meta_box(
249 205 'hrytmr-countdown__shortcode',
250 - __( 'Shortcode', 'hurrytimer' ),
251 - array( $this, 'shortcode_metabox_template' ),
206 + __('Shortcode', 'hurrytimer'),
207 + array($this, 'shortcode_metabox_template'),
252 208 $post_type,
253 209 'side',
254 210 'high'
255 211 );
@@ -271,36 +227,34 @@
271 227 */
272 228 public function settingsMetaboxTemplate()
273 229 {
274 230 global $post_id;
275 - $campaign = new Campaign( $post_id );
231 + $campaign = new Campaign($post_id);
276 232 $campaign->loadSettings();
277 - $resetCampaignAllVisitorsUrl = $this->createResetEvergreenCampaign( 'all' );
278 - $resetCampaignCurrentAdminUrl = $this->createResetEvergreenCampaign( 'admin' );
279 - $products = $this->getWcProductsNames( $campaign->wcProductsSelection,
280 - $campaign->wcProductsSelectionType );
233 + $resetCampaignAllVisitorsUrl = $this->createResetEvergreenCampaign('all');
234 + $resetCampaignCurrentAdminUrl = $this->createResetEvergreenCampaign('admin');
235 + $products = $this->getWcProductsNames($campaign->wcProductsSelection,
236 + $campaign->wcProductsSelectionType);
281 237 include HURRYT_DIR . '/admin/templates/campaign-settings.php';
282 238
283 239 }
284 240
285 - public function createResetEvergreenCampaign( $scope = 'admin' )
241 + public function createResetEvergreenCampaign($scope = 'admin')
286 242 {
287 243 global $post_id;
288 244
289 - $action = 'reset-evergreen-compaign';
290 -
291 245 return wp_nonce_url(
292 246 add_query_arg(
293 247 array(
294 - 'hurryt-action' => $action,
248 + 'hurryt-action' => 'reset-evergreen-compaign',
295 249 'hurryt-scope' => $scope,
296 250 'postid' => $post_id,
297 251 'post' => $post_id,
298 252 'action' => 'edit',
299 253 ),
300 - admin_url('post.php')
254 + network_admin_url('post.php')
301 255 ),
302 - $action
256 + 'reset-evergreen-compaign'
303 257 );
304 258 }
305 259
306 260 /**
@@ -308,16 +262,16 @@
308 262 * @param $selection
309 263 *
310 264 * @return array
311 265 */
312 - public function getWcProductsNames( $ids, $selection )
266 + public function getWcProductsNames($ids, $selection)
313 267 {
314 268 $result = [];
315 - if ( empty( $ids ) ) {
269 + if (empty($ids)) {
316 270 return $result;
317 271 }
318 272
319 - switch ( $selection ) {
273 + switch ($selection) {
320 274 case C::WC_PS_TYPE_ALL:
321 275 break;
322 276 case C::WC_PS_TYPE_INCLUDE_PRODUCTS:
323 277 case C::WC_PS_TYPE_EXCLUDE_PRODUCTS:
@@ -323,13 +277,11 @@
323 277 case C::WC_PS_TYPE_EXCLUDE_PRODUCTS:
324 278 $args = [
325 279 'post_type' => 'product',
326 280 'post__in' => $ids,
327 - 'post_status' => 'any',
328 - 'posts_per_page' => -1
329 281 ];
330 - $products = get_posts( $args );
331 - foreach ( $products as $product ) {
282 + $products = get_posts($args);
283 + foreach ($products as $product) {
332 284 $result[] = [
333 285 'id' => $product->ID,
334 286 'text' => $product->post_title,
335 287 ];
@@ -336,9 +288,9 @@
336 288 }
337 289 break;
338 290 case C::WC_PS_TYPE_INCLUDE_CATEGORIES:
339 291 case C::WC_PS_TYPE_EXCLUDE_CATEGORIES:
340 - $ids = array_map( 'intval', $ids );
292 + $ids = array_map('intval', $ids);
341 293 $args = [
342 294 'taxonomy' => 'product_cat',
343 295 'term_ids' => $ids,
344 296 'hide_empty' => false,
@@ -343,16 +295,16 @@
343 295 'term_ids' => $ids,
344 296 'hide_empty' => false,
345 297 ];
346 298
347 - $categories = get_terms( $args );
299 + $categories = get_terms($args);
348 300
349 - $categories = array_filter( $categories, function (
301 + $categories = array_filter($categories, function (
350 302 $_category
351 - ) use ( $ids ) {
352 - return in_array( $_category->term_id, $ids );
353 - } );
354 - foreach ( $categories as $category ) {
303 + ) use ($ids) {
304 + return in_array($_category->term_id, $ids);
305 + });
306 + foreach ($categories as $category) {
355 307 $result[] = [
356 308 'id' => $category->term_id,
357 309 'text' => $category->name,
358 310 ];
@@ -363,34 +315,6 @@
363 315 }
364 316
365 317 return $result;
366 318 }
367 -
368 - public function handle_duplicate_campaign()
369 - {
370 - if (isset($_POST['duplicate_campaign']) && $_POST['duplicate_campaign'] == '1') {
371 - $post_id = get_the_ID();
372 - $post = get_post($post_id);
373 - if ($post && $post->post_type === HURRYT_POST_TYPE) {
374 - $new_post_id = wp_insert_post([
375 - 'post_title' => $post->post_title . ' (Copy)',
376 - 'post_type' => $post->post_type,
377 - 'post_status' => 'draft',
378 - ]);
379 -
380 - if ($new_post_id) {
381 - // Copy post meta
382 - $meta = get_post_meta($post_id);
383 - foreach ($meta as $key => $values) {
384 - foreach ($values as $value) {
385 - add_post_meta($new_post_id, $key, maybe_unserialize($value));
386 - }
387 - }
388 - }
389 - }
390 - // Redirect to the new post edit page
391 - wp_redirect(admin_url('post.php?action=edit&post=' . $new_post_id));
392 - exit;
393 - }
394 - }
395 -
319 +
396 320 }