mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-02 01:01:18 +03:00
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.
This commit is contained in:
parent
8f5a81d6e9
commit
aaf8b1a712
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue