Skip to content

Commit

Permalink
Refactor methods to avoid boolean with special string in the same par…
Browse files Browse the repository at this point in the history
…ameter
  • Loading branch information
renatho committed Aug 17, 2023
1 parent fa4ba74 commit 99c974b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,10 @@ public static function is_promoted( $post_id ) {
* @return boolean
*/
public static function update_promotion( $post_id, $promoted ) {
if ( 'job_listing' !== get_post_type( $post_id ) ) {
if ( ! self::pre_change_promotion( $post_id ) ) {
return false;
}

delete_option( self::PROMOTED_JOB_TRACK_OPTION );

if ( 'force_delete' === $promoted ) {
return delete_post_meta( $post_id, self::PROMOTED_META_KEY );
}

return update_post_meta( $post_id, self::PROMOTED_META_KEY, $promoted ? '1' : '0' );
}

Expand All @@ -177,7 +171,30 @@ public static function update_promotion( $post_id, $promoted ) {
* @return boolean
*/
public static function deactivate_promotion( $post_id ) {
return self::update_promotion( $post_id, 'force_delete' );
if ( ! self::pre_change_promotion( $post_id ) ) {
return false;
}

return delete_post_meta( $post_id, self::PROMOTED_META_KEY );
}

/**
* Run necessary things before promotion change.
* - Check post type.
* - Clear job counter option.
*
* @param int $post_id
*
* @return boolean Whether pre change passed correctly.
*/
private static function pre_change_promotion( $post_id ) {
if ( 'job_listing' !== get_post_type( $post_id ) ) {
return false;
}

delete_option( self::PROMOTED_JOB_TRACK_OPTION );

return true;
}

/**
Expand Down

0 comments on commit 99c974b

Please sign in to comment.