diff --git a/includes/classes/class-add-listing.php b/includes/classes/class-add-listing.php
index 06d19384e5..b0faf629f8 100644
--- a/includes/classes/class-add-listing.php
+++ b/includes/classes/class-add-listing.php
@@ -377,6 +377,7 @@ public function atbdp_submit_listing() {
}
update_post_meta( $listing_id, '_featured', 0 );
+ // TODO: Status has been migrated, remove related code.
update_post_meta( $listing_id, '_listing_status', 'post_status' );
/*
@@ -931,9 +932,7 @@ public function parse_query( $query ) {
* @since 3.1.0
*/
private function renew_listing( $listing_id ) {
- $can_renew = get_directorist_option( 'can_renew_listing' );
-
- if ( ! $can_renew ) {
+ if ( ! directorist_can_user_renew_listings() ) {
return false;// vail if renewal option is turned off on the site.
}
@@ -963,8 +962,10 @@ private function renew_listing( $listing_id ) {
$directory_type = get_post_meta( $listing_id, '_directory_type', true );
// Update the post_meta into the database
- $old_status = get_post_meta( $listing_id, '_listing_status', true );
- if ( 'expired' == $old_status ) {
+ // TODO: Status has been migrated, remove related code.
+ // $old_status = get_post_meta( $listing_id, '_listing_status', true );
+ $old_status = get_post_status( $listing_id );
+ if ( 'expired' === $old_status ) {
$expiry_date = calc_listing_expiry_date();
} else {
$old_expiry_date = get_post_meta( $listing_id, '_expiry_date', true );
@@ -973,16 +974,13 @@ private function renew_listing( $listing_id ) {
// update related post meta_data
update_post_meta( $listing_id, '_expiry_date', $expiry_date );
+ // TODO: Status has been migrated, remove related code.
update_post_meta( $listing_id, '_listing_status', 'post_status' );
$exp_days = get_term_meta( $directory_type, 'default_expiration', true );
if ( $exp_days <= 0 ) {
update_post_meta( $listing_id, '_never_expire', 1 );
}
- // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- // else {
- // update_post_meta( $listing_id, '_never_expire', 0 );
- // }
do_action( 'atbdp_after_renewal', $listing_id );
$r_url = add_query_arg( 'renew', 'success', ATBDP_Permalink::get_dashboard_page_link() );
diff --git a/includes/classes/class-cron.php b/includes/classes/class-cron.php
index 5aacd1887e..044aae71a7 100644
--- a/includes/classes/class-cron.php
+++ b/includes/classes/class-cron.php
@@ -106,13 +106,10 @@ private function featured_listing_followup() {
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
- 'post_status' => 'public',
+ 'post_status' => 'publish',
+ 'cache_results' => false,
+ 'nopaging' => true,
'meta_query' => array(
- 'relation' => 'AND',
- array(
- 'key' => '_listing_status',
- 'value' => 'post_status',
- ),
array(
'key' => '_featured',
'value' => 1,
@@ -142,7 +139,7 @@ private function get_order_by_listing( $listing_id ) {
$args = array(
'post_type' => ATBDP_ORDER_POST_TYPE,
'posts_per_page' => 1,
- 'post_status' => 'public',
+ 'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
@@ -172,9 +169,9 @@ private function get_order_by_listing( $listing_id ) {
* @access private
*/
private function update_renewal_status() {
- $can_renew = get_directorist_option( 'can_renew_listing' );
- $renew_email_threshold = get_directorist_option( 'email_to_expire_day' ); // before how many days of expiration, a renewal message should be sent
- if ( $can_renew && $renew_email_threshold > 0 ) {
+ $renew_email_threshold = (int) get_directorist_option( 'email_to_expire_day' ); // before how many days of expiration, a renewal message should be sent
+
+ if ( directorist_can_user_renew_listings() && $renew_email_threshold > 0 ) {
$renew_email_threshold_date = date( 'Y-m-d H:i:s', strtotime( "+{$renew_email_threshold} days" ) );
// Define the query
@@ -182,39 +179,30 @@ private function update_renewal_status() {
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'publish',
+ 'cache_results' => false,
+ 'nopaging' => true,
'meta_query' => array(
'relation' => 'AND',
- array(
- 'key' => '_listing_status',
- 'value' => 'post_status',
+ 'never_expire' => array(
+ 'key' => '_never_expire',
+ 'compare' => 'NOT EXISTS',
),
- array(
+ 'expiry_date' => array(
'key' => '_expiry_date',
'value' => $renew_email_threshold_date,
'compare' => '<=',
// _expiry_date > $renew_email_threshold_date, '2018-04-15 09:24:00' < '2018-04-09 12:57:27'. eg. expiry date can not be greater than renewal threshold because threshold is the future date. expiration date should be equal to future date or less.
'type' => 'DATETIME',
),
- 'expiration' => array(
- 'relation' => 'OR',
- // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- // array(
- // 'key' => '_never_expire',
- // 'value' => array( '', '0' ),
- // 'compare' => 'IN',
- // ),
- array(
- 'key' => '_never_expire',
- 'compare' => 'NOT EXISTS',
- ),
- ),
),
);
$listings = new WP_Query( $args ); // get all the post that has post_status only and update their status and fire an email
+
if ( $listings->found_posts ) {
foreach ( $listings->posts as $listing ) {
update_post_meta( $listing->ID, '_listing_status', 'renewal' );
+
// hook for dev.
do_action( 'atbdp_status_updated_to_renewal', $listing->ID );
}
@@ -229,70 +217,67 @@ private function update_renewal_status() {
* @access private
*/
private function update_expired_status() {
-
- $can_renew = get_directorist_option( 'can_renew_listing' );
- $email_renewal_day = get_directorist_option( 'email_renewal_day' );
- $delete_in_days = get_directorist_option( 'delete_expired_listings_after' );
+ $email_renewal_day = (int) get_directorist_option( 'email_renewal_day' );
+ $delete_in_days = (int) get_directorist_option( 'delete_expired_listings_after' );
$del_exp_l = get_directorist_option( 'delete_expired_listing' );
// add renewal reminder days to deletion thresholds
- $delete_threshold = $can_renew ? (int) $email_renewal_day + (int) $delete_in_days : $delete_in_days;
+ $delete_threshold = directorist_can_user_renew_listings() ? ( $email_renewal_day + $delete_in_days ) : $delete_in_days;
// Define the query
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
+ 'cache_results' => false,
+ 'nopaging' => true,
'post_status' => 'publish', // get expired post with published status
'meta_query' => array(
'relation' => 'AND',
- array(
+ 'never_expire' => array(
+ 'key' => '_never_expire',
+ 'compare' => 'NOT EXISTS',
+ ),
+ 'expiry_date' => array(
'key' => '_expiry_date',
'value' => current_time( 'mysql' ),
'compare' => '<=', // eg. expire date 6 <= current date 7 will return the post
'type' => 'DATETIME',
),
- 'expiration' => array(
- 'relation' => 'OR',
- // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- // array(
- // 'key' => '_never_expire',
- // 'value' => array( '', '0' ),
- // 'compare' => 'IN',
- // ),
- array(
- 'key' => '_never_expire',
- 'compare' => 'NOT EXISTS',
- ),
- ),
),
);
$listings = new WP_Query( apply_filters( 'directorist_update_listings_expired_status_query_arguments ', $args ) );
- if ( $listings->found_posts ) {
+
+ if ( $listings->have_posts() ) {
foreach ( $listings->posts as $listing ) {
// prepare the post meta data
- $metas = array(
+ $meta_input = array(
+ // TODO: Status has been migrated, remove related code.
'_listing_status' => 'expired',
'_featured' => 0,
'_renewal_reminder_sent' => 0,
);
+
// delete expired listings?
if ( $del_exp_l ) {
// if deletion threshold is set then add deletion date
if ( $delete_threshold > 0 ) {
- $metas['_deletion_date'] = date( 'Y-m-d H:i:s', strtotime( '+' . $delete_threshold . ' days' ) );
+ $meta_input['_deletion_date'] = date( 'Y-m-d H:i:s', strtotime( '+' . $delete_threshold . ' days' ) );
} else {
- $metas['_deletion_date'] = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
+ $meta_input['_deletion_date'] = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
}
}
- wp_update_post(
- array(
- 'ID' => $listing->ID,
- 'post_status' => 'private', // update the status to private so that we do not run this func a second time
- 'meta_input' => $metas, // insert all meta data once to reduce update meta query
- )
- );
- // Hook for developers
- do_action( 'atbdp_listing_expired', $listing->ID );
+
+ $expired_listing_id = wp_update_post( array(
+ 'ID' => $listing->ID,
+ 'post_status' => 'expired',
+ 'meta_input' => $meta_input,
+ ) );
+
+ if ( is_wp_error( $expired_listing_id ) ) {
+ continue;
+ }
+
+ do_action( 'atbdp_listing_expired', $expired_listing_id );
}
}
}
@@ -304,50 +289,87 @@ private function update_expired_status() {
* @access private
*/
private function update_expired_listing_status() {
- // Define the query
- $args = array(
+ // TODO: Status has been migrated, remove related code.
+ // // Define the query
+ // $args = array(
+ // 'post_type' => ATBDP_POST_TYPE,
+ // 'posts_per_page' => -1,
+ // 'post_status' => 'publish', // get expired post with published status
+ // );
+ // $meta = array();
+ // $meta['renewed_by_admin'] = array(
+ // 'relation' => 'OR',
+ // array(
+ // 'key' => '_expiry_date',
+ // 'value' => current_time( 'mysql' ),
+ // 'compare' => '>', // eg. expire date 6 <= current date 7 will return the post
+ // 'type' => 'DATETIME',
+ // ),
+ // array(
+ // 'key' => '_never_expire',
+ // 'value' => 1,
+ // ),
+ // );
+ // $meta['get_expired'] = array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '=',
+ // );
+
+ // $args['meta_query'] = array_merge( array( 'relation' => 'AND' ), $meta );
+ // $listings = new WP_Query( $args );
+ // if ( $listings->found_posts ) {
+ // foreach ( $listings->posts as $listing ) {
+ // // prepare the post meta data
+ // $metas = array(
+ // '_listing_status' => 'post_status',
+ // '_renewal_reminder_sent' => 0,
+ // );
+ // wp_update_post(
+ // array(
+ // 'ID' => $listing->ID,
+ // 'post_status' => 'publish', // update the status to private so that we do not run this func a second time
+ // 'meta_input' => $metas, // insert all meta data once to reduce update meta query
+ // )
+ // );
+ // }
+ // }
+
+ $args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
- 'post_status' => 'publish', // get expired post with published status
- );
- $meta = array();
- $meta['renewed_by_admin'] = array(
+ 'post_status' => 'expired',
+ 'cache_results' => false,
+ 'nopaging' => true,
+ 'meta_query' => array(
'relation' => 'OR',
- array(
+ 'never_expire' => array(
+ 'key' => '_never_expire',
+ 'compare' => 'EXISTS',
+ ),
+ 'expiry_date' => array(
'key' => '_expiry_date',
'value' => current_time( 'mysql' ),
'compare' => '>', // eg. expire date 6 <= current date 7 will return the post
'type' => 'DATETIME',
),
- array(
- 'key' => '_never_expire',
- // 'value' => 1, // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- ),
- );
- $meta['get_expired'] = array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '=',
- );
+ )
+ );
- $args['meta_query'] = array_merge( array( 'relation' => 'AND' ), $meta );
- $listings = new WP_Query( $args );
- if ( $listings->found_posts ) {
- foreach ( $listings->posts as $listing ) {
- // prepare the post meta data
- $metas = array(
- '_listing_status' => 'post_status',
- '_renewal_reminder_sent' => 0,
- );
- wp_update_post(
- array(
- 'ID' => $listing->ID,
- 'post_status' => 'publish', // update the status to private so that we do not run this func a second time
- 'meta_input' => $metas, // insert all meta data once to reduce update meta query
- )
- );
- }
- }
+ $listings = new WP_Query( $args );
+
+ if ( $listings->have_posts() ) {
+ foreach ( $listings->posts as $listing ) {
+ wp_update_post( array(
+ 'ID' => $listing->ID,
+ 'post_status' => 'publish',
+ 'meta_input' => array(
+ '_listing_status' => 'post_status',
+ '_renewal_reminder_sent' => 0,
+ ),
+ ) );
+ }
+ }
}
/**
@@ -357,45 +379,38 @@ private function update_expired_listing_status() {
* @access private
*/
private function send_renewal_reminders() {
- $can_renew = get_directorist_option( 'can_renew_listing' );
- $email_renewal_day = get_directorist_option( 'email_renewal_day' );
+ $email_renewal_day = (int) get_directorist_option( 'email_renewal_day' );
- if ( $can_renew && $email_renewal_day > 0 ) {
+ if ( directorist_can_user_renew_listings() && $email_renewal_day > 0 ) {
// Define the query
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
- 'post_status' => 'private',
+ 'cache_results' => false,
+ 'nopaging' => true,
+ 'post_status' => 'expired',
'meta_query' => array(
'relation' => 'AND',
- array(
- 'key' => '_listing_status',
- 'value' => 'expired',
+ // TODO: Status has been migrated, remove related code.
+ // array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // ),
+ 'never_expire' => array(
+ 'key' => '_never_expire',
+ 'compare' => 'NOT EXISTS',
),
- array(
+ 'renewal_reminder_sent' => array(
'key' => '_renewal_reminder_sent',
'value' => 0,
),
- 'expiration' => array(
- 'relation' => 'OR',
- // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- // array(
- // 'key' => '_never_expire',
- // 'value' => array( '', '0' ),
- // 'compare' => 'IN',
- // ),
- array(
- 'key' => '_never_expire',
- 'compare' => 'NOT EXISTS',
- ),
- ),
),
);
$listings = new WP_Query( $args );
// Start the Loop
- if ( $listings->found_posts ) {
+ if ( $listings->have_posts() ) {
foreach ( $listings->posts as $listing ) {
// Send emails
$expiration_date = get_post_meta( $listing->ID, '_expiry_date', true );
@@ -430,32 +445,26 @@ private function delete_expired_listings() {
$args = array(
'post_type' => ATBDP_POST_TYPE,
'posts_per_page' => -1,
- 'post_status' => 'private',
+ 'cache_results' => false,
+ 'nopaging' => true,
+ 'post_status' => 'expired',
'meta_query' => array(
'relation' => 'AND',
- array(
- 'key' => '_listing_status',
- 'value' => 'expired',
+ // TODO: Status has been migrated, remove related code.
+ // array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // ),
+ 'never_expire' => array(
+ 'key' => '_never_expire',
+ 'compare' => 'NOT EXISTS',
),
- array(
+ 'deletion_date' => array(
'key' => '_deletion_date',
'value' => current_time( 'mysql' ),
'compare' => '<',
'type' => 'DATETIME',
),
- 'expiration' => array(
- 'relation' => 'OR',
- // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- // array(
- // 'key' => '_never_expire',
- // 'value' => array( '', '0' ),
- // 'compare' => 'IN',
- // ),
- array(
- 'key' => '_never_expire',
- 'compare' => 'NOT EXISTS',
- ),
- ),
),
);
diff --git a/includes/classes/class-custom-post.php b/includes/classes/class-custom-post.php
index 2da91a8e03..b76873e250 100644
--- a/includes/classes/class-custom-post.php
+++ b/includes/classes/class-custom-post.php
@@ -35,6 +35,24 @@ public function __construct() {
}
add_action( 'admin_footer', array( $this, 'quick_edit_scripts' ) );
+
+ add_action( 'init', array( $this, 'register_post_status' ) );
+ }
+
+ public function register_post_status() {
+ register_post_status(
+ 'expired',
+ array(
+ 'label' => _x( 'Expired', 'post status', 'directorist' ),
+ 'protected' => true,
+ /* translators: %s: Number of expired listings. */
+ 'label_count' => _n_noop(
+ 'Expired (%s)',
+ 'Expired (%s)',
+ 'directorist'
+ ),
+ )
+ );
}
public function quick_edit_scripts() {
@@ -377,9 +395,19 @@ public function manage_listing_columns( $column_name, $post_id ) {
break;
case 'atbdp_status':
- $status = get_post_meta( $post_id, '_listing_status', true );
- $status = ( $status !== 'post_status' ? $status : get_post_status( $post_id ) );
- echo esc_html( ucfirst( $status ) );
+ // TODO: Status has been migrated, remove related code.
+ // $status = get_post_meta( $post_id, '_listing_status', true );
+ // $status = ( $status !== 'post_status' ? $status : get_post_status( $post_id ) );
+
+ $status = get_post_status( $post_id );
+
+ if ( $status === 'publish' && get_post_meta( $post_id, '_listing_status', true ) === 'renewal' ) {
+ $status_label = _x( 'Renewal', 'Noun: listing status', 'directorist' );
+ } else {
+ $status_label = get_post_status_object( $status )->label;
+ }
+
+ echo esc_html( $status_label );
break;
case 'atbdp_featured':
diff --git a/includes/classes/class-installation.php b/includes/classes/class-installation.php
index defe4f175c..dd8d39fd41 100644
--- a/includes/classes/class-installation.php
+++ b/includes/classes/class-installation.php
@@ -25,9 +25,11 @@ class ATBDP_Installation {
* @var array
*/
private static $db_updates = array(
- '7.9.0' => [
- 'directorist_791_clean_falsy_never_expire_meta',
- 'directorist_791_update_db_version',
+ '7.10.0' => [
+ 'directorist_7100_clean_falsy_never_expire_meta',
+ 'directorist_7100_migrate_expired_meta_to_expired_status',
+ // 'directorist_7100_clean_listing_status_expired_meta', // Use this in future version to cleanup old data.
+ 'directorist_7100_update_db_version',
],
'7.1.0' => [
'directorist_710_migrate_reviews_table_to_comments_table',
diff --git a/includes/classes/class-metabox.php b/includes/classes/class-metabox.php
index 8b83e9841f..e6d089f566 100644
--- a/includes/classes/class-metabox.php
+++ b/includes/classes/class-metabox.php
@@ -180,7 +180,9 @@ public function render_expire_date( $listing_id, $term_id )
$featured = get_post_meta( $listing_id, '_featured', true);
$listing_type = get_post_meta( $listing_id, '_listing_type', true);
- $listing_status = get_post_meta( $listing_id, '_listing_status', true);
+ // TODO: Status has been migrated, remove related code.
+ // $listing_status = get_post_meta( $listing_id, '_listing_status', true);
+ $listing_status = get_post_status( $listing_id );
$default_expire_in_days = !empty( $default_expire_in_days ) ? $default_expire_in_days : '';
// load the meta fields
$data = compact('f_active', 'never_expire', 'expiry_date', 'featured', 'listing_type', 'listing_status', 'default_expire_in_days');
@@ -315,7 +317,9 @@ public function post_submitbox_meta($post)
$featured = get_post_meta($post->ID, '_featured', true);
$listing_type = get_post_meta($post->ID, '_listing_type', true);
- $listing_status = get_post_meta($post->ID, '_listing_status', true);
+ // TODO: Status has been migrated, remove related code.
+ // $listing_status = get_post_meta($post->ID, '_listing_status', true);
+ $listing_status = get_post_status( $post->ID );
$default_expire_in_days = !empty($default_expire_in_days) ? $default_expire_in_days : '';
// load the meta fields
$data = compact('f_active', 'never_expire', 'expiry_date', 'featured', 'listing_type', 'listing_status', 'default_expire_in_days');
@@ -418,8 +422,6 @@ public function save_post_meta( $post_id, $post ) {
$metas['_never_expire'] = true;
}
- // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
- // $metas['_never_expire'] = !empty($_POST['never_expire']) ? (int) directorist_clean( wp_unslash( $_POST['never_expire'] ) ) : $expiration_to_forever;
$exp_dt = !empty($_POST['exp_date']) ? directorist_clean( wp_unslash( $_POST['exp_date'] ) ) : array(); // get expiry date from the $_POST and then later sanitize it.
//prepare expiry date, if we receive complete expire date from the submitted post, then use it, else use the default data
if (!is_empty_v($exp_dt) && !empty($exp_dt['aa'])){
@@ -449,17 +451,18 @@ public function save_post_meta( $post_id, $post ) {
delete_post_thumbnail($post_id);
}
- $listing_status = get_post_meta($post_id, '_listing_status', true);
+ // TODO: Status has been migrated, remove related code.
+ // $listing_status = get_post_meta($post_id, '_listing_status', true);
$post_status = get_post_status($post_id);
$current_d = current_time('mysql');
// let's check is listing need to update
- if ( empty( $listing_status ) || ('expired' === $listing_status) && ('private' === $post_status)){
-
+ if ( 'expired' === $post_status ) {
if ( ( $exp_dt > $current_d ) || !empty( $_POST['never_expire'] ) ) {
wp_update_post( array(
- 'ID' => $post_id,
+ 'ID' => $post_id,
'post_status' => $post_status, // update the status to private so that we do not run this func a second time
+ // TODO: Status has been migrated, remove related code.
'meta_input' => array(
'_listing_status' => 'post_status',
), // insert all meta data once to reduce update meta query
@@ -472,6 +475,7 @@ public function save_post_meta( $post_id, $post ) {
update_post_meta( $post_id, '_featured', false );
}
+ // TODO: Status has been migrated, remove related code.
if ( ! metadata_exists( 'post', $post_id, '_listing_status' ) ) {
update_post_meta( $post_id, '_listing_status', 'post_status' );
}
diff --git a/includes/classes/class-setup-wizard.php b/includes/classes/class-setup-wizard.php
index ff8adc949b..cbc20a5a5a 100644
--- a/includes/classes/class-setup-wizard.php
+++ b/includes/classes/class-setup-wizard.php
@@ -238,8 +238,10 @@ public function atbdp_dummy_data_import()
$exp_dt = calc_listing_expiry_date();
update_post_meta($post_id, '_expiry_date', $exp_dt);
update_post_meta($post_id, '_featured', 0);
+
+ // TODO: Status has been migrated, remove related code.
update_post_meta($post_id, '_listing_status', 'post_status');
- $preview_url = isset($post['Image']) ? $post['Image'] : '';
+ $preview_url = isset($post['listing_prv_img']) ? $post['listing_prv_img'] : '';
if ( $preview_image && $preview_url ) {
$attachment_id = ATBDP_Tools::atbdp_insert_attachment_from_url($preview_url, $post_id);
diff --git a/includes/classes/class-tools.php b/includes/classes/class-tools.php
index cf8f242b67..ea63022379 100644
--- a/includes/classes/class-tools.php
+++ b/includes/classes/class-tools.php
@@ -207,6 +207,8 @@ public function atbdp_import_listing() {
$exp_dt = calc_listing_expiry_date( '', '', $directory_type );
update_post_meta( $post_id, '_expiry_date', $exp_dt );
update_post_meta( $post_id, '_featured', 0 );
+
+ // TODO: Status has been migrated, remove related code.
update_post_meta( $post_id, '_listing_status', 'post_status' );
if ( ! empty( $post['directory_type'] ) ) {
@@ -301,17 +303,17 @@ public static function atbdp_legacy_insert_attachment_from_url( $file_url, $post
return false;
}
$contents = @file_get_contents($file_url);
-
+
if ($contents === false) {
return false;
}
-
+
if( ! wp_check_filetype( $file_url )['ext'] ) {
-
+
$headers = array(
'Accept' => 'application/json',
);
-
+
$config = array(
'method' => 'GET',
'timeout' => 30,
@@ -320,29 +322,29 @@ public static function atbdp_legacy_insert_attachment_from_url( $file_url, $post
'headers' => $headers,
'cookies' => array(),
);
-
+
$upload = array();
-
+
try {
$response = wp_remote_get( $file_url, $config );
-
+
if ( ! is_wp_error( $response ) ) {
$type = wp_remote_retrieve_header( $response, 'content-type' );
$extension = preg_replace("/\w+\//", '', $type );
$upload = wp_upload_bits(basename( $file_url . '.'. $extension ), '', wp_remote_retrieve_body($response));
-
+
}
} catch ( Exception $e ) {
-
+
}
}else{
$upload = wp_upload_bits(basename($file_url), null, $contents);
}
-
+
if (isset($upload['error']) && $upload['error']) {
return false;
}
-
+
$type = '';
if (!empty($upload['type'])) {
$type = $upload['type'];
@@ -356,7 +358,7 @@ public static function atbdp_legacy_insert_attachment_from_url( $file_url, $post
$id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata($id, $upload['file']) );
return $id;
-
+
}
@@ -381,11 +383,11 @@ public static function atbdp_updated_insert_attachment_from_url( $image_url, $po
public static function atbdp_insert_attachment_from_url( $image_url, $post_id ) {
$legacy = apply_filters( 'directorist_legacy_attachment_importer', false, $image_url, $post_id );
-
+
if( ! $legacy ) {
return self::atbdp_updated_insert_attachment_from_url( $image_url, $post_id );
}
-
+
return self::atbdp_legacy_insert_attachment_from_url( $image_url, $post_id );
}
diff --git a/includes/custom-actions.php b/includes/custom-actions.php
index d05833ac59..04e6a95176 100644
--- a/includes/custom-actions.php
+++ b/includes/custom-actions.php
@@ -259,7 +259,7 @@ function atbdp_get_theme_file( $path = null ) {
}
}
-
+
/**
* @since 6.6.5
* @return URL if current theme has the file return the actual file path otherwise return false
@@ -512,8 +512,41 @@ function atbdp_country_code_to_name(){
'YE' => 'Yemen',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe');
- return $country_code_to_name;
+ return $country_code_to_name;
}
}
+/**
+ * Update listing status when _listing_status meta update.
+ *
+ * @since 7.10.0
+ *
+ * @param int $meta_id
+ * @param int $object_id
+ * @param string $meta_key
+ * @param mixed $meta_value
+ *
+ * @return void
+ */
+function directorist_updated_post_meta_action( $meta_id, $object_id, $meta_key, $meta_value ) {
+ if ( $meta_key !== '_listing_status' || ! directorist_is_listing_post_type( $object_id ) ) {
+ return;
+ }
+
+ if ( $meta_value === 'post_status' ) {
+ return;
+ }
+
+ if ( $meta_value === 'expired' || $meta_value === 'renewal' ) {
+ if ( $meta_value === 'renewal' ) {
+ $meta_value = 'publish';
+ }
+ wp_update_post( array(
+ 'ID' => $object_id,
+ 'post_status' => $meta_value
+ ), false );
+ }
+}
+add_action( 'added_post_meta', 'directorist_updated_post_meta_action', 99999, 4 );
+add_action( 'updated_post_meta', 'directorist_updated_post_meta_action', 99999, 4 );
diff --git a/includes/custom-filters.php b/includes/custom-filters.php
index c3c0529a6f..0ab0cfad89 100644
--- a/includes/custom-filters.php
+++ b/includes/custom-filters.php
@@ -26,3 +26,4 @@ function atbdp_get_image_source($id = null, $size = 'medium'){
$image_obj = wp_get_attachment_image_src($id, $size);
return is_array($image_obj) ? $image_obj[0] : '';
}
+
diff --git a/includes/directorist-core-functions.php b/includes/directorist-core-functions.php
index 1aa51d0103..12fa685ace 100644
--- a/includes/directorist-core-functions.php
+++ b/includes/directorist-core-functions.php
@@ -33,3 +33,7 @@ function directorist_get_currency() {
function directorist_get_currency_position() {
return get_directorist_option( 'g_currency_position' );
}
+
+function directorist_can_user_renew_listings() {
+ return (bool) get_directorist_option( 'can_renew_listing' );
+}
diff --git a/includes/helper-functions.php b/includes/helper-functions.php
index d24f0f515d..a79fb0ddc9 100644
--- a/includes/helper-functions.php
+++ b/includes/helper-functions.php
@@ -1427,7 +1427,6 @@ function atbdp_listings_count_by_tag($term_id)
),
array(
'key' => '_never_expire',
- // 'value' => 1, // TODO: Delete (refactored '_never_expire' for the sake of key comparison only).
),
))
);
diff --git a/includes/model/ListingAuthor.php b/includes/model/ListingAuthor.php
index 6873650948..5426829a75 100644
--- a/includes/model/ListingAuthor.php
+++ b/includes/model/ListingAuthor.php
@@ -204,13 +204,14 @@ public function author_listings_query() {
$args['tax_query'] = $category;
}
$meta_queries = array();
- $meta_queries['expired'] = array(
- array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '!=',
- ),
- );
+ // TODO: Status has been migrated, remove related code.
+ // $meta_queries['expired'] = array(
+ // array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '!=',
+ // ),
+ // );
$meta_queries = apply_filters( 'atbdp_author_listings_meta_queries', $meta_queries );
$count_meta_queries = count( $meta_queries );
diff --git a/includes/model/ListingDashboard.php b/includes/model/ListingDashboard.php
index e4f529dab8..0df61ad973 100644
--- a/includes/model/ListingDashboard.php
+++ b/includes/model/ListingDashboard.php
@@ -100,20 +100,27 @@ public function listings_query( $type = 'all', $paged = 1, $search = '' ) {
$args['no_found_rows'] = false;
}
- if ( $type == 'publish' ) {
+ // TODO: Status has been migrated, remove related code.
+ // if ( $type === 'publish' ) {
+ // $args['post_status'] = $type;
+ // }
+ // if ( $type == 'pending' ) {
+ // $args['post_status'] = 'pending';
+ // }
+ // elseif ( $type == 'expired' ) {
+ // $args['meta_query'] = array(
+ // array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired'
+ // ),
+ // );
+ // }
+
+ if ( $type === 'pending' || $type === 'expired' ) {
+ $args['post_status'] = $type;
+ } else {
$args['post_status'] = 'publish';
}
- if ( $type == 'pending' ) {
- $args['post_status'] = 'pending';
- }
- elseif ( $type == 'expired' ) {
- $args['meta_query'] = array(
- array(
- 'key' => '_listing_status',
- 'value' => 'expired'
- ),
- );
- }
if ( $search ) {
$args['s'] = $search;
@@ -138,14 +145,31 @@ public function get_listing_price_html() {
}
public function get_listing_expired_html() {
- $id = get_the_ID();
- $date_format = get_option('date_format');
- $exp_date = get_post_meta($id, '_expiry_date', true);
- $never_exp = get_post_meta($id, '_never_expire', true);
- $status = get_post_meta($id, '_listing_status', true);
- $exp_text = !empty($never_exp) ? __('Never Expires', 'directorist') : date_i18n($date_format, strtotime($exp_date));
- $exp_html = ( $status == 'expired' ) ? '' . __('Expired', 'directorist') . '' : $exp_text;
- return $exp_html;
+ // TODO: Status has been migrated, remove related code.
+ // $id = get_the_ID();
+ // $date_format = get_option('date_format');
+ // $exp_date = get_post_meta($id, '_expiry_date', true);
+ // $never_exp = get_post_meta($id, '_never_expire', true);
+ // $status = get_post_meta($id, '_listing_status', true);
+ // $exp_text = !empty($never_exp) ? __('Never Expires', 'directorist') : date_i18n($date_format, strtotime($exp_date));
+ // $exp_html = ( $status == 'expired' ) ? '' . __('Expired', 'directorist') . '' : $exp_text;
+ // return $exp_html;
+
+ if ( get_post_status( get_the_ID() ) === 'expired' ) {
+ return '' . esc_html__( 'Expired', 'directorist' ) . '';
+ }
+
+ $never_expire = (bool) get_post_meta( get_the_ID(), '_never_expire', true );
+ if ( $never_expire ) {
+ return '' . esc_html__( 'Never Expires', 'directorist' ) . '';
+ }
+
+ $expiry_date = strtotime( get_post_meta( get_the_ID(), '_expiry_date', true ) );
+ if ( $expiry_date ) {
+ return '' . date_i18n( get_option( 'date_format' ), $expiry_date ) . '';
+ }
+
+ return '';
}
public function listing_pagination( $base = '', $paged = '' ) {
@@ -517,33 +541,57 @@ public function render_shortcode( $atts ) {
}
public function can_renew() {
- $post_id = get_the_ID();
- $status = get_post_meta( $post_id, '_listing_status', true );
+ // TODO: Status has been migrated, remove related code.
+ // $post_id = get_the_ID();
+ // $status = get_post_meta( $post_id, '_listing_status', true );
+
+ // if ( 'renewal' == $status || 'expired' == $status ) {
+ // $can_renew = get_directorist_option( 'can_renew_listing' );
+ // if ( $can_renew ) {
+ // return true;
+ // }
+ // }
+
+ if ( ! directorist_can_user_renew_listings() ) {
+ return false;
+ }
- if ( 'renewal' == $status || 'expired' == $status ) {
- $can_renew = get_directorist_option( 'can_renew_listing' );
- if ( $can_renew ) {
- return true;
- }
+ $status = get_post_status( get_the_ID() );
+
+ if ( $status !== 'expired' || ( $status === 'publish' && get_post_meta( get_the_ID(), '_listing_status', true ) !== 'renewal' ) ) {
+ return false;
}
- return false;
+ return true;
}
public function can_promote() {
- $post_id = get_the_ID();
- $status = get_post_meta( $post_id, '_listing_status', true );
- $featured = get_post_meta( $post_id, '_featured', true );
+ // TODO: Status has been migrated, remove related code.
+ // $post_id = get_the_ID();
+ // $status = get_post_meta( $post_id, '_listing_status', true );
+ // $featured_active = get_directorist_option( 'enable_featured_listing' );
+ // $featured = get_post_meta( $post_id, '_featured', true );
+
+ // if ( 'renewal' == $status || 'expired' == $status ) {
+ // return false;
+ // }
- if ( 'renewal' == $status || 'expired' == $status ) {
+ if ( ! directorist_is_featured_listing_enabled() ) {
return false;
}
- if ( directorist_is_featured_listing_enabled() && empty( $featured ) ) {
- return true;
+ $status = get_post_status( get_the_ID() );
+
+ if ( $status === 'expired' || ( $status === 'publish' && get_post_meta( get_the_ID(), '_listing_status', true ) === 'renewal' ) ) {
+ return false;
+ }
+
+ $is_featured = (bool) get_post_meta( get_the_ID(), '_featured', true );
+ if ( $is_featured ) {
+ return false;
}
- return false;
+ return true;
}
public function get_renewal_link( $listing_id ) {
diff --git a/includes/model/ListingForm.php b/includes/model/ListingForm.php
index feab64b73f..72b8294159 100644
--- a/includes/model/ListingForm.php
+++ b/includes/model/ListingForm.php
@@ -299,7 +299,9 @@ public function get_listing_info() {
$listing_info['videourl'] = get_post_meta( $p_id, '_videourl', true );
$listing_info['price_range'] = get_post_meta( $p_id, '_price_range', true );
$listing_info['atbd_listing_pricing'] = get_post_meta( $p_id, '_atbd_listing_pricing', true );
- $listing_info['listing_status'] = get_post_meta( $p_id, '_listing_status', true );
+ // TODO: Status has been migrated, remove related code.
+ // $listing_info['listing_status'] = get_post_meta( $p_id, '_listing_status', true );
+ $listing_info['listing_status'] = get_post_status( $p_id );
$listing_info['tagline'] = get_post_meta( $p_id, '_tagline', true );
$listing_info['atbdp_post_views_count'] = directorist_get_listing_views_count( $p_id );
$listing_info['excerpt'] = get_post_meta( $p_id, '_excerpt', true );
diff --git a/includes/model/Listings.php b/includes/model/Listings.php
index c115f6a5df..9a45937e1d 100644
--- a/includes/model/Listings.php
+++ b/includes/model/Listings.php
@@ -471,11 +471,12 @@ private function execute_meta_query_args(&$args, &$meta_queries) {
'compare' => '=',
);
- $meta_queries['expired'] = array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '!=',
- );
+ // TODO: Status has been migrated, remove related code.
+ // $meta_queries['expired'] = array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '!=',
+ // );
if ( $this->has_featured ) {
if ( '_featured' == $this->filterby ) {
diff --git a/includes/model/SingleListing.php b/includes/model/SingleListing.php
index a1d74efb00..695af7198e 100644
--- a/includes/model/SingleListing.php
+++ b/includes/model/SingleListing.php
@@ -1178,11 +1178,12 @@ public function get_related_listings() {
}
$meta_queries = array();
- $meta_queries['expired'] = array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '!=',
- );
+ // TODO: Status has been migrated, remove related code.
+ // $meta_queries['expired'] = array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '!=',
+ // );
$meta_queries['directory_type'] = array(
'key' => '_directory_type',
'value' => $this->type,
diff --git a/includes/rest-api/Version1/class-listings-controller.php b/includes/rest-api/Version1/class-listings-controller.php
index 8fc3bfc771..760a8a9fe5 100644
--- a/includes/rest-api/Version1/class-listings-controller.php
+++ b/includes/rest-api/Version1/class-listings-controller.php
@@ -325,24 +325,26 @@ protected function prepare_objects_query( $request ) {
}
}
- // Expired listings query.
- $meta_query['expired'] = array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '!='
- );
-
- if ( $args['post_status'] === 'expired' ) {
- // Get only expired listings
- $meta_query['expired'] = array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '==',
- );
-
- // Expired listings have post_status => private hence we need to set any.
- $args['post_status'] = 'any';
- }
+ // TODO: Status has been migrated, remove related code.
+ // // Expired listings query.
+ // $meta_query['expired'] = array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '!='
+ // );
+
+ // if ( $args['post_status'] === 'expired' ) {
+ // // Get only expired listings
+ // $meta_query['expired'] = array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '==',
+ // );
+
+ // // Expired listings have post_status => private hence we need to set any.
+ // $args['post_status'] = 'any';
+ // }
+ // TODO: Remove the above lines due to listing status migration.
// Price query.
if ( isset( $request['min_price'] ) || isset( $request['max_price'] ) ) {
@@ -656,7 +658,7 @@ protected function get_images( $listing ) {
* @param WP_Post $listing WP_Post instance.
* @param WP_REST_Request $request Request object.
* @param string $context Request context. Options: 'view' and 'edit'.
- *
+ *
* @return array
*/
protected function get_listing_data( $listing, $request, $context = 'view' ) {
@@ -768,12 +770,14 @@ protected function get_listing_data( $listing, $request, $context = 'view' ) {
$base_data['popular'] = (bool) Helper::is_popular( $listing->ID );
break;
case 'status':
- $listing_status = get_post_meta( $listing->ID, '_listing_status', true );
- if ( $listing_status && $listing_status === 'expired' ) {
- $base_data['status'] = 'expired';
- } else {
- $base_data['status'] = $listing->post_status;
- }
+ // TODO: Status has been migrated, remove related code.
+ // $listing_status = get_post_meta( $listing->ID, '_listing_status', true );
+ // if ( $listing_status && $listing_status === 'expired' ) {
+ // $base_data['status'] = 'expired';
+ // } else {
+ // $base_data['status'] = $listing->post_status;
+ // }
+ $base_data['status'] = $listing->post_status;
break;
case 'reviews_allowed':
$base_data['reviews_allowed'] = directorist_is_review_enabled();
@@ -866,11 +870,12 @@ protected function get_related_listings_ids( $listing_id ) {
}
$meta_queries = array();
- $meta_queries['expired'] = array(
- 'key' => '_listing_status',
- 'value' => 'expired',
- 'compare' => '!=',
- );
+ // TODO: Status has been migrated, remove related code.
+ // $meta_queries['expired'] = array(
+ // 'key' => '_listing_status',
+ // 'value' => 'expired',
+ // 'compare' => '!=',
+ // );
$meta_queries['directory_type'] = array(
'key' => '_directory_type',
'value' => $directory_type,
diff --git a/includes/update-functions.php b/includes/update-functions.php
index b5fa486c94..b3b54bb352 100644
--- a/includes/update-functions.php
+++ b/includes/update-functions.php
@@ -137,7 +137,7 @@ function directorist_710_update_db_version() {
\ATBDP_Installation::update_db_version( '7.1.0' );
}
-function directorist_791_clean_falsy_never_expire_meta() {
+function directorist_7100_clean_falsy_never_expire_meta() {
global $wpdb;
$wp_postmeta = $wpdb->prefix . 'postmeta';
@@ -154,6 +154,46 @@ function directorist_791_clean_falsy_never_expire_meta() {
$wpdb->query( $query );
}
-function directorist_791_update_db_version() {
- \ATBDP_Installation::update_db_version( '7.9.1' );
+function directorist_7100_migrate_expired_meta_to_expired_status( $updater ) {
+ $listings = new \WP_Query( array(
+ 'post_status' => 'private',
+ 'post_type' => ATBDP_POST_TYPE,
+ 'posts_per_page' => 10,
+ 'cache_results' => false,
+ 'nopaging' => true,
+ 'meta_key' => '_listing_status',
+ 'meta_value' => 'expired',
+ ) );
+
+ while ( $listings->have_posts() ) {
+ $listings->the_post();
+
+ wp_update_post( array(
+ 'ID' => get_the_ID(),
+ 'post_status' => 'expired',
+ ) );
+ }
+ wp_reset_postdata();
+
+ return $listings->have_posts();
+}
+
+function directorist_7100_clean_listing_status_expired_meta() {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . 'postmeta';
+ $meta_key = '_listing_status';
+ $meta_value = 'expired';
+
+ $wpdb->query(
+ $wpdb->prepare(
+ "DELETE FROM $table_name WHERE meta_key = %s AND meta_value = %s",
+ $meta_key,
+ $meta_value
+ )
+ );
+}
+
+function directorist_7100_update_db_version() {
+ \ATBDP_Installation::update_db_version( '7.10.0' );
}