| @@ -32,57 +32,26 @@ | ||
| 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_action( "updated_post_meta", [ $this, 'maybe_reset_running_countdown' ], 10, 4 ); | |
| 51 | - add_action( 'edit_form_before_permalink', [ $this, 'show_headline_moved_notice' ] ); | |
| 50 | + add_action("updated_post_meta", [$this, 'maybe_reset_running_countdown'], 10, 4); | |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | - function show_headline_moved_notice( $post ) | |
| 55 | - { | |
| 56 | - if ( !$post || $post->post_type !== HURRYT_POST_TYPE ) { | |
| 57 | - return; | |
| 58 | - } | |
| 59 | 53 | |
| 60 | - if( get_option('hurryt_headline_moved_notice_dismissed') ){ | |
| 61 | - return; | |
| 62 | - } | |
| 63 | - | |
| 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 | - } | |
| 70 | - | |
| 71 | - if ( !Installer::get_instance()->has_upgraded_from_2_2_28_or_prior() ) { | |
| 72 | - return; | |
| 73 | - } | |
| 74 | - | |
| 75 | - ?> | |
| 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> | |
| 81 | - <?php | |
| 82 | - } | |
| 83 | - | |
| 84 | - | |
| 85 | 54 | /** |
| 86 | 55 | * Edit notices messages. |
| 87 | 56 | * |
| 88 | 57 | * @param array $messages |
| @@ -88,29 +57,33 @@ | ||
| 88 | 57 | * @param array $messages |
| 89 | 58 | * |
| 90 | 59 | * @return array |
| 91 | 60 | */ |
| 92 | - public function custom_updated_messages( $messages ) | |
| 61 | + public function custom_updated_messages($messages) | |
| 93 | 62 | { |
| 94 | 63 | global $post; |
| 95 | - $messages[ HURRYT_POST_TYPE ] = array( | |
| 64 | + global $post_id; | |
| 65 | + $messages[HURRYT_POST_TYPE] = array( | |
| 96 | 66 | 0 => '', |
| 97 | - 1 => __( 'Campaign updated.', 'hurrytimer' ), | |
| 67 | + 1 => __('Campaign updated', "hurrytimer"), | |
| 98 | 68 | 2 => '', |
| 99 | 69 | 3 => '', |
| 100 | - 4 => __( 'Campaign updated.', 'hurrytimer' ), | |
| 70 | + 4 => __('Campaign updated.', "hurrytimer"), | |
| 101 | 71 | 5 => '', |
| 102 | - 6 => __( 'Campaign published.', 'hurrytimer' ), | |
| 103 | - 7 => __( 'Campaign saved.', 'hurrytimer' ), | |
| 104 | - 8 => __( 'Campaign submitted.', 'hurrytimer' ), | |
| 72 | + 6 => __('Campaign published', "hurrytimer"), | |
| 73 | + 7 => __('Campaign saved.', "hurrytimer"), | |
| 74 | + 8 => __('Campaign submitted.', "hurrytimer"), | |
| 105 | 75 | 9 => sprintf( |
| 106 | 76 | __( |
| 107 | 77 | 'Campaign scheduled for: <strong>%1$s</strong>.', |
| 108 | - 'hurrytimer' | |
| 78 | + "hurrytimer" | |
| 109 | 79 | ), |
| 110 | - 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 | + ) | |
| 111 | 84 | ), |
| 112 | - 10 => __( 'Campaign draft updated.', 'hurrytimer' ), | |
| 85 | + 10 => __('Campaign draft updated.', "hurrytimer"), | |
| 113 | 86 | ); |
| 114 | 87 | |
| 115 | 88 | return $messages; |
| 116 | 89 | } |
| @@ -117,10 +90,10 @@ | ||
| 117 | 90 | |
| 118 | 91 | /** |
| 119 | 92 | * If time is edited, reset compaign. |
| 120 | 93 | * |
| 121 | - * @param int $meta_id | |
| 122 | - * @param int $object_id | |
| 94 | + * @param int $meta_id | |
| 95 | + * @param int $object_id | |
| 123 | 96 | * @param string $meta_key |
| 124 | 97 | * @param string $meta_value |
| 125 | 98 | * |
| 126 | 99 | * @return void |
| @@ -130,9 +103,9 @@ | ||
| 130 | 103 | $object_id, |
| 131 | 104 | $meta_key, |
| 132 | 105 | $meta_value |
| 133 | 106 | ) { |
| 134 | - if ( !in_array( $meta_key, [ 'duration' ] ) ) { | |
| 107 | + if (!in_array($meta_key, ['duration'])) { | |
| 135 | 108 | return; |
| 136 | 109 | } |
| 137 | 110 | |
| 138 | 111 | // (new EvergreenCampaign($object_id))->reset(); |
| @@ -137,9 +110,9 @@ | ||
| 137 | 110 | |
| 138 | 111 | // (new EvergreenCampaign($object_id))->reset(); |
| 139 | 112 | } |
| 140 | 113 | |
| 141 | - public function maybe_delete_running_countdown( $post_id ) | |
| 114 | + public function maybe_delete_running_countdown($post_id) | |
| 142 | 115 | { |
| 143 | 116 | //Evergreen_Countdown::reset($post_id); |
| 144 | 117 | } |
| 145 | 118 | |
| @@ -149,14 +122,14 @@ | ||
| 149 | 122 | * @param string $title |
| 150 | 123 | * |
| 151 | 124 | * @return string |
| 152 | 125 | */ |
| 153 | - public function change_countdown_title( $title ) | |
| 126 | + public function change_countdown_title($title) | |
| 154 | 127 | { |
| 155 | 128 | global $post; |
| 156 | - if ( $post && $post->post_type === HURRYT_POST_TYPE ) { | |
| 129 | + if ($post->post_type === HURRYT_POST_TYPE) { | |
| 157 | 130 | return __( |
| 158 | - 'Campaign name (optional)', | |
| 131 | + 'Headline (optional)', | |
| 159 | 132 | "hurrytimer" |
| 160 | 133 | ); |
| 161 | 134 | } |
| 162 | 135 | |
| @@ -170,19 +143,19 @@ | ||
| 170 | 143 | */ |
| 171 | 144 | public function post_publish_metabox() |
| 172 | 145 | { |
| 173 | 146 | global $post_id, $post; |
| 174 | - if ( $post->post_type !== HURRYT_POST_TYPE ) { | |
| 147 | + if ($post->post_type !== HURRYT_POST_TYPE) { | |
| 175 | 148 | return; |
| 176 | 149 | } |
| 177 | 150 | |
| 178 | - if ( Utils\Helpers::isNewPost( $post_id ) ) { | |
| 151 | + if (Utils\Helpers::isNewPost($post_id)) { | |
| 179 | 152 | return; |
| 180 | 153 | } |
| 181 | - $isActive = Utils\Helpers::isPostActive( $post_id ); | |
| 182 | - $publich_date = Utils\Helpers::format_date( $post->post_date ); | |
| 183 | - $deactivateUrl = Utils\Helpers::deactivateUrl( $post_id ); | |
| 184 | - $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); | |
| 185 | 158 | |
| 186 | 159 | include HURRYT_DIR . '/admin/templates/post-publish-metabox.php'; |
| 187 | 160 | |
| 188 | 161 | } |
| @@ -194,47 +167,45 @@ | ||
| 194 | 167 | * |
| 195 | 168 | * @return void |
| 196 | 169 | */ |
| 197 | 170 | |
| 198 | - public function save_settings( $post_id ) | |
| 171 | + public function save_settings($post_id) | |
| 199 | 172 | { |
| 200 | - if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) | |
| 201 | - || (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID']) | |
| 202 | - || (!current_user_can('edit_post', $post_id)) | |
| 203 | - | |
| 204 | - ) { | |
| 173 | + if (wp_is_post_revision($post_id)) { | |
| 205 | 174 | return; |
| 206 | 175 | } |
| 207 | - | |
| 208 | - $countdown = new Campaign( $post_id ); | |
| 209 | - $countdown->storeSettings( $_POST ); | |
| 176 | + if (!current_user_can('edit_post', $post_id)) { | |
| 177 | + return; | |
| 178 | + } | |
| 179 | + $countdown = new Campaign($post_id); | |
| 180 | + $countdown->storeSettings($_POST); | |
| 210 | 181 | } |
| 211 | 182 | |
| 212 | - public function add_settings_metabox_template( $post_type ) | |
| 183 | + public function add_settings_metabox_template($post_type) | |
| 213 | 184 | { |
| 214 | 185 | global $post_id; |
| 215 | - if ( $post_type != HURRYT_POST_TYPE ) { | |
| 186 | + if ($post_type != HURRYT_POST_TYPE) { | |
| 216 | 187 | return; |
| 217 | 188 | } |
| 218 | - remove_meta_box( 'wpseo_meta', HURRYT_POST_TYPE, 'normal' ); | |
| 219 | - remove_meta_box( 'slugdiv', HURRYT_POST_TYPE, 'normal' ); | |
| 220 | - 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'); | |
| 221 | 192 | |
| 222 | 193 | add_meta_box( |
| 223 | 194 | 'hurrytimer-settings', |
| 224 | - __( 'Settings <a href="#" class="hurryt-fullscreen hidden"></a>', | |
| 225 | - 'hurrytimer' ), | |
| 226 | - array( $this, 'settingsMetaboxTemplate' ), | |
| 195 | + __('Settings <a href="#" class="hurryt-fullscreen hidden"></a>', | |
| 196 | + 'hurrytimer'), | |
| 197 | + array($this, 'settingsMetaboxTemplate'), | |
| 227 | 198 | $post_type, |
| 228 | 199 | 'normal', |
| 229 | 200 | 'high' |
| 230 | 201 | ); |
| 231 | 202 | |
| 232 | - if ( $post_id ) { | |
| 203 | + if ($post_id) { | |
| 233 | 204 | add_meta_box( |
| 234 | 205 | 'hrytmr-countdown__shortcode', |
| 235 | - __( 'Shortcode', 'hurrytimer' ), | |
| 236 | - array( $this, 'shortcode_metabox_template' ), | |
| 206 | + __('Shortcode', 'hurrytimer'), | |
| 207 | + array($this, 'shortcode_metabox_template'), | |
| 237 | 208 | $post_type, |
| 238 | 209 | 'side', |
| 239 | 210 | 'high' |
| 240 | 211 | ); |
| @@ -256,36 +227,34 @@ | ||
| 256 | 227 | */ |
| 257 | 228 | public function settingsMetaboxTemplate() |
| 258 | 229 | { |
| 259 | 230 | global $post_id; |
| 260 | - $campaign = new Campaign( $post_id ); | |
| 231 | + $campaign = new Campaign($post_id); | |
| 261 | 232 | $campaign->loadSettings(); |
| 262 | - $resetCampaignAllVisitorsUrl = $this->createResetEvergreenCampaign( 'all' ); | |
| 263 | - $resetCampaignCurrentAdminUrl = $this->createResetEvergreenCampaign( 'admin' ); | |
| 264 | - $products = $this->getWcProductsNames( $campaign->wcProductsSelection, | |
| 265 | - $campaign->wcProductsSelectionType ); | |
| 233 | + $resetCampaignAllVisitorsUrl = $this->createResetEvergreenCampaign('all'); | |
| 234 | + $resetCampaignCurrentAdminUrl = $this->createResetEvergreenCampaign('admin'); | |
| 235 | + $products = $this->getWcProductsNames($campaign->wcProductsSelection, | |
| 236 | + $campaign->wcProductsSelectionType); | |
| 266 | 237 | include HURRYT_DIR . '/admin/templates/campaign-settings.php'; |
| 267 | 238 | |
| 268 | 239 | } |
| 269 | 240 | |
| 270 | - public function createResetEvergreenCampaign( $scope = 'admin' ) | |
| 241 | + public function createResetEvergreenCampaign($scope = 'admin') | |
| 271 | 242 | { |
| 272 | 243 | global $post_id; |
| 273 | 244 | |
| 274 | - $action = 'reset-evergreen-compaign'; | |
| 275 | - | |
| 276 | 245 | return wp_nonce_url( |
| 277 | 246 | add_query_arg( |
| 278 | 247 | array( |
| 279 | - 'hurryt-action' => $action, | |
| 248 | + 'hurryt-action' => 'reset-evergreen-compaign', | |
| 280 | 249 | 'hurryt-scope' => $scope, |
| 281 | 250 | 'postid' => $post_id, |
| 282 | 251 | 'post' => $post_id, |
| 283 | 252 | 'action' => 'edit', |
| 284 | 253 | ), |
| 285 | - admin_url( 'post.php' ) | |
| 254 | + network_admin_url('post.php') | |
| 286 | 255 | ), |
| 287 | - $action | |
| 256 | + 'reset-evergreen-compaign' | |
| 288 | 257 | ); |
| 289 | 258 | } |
| 290 | 259 | |
| 291 | 260 | /** |
| @@ -293,16 +262,16 @@ | ||
| 293 | 262 | * @param $selection |
| 294 | 263 | * |
| 295 | 264 | * @return array |
| 296 | 265 | */ |
| 297 | - public function getWcProductsNames( $ids, $selection ) | |
| 266 | + public function getWcProductsNames($ids, $selection) | |
| 298 | 267 | { |
| 299 | 268 | $result = []; |
| 300 | - if ( empty( $ids ) ) { | |
| 269 | + if (empty($ids)) { | |
| 301 | 270 | return $result; |
| 302 | 271 | } |
| 303 | 272 | |
| 304 | - switch ( $selection ) { | |
| 273 | + switch ($selection) { | |
| 305 | 274 | case C::WC_PS_TYPE_ALL: |
| 306 | 275 | break; |
| 307 | 276 | case C::WC_PS_TYPE_INCLUDE_PRODUCTS: |
| 308 | 277 | case C::WC_PS_TYPE_EXCLUDE_PRODUCTS: |
| @@ -308,13 +277,11 @@ | ||
| 308 | 277 | case C::WC_PS_TYPE_EXCLUDE_PRODUCTS: |
| 309 | 278 | $args = [ |
| 310 | 279 | 'post_type' => 'product', |
| 311 | 280 | 'post__in' => $ids, |
| 312 | - 'post_status' => 'any', | |
| 313 | - 'posts_per_page' => -1 | |
| 314 | 281 | ]; |
| 315 | - $products = get_posts( $args ); | |
| 316 | - foreach ( $products as $product ) { | |
| 282 | + $products = get_posts($args); | |
| 283 | + foreach ($products as $product) { | |
| 317 | 284 | $result[] = [ |
| 318 | 285 | 'id' => $product->ID, |
| 319 | 286 | 'text' => $product->post_title, |
| 320 | 287 | ]; |
| @@ -321,9 +288,9 @@ | ||
| 321 | 288 | } |
| 322 | 289 | break; |
| 323 | 290 | case C::WC_PS_TYPE_INCLUDE_CATEGORIES: |
| 324 | 291 | case C::WC_PS_TYPE_EXCLUDE_CATEGORIES: |
| 325 | - $ids = array_map( 'intval', $ids ); | |
| 292 | + $ids = array_map('intval', $ids); | |
| 326 | 293 | $args = [ |
| 327 | 294 | 'taxonomy' => 'product_cat', |
| 328 | 295 | 'term_ids' => $ids, |
| 329 | 296 | 'hide_empty' => false, |
| @@ -328,16 +295,16 @@ | ||
| 328 | 295 | 'term_ids' => $ids, |
| 329 | 296 | 'hide_empty' => false, |
| 330 | 297 | ]; |
| 331 | 298 | |
| 332 | - $categories = get_terms( $args ); | |
| 299 | + $categories = get_terms($args); | |
| 333 | 300 | |
| 334 | - $categories = array_filter( $categories, function ( | |
| 301 | + $categories = array_filter($categories, function ( | |
| 335 | 302 | $_category |
| 336 | - ) use ( $ids ) { | |
| 337 | - return in_array( $_category->term_id, $ids ); | |
| 338 | - } ); | |
| 339 | - foreach ( $categories as $category ) { | |
| 303 | + ) use ($ids) { | |
| 304 | + return in_array($_category->term_id, $ids); | |
| 305 | + }); | |
| 306 | + foreach ($categories as $category) { | |
| 340 | 307 | $result[] = [ |
| 341 | 308 | 'id' => $category->term_id, |
| 342 | 309 | 'text' => $category->name, |
| 343 | 310 | ]; |
| @@ -348,6 +315,6 @@ | ||
| 348 | 315 | } |
| 349 | 316 | |
| 350 | 317 | return $result; |
| 351 | 318 | } |
| 352 | - | |
| 319 | + | |
| 353 | 320 | } |