| @@ -46,52 +46,13 @@ | ||
| 46 | 46 | |
| 47 | 47 | // Campaign settings metabox. |
| 48 | 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); | |
| 51 | - | |
| 52 | 50 | add_action("updated_post_meta", [$this, 'maybe_reset_running_countdown'], 10, 4); |
| 53 | - | |
| 54 | - // Skip trash | |
| 55 | - add_action("trashed_post", [$this, 'skip_trash']); | |
| 56 | - | |
| 57 | - // Edit delete link text. | |
| 58 | - add_action('post_submitbox_start', [$this, 'delete_permanently_link']); | |
| 59 | 51 | } |
| 60 | 52 | |
| 61 | - public function delete_permanently_link($post) | |
| 62 | - { | |
| 63 | - if($post->post_type !== HURRYT_POST_TYPE){ | |
| 64 | - return; | |
| 65 | - } | |
| 66 | - ?> | |
| 67 | 53 | |
| 68 | - <div id="delete-action" class="is-delete-permanently"> | |
| 69 | - <?php if (current_user_can("delete_post", $post->ID)) { | |
| 70 | - $delete_text = __('Delete', "hurrytimer"); ?> | |
| 71 | - <a class="submitdelete deletion" href="<?php echo get_delete_post_link( | |
| 72 | - $post->ID | |
| 73 | - ); ?>"> | |
| 74 | - <?php echo $delete_text; ?></a> | |
| 75 | - <?php | |
| 76 | - } ?> | |
| 77 | - </div> | |
| 78 | - <?php | |
| 79 | - } | |
| 80 | - | |
| 81 | 54 | /** |
| 82 | - * Skip trash when deleting. | |
| 83 | - * | |
| 84 | - * @param int $post_id | |
| 85 | - * | |
| 86 | - * @return void | |
| 87 | - */ | |
| 88 | - public function skip_trash($post_id) | |
| 89 | - { | |
| 90 | - wp_delete_post($post_id, true); | |
| 91 | - } | |
| 92 | - | |
| 93 | - /** | |
| 94 | 55 | * Edit notices messages. |
| 95 | 56 | * |
| 96 | 57 | * @param array $messages |
| 97 | 58 | * |
| @@ -101,18 +62,18 @@ | ||
| 101 | 62 | { |
| 102 | 63 | global $post; |
| 103 | 64 | global $post_id; |
| 104 | 65 | $messages[HURRYT_POST_TYPE] = array( |
| 105 | - 0 => '', | |
| 106 | - 1 => __('Campaign updated', "hurrytimer"), | |
| 107 | - 2 => '', | |
| 108 | - 3 => '', | |
| 109 | - 4 => __('Campaign updated.', "hurrytimer"), | |
| 110 | - 5 => '', | |
| 111 | - 6 => __('Campaign published', "hurrytimer"), | |
| 112 | - 7 => __('Campaign saved.', "hurrytimer"), | |
| 113 | - 8 => __('Campaign submitted.', "hurrytimer"), | |
| 114 | - 9 => sprintf( | |
| 66 | + 0 => '', | |
| 67 | + 1 => __('Campaign updated', "hurrytimer"), | |
| 68 | + 2 => '', | |
| 69 | + 3 => '', | |
| 70 | + 4 => __('Campaign updated.', "hurrytimer"), | |
| 71 | + 5 => '', | |
| 72 | + 6 => __('Campaign published', "hurrytimer"), | |
| 73 | + 7 => __('Campaign saved.', "hurrytimer"), | |
| 74 | + 8 => __('Campaign submitted.', "hurrytimer"), | |
| 75 | + 9 => sprintf( | |
| 115 | 76 | __( |
| 116 | 77 | 'Campaign scheduled for: <strong>%1$s</strong>.', |
| 117 | 78 | "hurrytimer" |
| 118 | 79 | ), |
| @@ -142,9 +103,9 @@ | ||
| 142 | 103 | $object_id, |
| 143 | 104 | $meta_key, |
| 144 | 105 | $meta_value |
| 145 | 106 | ) { |
| 146 | - if ( ! in_array($meta_key, ['duration'])) { | |
| 107 | + if (!in_array($meta_key, ['duration'])) { | |
| 147 | 108 | return; |
| 148 | 109 | } |
| 149 | 110 | |
| 150 | 111 | // (new EvergreenCampaign($object_id))->reset(); |
| @@ -189,13 +150,12 @@ | ||
| 189 | 150 | |
| 190 | 151 | if (Utils\Helpers::isNewPost($post_id)) { |
| 191 | 152 | return; |
| 192 | 153 | } |
| 193 | - | |
| 194 | - $isActive = Utils\Helpers::isPostActive($post_id); | |
| 195 | - $publich_date = Utils\Helpers::format_date($post->post_date); | |
| 154 | + $isActive = Utils\Helpers::isPostActive($post_id); | |
| 155 | + $publich_date = Utils\Helpers::format_date($post->post_date); | |
| 196 | 156 | $deactivateUrl = Utils\Helpers::deactivateUrl($post_id); |
| 197 | - $activateUrl = Utils\Helpers::activateUrl($post_id); | |
| 157 | + $activateUrl = Utils\Helpers::activateUrl($post_id); | |
| 198 | 158 | |
| 199 | 159 | include HURRYT_DIR . '/admin/templates/post-publish-metabox.php'; |
| 200 | 160 | |
| 201 | 161 | } |
| @@ -212,9 +172,9 @@ | ||
| 212 | 172 | { |
| 213 | 173 | if (wp_is_post_revision($post_id)) { |
| 214 | 174 | return; |
| 215 | 175 | } |
| 216 | - if ( ! current_user_can('edit_post', $post_id)) { | |
| 176 | + if (!current_user_can('edit_post', $post_id)) { | |
| 217 | 177 | return; |
| 218 | 178 | } |
| 219 | 179 | $countdown = new Campaign($post_id); |
| 220 | 180 | $countdown->storeSettings($_POST); |
| @@ -231,9 +191,10 @@ | ||
| 231 | 191 | remove_meta_box('eg-meta-box', HURRYT_POST_TYPE, 'normal'); |
| 232 | 192 | |
| 233 | 193 | add_meta_box( |
| 234 | 194 | 'hurrytimer-settings', |
| 235 | - __('Settings', 'hurrytimer'), | |
| 195 | + __('Settings <a href="#" class="hurryt-fullscreen hidden"></a>', | |
| 196 | + 'hurrytimer'), | |
| 236 | 197 | array($this, 'settingsMetaboxTemplate'), |
| 237 | 198 | $post_type, |
| 238 | 199 | 'normal', |
| 239 | 200 | 'high' |
| @@ -241,9 +202,9 @@ | ||
| 241 | 202 | |
| 242 | 203 | if ($post_id) { |
| 243 | 204 | add_meta_box( |
| 244 | 205 | 'hrytmr-countdown__shortcode', |
| 245 | - __('CampaignShortcode', 'hurrytimer'), | |
| 206 | + __('Shortcode', 'hurrytimer'), | |
| 246 | 207 | array($this, 'shortcode_metabox_template'), |
| 247 | 208 | $post_type, |
| 248 | 209 | 'side', |
| 249 | 210 | 'high' |
| @@ -268,8 +229,10 @@ | ||
| 268 | 229 | { |
| 269 | 230 | global $post_id; |
| 270 | 231 | $campaign = new Campaign($post_id); |
| 271 | 232 | $campaign->loadSettings(); |
| 233 | + $resetCampaignAllVisitorsUrl = $this->createResetEvergreenCampaign('all'); | |
| 234 | + $resetCampaignCurrentAdminUrl = $this->createResetEvergreenCampaign('admin'); | |
| 272 | 235 | $products = $this->getWcProductsNames($campaign->wcProductsSelection, |
| 273 | 236 | $campaign->wcProductsSelectionType); |
| 274 | 237 | include HURRYT_DIR . '/admin/templates/campaign-settings.php'; |
| 275 | 238 | |
| @@ -274,8 +237,27 @@ | ||
| 274 | 237 | include HURRYT_DIR . '/admin/templates/campaign-settings.php'; |
| 275 | 238 | |
| 276 | 239 | } |
| 277 | 240 | |
| 241 | + public function createResetEvergreenCampaign($scope = 'admin') | |
| 242 | + { | |
| 243 | + global $post_id; | |
| 244 | + | |
| 245 | + return wp_nonce_url( | |
| 246 | + add_query_arg( | |
| 247 | + array( | |
| 248 | + 'hurryt-action' => 'reset-evergreen-compaign', | |
| 249 | + 'hurryt-scope' => $scope, | |
| 250 | + 'postid' => $post_id, | |
| 251 | + 'post' => $post_id, | |
| 252 | + 'action' => 'edit', | |
| 253 | + ), | |
| 254 | + network_admin_url('post.php') | |
| 255 | + ), | |
| 256 | + 'reset-evergreen-compaign' | |
| 257 | + ); | |
| 258 | + } | |
| 259 | + | |
| 278 | 260 | /** |
| 279 | 261 | * @param array $ids |
| 280 | 262 | * @param $selection |
| 281 | 263 | * |
| @@ -292,16 +274,16 @@ | ||
| 292 | 274 | case C::WC_PS_TYPE_ALL: |
| 293 | 275 | break; |
| 294 | 276 | case C::WC_PS_TYPE_INCLUDE_PRODUCTS: |
| 295 | 277 | case C::WC_PS_TYPE_EXCLUDE_PRODUCTS: |
| 296 | - $args = [ | |
| 278 | + $args = [ | |
| 297 | 279 | 'post_type' => 'product', |
| 298 | - 'post__in' => $ids, | |
| 280 | + 'post__in' => $ids, | |
| 299 | 281 | ]; |
| 300 | 282 | $products = get_posts($args); |
| 301 | 283 | foreach ($products as $product) { |
| 302 | 284 | $result[] = [ |
| 303 | - 'id' => $product->ID, | |
| 285 | + 'id' => $product->ID, | |
| 304 | 286 | 'text' => $product->post_title, |
| 305 | 287 | ]; |
| 306 | 288 | } |
| 307 | 289 | break; |
| @@ -306,12 +288,12 @@ | ||
| 306 | 288 | } |
| 307 | 289 | break; |
| 308 | 290 | case C::WC_PS_TYPE_INCLUDE_CATEGORIES: |
| 309 | 291 | case C::WC_PS_TYPE_EXCLUDE_CATEGORIES: |
| 310 | - $ids = array_map('intval', $ids); | |
| 292 | + $ids = array_map('intval', $ids); | |
| 311 | 293 | $args = [ |
| 312 | - 'taxonomy' => 'product_cat', | |
| 313 | - 'term_ids' => $ids, | |
| 294 | + 'taxonomy' => 'product_cat', | |
| 295 | + 'term_ids' => $ids, | |
| 314 | 296 | 'hide_empty' => false, |
| 315 | 297 | ]; |
| 316 | 298 | |
| 317 | 299 | $categories = get_terms($args); |
| @@ -322,9 +304,9 @@ | ||
| 322 | 304 | return in_array($_category->term_id, $ids); |
| 323 | 305 | }); |
| 324 | 306 | foreach ($categories as $category) { |
| 325 | 307 | $result[] = [ |
| 326 | - 'id' => $category->term_id, | |
| 308 | + 'id' => $category->term_id, | |
| 327 | 309 | 'text' => $category->name, |
| 328 | 310 | ]; |
| 329 | 311 | } |
| 330 | 312 | break; |
| @@ -333,5 +315,6 @@ | ||
| 333 | 315 | } |
| 334 | 316 | |
| 335 | 317 | return $result; |
| 336 | 318 | } |
| 319 | + | |
| 337 | 320 | } |