mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-05 02:15:45 +03:00
Trigger an email on user-initiated pledge deactivation
This commit is contained in:
parent
7024cf3b2e
commit
dbe5868a41
3 changed files with 49 additions and 11 deletions
|
@ -205,10 +205,7 @@ function handle_activation_action( $post_id ) {
|
|||
$sendback = remove_query_arg( [ 'deactivated', 'reactivated' ], $sendback );
|
||||
|
||||
if ( 'deactivate' === $action ) {
|
||||
wp_update_post( array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => DEACTIVE_STATUS,
|
||||
) );
|
||||
deactivate( $post_id );
|
||||
wp_redirect( add_query_arg( 'deactivated', 1, $sendback ) );
|
||||
exit();
|
||||
} else {
|
||||
|
@ -355,6 +352,31 @@ function create_new_pledge( $name ) {
|
|||
return $pledge_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a pledge from view by setting its status to "deactivated".
|
||||
*
|
||||
* @param int $pledge_id The pledge to deactivate.
|
||||
* @param bool $notify Whether the pledge admin should be notified of the deactivation.
|
||||
*
|
||||
* @return int|WP_Error Post ID on success. Otherwise WP_Error.
|
||||
*/
|
||||
function deactivate( $pledge_id, $notify = false ) {
|
||||
$pledge = get_post( $pledge_id );
|
||||
$result = wp_update_post(
|
||||
array(
|
||||
'ID' => $pledge_id,
|
||||
'post_status' => DEACTIVE_STATUS,
|
||||
),
|
||||
true // Return a WP_Error.
|
||||
);
|
||||
|
||||
if ( $notify && ! is_wp_error( $result ) ) {
|
||||
Email\send_pledge_deactivation_email( $pledge );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter query for archive & search pages to ensure we're only showing the expected data.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue