From aaf8b1a712c5874c3defeb1eb8400d532c37c837 Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Mon, 21 Oct 2019 14:58:14 -0700 Subject: [PATCH] Pledges: Move `create_new_pledge` to Pledge namespace It makes more sense grouping this function with others related to the pledge CPT itself, rather than the pledge forms. --- plugins/wporg-5ftf/includes/pledge-form.php | 28 ++++++--------------- plugins/wporg-5ftf/includes/pledge.php | 18 +++++++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/plugins/wporg-5ftf/includes/pledge-form.php b/plugins/wporg-5ftf/includes/pledge-form.php index fd819a1..b989573 100755 --- a/plugins/wporg-5ftf/includes/pledge-form.php +++ b/plugins/wporg-5ftf/includes/pledge-form.php @@ -8,6 +8,7 @@ namespace WordPressDotOrg\FiveForTheFuture\PledgeForm; use WordPressDotOrg\FiveForTheFuture; use WordPressDotOrg\FiveForTheFuture\Pledge; use WordPressDotOrg\FiveForTheFuture\PledgeMeta; +use WordPressDotOrg\FiveForTheFuture\Contributor; use WP_Error, WP_Post, WP_User; defined( 'WPINC' ) || die(); @@ -94,10 +95,14 @@ function process_form_new() { Pledge\CPT_ID ); - $created = create_new_pledge( $name ); + $new_pledge_id = Pledge\create_new_pledge( $name ); - if ( is_wp_error( $created ) ) { - return $created; + if ( is_wp_error( $new_pledge_id ) ) { + return $new_pledge_id; + } + + foreach ( $contributors as $wporg_username ) { + Contributor\create_new_contributor( $wporg_username, $new_pledge_id ); } return 'success'; @@ -318,20 +323,3 @@ function parse_contributors( $contributors ) { return $sanitized_contributors; } - -/** - * - * - * @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 = [ - 'post_type' => Pledge\CPT_ID, - 'post_title' => $name, - 'post_status' => 'draft', - ]; - - return wp_insert_post( $args, true ); -} diff --git a/plugins/wporg-5ftf/includes/pledge.php b/plugins/wporg-5ftf/includes/pledge.php index 7e83d75..02d3eec 100755 --- a/plugins/wporg-5ftf/includes/pledge.php +++ b/plugins/wporg-5ftf/includes/pledge.php @@ -7,6 +7,7 @@ namespace WordPressDotOrg\FiveForTheFuture\Pledge; use WordPressDotOrg\FiveForTheFuture; +use WP_Error; defined( 'WPINC' ) || die(); @@ -100,3 +101,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 ); +}