mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 18:05:45 +03:00
Refactor to use JSON + templates for contributors
This will make it easier to show contributors as they're added
This commit is contained in:
parent
aa79c8147e
commit
b0672a6f6e
5 changed files with 151 additions and 69 deletions
|
@ -238,6 +238,41 @@ 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,
|
||||
'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.
|
||||
*
|
||||
|
|
|
@ -34,6 +34,7 @@ function handler() {
|
|||
Contributor\remove_contributor( $contributor_id );
|
||||
wp_die( wp_json_encode( [
|
||||
'success' => true,
|
||||
'contributors' => Contributor\get_pledge_contributors_data( $pledge_id ),
|
||||
] ) );
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ function render_meta_boxes( $pledge, $box ) {
|
|||
$data[ $key ] = get_post_meta( $pledge->ID, META_PREFIX . $key, $config['single'] );
|
||||
}
|
||||
|
||||
$contributors = Contributor\get_pledge_contributors( $pledge->ID, 'all' );
|
||||
$contributors = Contributor\get_pledge_contributors_data( $pledge->ID );
|
||||
|
||||
echo '<div class="pledge-form">';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue