Log: Record when contributors are added to a pledge

This also updates the function that creates new contributor posts. It
replaces `create_new_contributor` with `add_pledge_contributors`. This
way we can capture a batch of contributor additions all in one event by
collecting all the `wp_insert_post` results in an array and including
it as an action parameter.
This commit is contained in:
Corey McKrill 2019-10-28 12:26:18 -07:00
parent a41ecd7665
commit 461278f525
No known key found for this signature in database
GPG key ID: C2C0746F7BF17E38
3 changed files with 55 additions and 15 deletions

View file

@ -17,6 +17,7 @@ add_action( 'save_post_' . Pledge\CPT_ID, __NAMESPACE__ . '\capture_save_post',
add_action( 'updated_postmeta', __NAMESPACE__ . '\capture_updated_postmeta', 99, 4 );
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 );
/**
* Adds a meta box for the log on the custom post type.
@ -234,3 +235,26 @@ function capture_transition_post_status( $new_status, $old_status, WP_Post $post
get_current_user_id()
);
}
/**
* Record a log for the event of contributors being added to a pledge.
*
* @param int $pledge_id The post ID of the pledge.
* @param array $contributors Array of contributor wporg usernames.
* @param array $results Associative array, key is wporg username, value is post ID on success,
* or an error code on failure.
*
* @return void
*/
function capture_add_pledge_contributors( $pledge_id, $contributors, $results ) {
add_log_entry(
$pledge_id,
'contributors_added',
sprintf(
'Contributors added: <code>%s</code>',
implode( '</code>, <code>', $contributors )
),
$results,
get_current_user_id()
);
}