Plugin: Minor cleanup

This commit is contained in:
Ian Dunn 2022-04-28 09:32:07 -07:00
parent 53ae291a53
commit 834c62c0d0
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB
3 changed files with 24 additions and 24 deletions

View file

@ -178,10 +178,11 @@ function add_pledge_contributors( $pledge_id, $contributors ) {
*/ */
function remove_contributor( $contributor_post_id ) { function remove_contributor( $contributor_post_id ) {
$contributor = get_post( $contributor_post_id ); $contributor = get_post( $contributor_post_id );
$old_status = $contributor->post_status;
$pledge_id = $contributor->post_parent; $pledge_id = $contributor->post_parent;
$result = wp_trash_post( $contributor_post_id ); $result = wp_trash_post( $contributor_post_id );
if ( $result && 'publish' === $contributor->post_status ) { if ( $result && 'publish' === $old_status ) {
Email\send_contributor_removed_email( $pledge_id, $contributor ); Email\send_contributor_removed_email( $pledge_id, $contributor );
} }
@ -422,21 +423,21 @@ function process_my_pledges_form() {
wp_verify_nonce( $unverified_nonce, $nonce_action ) || wp_nonce_ays( $nonce_action ); wp_verify_nonce( $unverified_nonce, $nonce_action ) || wp_nonce_ays( $nonce_action );
$new_status = 'publish'; $new_status = 'publish';
$message = "You have joined the pledge from {$pledge->post_title}."; $message = "You have joined the pledge from $pledge->post_title.";
} elseif ( filter_input( INPUT_POST, 'decline_invitation' ) ) { } elseif ( filter_input( INPUT_POST, 'decline_invitation' ) ) {
$nonce_action = 'join_decline_organization_' . $contributor_post_id; $nonce_action = 'join_decline_organization_' . $contributor_post_id;
wp_verify_nonce( $unverified_nonce, $nonce_action ) || wp_nonce_ays( $nonce_action ); wp_verify_nonce( $unverified_nonce, $nonce_action ) || wp_nonce_ays( $nonce_action );
$new_status = 'trash'; $new_status = 'trash';
$message = "You have declined the pledge invitation from {$pledge->post_title}."; $message = "You have declined the pledge invitation from $pledge->post_title.";
} elseif ( filter_input( INPUT_POST, 'leave_organization' ) ) { } elseif ( filter_input( INPUT_POST, 'leave_organization' ) ) {
$nonce_action = 'leave_organization_' . $contributor_post_id; $nonce_action = 'leave_organization_' . $contributor_post_id;
wp_verify_nonce( $unverified_nonce, $nonce_action ) || wp_nonce_ays( $nonce_action ); wp_verify_nonce( $unverified_nonce, $nonce_action ) || wp_nonce_ays( $nonce_action );
$new_status = 'trash'; $new_status = 'trash';
$message = "You have left the {$pledge->post_title} pledge."; $message = "You have left the $pledge->post_title pledge.";
} }
if ( 'publish' === $new_status && 'publish' !== $contributor_post->post_status ) { if ( 'publish' === $new_status && 'publish' !== $contributor_post->post_status ) {

View file

@ -8,7 +8,7 @@ namespace WordPressDotOrg\FiveForTheFuture\Email;
use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor }; use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor };
use const WordPressDotOrg\FiveForTheFuture\PREFIX; use const WordPressDotOrg\FiveForTheFuture\PREFIX;
use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX; use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX;
use WP_Error; use WP_Post, WP_Error;
defined( 'WPINC' ) || die(); defined( 'WPINC' ) || die();

View file

@ -7,8 +7,8 @@
namespace WordPressDotOrg\FiveForTheFuture\Pledge; namespace WordPressDotOrg\FiveForTheFuture\Pledge;
use WordPressDotOrg\FiveForTheFuture; use WordPressDotOrg\FiveForTheFuture;
use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor, Email }; use WordPressDotOrg\FiveForTheFuture\{ Contributor, Email };
use WP_Error, WP_Query; use WP_Post, WP_Error, WP_Query;
use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX; use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX;
@ -206,16 +206,18 @@ function handle_activation_action( $post_id ) {
if ( 'deactivate' === $action ) { if ( 'deactivate' === $action ) {
deactivate( $post_id, false, 'Site admin deactivated via wp-admin list table.' ); deactivate( $post_id, false, 'Site admin deactivated via wp-admin list table.' );
wp_safe_redirect( add_query_arg( 'deactivated', 1, $sendback ) ); $url = add_query_arg( 'deactivated', 1, $sendback );
exit();
} else { } else {
wp_update_post( array( wp_update_post( array(
'ID' => $post_id, 'ID' => $post_id,
'post_status' => 'publish', 'post_status' => 'publish',
) ); ) );
wp_safe_redirect( add_query_arg( 'reactivated', 1, $sendback ) ); $url = add_query_arg( 'reactivated', 1, $sendback );
exit();
} }
wp_safe_redirect( $url );
exit();
} }
/** /**
@ -244,11 +246,7 @@ function action_success_message() {
* @return array The filtered list of post display states. * @return array The filtered list of post display states.
*/ */
function add_status_to_display( $post_states, $post ) { function add_status_to_display( $post_states, $post ) {
if ( isset( $_REQUEST['post_status'] ) ) { $showing_status = $_REQUEST['post_status'] ?? $showing_status = '';
$showing_status = $_REQUEST['post_status'];
} else {
$showing_status = '';
}
$status = DEACTIVE_STATUS; $status = DEACTIVE_STATUS;
if ( $showing_status !== $status && $status === $post->post_status ) { if ( $showing_status !== $status && $status === $post->post_status ) {
@ -310,15 +308,16 @@ function add_list_table_columns( $columns ) {
function populate_list_table_columns( $column, $post_id ) { function populate_list_table_columns( $column, $post_id ) {
switch ( $column ) { switch ( $column ) {
case 'contributor_counts': case 'contributor_counts':
$contribs = Contributor\get_pledge_contributors( $post_id, 'all' ); $contributors = Contributor\get_pledge_contributors( $post_id, 'all' );
$confirmed = sprintf( $confirmed = sprintf(
_n( '%s confirmed', '%s confirmed', count( $contribs['publish'] ), 'wporg-5ftf' ), _n( '%s confirmed', '%s confirmed', count( $contributors['publish'] ), 'wporg-5ftf' ),
number_format_i18n( count( $contribs['publish'] ) ) number_format_i18n( count( $contributors['publish'] ) )
); );
$unconfirmed = sprintf( $unconfirmed = sprintf(
_n( '%s unconfirmed', '%s unconfirmed', count( $contribs['pending'] ), 'wporg-5ftf' ), _n( '%s unconfirmed', '%s unconfirmed', count( $contributors['pending'] ), 'wporg-5ftf' ),
number_format_i18n( count( $contribs['pending'] ) ) number_format_i18n( count( $contributors['pending'] ) )
); );
printf( '%s<br />%s', esc_html( $confirmed ), esc_html( $unconfirmed ) ); printf( '%s<br />%s', esc_html( $confirmed ), esc_html( $unconfirmed ) );
break; break;
case 'domain': case 'domain':
@ -424,7 +423,7 @@ function filter_query( $query ) {
if ( $query->is_archive && CPT_ID === $query->get( 'post_type' ) ) { if ( $query->is_archive && CPT_ID === $query->get( 'post_type' ) ) {
// Archives should only show pledges with contributors. // Archives should only show pledges with contributors.
$query->set( 'meta_query', $meta_queries ); $query->set( 'meta_query', $meta_queries );
$order = isset( $_GET['order'] ) ? $_GET['order'] : ''; $order = $_GET['order'] ?? '';
switch ( $order ) { switch ( $order ) {
case 'alphabetical': case 'alphabetical':