Add a Contributor custom post type (#42)

Contributors associated with pledges have a state: they can be confirmed or unconfirmed. They also have some important meta data, namely when they were confirmed. Thus, managing contributor data for pledges is more robust if we treat them as their own post type instead of as a multidimensional array of post meta data.

This also reorganizes some of the functions related to pledges so that things are more consistent between the pledge CPT and the contributior CPT.

Fixes #11
This commit is contained in:
Corey McKrill 2019-10-21 15:43:20 -07:00 committed by GitHub
parent 2927532544
commit 266ba447b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 265 additions and 66 deletions

View file

@ -8,6 +8,7 @@ namespace WordPressDotOrg\FiveForTheFuture\PledgeMeta;
use WordPressDotOrg\FiveForTheFuture;
use WordPressDotOrg\FiveForTheFuture\Pledge;
use WordPressDotOrg\FiveForTheFuture\PledgeForm;
use WordPressDotOrg\FiveForTheFuture\Contributor;
use WP_Post, WP_Error;
defined( 'WPINC' ) || die();
@ -60,12 +61,6 @@ function get_pledge_meta_config( $context = '' ) {
'show_in_rest' => false,
'php_filter' => FILTER_VALIDATE_INT,
),
'org-pledge-contributors' => array(
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => false,
'php_filter' => FILTER_SANITIZE_STRING,
),
);
$generated = array(
@ -153,12 +148,14 @@ function add_meta_boxes() {
*/
function render_meta_boxes( $pledge, $box ) {
$readonly = ! current_user_can( 'edit_page', $pledge->ID );
$data = array();
$data = array();
foreach ( get_pledge_meta_config() as $key => $config ) {
$data[ $key ] = get_post_meta( $pledge->ID, META_PREFIX . $key, $config['single'] );
}
$contributors = Contributor\get_pledge_contributors( $pledge->ID, 'all' );
echo '<div class="pledge-form">';
switch ( $box['id'] ) {