Pledge: Log the reason why a pledge was deactivated.

This commit is contained in:
Ian Dunn 2022-03-17 14:30:58 -07:00
parent ac25f4c008
commit d22f13f2c1
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB
3 changed files with 24 additions and 4 deletions

View file

@ -271,7 +271,7 @@ function process_form_remove( $pledge_id, $auth_token ) {
);
}
$result = Pledge\deactivate( $pledge_id, true );
$result = Pledge\deactivate( $pledge_id, true, 'Organization admin deactivated via Manage form.' );
if ( is_wp_error( $result ) ) {
return $result;

View file

@ -21,6 +21,8 @@ add_action( 'transition_post_status', __NAMESPACE__ . '\capture_transition_post_
add_action( FiveForTheFuture\PREFIX . '_add_pledge_contributors', __NAMESPACE__ . '\capture_add_pledge_contributors', 99, 3 );
add_action( FiveForTheFuture\PREFIX . '_remove_contributor', __NAMESPACE__ . '\capture_remove_contributor', 99, 3 );
add_action( FiveForTheFuture\PREFIX . '_email_result', __NAMESPACE__ . '\capture_email_result', 99, 6 );
add_action( FiveForTheFuture\PREFIX . '_deactivated_pledge', __NAMESPACE__ . '\capture_pledge_deactivation', 99, 4 );
/**
* Adds a meta box for the log on the custom post type.
@ -121,7 +123,7 @@ function add_log_entry( $pledge_id, $type, $message, array $data = array(), $use
} elseif ( 'cli' === php_sapi_name() ) {
/*
* `wp_shell`, etc can only be run from w.org sandboxes, and the hostname is the best way to identify
* `wp shell`, etc can only be run from w.org sandboxes, and the hostname is the best way to identify
* which sandbox was used.
*/
$entry['user_id'] = gethostname();
@ -385,3 +387,18 @@ function capture_email_result( $to, $subject, $message, $headers, $result, $pled
compact( 'to', 'subject', 'message', 'headers', 'result' )
);
}
/**
* Capture the results of an attempt to send an email.
*/
function capture_pledge_deactivation( int $pledge_id, bool $notify, string $reason, /* mixed */ $result ) : void {
add_log_entry(
$pledge_id,
'deactivated_pledge',
sprintf(
'Reason for deactivation was: %s',
$reason ?? 'No reason given.'
),
compact( 'notify', 'result' )
);
}

View file

@ -205,7 +205,7 @@ function handle_activation_action( $post_id ) {
$sendback = remove_query_arg( array( 'deactivated', 'reactivated' ), $sendback );
if ( 'deactivate' === $action ) {
deactivate( $post_id );
deactivate( $post_id, false, 'Site admin deactivated via wp-admin list table.' );
wp_redirect( add_query_arg( 'deactivated', 1, $sendback ) );
exit();
} else {
@ -368,10 +368,11 @@ function create_new_pledge( $name ) {
*
* @param int $pledge_id The pledge to deactivate.
* @param bool $notify Whether the pledge admin should be notified of the deactivation.
* @param string $reason The reason why the pledge is being deactivated.
*
* @return int|WP_Error Post ID on success. Otherwise WP_Error.
*/
function deactivate( $pledge_id, $notify = false ) {
function deactivate( $pledge_id, $notify = false, $reason = '' ) {
$pledge = get_post( $pledge_id );
$result = wp_update_post(
array(
@ -385,6 +386,8 @@ function deactivate( $pledge_id, $notify = false ) {
Email\send_pledge_deactivation_email( $pledge );
}
do_action( FiveForTheFuture\PREFIX . '_deactivated_pledge', $pledge_id, $notify, $reason, $result );
return $result;
}