Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/advanced.../classes
File: ad-expiration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Ad Expiration functionality.
[3] Fix | Delete
*/
[4] Fix | Delete
class Advanced_Ads_Ad_Expiration {
[5] Fix | Delete
const POST_STATUS = 'advanced_ads_expired';
[6] Fix | Delete
const POST_META = 'advanced_ads_expiration_time';
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* The current ad object.
[10] Fix | Delete
*
[11] Fix | Delete
* @var Advanced_Ads_Ad
[12] Fix | Delete
*/
[13] Fix | Delete
private $ad;
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Inject ad object, hook to option saving.
[17] Fix | Delete
*
[18] Fix | Delete
* @param Advanced_Ads_Ad $ad the current ad object.
[19] Fix | Delete
*/
[20] Fix | Delete
public function __construct( Advanced_Ads_Ad $ad ) {
[21] Fix | Delete
$this->ad = $ad;
[22] Fix | Delete
[23] Fix | Delete
add_filter( 'advanced-ads-save-options', [ $this, 'save_expiration_date' ], 10, 2 );
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Check whether this ad is expired.
[28] Fix | Delete
*
[29] Fix | Delete
* @return bool
[30] Fix | Delete
*/
[31] Fix | Delete
public function is_ad_expired() {
[32] Fix | Delete
if ( $this->ad->expiry_date <= 0 || $this->ad->expiry_date > time() ) {
[33] Fix | Delete
return false;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
// if the ad is not trashed, but has a different status than expired, transition the status.
[37] Fix | Delete
if ( ! in_array( $this->ad->status, [ self::POST_STATUS, 'trash' ], true ) ) {
[38] Fix | Delete
$this->transition_post_status();
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
return true;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Extract the expiration date from the options array and save it as post_meta directly.
[46] Fix | Delete
*
[47] Fix | Delete
* @param array $options array with all ad options.
[48] Fix | Delete
* @param Advanced_Ads_Ad $ad the current ad object.
[49] Fix | Delete
*
[50] Fix | Delete
* @return array
[51] Fix | Delete
*/
[52] Fix | Delete
public function save_expiration_date( $options, Advanced_Ads_Ad $ad ) {
[53] Fix | Delete
if ( empty( $options['expiry_date'] ) ) {
[54] Fix | Delete
delete_post_meta( $ad->id, self::POST_META );
[55] Fix | Delete
return $options;
[56] Fix | Delete
}
[57] Fix | Delete
$datetime = ( new DateTimeImmutable() )->setTimestamp( (int) $options['expiry_date'] );
[58] Fix | Delete
update_post_meta( $ad->id, self::POST_META, $datetime->format( 'Y-m-d H:i:s' ) );
[59] Fix | Delete
[60] Fix | Delete
return $options;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Transition the post form previous status to self::POST_STATUS.
[65] Fix | Delete
* Remove kses filters before updating the post so that expiring ads don’t lose HTML or other code.
[66] Fix | Delete
*/
[67] Fix | Delete
private function transition_post_status() {
[68] Fix | Delete
kses_remove_filters();
[69] Fix | Delete
wp_update_post(
[70] Fix | Delete
[
[71] Fix | Delete
'ID' => $this->ad->id,
[72] Fix | Delete
'post_status' => self::POST_STATUS,
[73] Fix | Delete
]
[74] Fix | Delete
);
[75] Fix | Delete
kses_init_filters();
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Register custom post status for expired ads.
[80] Fix | Delete
*/
[81] Fix | Delete
public static function register_post_status() {
[82] Fix | Delete
register_post_status( self::POST_STATUS, [
[83] Fix | Delete
'label' => __( 'Expired', 'advanced-ads' ),
[84] Fix | Delete
'private' => true,
[85] Fix | Delete
] );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Hook into wp_untrash_post_status, to revert ads that previously had the expired status to that status instead of draft.
[90] Fix | Delete
*
[91] Fix | Delete
* @param string $new_status The new status after untrashing a post.
[92] Fix | Delete
* @param int $post_id The post id of the post to be untrashed.
[93] Fix | Delete
* @param string $previous_status The post status before trashing.
[94] Fix | Delete
*
[95] Fix | Delete
* @return string
[96] Fix | Delete
*/
[97] Fix | Delete
public static function wp_untrash_post_status( $new_status, $post_id, $previous_status ) {
[98] Fix | Delete
if ( $previous_status === self::POST_STATUS ) {
[99] Fix | Delete
return $previous_status;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
return $new_status;
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function