mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-05 02:15:45 +03:00
Manage a Pledge: Enable adding/removing contributors from wp-admin. (#99)
This updates the display of contributors into a table view, and adds the ability to add and remove contributors to existing pledges. The display has been refactored to use JS templates & JSON contributor data– the data is output onto the page when loaded from the server, and rendered when the page finishes loading. Adding & removing contributors now submits to an admin-ajax.php endpoint, which, if successful, return the new list of contributors. This ensures the display is always up to date. Fixes #3
This commit is contained in:
parent
f32d26ef47
commit
82192eea4c
10 changed files with 437 additions and 73 deletions
|
@ -135,7 +135,7 @@ function populate_list_table_columns( $column, $post_id ) {
|
|||
* @param int $pledge_id The post ID of the pledge.
|
||||
* @param array $contributors Array of contributor wporg usernames.
|
||||
*
|
||||
* @return void
|
||||
* @return array List of the new contributor post IDs, mapped from username => ID.
|
||||
*/
|
||||
function add_pledge_contributors( $pledge_id, $contributors ) {
|
||||
$results = array();
|
||||
|
@ -162,6 +162,8 @@ function add_pledge_contributors( $pledge_id, $contributors ) {
|
|||
* or an error code on failure.
|
||||
*/
|
||||
do_action( FiveForTheFuture\PREFIX . '_add_pledge_contributors', $pledge_id, $contributors, $results );
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,6 +240,43 @@ function get_pledge_contributors( $pledge_id, $status = 'publish', $contributor_
|
|||
return $posts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contributor posts in the format used for the JS templates.
|
||||
*
|
||||
* @param int $pledge_id The post ID of the pledge.
|
||||
*
|
||||
* @return array An array of contributor data, ready to be used in the JS templates.
|
||||
*/
|
||||
function get_pledge_contributors_data( $pledge_id ) {
|
||||
$contrib_data = array();
|
||||
$contributors = get_pledge_contributors( $pledge_id, 'all' );
|
||||
|
||||
foreach ( $contributors as $contributor_status => $group ) {
|
||||
$contrib_data[ $contributor_status ] = array_map(
|
||||
function( $contributor_post ) use ( $contributor_status, $pledge_id ) {
|
||||
$name = $contributor_post->post_title;
|
||||
$contributor = get_user_by( 'login', $name );
|
||||
|
||||
return [
|
||||
'pledgeId' => $pledge_id,
|
||||
'contributorId' => $contributor_post->ID,
|
||||
'status' => $contributor_status,
|
||||
'avatar' => get_avatar( $contributor, 32 ),
|
||||
// @todo Add full name, from `$contributor`?
|
||||
'name' => $name,
|
||||
'displayName' => $contributor->display_name,
|
||||
'publishDate' => get_the_date( '', $contributor_post ),
|
||||
'resendLabel' => __( 'Resend Confirmation', 'wporg' ),
|
||||
'removeConfirm' => sprintf( __( 'Remove %s from this pledge?', 'wporg-5ftf' ), $name ),
|
||||
'removeLabel' => sprintf( __( 'Remove %s', 'wporg' ), $name ),
|
||||
];
|
||||
},
|
||||
$group
|
||||
);
|
||||
}
|
||||
return $contrib_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user objects that correspond with pledge contributor posts.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue