From bb170be179cf50ab359024d56920a5684feb27a4 Mon Sep 17 00:00:00 2001 From: obiPlabon Date: Tue, 21 May 2024 16:16:37 +0600 Subject: [PATCH 1/2] Refactored utility --- includes/directorist-directory-functions.php | 26 +++++++++++++++++--- includes/helper-functions.php | 19 -------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/includes/directorist-directory-functions.php b/includes/directorist-directory-functions.php index 15667134b1..887e7457f1 100644 --- a/includes/directorist-directory-functions.php +++ b/includes/directorist-directory-functions.php @@ -101,12 +101,30 @@ function directorist_should_check_privacy_policy( int $directory_id ) { return ( directorist_is_privacy_policy_enabled( $directory_id ) && directorist_is_privacy_policy_required( $directory_id ) ); } -function directorist_get_new_listing_status( int $directory_id ) { - return directorist_get_directory_meta( $directory_id, 'new_listing_status' ); +/** + * Get listing default create status from directory settings. + * + * @param int $directory_id + * + * @return string Default create status. + */ +function directorist_get_listing_create_status( int $directory_id ) { + $status = directorist_get_directory_meta( $directory_id, 'new_listing_status' ); + + return apply_filters( 'directorist_listing_create_status', $status, $directory_id ); } -function directorist_get_edit_listing_status( int $directory_id ) { - return directorist_get_directory_meta( $directory_id, 'edit_listing_status' ); +/** + * Get listing default edit status from directory settings. + * + * @param int $directory_id + * + * @return string Default edit status. + */ +function directorist_get_listing_edit_status( int $directory_id ) { + $status = directorist_get_directory_meta( $directory_id, 'edit_listing_status' ); + + return apply_filters( 'directorist_listing_edit_status', $status, $directory_id ); } function directorist_get_default_expiration( int $directory_id ) { diff --git a/includes/helper-functions.php b/includes/helper-functions.php index a79fb0ddc9..18e13484ab 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -4212,25 +4212,6 @@ function directorist_background_image_process( $images ) { } } -/** - * Get or modify the status of a directory listing during editing. - * - * @param int $directory_type The directory type ID. - * @param int $listing_id The listing ID. - * - * @return string The edited or original status for the listing. - */ -function directorist_get_listing_edit_status( $directory_type ) { - $edit_listing_status = get_term_meta( $directory_type, 'edit_listing_status', true ); - $new_listing_status = get_term_meta( $directory_type, 'new_listing_status', true ); - - if ( 'publish' !== $new_listing_status && 'publish' === $edit_listing_status ) { - $edit_listing_status = $new_listing_status; - } - - return apply_filters( 'directorist_edit_listing_status', $edit_listing_status, $directory_type ); -} - /** * Delete directory even when non empty. * From e122a68f471fefc578466eb5f2a2b09660feaa57 Mon Sep 17 00:00:00 2001 From: obiPlabon Date: Tue, 21 May 2024 16:32:10 +0600 Subject: [PATCH 2/2] Refactored --- includes/classes/class-add-listing.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/classes/class-add-listing.php b/includes/classes/class-add-listing.php index b0faf629f8..e17e31e875 100644 --- a/includes/classes/class-add-listing.php +++ b/includes/classes/class-add-listing.php @@ -301,10 +301,10 @@ public function atbdp_submit_listing() { $meta_data['_t_c_check'] = (bool) $posted_data['t_c_check']; } - $new_listing_status = get_term_meta( $directory_id, 'new_listing_status', true ); - $edit_listing_status = directorist_get_listing_edit_status( $directory_id ); - $default_expiration = get_term_meta( $directory_id, 'default_expiration', true ); - $preview_enable = atbdp_is_truthy( get_term_meta( $directory_id, 'preview_mode', true ) ); + $listing_create_status = directorist_get_listing_create_status( $directory_id ); + $listing_edit_status = directorist_get_listing_edit_status( $directory_id ); + $default_expiration = get_term_meta( $directory_id, 'default_expiration', true ); + $preview_enable = atbdp_is_truthy( get_term_meta( $directory_id, 'preview_mode', true ) ); /** * It applies a filter to the meta values that are going to be saved with the listing submitted from the front end @@ -329,7 +329,7 @@ public function atbdp_submit_listing() { if ( $preview_enable ) { $listing_data['post_status'] = 'private'; } else { - $listing_data['post_status'] = $edit_listing_status; + $listing_data['post_status'] = $listing_edit_status; } $listing_id = wp_update_post( $listing_data ); @@ -354,7 +354,7 @@ public function atbdp_submit_listing() { if ( $preview_enable ) { $listing_data['post_status'] = 'private'; } else { - $listing_data['post_status'] = $edit_listing_status; + $listing_data['post_status'] = $listing_create_status; } $listing_id = wp_insert_post( $listing_data ); @@ -368,7 +368,7 @@ public function atbdp_submit_listing() { do_action( 'atbdp_listing_inserted', $listing_id ); // for sending email notification // Every post with the published status should contain all the post meta keys so that we can include them in query. - if ( 'publish' === $new_listing_status || 'pending' === $new_listing_status ) { + if ( 'publish' === $listing_create_status || 'pending' === $listing_create_status ) { if ( ! $default_expiration ) { update_post_meta( $listing_id, '_never_expire', 1 ); } else { @@ -387,7 +387,7 @@ public function atbdp_submit_listing() { do_action( 'atbdp_before_processing_listing_frontend', $listing_id ); } - if ( 'publish' === $new_listing_status ) { + if ( 'publish' === $listing_create_status ) { do_action( 'atbdp_listing_published', $listing_id );// for sending email notification } }