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

@ -7,6 +7,7 @@
namespace WordPressDotOrg\FiveForTheFuture\Pledge;
use WordPressDotOrg\FiveForTheFuture;
use WP_Error;
defined( 'WPINC' ) || die();
@ -15,6 +16,7 @@ const SLUG_PL = 'pledges';
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
add_action( 'init', __NAMESPACE__ . '\register', 0 );
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
/**
* Register all the things.
@ -26,6 +28,15 @@ function register() {
register_custom_post_status();
}
/**
* Adjustments to the Five for the Future admin menu.
*
* @return void
*/
function admin_menu() {
remove_submenu_page( 'edit.php?post_type=' . CPT_ID, 'post-new.php?post_type=' . CPT_ID );
}
/**
* Register the post type(s).
*
@ -39,7 +50,7 @@ function register_custom_post_type() {
'archives' => __( 'Pledge Archives', 'wporg' ),
'attributes' => __( 'Pledge Attributes', 'wporg' ),
'parent_item_colon' => __( 'Parent Pledge:', 'wporg' ),
'all_items' => __( 'All Pledges', 'wporg' ),
'all_items' => __( 'Pledges', 'wporg' ),
'add_new_item' => __( 'Add New Pledge', 'wporg' ),
'add_new' => __( 'Add New', 'wporg' ),
'new_item' => __( 'New Pledge', 'wporg' ),
@ -100,3 +111,20 @@ function register_custom_post_status() {
)
);
}
/**
* Create a new pledge post.
*
* @param string $name The name of the company to use as the post title.
*
* @return int|WP_Error Post ID on success. Otherwise WP_Error.
*/
function create_new_pledge( $name ) {
$args = array(
'post_type' => CPT_ID,
'post_title' => $name,
'post_status' => 'draft',
);
return wp_insert_post( $args, true );
}