Manage Pledge: Notify removed contributors (#109)

If a contributor is removed from a pledge, they should be notified of the change. This will send an email to any confirmed contributors letting them know.
This commit is contained in:
Kelly Dwan 2019-12-16 17:33:43 -05:00 committed by GitHub
parent b1cbcdb01b
commit 183f7a95bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View file

@ -2,7 +2,7 @@
namespace WordPressDotOrg\FiveForTheFuture\Contributor;
use WordPressDotOrg\FiveForTheFuture;
use WordPressDotOrg\FiveForTheFuture\{ Pledge, XProfile };
use WordPressDotOrg\FiveForTheFuture\{ Email, Pledge, XProfile };
use WP_Error, WP_Post, WP_User;
defined( 'WPINC' ) || die();
@ -177,8 +177,13 @@ function add_pledge_contributors( $pledge_id, $contributors ) {
* @return false|WP_Post|null
*/
function remove_contributor( $contributor_post_id ) {
$pledge_id = get_post( $contributor_post_id )->post_parent;
$result = wp_trash_post( $contributor_post_id );
$contributor = get_post( $contributor_post_id );
$pledge_id = $contributor->post_parent;
$result = wp_trash_post( $contributor_post_id );
if ( $result && 'publish' === $contributor->post_status ) {
Email\send_contributor_removed_email( $pledge_id, $contributor );
}
/**
* Action: Fires when a contributor is removed from a pledge.
@ -326,6 +331,7 @@ function get_contributor_user_ids( $contributor_posts ) {
";
$user_ids = $wpdb->get_col(
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- phpcs is confused by the variable, but it does correctly prepare.
$wpdb->prepare( $query, $usernames )
);