mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-02 01:01:18 +03:00
Log: Record event when contributor is removed from pledge
This commit is contained in:
parent
4476765503
commit
7da0387df2
|
@ -170,7 +170,19 @@ function add_pledge_contributors( $pledge_id, $contributors ) {
|
|||
* @return false|WP_Post|null
|
||||
*/
|
||||
function remove_contributor( $contributor_post_id ) {
|
||||
return wp_trash_post( $contributor_post_id );
|
||||
$pledge_id = get_post( $contributor_post_id )->post_parent;
|
||||
$result = wp_trash_post( $contributor_post_id );
|
||||
|
||||
/**
|
||||
* Action: Fires when a contributor is removed from a pledge.
|
||||
*
|
||||
* @param int $pledge_id
|
||||
* @param int $contributor_post_id
|
||||
* @param WP_Post|false|null $result
|
||||
*/
|
||||
do_action( FiveForTheFuture\PREFIX . '_remove_contributor', $pledge_id, $contributor_post_id, $result );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@ add_action( 'updated_postmeta', __NAMESPACE__ . '\capture_updated_postmeta', 99,
|
|||
add_action( 'added_post_meta', __NAMESPACE__ . '\capture_added_post_meta', 99, 4 );
|
||||
add_action( 'transition_post_status', __NAMESPACE__ . '\capture_transition_post_status', 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 );
|
||||
|
||||
/**
|
||||
* Adds a meta box for the log on the custom post type.
|
||||
|
@ -266,3 +267,32 @@ function capture_add_pledge_contributors( $pledge_id, $contributors, $results )
|
|||
get_current_user_id()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a log for the event when a contributor is removed from a pledge.
|
||||
*
|
||||
* @param int $pledge_id The post ID of the pledge.
|
||||
* @param int $contributor_post_id The post ID of the pledge.
|
||||
* @param WP_Post|false|null $result The result of the attempt to trash the post.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function capture_remove_contributor( $pledge_id, $contributor_post_id, $result ) {
|
||||
// If the result isn't a post object, then it was already trashed, or didn't exist.
|
||||
if ( $result instanceof WP_Post ) {
|
||||
$contributor_post = get_post( $contributor_post_id );
|
||||
|
||||
add_log_entry(
|
||||
$pledge_id,
|
||||
'contributor_removed',
|
||||
sprintf(
|
||||
'Contributor removed: <code>%s</code>',
|
||||
esc_html( $contributor_post->post_title )
|
||||
),
|
||||
array(
|
||||
'previous_status' => $contributor_post->_wp_trash_meta_status,
|
||||
),
|
||||
get_current_user_id()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue