| @@ -2,15 +2,12 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Hurrytimer; |
| 4 | 4 | |
| 5 | 5 | use DateTime; |
| 6 | -use Hurrytimer\Utils\Helpers; | |
| 6 | +use Hurrytimer\CSS_Builder; | |
| 7 | 7 | |
| 8 | -if (!defined('ABSPATH')) { | |
| 9 | - exit; // Exit if accessed directly | |
| 10 | -} | |
| 11 | - | |
| 12 | -class Admin { | |
| 8 | +class Admin | |
| 9 | +{ | |
| 13 | 10 | /** |
| 14 | 11 | * The ID of this plugin. |
| 15 | 12 | * |
| 16 | 13 | * @since 1.0.0 |
| @@ -36,238 +33,135 @@ | ||
| 36 | 33 | * |
| 37 | 34 | * @since 1.0.0 |
| 38 | 35 | * |
| 39 | 36 | */ |
| 40 | - public function __construct($pluginName, $version) { | |
| 37 | + public function __construct( $pluginName, $version ) | |
| 38 | + { | |
| 41 | 39 | $this->pluginName = $pluginName; |
| 42 | 40 | $this->version = $version; |
| 43 | - add_action('wp_insert_post', [$this, 'regenerate_css'], 10, 3); | |
| 44 | - add_action('wp_ajax_wcSearchProducts', [$this, 'ajaxWcSearchProducts']); | |
| 45 | - add_action('wp_ajax_hurrytimer/search_wc_coupon', [$this, 'search_wc_coupon']); | |
| 46 | - add_action('wp_ajax_add_wc_condition_group', [$this, 'ajaxAddWcConditionGroup']); | |
| 47 | - add_action('wp_ajax_add_wc_condition', [$this, 'ajaxAddWcCondition']); | |
| 48 | - add_action('wp_ajax_load_wc_condition', [$this, 'ajaxLoadWcCondition']); | |
| 49 | - add_action('wp_ajax_hurryt_dismiss_leave_review_notice', [$this, 'dismiss_leave_review_ajax']); | |
| 50 | - add_action('wp_ajax_hurryt_remind_leave_review_notice', [$this, 'remind_leave_review_ajax']); | |
| 51 | - add_action('admin_init', [$this, 'activateCampaign']); | |
| 52 | - add_action('admin_init', [$this, 'deactivateCampaign']); | |
| 53 | - add_action('admin_init', [$this, 'resetEvergreenCampaign']); | |
| 54 | - add_action('admin_init', [$this, 'resetAllEvergreenCampaigns']); | |
| 55 | - add_action('admin_init', [$this, 'pluginSettings']); | |
| 56 | - add_filter('post_row_actions', [$this, 'campaignsListRowActions']); | |
| 57 | - add_action('admin_menu', [$this, 'menu']); | |
| 58 | - add_filter( | |
| 59 | - 'bulk_actions-edit-' . HURRYT_POST_TYPE, | |
| 60 | - [$this, 'campaignsListBulkActions',] | |
| 61 | - ); | |
| 41 | + add_action( 'wp_insert_post', [ $this, 'regenerate_css' ], 10, 3 ); | |
| 42 | + add_action( 'wp_ajax_wcSearchProducts', [ $this, 'ajaxWcSearchProducts' ] ); | |
| 43 | + add_action( 'wp_ajax_add_wc_condition_group', [ $this, 'ajaxAddWcConditionGroup' ] ); | |
| 44 | + add_action( 'wp_ajax_add_wc_condition', [ $this, 'ajaxAddWcCondition' ] ); | |
| 45 | + add_action( 'wp_ajax_load_wc_condition', [ $this, 'ajaxLoadWcCondition' ] ); | |
| 46 | + add_action( 'wp_ajax_hurryt_dismiss_leave_review_notice', [ $this, 'dismiss_leave_review_ajax' ] ); | |
| 47 | + add_action( 'wp_ajax_hurryt_remind_leave_review_notice', [ $this, 'remind_leave_review_ajax' ] ); | |
| 48 | + add_action( 'admin_init', [ $this, 'activateCampaign' ] ); | |
| 49 | + add_action( 'admin_init', [ $this, 'deactivateCampaign' ] ); | |
| 50 | + add_action( 'admin_init', [ $this, 'resetEvergreenCampaign' ] ); | |
| 51 | + add_action( 'admin_init', [ $this, 'resetAllEvergreenCampaigns' ] ); | |
| 52 | + add_action( 'admin_init', [ $this, 'pluginSettings' ] ); | |
| 53 | + add_filter( 'post_row_actions', [ $this, 'campaignsListRowActions' ] ); | |
| 54 | + add_action( 'admin_menu', [ $this, 'menu' ] ); | |
| 55 | + add_filter( 'bulk_actions-edit-' . HURRYT_POST_TYPE, | |
| 56 | + [ $this, 'campaignsListBulkActions', ] ); | |
| 62 | 57 | |
| 63 | - add_filter( | |
| 64 | - 'manage_' . HURRYT_POST_TYPE . '_posts_columns', | |
| 65 | - [$this, 'campaignsListColumns',] | |
| 66 | - ); | |
| 58 | + add_filter( 'manage_' . HURRYT_POST_TYPE . '_posts_columns', | |
| 59 | + [ $this, 'campaignsListColumns', ] ); | |
| 67 | 60 | |
| 68 | 61 | |
| 69 | - add_action( | |
| 70 | - 'manage_' . HURRYT_POST_TYPE . '_posts_custom_column', | |
| 71 | - [$this, 'countdownListColumnsContent'], | |
| 72 | - 10, | |
| 73 | - 2 | |
| 74 | - ); | |
| 62 | + add_action( 'manage_' . HURRYT_POST_TYPE . '_posts_custom_column', | |
| 63 | + [ $this, 'countdownListColumnsContent' ], 10, 2 ); | |
| 75 | 64 | |
| 76 | - add_filter( | |
| 77 | - 'bulk_post_updated_messages', | |
| 78 | - [$this, 'customBulkPostUpdatedMessages'], | |
| 79 | - 10, | |
| 80 | - 2 | |
| 81 | - ); | |
| 65 | + add_filter( 'bulk_post_updated_messages', | |
| 66 | + [ $this, 'customBulkPostUpdatedMessages' ], 10, 2 ); | |
| 82 | 67 | |
| 83 | - add_action('admin_menu', [$this, 'helpTabs']); | |
| 84 | - add_action('admin_notices', [$this, 'resetEvergreenCampaignNotice']); | |
| 85 | - add_action('admin_notices', [$this, 'resetAllEvergreenCampaignNotice']); | |
| 68 | + add_action( 'admin_menu', [ $this, 'helpTabs' ] ); | |
| 69 | + add_action( 'admin_notices', [ $this, 'resetEvergreenCampaignNotice' ] ); | |
| 70 | + add_action( 'admin_notices', [ $this, 'resetAllEvergreenCampaignNotice' ] ); | |
| 86 | 71 | |
| 87 | - add_action('admin_notices', [$this, 'countdown_activation_notice']); | |
| 88 | - add_filter('admin_footer_text', [$this, 'admin_footer_text']); | |
| 89 | - add_filter('wp_insert_post_data', [$this, 'mark_post_being_saved']); | |
| 72 | + add_action( 'admin_notices', [ $this, 'countdown_activation_notice' ] ); | |
| 73 | + add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] ); | |
| 74 | + add_filter( 'wp_insert_post_data', [ $this, 'mark_post_being_saved' ] ); | |
| 90 | 75 | |
| 91 | - add_filter('plugin_action_links_' . HURRYT_BASENAME, [$this, 'set_plugin_action_links']); | |
| 92 | - | |
| 76 | + add_filter( 'plugin_action_links_' . HURRYT_BASENAME, [ $this, 'set_plugin_action_links' ] ); | |
| 77 | + | |
| 93 | 78 | //removeIf(pro) |
| 94 | - add_action('admin_notices', [$this, 'leave_review_notice']); | |
| 79 | + add_action( 'admin_notices', [ $this, 'leave_review_notice' ] ); | |
| 95 | 80 | //endRemoveIf(pro) |
| 96 | 81 | |
| 97 | - add_action('wp_ajax_hurryt_dismiss_headline_moved_notice', [$this, 'dismiss_headline_moved_notice']); | |
| 82 | + add_action( 'wp_ajax_hurryt_dismiss_headline_moved_notice', [ $this, 'dismiss_headline_moved_notice' ] ); | |
| 98 | 83 | |
| 99 | - add_action('admin_enqueue_scripts', [$this, 'enqueue_review_scripts']); | |
| 100 | - | |
| 101 | - add_action('admin_init', [$this, 'handle_duplicate_campaign']); | |
| 102 | 84 | } |
| 103 | 85 | |
| 104 | - public function handle_duplicate_campaign() { | |
| 105 | - if ( | |
| 106 | - isset($_GET['action']) && $_GET['action'] === 'duplicate_campaign' && | |
| 107 | - isset($_GET['post']) && isset($_GET['_wpnonce']) && | |
| 108 | - wp_verify_nonce($_GET['_wpnonce'], 'duplicate_campaign_' . $_GET['post']) | |
| 109 | - ) { | |
| 110 | - $post_id = intval($_GET['post']); | |
| 111 | - | |
| 112 | - // Check if the user has permission to edit this post | |
| 113 | - if (!current_user_can('edit_post', $post_id) || !current_user_can('publish_posts')) { | |
| 114 | - wp_die(__('You do not have permission to duplicate this campaign.', 'hurrytimer')); | |
| 115 | - } | |
| 116 | - | |
| 117 | - $post = get_post($post_id); | |
| 118 | - if ($post && $post->post_type === HURRYT_POST_TYPE) { | |
| 119 | - $new_post_id = wp_insert_post([ | |
| 120 | - 'post_title' => $post->post_title . ' (Copy)', | |
| 121 | - 'post_type' => $post->post_type, | |
| 122 | - 'post_status' => 'draft', | |
| 123 | - ]); | |
| 124 | - | |
| 125 | - if ($new_post_id) { | |
| 126 | - // Copy post meta | |
| 127 | - $meta = get_post_meta($post_id); | |
| 128 | - foreach ($meta as $key => $values) { | |
| 129 | - foreach ($values as $value) { | |
| 130 | - add_post_meta($new_post_id, $key, maybe_unserialize($value)); | |
| 131 | - } | |
| 132 | - } | |
| 133 | - } | |
| 134 | - $source = isset($_GET['source']) ? sanitize_text_field($_GET['source']) : ''; | |
| 135 | - if ($source === 'list') { | |
| 136 | - // Redirect back to the list of campaigns | |
| 137 | - wp_safe_redirect(admin_url('edit.php?post_type=' . HURRYT_POST_TYPE)); | |
| 138 | - exit; | |
| 139 | - } else { | |
| 140 | - // Redirect to the newly created campaign | |
| 141 | - wp_safe_redirect(admin_url('post.php?action=edit&post=' . $new_post_id)); | |
| 142 | - exit; | |
| 143 | - } | |
| 144 | - } | |
| 145 | - } | |
| 86 | + public function dismiss_leave_review_ajax(){ | |
| 87 | + check_ajax_referer( 'hurryt-admin', 'nonce' ); | |
| 88 | + add_option('hurryt_leave_review_dismissed','1'); | |
| 146 | 89 | } |
| 147 | - | |
| 148 | - function enqueue_review_scripts(){ | |
| 149 | - wp_enqueue_script( | |
| 150 | - 'hurryt-review', | |
| 151 | - HURRYT_URL . 'assets/js/review.js', | |
| 152 | - ['jquery'], | |
| 153 | - HURRYT_VERSION, | |
| 154 | - true | |
| 155 | - ); | |
| 156 | - | |
| 157 | - wp_localize_script( | |
| 158 | - 'hurryt-review', | |
| 159 | - 'hurrytimer_ajax_review', | |
| 160 | - [ | |
| 161 | - 'url' => admin_url('admin-ajax.php'), | |
| 162 | - 'nonce' => wp_create_nonce('hurryt-review-nonce'), | |
| 163 | - ] | |
| 164 | - ); | |
| 165 | - | |
| 90 | + public function remind_leave_review_ajax(){ | |
| 91 | + check_ajax_referer( 'hurryt-admin', 'nonce' ); | |
| 92 | + set_transient('hurryt_remind_review_notice','1', 86400); | |
| 166 | 93 | } |
| 167 | - public function search_wc_coupon() { | |
| 168 | - check_ajax_referer('hurryt-admin', 'nonce'); | |
| 169 | 94 | |
| 170 | - if (!current_user_can('edit_posts')) { | |
| 171 | - wp_send_json_error(__('You do not have permission to perform this action.', 'hurrytimer'), 403); | |
| 172 | - } | |
| 95 | + public function dismiss_headline_moved_notice(){ | |
| 96 | + check_ajax_referer( 'hurryt-admin', 'nonce' ); | |
| 97 | + add_option('hurryt_headline_moved_notice_dismissed','1'); | |
| 173 | 98 | |
| 174 | - $search = isset($_GET['search']) ? sanitize_text_field($_GET['search']) : ''; | |
| 175 | - $exclude = isset($_GET['exclude']) ? array_map('intval', (array)$_GET['exclude']) : []; | |
| 176 | - | |
| 177 | - $items = get_posts([ | |
| 178 | - 'post_type' => 'shop_coupon', | |
| 179 | - 's' => $search, | |
| 180 | - 'post__not_in' => $exclude, | |
| 181 | - 'post_status' => 'any', | |
| 182 | - 'numberposts' => 30 | |
| 183 | - ]); | |
| 184 | - | |
| 185 | - $results = array_map(function ($item) { | |
| 186 | - return [ | |
| 187 | - "id" => $item->post_title, | |
| 188 | - "text" => $item->post_title, | |
| 189 | - ]; | |
| 190 | - }, $items); | |
| 191 | - wp_send_json(["results" => $results, "pagination" => true]); | |
| 192 | 99 | } |
| 193 | - public function dismiss_leave_review_ajax() { | |
| 194 | - check_ajax_referer('hurryt-review-nonce', 'nonce'); | |
| 195 | - add_option('hurryt_leave_review_dismissed', '1'); | |
| 196 | - } | |
| 197 | - public function remind_leave_review_ajax() { | |
| 198 | - check_ajax_referer('hurryt-review-nonce', 'nonce'); | |
| 199 | - set_transient('hurryt_remind_review_notice', '1', 86400); | |
| 200 | - } | |
| 201 | 100 | |
| 202 | - public function dismiss_headline_moved_notice() { | |
| 203 | - check_ajax_referer('hurryt-admin', 'nonce'); | |
| 204 | - add_option('hurryt_headline_moved_notice_dismissed', '1'); | |
| 205 | - } | |
| 101 | + private function should_ask_for_review(){ | |
| 206 | 102 | |
| 207 | - private function should_ask_for_review() { | |
| 208 | - | |
| 209 | - if (!apply_filters('hurryt_show_plugin_review_notice', true)) { | |
| 210 | - return false; | |
| 211 | - } | |
| 212 | - | |
| 213 | - if (get_transient('hurryt_remind_review_notice')) { | |
| 214 | - return false; | |
| 215 | - } | |
| 216 | - if (get_option('hurryt_leave_review_dismissed')) { | |
| 217 | - return false; | |
| 218 | - } | |
| 219 | - if (isset($_COOKIE['hurryt_leave_review_remind'])) { | |
| 220 | - return false; | |
| 221 | - } | |
| 222 | - if (isset($_COOKIE['hurryt_leave_review_dismissed'])) { | |
| 223 | - return false; | |
| 224 | - } | |
| 225 | - | |
| 226 | 103 | $campaigns = get_posts([ |
| 227 | - 'post_type' => HURRYT_POST_TYPE, | |
| 228 | - 'post_status' => 'publish', | |
| 229 | - 'posts_per_page' => 1, | |
| 230 | - 'orderby' => 'post_date', | |
| 231 | - 'order' => 'ASC' | |
| 104 | + 'post_type' => HURRYT_POST_TYPE, | |
| 105 | + 'post_status'=> 'publish', | |
| 106 | + 'posts_per_page'=> 1, | |
| 107 | + 'orderby'=> 'post_date', | |
| 108 | + 'order' => 'ASC' | |
| 232 | 109 | ]); |
| 233 | 110 | |
| 234 | - if (is_wp_error($campaigns) || empty($campaigns) || !is_array($campaigns)) { | |
| 111 | + if( is_wp_error($campaigns) || empty( $campaigns ) || ! is_array( $campaigns )){ | |
| 235 | 112 | return false; |
| 236 | 113 | } |
| 237 | 114 | |
| 238 | - $post_date = new DateTime($campaigns[0]->post_date); | |
| 115 | + $post_date = new DateTime( $campaigns[0]->post_date); | |
| 239 | 116 | |
| 240 | - $now = new DateTime(current_time('mysql')); | |
| 117 | + $now = new DateTime( current_time('mysql') ); | |
| 241 | 118 | |
| 242 | 119 | $diff = $post_date->diff($now); |
| 243 | - | |
| 244 | - if (!$diff) { | |
| 120 | + | |
| 121 | + if( ! $diff ){ | |
| 245 | 122 | return false; |
| 246 | 123 | } |
| 247 | 124 | |
| 248 | - return $diff->d >= 1; | |
| 125 | + return $diff->d >=1; | |
| 249 | 126 | } |
| 250 | 127 | |
| 251 | - public function leave_review_notice() { | |
| 252 | - if(! $this->should_ask_for_review()){ | |
| 253 | - return; | |
| 254 | - } | |
| 255 | -?> | |
| 256 | - <div class="notice notice-info is-dismissible"> | |
| 257 | - <h3>Support the development of HurryTimer plugin!</h3> | |
| 258 | - <p>Thank you for choosing <b>HurryTimer</b>. If you liked the plugin, kindly leave us a 5-star review on <a href="https://wordpress.org/support/plugin/hurrytimer/reviews/?filter=5" target="_blank">WordPress.org</a>. We really appreciate your support!</p> | |
| 128 | + public function leave_review_notice(){ | |
| 129 | + if(! apply_filters('hurryt_show_plugin_review_notice', true) ){ | |
| 130 | + return; | |
| 131 | + } | |
| 259 | 132 | |
| 260 | - <p> | |
| 261 | - <a href="https://wordpress.org/support/plugin/hurrytimer/reviews/?filter=5" class="button-primary">Leave a review</a> | |
| 262 | - <button type="button" class="button button-default" id="hurryt-remind-review-notice">Remind me later</button> | |
| 263 | - <button type="button" class="button-link" id="hurryt-dismiss-review-notice" style="margin-left:10px">Already done!</button> | |
| 264 | - </p> | |
| 265 | - </div> | |
| 266 | - <?php | |
| 133 | + if( ! $this->should_ask_for_review() ){ | |
| 134 | + return; | |
| 135 | + } | |
| 136 | + | |
| 137 | + if(get_transient('hurryt_remind_review_notice')){ | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + if(get_option('hurryt_leave_review_dismissed')){ | |
| 141 | + return; | |
| 142 | + } | |
| 143 | + if(isset($_COOKIE['hurryt_leave_review_remind'])){ | |
| 144 | + return; | |
| 145 | + } | |
| 146 | + if(isset($_COOKIE['hurryt_leave_review_dismissed'])){ | |
| 147 | + return; | |
| 148 | + } | |
| 149 | + ?> | |
| 150 | + <div class="notice notice-info is-dismissible"> | |
| 151 | + <h3>Support the development of HurryTimer plugin!</h3> | |
| 152 | + <p>Thank you for choosing <b>HurryTimer</b>. If you liked the plugin, kindly leave us a 5-star review on <a href="https://wordpress.org/support/plugin/hurrytimer/reviews/?filter=5" target="_blank">WordPress.org</a>. We really appreciate your support!</p> | |
| 153 | + | |
| 154 | + <p> <a href="https://wordpress.org/support/plugin/hurrytimer/reviews/?filter=5" class="button-primary">Leave a review</a> | |
| 155 | + <button type="button" class="button button-default" id="hurryt-remind-review-notice" >Remind me later</a> | |
| 156 | + <button type="button" class="button-link" id="hurryt-dismiss-review-notice" style="margin-left:10px">Already done!</a> | |
| 157 | + | |
| 158 | +</p> | |
| 159 | + </div> | |
| 160 | + <?php | |
| 267 | 161 | } |
| 268 | 162 | |
| 269 | - function mark_post_being_saved($data) { | |
| 163 | + function mark_post_being_saved( $data ) { | |
| 270 | 164 | |
| 271 | 165 | global $hurryt_saving_post; |
| 272 | 166 | |
| 273 | 167 | $hurryt_saving_post = 1; |
| @@ -281,40 +175,48 @@ | ||
| 281 | 175 | * @param $post_id |
| 282 | 176 | * @param $post |
| 283 | 177 | * @param $update |
| 284 | 178 | */ |
| 285 | - function regenerate_css($post_id, $post, $update) { | |
| 286 | - if (wp_is_post_revision($post_id)) { | |
| 179 | + function regenerate_css( $post_id, $post, $update ) | |
| 180 | + { | |
| 181 | + if ( wp_is_post_revision( $post_id ) ) { | |
| 287 | 182 | return; |
| 288 | 183 | } |
| 289 | 184 | |
| 290 | - if ($post->post_type !== HURRYT_POST_TYPE) { | |
| 185 | + if ( $post->post_type !== HURRYT_POST_TYPE ) { | |
| 291 | 186 | return; |
| 292 | 187 | } |
| 293 | 188 | |
| 294 | - if ($update) { | |
| 295 | - CSS_Builder::get_instance()->generate_css(); | |
| 189 | + if ( $update ) { | |
| 190 | + CSS_Builder::get_instance()->build(); | |
| 296 | 191 | } |
| 192 | + | |
| 297 | 193 | } |
| 298 | 194 | |
| 299 | - public function admin_footer_text() { | |
| 195 | + public function admin_footer_text() | |
| 196 | + { | |
| 300 | 197 | $screen = get_current_screen(); |
| 301 | - if ($screen->post_type === HURRYT_POST_TYPE) { | |
| 198 | + if ( $screen->post_type === HURRYT_POST_TYPE ) { | |
| 302 | 199 | include HURRYT_DIR . 'admin/templates/footer-rate-plugin.php'; |
| 303 | 200 | } |
| 304 | 201 | } |
| 305 | 202 | |
| 306 | - public function set_plugin_action_links($links) { | |
| 307 | - $settings_url = admin_url('admin.php?page=hurrytimer_settings'); | |
| 308 | - $settings_anchor = '<a href="' . $settings_url . '">' . __('Settings') . '</a>'; | |
| 309 | - $manage_url = admin_url('edit.php?post_type=' . HURRYT_POST_TYPE); | |
| 310 | - $manage_anchor = '<a href="' . $manage_url . '">' . __('Campaigns', 'hurrytimer') . '</a>'; | |
| 203 | + public function set_plugin_action_links( $links ) | |
| 204 | + { | |
| 205 | + $settings_url = admin_url( 'admin.php?page=hurrytimer_settings' ); | |
| 206 | + $settings_anchor = '<a href="' . $settings_url . '">' . __( 'Settings' ) . '</a>'; | |
| 207 | + $manage_url = admin_url( 'edit.php?post_type=' . HURRYT_POST_TYPE ); | |
| 208 | + $manage_anchor = '<a href="' . $manage_url . '">' . __( 'Campaigns', 'hurrytimer' ) . '</a>'; | |
| 311 | 209 | $links[] = $manage_anchor; |
| 312 | 210 | $links[] = $settings_anchor; |
| 313 | 211 | |
| 314 | 212 | //removeIf(pro) |
| 213 | + $manage_license_link = admin_url( 'admin.php?page=hurrytimer_license' ); | |
| 214 | + $manage_license_anchor = '<a href="' . $manage_license_link . '">' . __( 'License' ) . '</a>'; | |
| 215 | + $links[] = $manage_license_anchor; | |
| 216 | + | |
| 315 | 217 | $links[] |
| 316 | - = '<a href="https://hurrytimer.com/?utm_source=plugin&utm_medium=installed_plugins&utm_campaign=go_pro" target="_blank" style="font-weight:bold;color:#F37335">Go Pro</a>'; | |
| 218 | + = '<a href="https://hurrytimer.com/?utm_source=plugin&utm_medium=installed_plugins&utm_campaign=go_pro" target="_blank" class="hurryt-text-green-500 hurryt-font-bold">Go Pro</a>'; | |
| 317 | 219 | |
| 318 | 220 | //endRemoveIf(pro) |
| 319 | 221 | |
| 320 | 222 | return $links; |
| @@ -320,19 +222,20 @@ | ||
| 320 | 222 | return $links; |
| 321 | 223 | } |
| 322 | 224 | |
| 323 | 225 | |
| 324 | - public function countdown_activation_notice() { | |
| 325 | - $post_id = filter_input(INPUT_GET, 'post', FILTER_VALIDATE_INT); | |
| 326 | - $status = filter_input(INPUT_GET, 'hurrytimer_action'); | |
| 226 | + public function countdown_activation_notice() | |
| 227 | + { | |
| 228 | + $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); | |
| 229 | + $status = filter_input( INPUT_GET, 'hurrytimer_action' ); | |
| 327 | 230 | |
| 328 | - if (!$post_id || !$status || !($post = get_post($post_id))) { | |
| 231 | + if ( !$post_id || !$status || !( $post = get_post( $post_id ) ) ) { | |
| 329 | 232 | return; |
| 330 | 233 | } |
| 331 | 234 | if ( |
| 332 | 235 | $status === "activate-compaign" |
| 333 | 236 | && |
| 334 | - !Utils\Helpers::isPostActive($post_id) | |
| 237 | + !Utils\Helpers::isPostActive( $post_id ) | |
| 335 | 238 | ) { ?> |
| 336 | 239 | <div class="notice notice-success is-dismissible"> |
| 337 | 240 | <p><?php _e( |
| 338 | 241 | 'Countdown timer deactivated.', |
| @@ -340,53 +243,56 @@ | ||
| 340 | 243 | ); ?></p> |
| 341 | 244 | </div> |
| 342 | 245 | <?php } else { ?> |
| 343 | 246 | <div class="notice notice-success is-dismissible"> |
| 344 | - <p><?php _e('Countdown timer activated.', "hurrytimer"); ?></p> | |
| 247 | + <p><?php _e( 'Countdown timer activated.', "hurrytimer" ); ?></p> | |
| 345 | 248 | </div> |
| 346 | - <?php } | |
| 249 | + <?php } | |
| 347 | 250 | } |
| 348 | 251 | |
| 349 | - public function helpTabs() { | |
| 350 | - add_action('load-edit.php', [$this, 'editHelpTabs']); | |
| 351 | - add_action('load-post-new.php', [$this, 'editHelpTabs']); | |
| 352 | - add_action('load-post.php', [$this, 'editHelpTabs']); | |
| 252 | + public function helpTabs() | |
| 253 | + { | |
| 254 | + add_action( 'load-edit.php', [ $this, 'editHelpTabs' ] ); | |
| 255 | + add_action( 'load-post-new.php', [ $this, 'editHelpTabs' ] ); | |
| 256 | + add_action( 'load-post.php', [ $this, 'editHelpTabs' ] ); | |
| 353 | 257 | } |
| 354 | 258 | |
| 355 | - public function editHelpTabs() { | |
| 259 | + public function editHelpTabs() | |
| 260 | + { | |
| 356 | 261 | $screen = get_current_screen(); |
| 357 | - if (strpos($screen->id, 'hurrytimer_countdown') === false) { | |
| 262 | + if ( strpos( $screen->id, 'hurrytimer_countdown' ) === false ) { | |
| 358 | 263 | return; |
| 359 | 264 | } |
| 360 | 265 | $screen->remove_help_tabs(); |
| 361 | 266 | } |
| 362 | 267 | |
| 363 | - public function customBulkPostUpdatedMessages($bulk_messages, $bulk_counts) { | |
| 364 | - $bulk_messages[HURRYT_POST_TYPE] = [ | |
| 268 | + public function customBulkPostUpdatedMessages( $bulk_messages, $bulk_counts ) | |
| 269 | + { | |
| 270 | + $bulk_messages[ HURRYT_POST_TYPE ] = [ | |
| 365 | 271 | 'updated' => _n( |
| 366 | 272 | '%s countdown timer updated.', |
| 367 | 273 | '%s countdown timers updated.', |
| 368 | - $bulk_counts['updated'] | |
| 274 | + $bulk_counts[ 'updated' ] | |
| 369 | 275 | ), |
| 370 | 276 | 'locked' => _n( |
| 371 | 277 | '%s countdown timer not updated, somebody is editing it.', |
| 372 | 278 | '%s countdown timers not updated, somebody is editing them.', |
| 373 | - $bulk_counts['locked'] | |
| 279 | + $bulk_counts[ 'locked' ] | |
| 374 | 280 | ), |
| 375 | 281 | 'deleted' => _n( |
| 376 | 282 | '%s countdown timer permanently deleted.', |
| 377 | 283 | '%s countdown timers permanently deleted.', |
| 378 | - $bulk_counts['deleted'] | |
| 284 | + $bulk_counts[ 'deleted' ] | |
| 379 | 285 | ), |
| 380 | 286 | 'trashed' => _n( |
| 381 | 287 | '%s countdown timer deleted.', |
| 382 | 288 | '%s countdown timers deleted.', |
| 383 | - $bulk_counts['trashed'] | |
| 289 | + $bulk_counts[ 'trashed' ] | |
| 384 | 290 | ), |
| 385 | 291 | 'untrashed' => _n( |
| 386 | 292 | '%s countdown timer restored from the Trash.', |
| 387 | 293 | '%s countdown timers restored from the Trash.', |
| 388 | - $bulk_counts['untrashed'] | |
| 294 | + $bulk_counts[ 'untrashed' ] | |
| 389 | 295 | ), |
| 390 | 296 | ]; |
| 391 | 297 | |
| 392 | 298 | return $bulk_messages; |
| @@ -391,71 +297,61 @@ | ||
| 391 | 297 | |
| 392 | 298 | return $bulk_messages; |
| 393 | 299 | } |
| 394 | 300 | |
| 395 | - public function countdownListColumnsContent($column, $post_id) { | |
| 396 | - $campaign = new Campaign($post_id); | |
| 397 | - $campaign->loadSettings(); | |
| 398 | - switch ($column) { | |
| 399 | - case 'status': // Case for countdown status | |
| 400 | - | |
| 401 | - if($campaign->is_published()){ | |
| 402 | - if ($campaign->is_expired()) { | |
| 403 | - echo __('Expired', 'hurrytimer'); | |
| 404 | - } | |
| 405 | - elseif (!$campaign->is_scheduled()) { | |
| 406 | - echo __('Active', 'hurrytimer'); | |
| 407 | - } | |
| 408 | - }elseif($campaign->is_scheduled()){ | |
| 409 | - echo __('Scheduled', 'hurrytimer'); | |
| 410 | - | |
| 411 | - }else{ | |
| 412 | - echo __('Inactive', 'hurrytimer'); | |
| 413 | - } | |
| 301 | + public function countdownListColumnsContent( $column, $post_id ) | |
| 302 | + { | |
| 303 | + $campaign = new Campaign( $post_id ); | |
| 304 | + switch ( $column ) { | |
| 305 | + case 'status': | |
| 306 | + echo $campaign->is_published() | |
| 307 | + ? __( 'Active', "hurrytimer" ) | |
| 308 | + : __( 'Inactive', "hurrytimer" ); | |
| 414 | 309 | break; |
| 415 | 310 | case 'mode': |
| 416 | - if ($campaign->is_evergreen()) { | |
| 417 | - echo __('Evergreen', 'hurrytimer'); | |
| 311 | + if ( $campaign->is_evergreen() ) { | |
| 312 | + echo __( 'Evergreen', "hurrytimer" ); | |
| 418 | 313 | } |
| 419 | - if ($campaign->is_one_time()) { | |
| 420 | - echo __('One-Time', 'hurrytimer'); | |
| 314 | + if ( $campaign->is_one_time() ) { | |
| 315 | + echo __( 'One-Time', "hurrytimer" ); | |
| 421 | 316 | } |
| 422 | - if ($campaign->is_recurring()) { | |
| 423 | - echo __('Recurring', 'hurrytimer'); | |
| 317 | + if ( $campaign->is_recurring() ) { | |
| 318 | + echo __( 'Recurring', "hurrytimer" ); | |
| 424 | 319 | } |
| 425 | 320 | break; |
| 426 | 321 | case 'shortcode': |
| 427 | - ?> | |
| 428 | - <input style="min-width:100%" type="text" readonly onfocus="this.select()" value="[hurrytimer id="<?php echo $post_id ?>"]"> | |
| 429 | - <?php | |
| 430 | - | |
| 322 | + ?> | |
| 323 | +<input style="min-width:100%" type="text" readonly onfocus="this.select()" value="[hurrytimer id="<?php echo $post_id ?>"]"> | |
| 324 | + <?php | |
| 325 | + | |
| 431 | 326 | break; |
| 432 | - | |
| 433 | 327 | } |
| 434 | 328 | } |
| 435 | 329 | |
| 436 | - public function campaignsListBulkActions($actions) { | |
| 437 | - unset($actions['edit']); | |
| 330 | + public function campaignsListBulkActions( $actions ) | |
| 331 | + { | |
| 332 | + unset( $actions[ 'edit' ] ); | |
| 438 | 333 | return $actions; |
| 439 | 334 | } |
| 440 | 335 | |
| 441 | - public function campaignsListColumns($columns) { | |
| 336 | + public function campaignsListColumns( $columns ) | |
| 337 | + { | |
| 442 | 338 | $allowed_columns = []; |
| 443 | - foreach ($columns as $column_name => $value) { | |
| 444 | - if (in_array($column_name, ['cb', 'title', 'date'])) { | |
| 445 | - $allowed_columns[$column_name] = $value; | |
| 339 | + foreach ( $columns as $column_name => $value ) { | |
| 340 | + if ( in_array( $column_name, [ 'cb', 'title', 'date' ] ) ) { | |
| 341 | + $allowed_columns[ $column_name ] = $value; | |
| 446 | 342 | } |
| 447 | 343 | } |
| 448 | 344 | |
| 449 | 345 | $columns = $allowed_columns; |
| 450 | - $date = $columns['date']; | |
| 451 | - unset($columns['date']); | |
| 452 | - $columns = array_merge($columns, [ | |
| 453 | - 'status' => __('Status', "hurrytimer"), | |
| 454 | - 'mode' => __('Mode', "hurrytimer"), | |
| 455 | - 'shortcode' => __('Shortcode', "hurrytimer"), | |
| 456 | - ]); | |
| 457 | - $columns['date'] = $date; | |
| 346 | + $date = $columns[ 'date' ]; | |
| 347 | + unset( $columns[ 'date' ] ); | |
| 348 | + $columns = array_merge( $columns, [ | |
| 349 | + 'status' => __( 'Status', "hurrytimer" ), | |
| 350 | + 'mode' => __( 'Mode', "hurrytimer" ), | |
| 351 | + 'shortcode' => __( 'Shortcode', "hurrytimer" ), | |
| 352 | + ] ); | |
| 353 | + $columns[ 'date' ] = $date; | |
| 458 | 354 | |
| 459 | 355 | return $columns; |
| 460 | 356 | } |
| 461 | 357 | |
| @@ -463,20 +359,15 @@ | ||
| 463 | 359 | * Register the stylesheets for the admin area. |
| 464 | 360 | * |
| 465 | 361 | * @since 1.0.0 |
| 466 | 362 | */ |
| 467 | - | |
| 468 | - public function enqueueStyles() { | |
| 363 | + public function enqueueStyles() | |
| 364 | + { | |
| 365 | + $version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : $this->version; | |
| 469 | 366 | |
| 470 | - if (!$this->should_enqueue_scripts()) { | |
| 471 | - return; | |
| 472 | - } | |
| 367 | + wp_enqueue_style( 'wp-color-picker' ); | |
| 368 | + wp_dequeue_style( 'select2' ); | |
| 473 | 369 | |
| 474 | - $version = defined('WP_DEBUG') && WP_DEBUG ? time() : $this->version; | |
| 475 | - | |
| 476 | - wp_enqueue_style('wp-color-picker'); | |
| 477 | - wp_dequeue_style('select2'); | |
| 478 | - | |
| 479 | 370 | wp_enqueue_style( |
| 480 | 371 | "codemirror", |
| 481 | 372 | HURRYT_URL . 'assets/css/codemirror.css', |
| 482 | 373 | [], |
| @@ -501,32 +392,21 @@ | ||
| 501 | 392 | |
| 502 | 393 | wp_enqueue_style( |
| 503 | 394 | $this->pluginName, |
| 504 | 395 | HURRYT_URL . 'assets/css/admin.css', |
| 505 | - ['wp-color-picker', 'hurryt-base-css', 'hurryt-select2'], | |
| 396 | + [ 'wp-color-picker', 'hurryt-base-css', 'hurryt-select2' ], | |
| 506 | 397 | $version, |
| 507 | 398 | 'all' |
| 508 | 399 | ); |
| 509 | 400 | } |
| 510 | 401 | |
| 511 | - public function campaignsListRowActions($actions) { | |
| 402 | + public function campaignsListRowActions( $actions ) | |
| 403 | + { | |
| 512 | 404 | global $post; |
| 513 | - if ($post->post_type === HURRYT_POST_TYPE) { | |
| 514 | - unset($actions['inline hide-if-no-js']); | |
| 515 | - // Add a "Duplicate" link | |
| 516 | - $duplicate_nonce = wp_create_nonce('duplicate_campaign_' . $post->ID); | |
| 517 | - $duplicate_link = admin_url('admin.php?action=duplicate_campaign&post=' . $post->ID . '&_wpnonce=' . $duplicate_nonce . '&source=list'); | |
| 518 | - $actions['duplicate'] = '<a href="' . esc_url($duplicate_link) . '">' . __('Duplicate', 'hurrytimer') . '</a>'; | |
| 519 | - | |
| 520 | - // Move 'duplicate' before 'trash' | |
| 521 | - if (isset($actions['trash'])) { | |
| 522 | - $trash = $actions['trash']; | |
| 523 | - unset($actions['trash']); | |
| 524 | - $actions['duplicate'] = '<a href="' . esc_url($duplicate_link) . '">' . __('Duplicate', 'hurrytimer') . '</a>'; | |
| 525 | - $actions['trash'] = $trash; | |
| 526 | - } | |
| 405 | + if ( $post->post_type === HURRYT_POST_TYPE ) { | |
| 406 | + unset( $actions[ 'inline hide-if-no-js' ] ); | |
| 527 | 407 | } |
| 528 | - | |
| 408 | + | |
| 529 | 409 | return $actions; |
| 530 | 410 | } |
| 531 | 411 | |
| 532 | 412 | /** |
| @@ -533,33 +413,16 @@ | ||
| 533 | 413 | * Register the JavaScript for the admin area. |
| 534 | 414 | * |
| 535 | 415 | * @since 1.0.0 |
| 536 | 416 | */ |
| 417 | + public function enqueueScripts() | |
| 418 | + { | |
| 419 | + wp_enqueue_script( 'jquery-ui-core' ); | |
| 420 | + wp_enqueue_script( 'jquery-ui-tooltip' ); | |
| 421 | + wp_enqueue_script( 'wp-color-picker' ); | |
| 422 | + wp_enqueue_script( 'jquery-ui-slider' ); | |
| 423 | + wp_dequeue_script( 'select2' ); | |
| 537 | 424 | |
| 538 | - private function should_enqueue_scripts() { | |
| 539 | - $screen = get_current_screen(); | |
| 540 | - $screen_id = $screen ? $screen->id : ''; | |
| 541 | - | |
| 542 | - $screens = [ | |
| 543 | - 'edit-hurrytimer_countdown', | |
| 544 | - 'hurrytimer_countdown', | |
| 545 | - 'hurrytimer_page_hurrytimer_settings', | |
| 546 | - 'hurrytimer_page_hurrytimer_license' | |
| 547 | - ]; | |
| 548 | - | |
| 549 | - return apply_filters('hurrytimer/enqueue_scripts', in_array($screen_id, $screens, true)); | |
| 550 | - } | |
| 551 | - public function enqueueScripts() { | |
| 552 | - if (!$this->should_enqueue_scripts()) { | |
| 553 | - return; | |
| 554 | - } | |
| 555 | - wp_enqueue_editor(); | |
| 556 | - wp_enqueue_script('jquery-ui-core'); | |
| 557 | - wp_enqueue_script('jquery-ui-tooltip'); | |
| 558 | - wp_enqueue_script('wp-color-picker'); | |
| 559 | - wp_enqueue_script('jquery-ui-slider'); | |
| 560 | - wp_dequeue_script('select2'); | |
| 561 | - | |
| 562 | 425 | wp_enqueue_script( |
| 563 | 426 | 'hurryt-cookie', |
| 564 | 427 | HURRYT_URL . 'assets/js/cookie.min.js', |
| 565 | 428 | [], |
| @@ -569,9 +432,9 @@ | ||
| 569 | 432 | |
| 570 | 433 | wp_enqueue_script( |
| 571 | 434 | 'jq-date-picker-addon', |
| 572 | 435 | HURRYT_URL . 'assets/js/timepicker-addon.js', |
| 573 | - ['jquery-ui-datepicker'], | |
| 436 | + [ 'jquery-ui-datepicker' ], | |
| 574 | 437 | '1.6.3', |
| 575 | 438 | true |
| 576 | 439 | ); |
| 577 | 440 | |
| @@ -577,16 +440,16 @@ | ||
| 577 | 440 | |
| 578 | 441 | wp_enqueue_script( |
| 579 | 442 | 'hurryt-select2', |
| 580 | 443 | HURRYT_URL . 'assets/js/select2.min.js', |
| 581 | - ['jquery'], | |
| 444 | + [ 'jquery' ], | |
| 582 | 445 | '4.0.5', |
| 583 | 446 | true |
| 584 | 447 | ); |
| 585 | 448 | |
| 586 | - $deps = ['wp-color-picker', 'hurryt-cookie', 'jq-date-picker-addon', 'hurryt-select2']; | |
| 449 | + $deps = [ 'wp-color-picker', 'hurryt-cookie', 'jq-date-picker-addon', 'hurryt-select2' ]; | |
| 587 | 450 | |
| 588 | - $version = defined('WP_DEBUG') && WP_DEBUG ? time() : $this->version; | |
| 451 | + $version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : $this->version; | |
| 589 | 452 | |
| 590 | 453 | wp_enqueue_script( |
| 591 | 454 | $this->pluginName, |
| 592 | 455 | HURRYT_URL . 'assets/js/admin.js', |
| @@ -594,11 +457,11 @@ | ||
| 594 | 457 | $version, |
| 595 | 458 | true |
| 596 | 459 | ); |
| 597 | 460 | |
| 598 | - wp_localize_script($this->pluginName, 'hurrytimer_ajax_object', array( | |
| 599 | - 'ajax_nonce' => wp_create_nonce('hurryt-admin'), | |
| 600 | - 'ajax_url' => admin_url('admin-ajax.php'), | |
| 461 | + wp_localize_script( $this->pluginName, 'hurrytimer_ajax_object', array( | |
| 462 | + 'ajax_nonce' => wp_create_nonce( 'hurryt-admin' ), | |
| 463 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 601 | 464 | 'headline_pos' => [ |
| 602 | 465 | 'above_timer' => C::HEADLINE_POSITION_ABOVE_TIMER, |
| 603 | 466 | 'below_timer' => C::HEADLINE_POSITION_BELOW_TIMER, |
| 604 | 467 | ], |
| @@ -606,20 +469,21 @@ | ||
| 606 | 469 | 'evergreen' => C::MODE_EVERGREEN, |
| 607 | 470 | 'regular' => C::MODE_REGULAR, |
| 608 | 471 | 'recurring' => C::MODE_RECURRING, |
| 609 | 472 | ], |
| 610 | - 'COOKIEPATH' => defined('COOKIEPATH') ? COOKIEPATH : '', | |
| 611 | - 'COOKIE_DOMAIN' => defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : '', | |
| 612 | - 'searchProductsNonce' => wp_create_nonce('search-products') | |
| 613 | - )); | |
| 473 | + 'COOKIEPATH' => defined( 'COOKIEPATH' ) ? COOKIEPATH : '', | |
| 474 | + 'COOKIE_DOMAIN' => defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '', | |
| 475 | + ) ); | |
| 476 | + | |
| 614 | 477 | } |
| 615 | 478 | |
| 616 | - public function menu() { | |
| 479 | + public function menu() | |
| 480 | + { | |
| 617 | 481 | |
| 618 | 482 | add_menu_page( |
| 619 | 483 | 'HurryTimer', |
| 620 | 484 | 'HurryTimer', |
| 621 | - apply_filters('hurryt_admin_capability', 'edit_posts', 'campaigns_list'), | |
| 485 | + apply_filters( 'hurryt_admin_capability', 'edit_posts', 'campaigns_list' ), | |
| 622 | 486 | 'hurrytimer', |
| 623 | 487 | null, |
| 624 | 488 | 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNjkuNTYgNzAuNjIiPiAgPGRlZnM+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIiB5MT0iMzUuMzEiIHgyPSI2NS4wNyIgeTI9IjM1LjMxIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+ICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZjg1MzdmIi8+ICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjNjIi8+ICAgIDwvbGluZWFyR3JhZGllbnQ+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1IiB4MT0iMTUuODgiIHkxPSIyOS4zIiB4Mj0iNjkuNTYiIHkyPSIyOS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DIuNDEsMCwwLDAsMy4zLS4zMUw2OS41Niw3LjgxbC0xMiwuMzJhMi40MSwyLjQxLDAsMCwwLC4xMyw0LjgyWiIgc3R5bGU9ImZpbGw6IHVybCgjYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1KSIvPiAgICAgIDwvZz4gICAgPC9nPiAgPC9nPjwvc3ZnPg==' |
| 625 | 489 | ); |
| 626 | 490 | add_submenu_page( |
| 627 | 491 | 'hurrytimer', |
| 628 | - __('Add Campaign', 'hurrytimer'), | |
| 629 | - __('Add Campaign', 'hurrytimer'), | |
| 630 | - apply_filters('hurryt_admin_capability', 'edit_posts', 'add_campaign'), | |
| 492 | + __( 'Add Campaign', 'hurrytimer' ), | |
| 493 | + __( 'Add Campaign', 'hurrytimer' ), | |
| 494 | + apply_filters( 'hurryt_admin_capability', 'edit_posts', 'add_campaign' ), | |
| 631 | 495 | 'post-new.php?post_type=hurrytimer_countdown' |
| 632 | 496 | ); |
| 633 | 497 | |
| 634 | 498 | add_submenu_page( |
| 635 | 499 | 'hurrytimer', |
| 636 | - __('Settings', 'hurrytimer'), | |
| 637 | - __('Settings', 'hurrytimer'), | |
| 638 | - apply_filters('hurryt_admin_capability', 'manage_options', 'settings'), | |
| 500 | + __( 'Settings', 'hurrytimer' ), | |
| 501 | + __( 'Settings', 'hurrytimer' ), | |
| 502 | + apply_filters( 'hurryt_admin_capability', 'manage_options', 'settings' ), | |
| 639 | 503 | 'hurrytimer_settings', |
| 640 | - [$this, 'settings'] | |
| 504 | + [ $this, 'settings' ] | |
| 641 | 505 | ); |
| 642 | 506 | |
| 643 | 507 | } |
| 644 | 508 | |
| 645 | - public function settings() { | |
| 509 | + public function settings() | |
| 510 | + { | |
| 646 | 511 | include_once HURRYT_DIR . 'admin/templates/settings.php'; |
| 647 | 512 | } |
| 648 | 513 | |
| 649 | - public function activateCampaign() { | |
| 514 | + public function activateCampaign() | |
| 515 | + { | |
| 650 | 516 | if ( |
| 651 | - isset($_GET['hurrytimer_action']) | |
| 652 | - && $_GET['hurrytimer_action'] === "activate-compaign" | |
| 653 | - && isset($_GET['_wpnonce']) | |
| 654 | - && wp_verify_nonce($_GET['_wpnonce'], 'activate-compaign') | |
| 655 | - && isset($_GET['post']) | |
| 517 | + isset( $_GET[ 'hurrytimer_action' ] ) | |
| 518 | + && $_GET[ 'hurrytimer_action' ] === "activate-compaign" | |
| 519 | + && isset( $_GET[ '_wpnonce' ] ) | |
| 520 | + && wp_verify_nonce( $_GET[ '_wpnonce' ], 'activate-compaign' ) | |
| 656 | 521 | ) { |
| 657 | - $postId = intval($_GET['post']); | |
| 658 | - | |
| 659 | - if (!current_user_can('publish_posts') || !current_user_can('edit_post', $postId)) { | |
| 660 | - wp_die(__('You do not have permission to publish this post.', 'hurrytimer')); | |
| 661 | - } | |
| 662 | - | |
| 663 | - // Verify the post exists and is of the correct type | |
| 664 | - $post = get_post($postId); | |
| 665 | - if (!$post || $post->post_type !== HURRYT_POST_TYPE) { | |
| 666 | - wp_die(__('Invalid post.', 'hurrytimer')); | |
| 667 | - } | |
| 668 | - | |
| 669 | - // Update the post status to 'publish' | |
| 670 | - $updated = wp_update_post([ | |
| 671 | - 'ID' => $postId, | |
| 672 | - 'post_status' => 'publish' | |
| 673 | - ]); | |
| 674 | - | |
| 675 | - if (is_wp_error($updated)) { | |
| 676 | - wp_die($updated->get_error_message()); | |
| 677 | - } | |
| 678 | - | |
| 679 | - // Redirect back to the previous page with a success message | |
| 680 | - wp_safe_redirect(add_query_arg('activated', '1', wp_get_referer())); | |
| 681 | - exit; | |
| 522 | + $postId = intval( $_GET[ 'post' ] ); | |
| 523 | + wp_update_post( [ 'ID' => $postId, 'post_status' => 'publish' ] ); | |
| 682 | 524 | } |
| 683 | 525 | } |
| 684 | 526 | |
| 685 | - function resetEvergreenCampaignNotice() { | |
| 527 | + function resetEvergreenCampaignNotice() | |
| 528 | + { | |
| 686 | 529 | if ( |
| 687 | - isset($_GET['hurryt-action']) | |
| 688 | - && isset($_GET['hurryt-scope']) | |
| 689 | - && isset($_GET['post']) | |
| 690 | - && $_GET['hurryt-action'] === "reset-evergreen-compaign" | |
| 691 | - && isset($_GET['_wpnonce']) | |
| 692 | - && wp_verify_nonce($_GET['_wpnonce'], 'reset-evergreen-compaign') | |
| 530 | + isset( $_GET[ 'hurryt-action' ] ) | |
| 531 | + && isset( $_GET[ 'hurryt-scope' ] ) | |
| 532 | + && isset( $_GET[ 'post' ] ) | |
| 533 | + && $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign" | |
| 534 | + && isset( $_GET[ '_wpnonce' ] ) | |
| 535 | + && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' ) | |
| 693 | 536 | ) { |
| 694 | 537 | $scopeText |
| 695 | - = $_GET['hurryt-scope'] === 'admin' | |
| 538 | + = $_GET[ 'hurryt-scope' ] === 'admin' | |
| 696 | 539 | ? ' you ' |
| 697 | 540 | : ' all visitors '; ?> |
| 698 | 541 | <div class="notice notice-success is-dismissible"> |
| 699 | - <p><?php echo sprintf(__('Campaign has been reset for %1$s successfully.', 'hurrytimer'), $scopeText); ?> | |
| 700 | - | |
| 701 | - </p> | |
| 542 | + <p><?php _e( | |
| 543 | + "Campaign has been reset for $scopeText successfully.", | |
| 544 | + 'hurrytimer' | |
| 545 | + ); ?></p> | |
| 702 | 546 | </div> |
| 703 | - <?php | |
| 547 | + <?php | |
| 704 | 548 | } |
| 705 | 549 | } |
| 706 | 550 | |
| 707 | - function resetAllEvergreenCampaignNotice() { | |
| 551 | + function resetAllEvergreenCampaignNotice() | |
| 552 | + { | |
| 708 | 553 | if ( |
| 709 | - isset($_GET['hurryt-page']) | |
| 710 | - && isset($_GET['hurryt-scope']) | |
| 711 | - && isset($_GET['hurryt-action']) | |
| 712 | - && $_GET['hurryt-page'] === "hurrytimer_settings" | |
| 713 | - && $_GET['hurryt-action'] === "reset-all-evergreen-compaigns" | |
| 714 | - && isset($_GET['_wpnonce']) | |
| 715 | - && wp_verify_nonce($_GET['_wpnonce'], 'reset-all-evergreen-compaigns') | |
| 554 | + isset( $_GET[ 'hurryt-page' ] ) | |
| 555 | + && isset( $_GET[ 'hurryt-scope' ] ) | |
| 556 | + && isset( $_GET[ 'hurryt-action' ] ) | |
| 557 | + && $_GET[ 'hurryt-page' ] === "hurrytimer_settings" | |
| 558 | + && $_GET[ 'hurryt-action' ] === "reset-all-evergreen-compaigns" | |
| 559 | + && isset( $_GET[ '_wpnonce' ] ) | |
| 560 | + && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-all-evergreen-compaigns' ) | |
| 716 | 561 | ) { |
| 717 | 562 | $scopeText |
| 718 | - = $_GET['hurryt-scope'] === 'admin' | |
| 563 | + = $_GET[ 'hurryt-scope' ] === 'admin' | |
| 719 | 564 | ? ' you ' |
| 720 | 565 | : ' all visitors '; ?> |
| 721 | 566 | <div class="notice notice-success is-dismissible"> |
| 722 | 567 | <p><?php _e( |
| @@ -723,125 +568,69 @@ | ||
| 723 | 568 | "All evergreen campaigns have been reset for $scopeText successfully.", |
| 724 | 569 | 'hurrytimer' |
| 725 | 570 | ); ?></p> |
| 726 | 571 | </div> |
| 727 | - <?php | |
| 572 | + <?php | |
| 728 | 573 | } |
| 729 | 574 | } |
| 730 | 575 | |
| 731 | - public function resetEvergreenCampaign() { | |
| 576 | + public function resetEvergreenCampaign() | |
| 577 | + { | |
| 732 | 578 | if ( |
| 733 | - isset($_GET['hurryt-action']) | |
| 734 | - && isset($_GET['hurryt-scope']) | |
| 735 | - && isset($_GET['post']) | |
| 736 | - && $_GET['hurryt-action'] === "reset-evergreen-compaign" | |
| 737 | - && isset($_GET['_wpnonce']) | |
| 738 | - && wp_verify_nonce($_GET['_wpnonce'], 'reset-evergreen-compaign') | |
| 579 | + isset( $_GET[ 'hurryt-action' ] ) | |
| 580 | + && isset( $_GET[ 'hurryt-scope' ] ) | |
| 581 | + && isset( $_GET[ 'post' ] ) | |
| 582 | + && $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign" | |
| 583 | + && isset( $_GET[ '_wpnonce' ] ) | |
| 584 | + && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' ) | |
| 739 | 585 | ) { |
| 740 | - $postId = intval($_GET['post']); | |
| 586 | + $postId = intval( $_GET[ 'post' ] ); | |
| 741 | 587 | |
| 742 | - if (!current_user_can('edit_post', $postId)) { | |
| 743 | - wp_die(__('You do not have permission to perform this action.', 'hurrytimer')); | |
| 744 | - } | |
| 745 | - | |
| 746 | - $scope = sanitize_text_field($_GET['hurryt-scope']); | |
| 747 | - if (!in_array($scope, ['admin', 'all'], true)) { | |
| 748 | - wp_die(__('Invalid scope specified.', 'hurrytimer')); | |
| 749 | - } | |
| 750 | - | |
| 751 | - $campaign = new EvergreenCampaign($postId); | |
| 752 | - $campaign->reset($scope); | |
| 588 | + $campaign = new EvergreenCampaign( $postId ); | |
| 589 | + $campaign->reset( sanitize_text_field( $_GET[ 'hurryt-scope' ] ) ); | |
| 753 | 590 | } |
| 754 | 591 | } |
| 755 | 592 | |
| 756 | - public function resetAllEvergreenCampaigns() { | |
| 593 | + public function resetAllEvergreenCampaigns() | |
| 594 | + { | |
| 757 | 595 | |
| 758 | - | |
| 759 | - if ( | |
| 760 | - isset($_GET['hurryt-scope']) | |
| 761 | - && isset($_GET['hurryt-action']) | |
| 762 | - && $_GET['hurryt-action'] === "reset-all-evergreen-compaigns" | |
| 763 | - && isset($_GET['_wpnonce']) | |
| 764 | - && wp_verify_nonce($_GET['_wpnonce'], 'reset-all-evergreen-compaigns') | |
| 596 | + if ( isset( $_GET[ 'hurryt-scope' ] ) | |
| 597 | + && isset( $_GET[ 'hurryt-action' ] ) | |
| 598 | + && $_GET[ 'hurryt-action' ] === "reset-all-evergreen-compaigns" | |
| 599 | + && isset( $_GET[ '_wpnonce' ] ) | |
| 600 | + && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-all-evergreen-compaigns' ) | |
| 765 | 601 | ) { |
| 766 | - | |
| 767 | - | |
| 768 | - if (!current_user_can('manage_options')) { | |
| 769 | - wp_die(__('You do not have sufficient permissions to perform this action.', 'hurrytimer')); | |
| 770 | - } | |
| 771 | - // Validate and sanitize the scope | |
| 772 | - $scope = sanitize_text_field($_GET['hurryt-scope']); | |
| 773 | - if (!in_array($scope, ['admin', 'all'], true)) { | |
| 774 | - wp_die(__('Invalid scope specified.', 'hurrytimer')); | |
| 775 | - } | |
| 776 | - | |
| 777 | - // Perform the reset action | |
| 778 | 602 | $evergreenCampaign = new EvergreenCampaign(); |
| 779 | - $resetResult = $evergreenCampaign->resetAll($scope); | |
| 780 | - | |
| 781 | - if ($resetResult === false) { | |
| 782 | - wp_die(__('An error occurred while resetting the campaigns.', 'hurrytimer')); | |
| 783 | - } | |
| 784 | - | |
| 785 | - wp_safe_redirect(add_query_arg( | |
| 786 | - [ | |
| 787 | - 'page' => 'hurrytimer_settings', | |
| 788 | - 'reset' => 'success', | |
| 789 | - 'scope' => $scope | |
| 790 | - ], | |
| 791 | - admin_url('admin.php') | |
| 792 | - )); | |
| 793 | - exit; | |
| 603 | + $evergreenCampaign->resetAll( sanitize_text_field( $_GET[ 'hurryt-scope' ] ) ); | |
| 794 | 604 | } |
| 795 | 605 | } |
| 796 | 606 | |
| 797 | - public function deactivateCampaign() { | |
| 607 | + public function deactivateCampaign() | |
| 608 | + { | |
| 798 | 609 | if ( |
| 799 | - isset($_GET['hurrytimer_action']) | |
| 800 | - && $_GET['hurrytimer_action'] === "deactivate-compaign" | |
| 801 | - && isset($_GET['_wpnonce']) | |
| 802 | - && wp_verify_nonce($_GET['_wpnonce'], 'deactivate-compaign') | |
| 803 | - && isset($_GET['post']) | |
| 610 | + isset( $_GET[ 'hurrytimer_action' ] ) | |
| 611 | + && $_GET[ 'hurrytimer_action' ] === "deactivate-compaign" | |
| 612 | + && isset( $_GET[ '_wpnonce' ] ) | |
| 613 | + && wp_verify_nonce( $_GET[ '_wpnonce' ], 'deactivate-compaign' ) | |
| 804 | 614 | ) { |
| 805 | - $postId = intval($_GET['post']); | |
| 806 | - | |
| 807 | - if (!current_user_can('publish_posts') || !current_user_can('edit_post', $postId)) { | |
| 808 | - wp_die(__('You do not have permission to change the status of this post.', 'hurrytimer')); | |
| 809 | - } | |
| 810 | - | |
| 811 | - // Verify the post exists and is of the correct type | |
| 812 | - $post = get_post($postId); | |
| 813 | - if (!$post || $post->post_type !== HURRYT_POST_TYPE) { | |
| 814 | - wp_die(__('Invalid post.', 'hurrytimer')); | |
| 815 | - } | |
| 816 | - | |
| 817 | - // Update the post status to 'draft' | |
| 818 | - $updated = wp_update_post([ | |
| 819 | - 'ID' => $postId, | |
| 820 | - 'post_status' => 'draft' | |
| 821 | - ]); | |
| 822 | - | |
| 823 | - if (is_wp_error($updated)) { | |
| 824 | - wp_die($updated->get_error_message()); | |
| 825 | - } | |
| 826 | - | |
| 827 | - // Redirect back to the previous page with a success message | |
| 828 | - wp_safe_redirect(add_query_arg('deactivated', '1', wp_get_referer())); | |
| 829 | - exit; | |
| 615 | + $postId = intval( $_GET[ 'post' ] ); | |
| 616 | + wp_update_post( [ 'ID' => $postId, 'post_status' => 'draft' ] ); | |
| 830 | 617 | } |
| 831 | 618 | } |
| 832 | 619 | |
| 833 | - public function settingsBox() { | |
| 834 | - require plugin_dir_path(dirname(__FILE__)) . | |
| 620 | + public function settingsBox() | |
| 621 | + { | |
| 622 | + require plugin_dir_path( dirname( __FILE__ ) ) . | |
| 835 | 623 | 'admin/CampaignSettings.php'; |
| 836 | 624 | new CampaignSettings(); |
| 837 | 625 | } |
| 838 | 626 | |
| 839 | 627 | //removeIf(pro) |
| 840 | - public function upgradeBanner() { | |
| 628 | + public function upgradeBanner() | |
| 629 | + { | |
| 841 | 630 | add_meta_box( |
| 842 | 631 | 'hurrytimer-upgrade-banner', |
| 843 | - __('Get the Most of HurryTimer', 'hurrytimer'), | |
| 632 | + __( 'Get the Most of HurryTimer', 'hurrytimer' ), | |
| 844 | 633 | function () { |
| 845 | 634 | include HURRYT_DIR . 'admin/templates/upgrade-banner.php'; |
| 846 | 635 | }, |
| 847 | 636 | HURRYT_POST_TYPE, |
| @@ -855,26 +644,19 @@ | ||
| 855 | 644 | * Search products |
| 856 | 645 | * |
| 857 | 646 | * @return void |
| 858 | 647 | */ |
| 859 | - public function ajaxWcSearchProducts() { | |
| 648 | + public function ajaxWcSearchProducts() | |
| 649 | + { | |
| 650 | + $search = sanitize_text_field( $_GET[ 'search' ] ); | |
| 651 | + $selection = sanitize_text_field( $_GET[ 'productsSelection' ] ); | |
| 652 | + $exclude = array_map( 'intval', $_GET[ 'exclude' ] ); | |
| 860 | 653 | |
| 861 | - if (!current_user_can('edit_posts') || !current_user_can('publish_posts')) { | |
| 862 | - wp_die(__('You do not have permission to perform this action.', 'hurrytimer')); | |
| 863 | - } | |
| 864 | - | |
| 865 | - check_ajax_referer('search-products', 'searchProductsNonce'); | |
| 866 | - | |
| 867 | - | |
| 868 | - $search = isset($_GET['search']) ? sanitize_text_field($_GET['search']) : ''; | |
| 869 | - $selection = isset($_GET['productsSelection']) ? sanitize_text_field($_GET['productsSelection']) : -1; | |
| 870 | - $exclude = isset($_GET['exclude']) ? array_map('intval', (array)$_GET['exclude']) : []; | |
| 871 | - | |
| 872 | 654 | if ( |
| 873 | - in_array($selection, [ | |
| 874 | - C::WC_PS_TYPE_INCLUDE_CATEGORIES, | |
| 875 | - C::WC_PS_TYPE_EXCLUDE_CATEGORIES, | |
| 876 | - ]) | |
| 655 | + in_array( $selection, [ | |
| 656 | + C::WC_PS_TYPE_INCLUDE_CATEGORIES, | |
| 657 | + C::WC_PS_TYPE_EXCLUDE_CATEGORIES, | |
| 658 | + ] ) | |
| 877 | 659 | ) { |
| 878 | 660 | $args = [ |
| 879 | 661 | "hide_empty" => false, |
| 880 | 662 | "taxonomy" => "product_cat", |
| @@ -881,15 +663,15 @@ | ||
| 881 | 663 | "name__like" => $search, |
| 882 | 664 | 'exclude' => $exclude, |
| 883 | 665 | ]; |
| 884 | 666 | |
| 885 | - $items = get_terms($args); | |
| 886 | - $results = array_map(function ($item) { | |
| 667 | + $items = get_terms( $args ); | |
| 668 | + $results = array_map( function ( $item ) { | |
| 887 | 669 | return [ |
| 888 | 670 | "id" => $item->term_id, |
| 889 | 671 | "text" => $item->name, |
| 890 | 672 | ]; |
| 891 | - }, $items); | |
| 673 | + }, $items ); | |
| 892 | 674 | } else { |
| 893 | 675 | $args = [ |
| 894 | 676 | 's' => $search, |
| 895 | 677 | 'post_type' => 'product', |
| @@ -894,63 +676,57 @@ | ||
| 894 | 676 | 's' => $search, |
| 895 | 677 | 'post_type' => 'product', |
| 896 | 678 | 'post__not_in' => $exclude, |
| 897 | 679 | 'post_status' => 'any', |
| 898 | - 'numberposts' => 50 // TODO: apply paginating in select2 | |
| 680 | + 'posts_per_page' => -1 | |
| 899 | 681 | ]; |
| 900 | - $items = get_posts($args); | |
| 901 | - $results = array_map(function ($item) { | |
| 682 | + $items = get_posts( $args ); | |
| 683 | + $results = array_map( function ( $item ) { | |
| 902 | 684 | return [ |
| 903 | 685 | "id" => $item->ID, |
| 904 | 686 | "text" => $item->post_title, |
| 905 | 687 | ]; |
| 906 | - }, $items); | |
| 688 | + }, $items ); | |
| 907 | 689 | } |
| 908 | - exit(json_encode(["results" => $results, "pagination" => true])); | |
| 690 | + exit( json_encode( [ "results" => $results, "pagination" => true ] ) ); | |
| 909 | 691 | } |
| 910 | 692 | |
| 911 | - public function sanitize( $input ) { | |
| 912 | - $sanitized_input = Helpers::sanitize_array($input); | |
| 913 | - return $sanitized_input; | |
| 914 | - } | |
| 915 | - public function pluginSettings() { | |
| 916 | - | |
| 917 | - register_setting('hurrytimer_settings', 'hurryt_settings', [$this, 'sanitize']); | |
| 918 | - add_settings_section( | |
| 919 | - 'hurryt_settings_general', | |
| 920 | - __('General', 'hurrytimer'), | |
| 921 | - null, | |
| 922 | - 'hurrytimer_settings' | |
| 923 | - ); | |
| 924 | - add_settings_field( | |
| 925 | - 'hurryt_disable_actions_edit_mode', | |
| 926 | - 'Disable actions in the admin area', | |
| 927 | - function ($args) { | |
| 928 | - $options = get_option('hurryt_settings'); ?> | |
| 693 | + public function pluginSettings() | |
| 694 | + { | |
| 695 | + register_setting( 'hurrytimer_settings', 'hurryt_settings' ); | |
| 696 | + add_settings_section( | |
| 697 | + 'hurryt_settings_general', | |
| 698 | + __( 'General', 'hurrytimer' ), | |
| 699 | + null, | |
| 700 | + 'hurrytimer_settings' | |
| 701 | + ); | |
| 702 | + add_settings_field( | |
| 703 | + 'hurryt_disable_actions_edit_mode', | |
| 704 | + 'Disable actions in the admin area', | |
| 705 | + function ( $args ) { | |
| 706 | + $options = get_option( 'hurryt_settings' ); ?> | |
| 929 | 707 | <label for=""> |
| 930 | - <input type="checkbox" name="hurryt_settings[disable_actions]" <?php checked( | |
| 931 | - isset($options['disable_actions']) | |
| 932 | - && $options['disable_actions'], | |
| 933 | - 1 | |
| 934 | - ); ?> id="hurryt-disable-actions" value="1" /> | |
| 708 | + <input type="checkbox" | |
| 709 | + name="hurryt_settings[disable_actions]" <?php checked( | |
| 710 | + isset( $options[ 'disable_actions' ] ) | |
| 711 | + && $options[ 'disable_actions' ], | |
| 712 | + 1 | |
| 713 | + ); ?> id="hurryt-disable-actions" value="1"/> | |
| 935 | 714 | </label> |
| 936 | 715 | <p class="description"> |
| 937 | 716 | Don't run actions when editing or previewing a page in the admin area. |
| 938 | 717 | </p> |
| 939 | - <?php | |
| 940 | - }, | |
| 941 | - 'hurrytimer_settings', | |
| 942 | - 'hurryt_settings_general' | |
| 943 | - ); | |
| 718 | + <?php | |
| 719 | + }, | |
| 720 | + 'hurrytimer_settings', | |
| 721 | + 'hurryt_settings_general' | |
| 722 | + ); | |
| 944 | 723 | } |
| 945 | 724 | |
| 946 | - function ajaxAddWcConditionGroup() { | |
| 947 | - if (!current_user_can('edit_posts') || !current_user_can('publish_posts')) { | |
| 948 | - wp_die(__('You do not have permission to perform this action.', 'hurrytimer')); | |
| 949 | - } | |
| 725 | + function ajaxAddWcConditionGroup() | |
| 726 | + { | |
| 727 | + check_ajax_referer( 'hurryt-admin', 'nonce' ); | |
| 950 | 728 | |
| 951 | - check_ajax_referer('hurryt-admin', 'nonce'); | |
| 952 | - | |
| 953 | 729 | ob_start(); |
| 954 | 730 | include HURRYT_DIR . 'admin/templates/wc-condition-group.php'; |
| 955 | 731 | echo ob_get_clean(); |
| 956 | 732 | wp_die(); |
| @@ -955,31 +731,25 @@ | ||
| 955 | 731 | echo ob_get_clean(); |
| 956 | 732 | wp_die(); |
| 957 | 733 | } |
| 958 | 734 | |
| 959 | - function ajaxAddWcCondition() { | |
| 960 | - if (!current_user_can('edit_posts') || !current_user_can('publish_posts')) { | |
| 961 | - wp_die(__('You do not have permission to perform this action.', 'hurrytimer')); | |
| 962 | - } | |
| 735 | + function ajaxAddWcCondition() | |
| 736 | + { | |
| 737 | + check_ajax_referer( 'hurryt-admin', 'nonce' ); | |
| 963 | 738 | |
| 964 | - check_ajax_referer('hurryt-admin', 'nonce'); | |
| 965 | - | |
| 966 | 739 | ob_start(); |
| 967 | - $groupId = sanitize_key($_GET['group_id']); | |
| 740 | + $groupId = sanitize_key( $_GET[ 'group_id' ] ); | |
| 968 | 741 | include HURRYT_DIR . 'admin/templates/wc-condition.php'; |
| 969 | 742 | echo ob_get_clean(); |
| 970 | 743 | wp_die(); |
| 971 | 744 | } |
| 972 | 745 | |
| 973 | - function ajaxLoadWcCondition() { | |
| 974 | - if (!current_user_can('edit_posts') || !current_user_can('publish_posts')) { | |
| 975 | - wp_die(__('You do not have permission to perform this action.', 'hurrytimer')); | |
| 976 | - } | |
| 977 | - | |
| 978 | - check_ajax_referer('hurryt-admin', 'nonce'); | |
| 746 | + function ajaxLoadWcCondition() | |
| 747 | + { | |
| 748 | + check_ajax_referer( 'hurryt-admin', 'nonce' ); | |
| 979 | 749 | ob_start(); |
| 980 | - $groupId = sanitize_key($_GET['group_id']); | |
| 981 | - $selected = hurryt_wc_conditions()[sanitize_key($_GET['condition_key'])]; | |
| 750 | + $groupId = sanitize_key( $_GET[ 'group_id' ] ); | |
| 751 | + $selected = hurryt_wc_conditions()[ sanitize_key( $_GET[ 'condition_key' ] ) ]; | |
| 982 | 752 | include HURRYT_DIR . 'admin/templates/wc-condition.php'; |
| 983 | 753 | echo ob_get_clean(); |
| 984 | 754 | wp_die(); |
| 985 | 755 | } |