Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor edit create listing default status #1751

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions includes/classes/class-add-listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand Down
26 changes: 22 additions & 4 deletions includes/directorist-directory-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
19 changes: 0 additions & 19 deletions includes/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down