mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-05 02:15:45 +03:00
Contributors: Reset profile hours when pledge deactivated.
See https://github.com/WordPress/five-for-the-future/issues/169
This commit is contained in:
parent
834c62c0d0
commit
c6d7bbb7c1
6 changed files with 338 additions and 4 deletions
|
@ -166,6 +166,22 @@ function add_pledge_contributors( $pledge_id, $contributors ) {
|
|||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all of the contributors for the given pledge.
|
||||
*
|
||||
* Some contributors are sponsored by multiple companies. They'll have a `5ftf_contributor` post for each company,
|
||||
* but only the post associated with the given pledge should be removed.
|
||||
*/
|
||||
function remove_pledge_contributors( int $pledge_id ) : void {
|
||||
$contributors = get_pledge_contributors( $pledge_id, 'all' );
|
||||
|
||||
foreach ( $contributors as $status_group ) {
|
||||
foreach ( $status_group as $contributor ) {
|
||||
remove_contributor( $contributor->ID );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a contributor post from a pledge.
|
||||
*
|
||||
|
@ -186,6 +202,21 @@ function remove_contributor( $contributor_post_id ) {
|
|||
Email\send_contributor_removed_email( $pledge_id, $contributor );
|
||||
}
|
||||
|
||||
$has_additional_sponsors = get_posts( array(
|
||||
'post_type' => CPT_ID,
|
||||
'title' => $contributor->post_title,
|
||||
'post_status' => 'publish',
|
||||
) );
|
||||
|
||||
// `pending` contributors never confirmed they were associated with the company, so their profile data isn't
|
||||
// tied to the pledge, and shouldn't be reset. If a user has multiple sponsors, we don't know which hours are
|
||||
// sponsored by which company, so just leave them all.
|
||||
if ( 'publish' === $old_status && ! $has_additional_sponsors ) {
|
||||
$user = get_user_by( 'login', $contributor->post_title );
|
||||
|
||||
XProfile\reset_contribution_data( $user->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* Action: Fires when a contributor is removed from a pledge.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue