abstracts
9 months ago
admin
7 months ago
ads
9 months ago
compatibility
9 months ago
crons
1 year ago
frontend
11 months ago
groups
1 year ago
importers
1 year ago
installation
1 year ago
interfaces
1 year ago
placements
1 year ago
rest
1 year ago
traits
1 year ago
utilities
8 months ago
array_ad_conditions.php
1 year ago
cap_map.php
3 years ago
class-assets-registry.php
1 year ago
class-autoloader.php
1 year ago
class-constants.php
1 year ago
class-entities.php
7 months ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
8 months ago
class-post-data.php
10 months ago
class-shortcodes.php
1 year ago
class-upgrades.php
1 year ago
class-widget.php
11 months ago
default-hooks.php
1 year ago
functions-ad.php
1 year ago
functions-conditional.php
1 year ago
functions-core.php
1 year ago
functions-group.php
1 year ago
functions-placement.php
1 year ago
functions.php
1 year ago
index.php
2 years ago
load_modules.php
2 years ago
class-post-data.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Post Data. |
| 4 | * |
| 5 | * Standardize certain post data on save. |
| 6 | * |
| 7 | * @package AdvancedAds |
| 8 | * @author Advanced Ads <info@wpadvancedads.com> |
| 9 | * @since 1.48.2 |
| 10 | */ |
| 11 | |
| 12 | namespace AdvancedAds; |
| 13 | |
| 14 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 15 | |
| 16 | defined( 'ABSPATH' ) || exit; |
| 17 | |
| 18 | /** |
| 19 | * Post Data. |
| 20 | */ |
| 21 | class Post_Data implements Integration_Interface { |
| 22 | |
| 23 | /** |
| 24 | * Hook into WordPress. |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function hooks(): void { |
| 29 | add_filter( 'wp_untrash_post_status', [ $this, 'untrash_post_status' ], 10, 3 ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Ensure statuses are correctly reassigned when restoring ads that are previously expired. |
| 34 | * |
| 35 | * @param string $new_status The new status of the post being restored. |
| 36 | * @param int $post_id The ID of the post being restored. |
| 37 | * @param string $previous_status The status of the post at the point where it was trashed. |
| 38 | * |
| 39 | * @return null|string |
| 40 | */ |
| 41 | public function untrash_post_status( $new_status, $post_id, $previous_status ) { |
| 42 | $is_ours = in_array( get_post_type( $post_id ), [ Constants::POST_TYPE_AD, Constants::POST_TYPE_PLACEMENT ], true ); |
| 43 | if ( ! $is_ours ) { |
| 44 | return $new_status; |
| 45 | } |
| 46 | |
| 47 | if ( Constants::AD_STATUS_EXPIRED === $previous_status || 'draft' === $new_status ) { |
| 48 | return $previous_status; |
| 49 | } |
| 50 | |
| 51 | return $new_status; |
| 52 | } |
| 53 | } |
| 54 |