From d737f70a7ec9ef4c30544cab45cdb29a4b3b5f19 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Mon, 9 Dec 2019 17:45:49 -0500 Subject: [PATCH] Add `is_active_pledge` to check post type & status --- plugins/wporg-5ftf/includes/pledge-form.php | 2 +- plugins/wporg-5ftf/includes/pledge.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/wporg-5ftf/includes/pledge-form.php b/plugins/wporg-5ftf/includes/pledge-form.php index 48755e1..9d7187e 100755 --- a/plugins/wporg-5ftf/includes/pledge-form.php +++ b/plugins/wporg-5ftf/includes/pledge-form.php @@ -123,7 +123,7 @@ function render_form_manage() { if ( is_wp_error( $can_view_form ) ) { $errors = array( $can_view_form->get_error_message() ); - } else if ( ! in_array( get_post_status( $pledge_id ), array( 'pending', 'publish' ), true ) ) { + } else if ( ! Pledge\is_active_pledge( $pledge_id ) ) { $errors = array( sprintf( __( 'This pledge has been removed from Five for the Future. If this was a mistake, please contact us to reactivate your pledge.', 'wporg-5ftf' ), diff --git a/plugins/wporg-5ftf/includes/pledge.php b/plugins/wporg-5ftf/includes/pledge.php index 903cc17..4ab8e20 100755 --- a/plugins/wporg-5ftf/includes/pledge.php +++ b/plugins/wporg-5ftf/includes/pledge.php @@ -327,6 +327,17 @@ function populate_list_table_columns( $column, $post_id ) { break; } } +/** + * Check if a post is an active pledge (pending or published). + * + * @param int $post_id The ID of a post to check. + * + * @return bool + */ +function is_active_pledge( $post_id ) { + return CPT_ID === get_post_type( $post_id ) && + in_array( get_post_status( $post_id ), array( 'pending', 'publish' ), true ); +} /** * Create a new pledge post.