Skip to content

Commit

Permalink
Switch the post to a custom status, if it's present instead of pending
Browse files Browse the repository at this point in the history
  • Loading branch information
ingeniumed committed May 16, 2024
1 parent c59a8ad commit 432ef5d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ function install() {
'position' => 5,
),
),
array(
'term' => __( 'Expired', 'edit-flow' ),
'args' => array(
'slug' => 'expired',
'description' => __( 'Post has expired, and it has to bew updated an editor.', 'edit-flow' ),
'position' => 6,
),
),
);

// Okay, now add the default statuses to the db if they don't already exist
Expand Down Expand Up @@ -202,6 +210,20 @@ function upgrade( $previous_version ) {
// Custom status descriptions become base64_encoded, instead of maybe json_encoded.
$this->upgrade_074_term_descriptions( self::taxonomy_key );
}
// Upgrade path to v0.9.9
if ( version_compare( $previous_version, '0.9.9', '<' ) ) {
$expiry_custom_status = array(
'term' => __( 'Expired', 'edit-flow' ),
'args' => array(
'slug' => 'expired',
'description' => __( 'Post has expired, and it has to bew updated an editor.', 'edit-flow' ),
'position' => 6,
),
);

if( !term_exists( $expiry_custom_status['term'], self::taxonomy_key ) )
$this->add_custom_status( $expiry_custom_status['term'], $expiry_custom_status['args'] );
}

}

Expand Down
10 changes: 8 additions & 2 deletions modules/editorial-metadata/editorial-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,20 @@ function save_meta_box( $id, $post ) {
}

function unpublish_post_task( $post_id ) {
$post_status_to_set = 'pending';

if ( $this->module_enabled( 'custom-status' ) ) {
$post_status_to_set = 'expired';
}

// Bistro ToDo: Cancel the scheduled task to change the status of the post to pending_review.
$success_value = wp_update_post( array(
'ID' => $post_id,
'post_status' => 'pending'
'post_status' => $post_status_to_set
), true );

if ( is_wp_error( $success_value ) ) {
error_log( 'Error updating post status to pending: ' . $success_value->get_error_message() );
error_log( 'Error updating post status to ' . $post_status_to_set . ': ' . $success_value->get_error_message() );
}
}

Expand Down

0 comments on commit 432ef5d

Please sign in to comment.