| @@ -30,28 +30,26 @@ | ||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | private function intializeHooks() |
| 33 | 33 | { |
| 34 | - // Save campaign settings. | |
| 35 | - add_action('save_post_hurrytimer_countdown', [$this, 'save_settings'], 10, 3); | |
| 36 | 34 | |
| 35 | + // Save compaign settings. | |
| 36 | + add_action( 'save_post_hurrytimer_countdown', [ $this, 'save_settings' ], 10, 3 ); | |
| 37 | + | |
| 37 | 38 | // Custom publish metabox. |
| 38 | - add_action('post_submitbox_misc_actions', [$this, 'post_publish_metabox']); | |
| 39 | + add_action( 'post_submitbox_misc_actions', [ $this, 'post_publish_metabox' ] ); | |
| 39 | 40 | |
| 40 | - // Handle campaign duplication. | |
| 41 | - add_action('admin_init', [$this, 'handle_duplicate_campaign']); | |
| 42 | - | |
| 43 | 41 | // Edit placeholder for headline. |
| 44 | - add_filter('enter_title_here', [$this, 'change_countdown_title'], 10); | |
| 42 | + add_filter( 'enter_title_here', [ $this, 'change_countdown_title' ], 10 ); | |
| 45 | 43 | |
| 46 | 44 | // Edit messages. |
| 47 | - add_filter('post_updated_messages', [$this, 'custom_updated_messages'], 10); | |
| 45 | + add_filter( 'post_updated_messages', [ $this, 'custom_updated_messages' ], 10 ); | |
| 48 | 46 | |
| 49 | 47 | // Campaign settings metabox. |
| 50 | - add_filter('add_meta_boxes', [$this, 'add_settings_metabox_template'], 10); | |
| 48 | + add_filter( 'add_meta_boxes', [ $this, 'add_settings_metabox_template' ], 10 ); | |
| 51 | 49 | |
| 52 | - add_action("updated_post_meta", [$this, 'maybe_reset_running_countdown'], 10, 4); | |
| 53 | - add_action('edit_form_before_permalink', [$this, 'show_headline_moved_notice']); | |
| 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' ] ); | |
| 54 | 52 | } |
| 55 | 53 | |
| 56 | 54 | function show_headline_moved_notice( $post ) |
| 57 | 55 | { |
| @@ -95,24 +93,27 @@ | ||
| 95 | 93 | { |
| 96 | 94 | global $post; |
| 97 | 95 | $messages[ HURRYT_POST_TYPE ] = array( |
| 98 | 96 | 0 => '', |
| 99 | - 1 => __( 'Campaign updated.', 'hurrytimer' ), | |
| 97 | + 1 => __( 'Campaign updated', "hurrytimer" ), | |
| 100 | 98 | 2 => '', |
| 101 | 99 | 3 => '', |
| 102 | - 4 => __( 'Campaign updated.', 'hurrytimer' ), | |
| 100 | + 4 => __( 'Campaign updated.', "hurrytimer" ), | |
| 103 | 101 | 5 => '', |
| 104 | - 6 => __( 'Campaign published.', 'hurrytimer' ), | |
| 105 | - 7 => __( 'Campaign saved.', 'hurrytimer' ), | |
| 106 | - 8 => __( 'Campaign submitted.', 'hurrytimer' ), | |
| 102 | + 6 => __( 'Campaign published', "hurrytimer" ), | |
| 103 | + 7 => __( 'Campaign saved.', "hurrytimer" ), | |
| 104 | + 8 => __( 'Campaign submitted.', "hurrytimer" ), | |
| 107 | 105 | 9 => sprintf( |
| 108 | 106 | __( |
| 109 | 107 | 'Campaign scheduled for: <strong>%1$s</strong>.', |
| 110 | - 'hurrytimer' | |
| 108 | + "hurrytimer" | |
| 111 | 109 | ), |
| 112 | - date_i18n(__( 'M j, Y @ G:i', 'hurrytimer' ),strtotime( $post->post_date )) | |
| 110 | + date_i18n( | |
| 111 | + __( 'M j, Y @ G:i', "hurrytimer" ), | |
| 112 | + strtotime( $post->post_date ) | |
| 113 | + ) | |
| 113 | 114 | ), |
| 114 | - 10 => __( 'Campaign draft updated.', 'hurrytimer' ), | |
| 115 | + 10 => __( 'Campaign draft updated.', "hurrytimer" ), | |
| 115 | 116 | ); |
| 116 | 117 | |
| 117 | 118 | return $messages; |
| 118 | 119 | } |
| @@ -184,17 +185,8 @@ | ||
| 184 | 185 | $publich_date = Utils\Helpers::format_date( $post->post_date ); |
| 185 | 186 | $deactivateUrl = Utils\Helpers::deactivateUrl( $post_id ); |
| 186 | 187 | $activateUrl = Utils\Helpers::activateUrl( $post_id ); |
| 187 | 188 | |
| 188 | - $duplicateUrl = add_query_arg( | |
| 189 | - [ | |
| 190 | - 'action' => 'duplicate_campaign', | |
| 191 | - 'post' => $post_id, | |
| 192 | - '_wpnonce' => wp_create_nonce('duplicate_campaign_' . $post_id) | |
| 193 | - ], | |
| 194 | - admin_url('admin.php') | |
| 195 | - ); | |
| 196 | - | |
| 197 | 189 | include HURRYT_DIR . '/admin/templates/post-publish-metabox.php'; |
| 198 | 190 | |
| 199 | 191 | } |
| 200 | 192 | |
| @@ -205,24 +197,18 @@ | ||
| 205 | 197 | * |
| 206 | 198 | * @return void |
| 207 | 199 | */ |
| 208 | 200 | |
| 209 | - public function save_settings($post_id) | |
| 201 | + public function save_settings( $post_id ) | |
| 210 | 202 | { |
| 211 | - // Check for CSRF protection | |
| 212 | - if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-post_' . $post_id)) { | |
| 203 | + if ( wp_is_post_revision( $post_id ) ) { | |
| 213 | 204 | return; |
| 214 | 205 | } |
| 215 | - | |
| 216 | - if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) | |
| 217 | - || (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID']) | |
| 218 | - || (!current_user_can('publish_posts') || !current_user_can('edit_post', $post_id)) | |
| 219 | - ) { | |
| 206 | + if ( !current_user_can( 'edit_post', $post_id ) ) { | |
| 220 | 207 | return; |
| 221 | 208 | } |
| 222 | - // var_dump($_POST);exit; | |
| 223 | - $countdown = new Campaign($post_id); | |
| 224 | - $countdown->storeSettings(wp_unslash($_POST)); | |
| 209 | + $countdown = new Campaign( $post_id ); | |
| 210 | + $countdown->storeSettings( $_POST ); | |
| 225 | 211 | } |
| 226 | 212 | |
| 227 | 213 | public function add_settings_metabox_template( $post_type ) |
| 228 | 214 | { |
| @@ -296,9 +282,9 @@ | ||
| 296 | 282 | 'postid' => $post_id, |
| 297 | 283 | 'post' => $post_id, |
| 298 | 284 | 'action' => 'edit', |
| 299 | 285 | ), |
| 300 | - admin_url('post.php') | |
| 286 | + admin_url( 'post.php' ) | |
| 301 | 287 | ), |
| 302 | 288 | $action |
| 303 | 289 | ); |
| 304 | 290 | } |
| @@ -362,35 +348,7 @@ | ||
| 362 | 348 | break; |
| 363 | 349 | } |
| 364 | 350 | |
| 365 | 351 | return $result; |
| 366 | - } | |
| 367 | - | |
| 368 | - public function handle_duplicate_campaign() | |
| 369 | - { | |
| 370 | - if (isset($_POST['duplicate_campaign']) && $_POST['duplicate_campaign'] == '1') { | |
| 371 | - $post_id = get_the_ID(); | |
| 372 | - $post = get_post($post_id); | |
| 373 | - if ($post && $post->post_type === HURRYT_POST_TYPE) { | |
| 374 | - $new_post_id = wp_insert_post([ | |
| 375 | - 'post_title' => $post->post_title . ' (Copy)', | |
| 376 | - 'post_type' => $post->post_type, | |
| 377 | - 'post_status' => 'draft', | |
| 378 | - ]); | |
| 379 | - | |
| 380 | - if ($new_post_id) { | |
| 381 | - // Copy post meta | |
| 382 | - $meta = get_post_meta($post_id); | |
| 383 | - foreach ($meta as $key => $values) { | |
| 384 | - foreach ($values as $value) { | |
| 385 | - add_post_meta($new_post_id, $key, maybe_unserialize($value)); | |
| 386 | - } | |
| 387 | - } | |
| 388 | - } | |
| 389 | - } | |
| 390 | - // Redirect to the new post edit page | |
| 391 | - wp_redirect(admin_url('post.php?action=edit&post=' . $new_post_id)); | |
| 392 | - exit; | |
| 393 | - } | |
| 394 | 352 | } |
| 395 | 353 | |
| 396 | 354 | } |