PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.6.2
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.6.2
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 +122 -102 2.0.0 → 2.6.2 View file →
@@ -32,61 +32,56 @@
32 32 private function intializeHooks()
33 33 {
34 34
35 35 // Save compaign settings.
36 - add_action('save_post_hurrytimer_countdown', [$this, 'save_settings'], 10, 3);
36 + add_action( 'save_post_hurrytimer_countdown', [ $this, 'save_settings' ], 10, 3 );
37 37
38 38 // Custom publish metabox.
39 - add_action('post_submitbox_misc_actions', [$this, 'post_publish_metabox']);
39 + add_action( 'post_submitbox_misc_actions', [ $this, 'post_publish_metabox' ] );
40 40
41 41 // Edit placeholder for headline.
42 - add_filter('enter_title_here', [$this, 'change_countdown_title'], 10);
42 + add_filter( 'enter_title_here', [ $this, 'change_countdown_title' ], 10 );
43 43
44 44 // Edit messages.
45 - add_filter('post_updated_messages', [$this, 'custom_updated_messages'], 10);
45 + add_filter( 'post_updated_messages', [ $this, 'custom_updated_messages' ], 10 );
46 46
47 47 // Campaign settings metabox.
48 - add_filter('add_meta_boxes', [$this, 'add_settings_metabox_template'], 10);
48 + add_filter( 'add_meta_boxes', [ $this, 'add_settings_metabox_template' ], 10 );
49 49
50 - add_filter('after_delete_post', [$this, 'maybe_delete_running_countdown'], 10);
50 + add_action( "updated_post_meta", [ $this, 'maybe_reset_running_countdown' ], 10, 4 );
51 + add_action( 'edit_form_before_permalink', [ $this, 'show_headline_moved_notice' ] );
52 + }
51 53
52 - add_action("updated_post_meta", [$this, 'maybe_reset_running_countdown'], 10, 4);
54 + function show_headline_moved_notice( $post )
55 + {
56 + if ( !$post || $post->post_type !== HURRYT_POST_TYPE ) {
57 + return;
58 + }
53 59
54 - // Skip trash
55 - add_action("trashed_post", [$this, 'skip_trash']);
60 + if( get_option('hurryt_headline_moved_notice_dismissed') ){
61 + return;
62 + }
56 63
57 - // Edit delete link text.
58 - add_action('post_submitbox_start', [$this, 'delete_permanently_link']);
59 - }
64 + if(isset($_COOKIE['hurryt_headline_moved_notice_dismissed'])){
65 + return;
66 + }
67 + if ( !filter_var( apply_filters( 'hurryt_show_headline_moved_notice', true ), FILTER_VALIDATE_BOOLEAN ) ) {
68 + return;
69 + }
60 70
61 - public function delete_permanently_link($post)
62 - {
71 + if ( !Installer::get_instance()->has_upgraded_from_2_2_28_or_prior() ) {
72 + return;
73 + }
74 +
63 75 ?>
64 -
65 - <div id="delete-action" class="is-delete-permanently">
66 - <?php if (current_user_can("delete_post", $post->ID)) {
67 - $delete_text = __('Delete', "hurrytimer"); ?>
68 - <a class="submitdelete deletion" href="<?php echo get_delete_post_link(
69 - $post->ID
70 - ); ?>">
71 - <?php echo $delete_text; ?></a>
72 - <?php
73 - } ?>
74 - </div>
76 + <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%);">
77 + 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.
78 + <br>
79 + <button type="button" class="button-primary" style="margin-top:5px;" id="hurryt-dismiss-headline-moved-notice">OK, got it</button>
80 + </p>
75 81 <?php
76 82 }
77 83
78 - /**
79 - * Skip trash when deleting.
80 - *
81 - * @param int $post_id
82 - *
83 - * @return void
84 - */
85 - public function skip_trash($post_id)
86 - {
87 - wp_delete_post($post_id, true);
88 - }
89 84
90 85 /**
91 86 * Edit notices messages.
92 87 *
@@ -93,33 +88,32 @@
93 88 * @param array $messages
94 89 *
95 90 * @return array
96 91 */
97 - public function custom_updated_messages($messages)
92 + public function custom_updated_messages( $messages )
98 93 {
99 94 global $post;
100 - global $post_id;
101 - $messages[HURRYT_POST_TYPE] = array(
102 - 0 => '',
103 - 1 => __('Campaign updated', "hurrytimer"),
104 - 2 => '',
105 - 3 => '',
106 - 4 => __('Campaign updated.', "hurrytimer"),
107 - 5 => '',
108 - 6 => __('Campaign published', "hurrytimer"),
109 - 7 => __('Campaign saved.', "hurrytimer"),
110 - 8 => __('Campaign submitted.', "hurrytimer"),
111 - 9 => sprintf(
95 + $messages[ HURRYT_POST_TYPE ] = array(
96 + 0 => '',
97 + 1 => __( 'Campaign updated', "hurrytimer" ),
98 + 2 => '',
99 + 3 => '',
100 + 4 => __( 'Campaign updated.', "hurrytimer" ),
101 + 5 => '',
102 + 6 => __( 'Campaign published', "hurrytimer" ),
103 + 7 => __( 'Campaign saved.', "hurrytimer" ),
104 + 8 => __( 'Campaign submitted.', "hurrytimer" ),
105 + 9 => sprintf(
112 106 __(
113 107 'Campaign scheduled for: <strong>%1$s</strong>.',
114 108 "hurrytimer"
115 109 ),
116 110 date_i18n(
117 - __('M j, Y @ G:i', "hurrytimer"),
118 - strtotime($post->post_date)
111 + __( 'M j, Y @ G:i', "hurrytimer" ),
112 + strtotime( $post->post_date )
119 113 )
120 114 ),
121 - 10 => __('Campaign draft updated.', "hurrytimer"),
115 + 10 => __( 'Campaign draft updated.', "hurrytimer" ),
122 116 );
123 117
124 118 return $messages;
125 119 }
@@ -126,10 +120,10 @@
126 120
127 121 /**
128 122 * If time is edited, reset compaign.
129 123 *
130 - * @param int $meta_id
131 - * @param int $object_id
124 + * @param int $meta_id
125 + * @param int $object_id
132 126 * @param string $meta_key
133 127 * @param string $meta_value
134 128 *
135 129 * @return void
@@ -139,9 +133,9 @@
139 133 $object_id,
140 134 $meta_key,
141 135 $meta_value
142 136 ) {
143 - if ( ! in_array($meta_key, ['duration'])) {
137 + if ( !in_array( $meta_key, [ 'duration' ] ) ) {
144 138 return;
145 139 }
146 140
147 141 // (new EvergreenCampaign($object_id))->reset();
@@ -146,9 +140,9 @@
146 140
147 141 // (new EvergreenCampaign($object_id))->reset();
148 142 }
149 143
150 - public function maybe_delete_running_countdown($post_id)
144 + public function maybe_delete_running_countdown( $post_id )
151 145 {
152 146 //Evergreen_Countdown::reset($post_id);
153 147 }
154 148
@@ -158,14 +152,14 @@
158 152 * @param string $title
159 153 *
160 154 * @return string
161 155 */
162 - public function change_countdown_title($title)
156 + public function change_countdown_title( $title )
163 157 {
164 158 global $post;
165 - if ($post->post_type === HURRYT_POST_TYPE) {
159 + if ( $post && $post->post_type === HURRYT_POST_TYPE ) {
166 160 return __(
167 - 'Headline (optional)',
161 + 'Campaign name (optional)',
168 162 "hurrytimer"
169 163 );
170 164 }
171 165
@@ -179,21 +173,20 @@
179 173 */
180 174 public function post_publish_metabox()
181 175 {
182 176 global $post_id, $post;
183 - if ($post->post_type !== HURRYT_POST_TYPE) {
177 + if ( $post->post_type !== HURRYT_POST_TYPE ) {
184 178 return;
185 179 }
186 180
187 - if (Utils\Helpers::isNewPost($post_id)) {
181 + if ( Utils\Helpers::isNewPost( $post_id ) ) {
188 182 return;
189 183 }
184 + $isActive = Utils\Helpers::isPostActive( $post_id );
185 + $publich_date = Utils\Helpers::format_date( $post->post_date );
186 + $deactivateUrl = Utils\Helpers::deactivateUrl( $post_id );
187 + $activateUrl = Utils\Helpers::activateUrl( $post_id );
190 188
191 - $isActive = Utils\Helpers::isPostActive($post_id);
192 - $publich_date = Utils\Helpers::format_date($post->post_date);
193 - $deactivateUrl = Utils\Helpers::deactivateUrl($post_id);
194 - $activateUrl = Utils\Helpers::activateUrl($post_id);
195 -
196 189 include HURRYT_DIR . '/admin/templates/post-publish-metabox.php';
197 190
198 191 }
199 192
@@ -204,44 +197,45 @@
204 197 *
205 198 * @return void
206 199 */
207 200
208 - public function save_settings($post_id)
201 + public function save_settings( $post_id )
209 202 {
210 - if (wp_is_post_revision($post_id)) {
203 + if ( wp_is_post_revision( $post_id ) ) {
211 204 return;
212 205 }
213 - if ( ! current_user_can('edit_post', $post_id)) {
206 + if ( !current_user_can( 'edit_post', $post_id ) ) {
214 207 return;
215 208 }
216 - $countdown = new Campaign($post_id);
217 - $countdown->storeSettings($_POST);
209 + $countdown = new Campaign( $post_id );
210 + $countdown->storeSettings( $_POST );
218 211 }
219 212
220 - public function add_settings_metabox_template($post_type)
213 + public function add_settings_metabox_template( $post_type )
221 214 {
222 215 global $post_id;
223 - if ($post_type != HURRYT_POST_TYPE) {
216 + if ( $post_type != HURRYT_POST_TYPE ) {
224 217 return;
225 218 }
226 - remove_meta_box('wpseo_meta', HURRYT_POST_TYPE, 'normal');
227 - remove_meta_box('slugdiv', HURRYT_POST_TYPE, 'normal');
228 - remove_meta_box('eg-meta-box', HURRYT_POST_TYPE, 'normal');
219 + remove_meta_box( 'wpseo_meta', HURRYT_POST_TYPE, 'normal' );
220 + remove_meta_box( 'slugdiv', HURRYT_POST_TYPE, 'normal' );
221 + remove_meta_box( 'eg-meta-box', HURRYT_POST_TYPE, 'normal' );
229 222
230 223 add_meta_box(
231 224 'hurrytimer-settings',
232 - __('Settings', 'hurrytimer'),
233 - array($this, 'settingsMetaboxTemplate'),
225 + __( 'Settings <a href="#" class="hurryt-fullscreen hidden"></a>',
226 + 'hurrytimer' ),
227 + array( $this, 'settingsMetaboxTemplate' ),
234 228 $post_type,
235 229 'normal',
236 230 'high'
237 231 );
238 232
239 - if ($post_id) {
233 + if ( $post_id ) {
240 234 add_meta_box(
241 235 'hrytmr-countdown__shortcode',
242 - __('CampaignShortcode', 'hurrytimer'),
243 - array($this, 'shortcode_metabox_template'),
236 + __( 'Shortcode', 'hurrytimer' ),
237 + array( $this, 'shortcode_metabox_template' ),
244 238 $post_type,
245 239 'side',
246 240 'high'
247 241 );
@@ -263,16 +257,39 @@
263 257 */
264 258 public function settingsMetaboxTemplate()
265 259 {
266 260 global $post_id;
267 - $campaign = new Campaign($post_id);
261 + $campaign = new Campaign( $post_id );
268 262 $campaign->loadSettings();
269 - $products = $this->getWcProductsNames($campaign->wcProductsSelection,
270 - $campaign->wcProductsSelectionType);
263 + $resetCampaignAllVisitorsUrl = $this->createResetEvergreenCampaign( 'all' );
264 + $resetCampaignCurrentAdminUrl = $this->createResetEvergreenCampaign( 'admin' );
265 + $products = $this->getWcProductsNames( $campaign->wcProductsSelection,
266 + $campaign->wcProductsSelectionType );
271 267 include HURRYT_DIR . '/admin/templates/campaign-settings.php';
272 268
273 269 }
274 270
271 + public function createResetEvergreenCampaign( $scope = 'admin' )
272 + {
273 + global $post_id;
274 +
275 + $action = 'reset-evergreen-compaign';
276 +
277 + return wp_nonce_url(
278 + add_query_arg(
279 + array(
280 + 'hurryt-action' => $action,
281 + 'hurryt-scope' => $scope,
282 + 'postid' => $post_id,
283 + 'post' => $post_id,
284 + 'action' => 'edit',
285 + ),
286 + admin_url( 'post.php' )
287 + ),
288 + $action
289 + );
290 + }
291 +
275 292 /**
276 293 * @param array $ids
277 294 * @param $selection
278 295 *
@@ -277,28 +294,30 @@
277 294 * @param $selection
278 295 *
279 296 * @return array
280 297 */
281 - public function getWcProductsNames($ids, $selection)
298 + public function getWcProductsNames( $ids, $selection )
282 299 {
283 300 $result = [];
284 - if (empty($ids)) {
301 + if ( empty( $ids ) ) {
285 302 return $result;
286 303 }
287 304
288 - switch ($selection) {
305 + switch ( $selection ) {
289 306 case C::WC_PS_TYPE_ALL:
290 307 break;
291 308 case C::WC_PS_TYPE_INCLUDE_PRODUCTS:
292 309 case C::WC_PS_TYPE_EXCLUDE_PRODUCTS:
293 - $args = [
310 + $args = [
294 311 'post_type' => 'product',
295 - 'post__in' => $ids,
312 + 'post__in' => $ids,
313 + 'post_status' => 'any',
314 + 'posts_per_page' => -1
296 315 ];
297 - $products = get_posts($args);
298 - foreach ($products as $product) {
316 + $products = get_posts( $args );
317 + foreach ( $products as $product ) {
299 318 $result[] = [
300 - 'id' => $product->ID,
319 + 'id' => $product->ID,
301 320 'text' => $product->post_title,
302 321 ];
303 322 }
304 323 break;
@@ -303,25 +322,25 @@
303 322 }
304 323 break;
305 324 case C::WC_PS_TYPE_INCLUDE_CATEGORIES:
306 325 case C::WC_PS_TYPE_EXCLUDE_CATEGORIES:
307 - $ids = array_map('intval', $ids);
326 + $ids = array_map( 'intval', $ids );
308 327 $args = [
309 - 'taxonomy' => 'product_cat',
310 - 'term_ids' => $ids,
328 + 'taxonomy' => 'product_cat',
329 + 'term_ids' => $ids,
311 330 'hide_empty' => false,
312 331 ];
313 332
314 - $categories = get_terms($args);
333 + $categories = get_terms( $args );
315 334
316 - $categories = array_filter($categories, function (
335 + $categories = array_filter( $categories, function (
317 336 $_category
318 - ) use ($ids) {
319 - return in_array($_category->term_id, $ids);
320 - });
321 - foreach ($categories as $category) {
337 + ) use ( $ids ) {
338 + return in_array( $_category->term_id, $ids );
339 + } );
340 + foreach ( $categories as $category ) {
322 341 $result[] = [
323 - 'id' => $category->term_id,
342 + 'id' => $category->term_id,
324 343 'text' => $category->name,
325 344 ];
326 345 }
327 346 break;
@@ -330,5 +349,6 @@
330 349 }
331 350
332 351 return $result;
333 352 }
353 +
334 354 }