mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-22 11:03:43 +03:00
Pledge: Log the reason why a pledge was deactivated.
This commit is contained in:
parent
ac25f4c008
commit
d22f13f2c1
|
@ -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 ) ) {
|
if ( is_wp_error( $result ) ) {
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -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 . '_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 . '_remove_contributor', __NAMESPACE__ . '\capture_remove_contributor', 99, 3 );
|
||||||
add_action( FiveForTheFuture\PREFIX . '_email_result', __NAMESPACE__ . '\capture_email_result', 99, 6 );
|
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.
|
* 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() ) {
|
} 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.
|
* which sandbox was used.
|
||||||
*/
|
*/
|
||||||
$entry['user_id'] = gethostname();
|
$entry['user_id'] = gethostname();
|
||||||
|
@ -385,3 +387,18 @@ function capture_email_result( $to, $subject, $message, $headers, $result, $pled
|
||||||
compact( 'to', 'subject', 'message', 'headers', 'result' )
|
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' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ function handle_activation_action( $post_id ) {
|
||||||
$sendback = remove_query_arg( array( 'deactivated', 'reactivated' ), $sendback );
|
$sendback = remove_query_arg( array( 'deactivated', 'reactivated' ), $sendback );
|
||||||
|
|
||||||
if ( 'deactivate' === $action ) {
|
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 ) );
|
wp_redirect( add_query_arg( 'deactivated', 1, $sendback ) );
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
|
@ -368,10 +368,11 @@ function create_new_pledge( $name ) {
|
||||||
*
|
*
|
||||||
* @param int $pledge_id The pledge to deactivate.
|
* @param int $pledge_id The pledge to deactivate.
|
||||||
* @param bool $notify Whether the pledge admin should be notified of the deactivation.
|
* @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.
|
* @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 );
|
$pledge = get_post( $pledge_id );
|
||||||
$result = wp_update_post(
|
$result = wp_update_post(
|
||||||
array(
|
array(
|
||||||
|
@ -385,6 +386,8 @@ function deactivate( $pledge_id, $notify = false ) {
|
||||||
Email\send_pledge_deactivation_email( $pledge );
|
Email\send_pledge_deactivation_email( $pledge );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do_action( FiveForTheFuture\PREFIX . '_deactivated_pledge', $pledge_id, $notify, $reason, $result );
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue