From 286e6d55ef5d96670fbacfe806f5b61d925da735 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 21 Nov 2019 19:00:12 -0500 Subject: [PATCH] Manage Pledge: Save a new logo if one is uploaded - Add logo display & field to manage form - Save the new logo if submitted (do nothing if not) - Delete the original logo when a new one is uploaded, checking that the attachment parent is the pledge (just in case of changes via Media Library) --- plugins/wporg-5ftf/includes/pledge-form.php | 24 ++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/wporg-5ftf/includes/pledge-form.php b/plugins/wporg-5ftf/includes/pledge-form.php index 380b4a4..e2fdf57 100755 --- a/plugins/wporg-5ftf/includes/pledge-form.php +++ b/plugins/wporg-5ftf/includes/pledge-form.php @@ -232,7 +232,29 @@ function process_form_manage( $pledge_id, $auth_token ) { PledgeMeta\save_pledge_meta( $pledge_id, $submission ); - // @todo Upload & attach logo. + if ( isset( $_FILES['org-logo'], $_FILES['org-logo']['tmp_name'] ) && ! empty( $_FILES['org-logo']['tmp_name'] ) ) { + $original_logo_id = get_post_thumbnail_id( $pledge_id ); + $logo_attachment_id = upload_image( $_FILES['org-logo'] ); + if ( is_wp_error( $logo_attachment_id ) ) { + return $logo_attachment_id; + } + + // Attach new logo to the pledge. + wp_update_post( array( + 'ID' => $logo_attachment_id, + 'post_parent' => $pledge_id, + ) ); + $updated = set_post_thumbnail( $pledge_id, $logo_attachment_id ); + + // Trash the old logo. + if ( $updated ) { + $orig_logo_attachment = get_post( $original_logo_id ); + if ( $orig_logo_attachment && $pledge_id === $orig_logo_attachment->post_parent ) { + wp_delete_attachment( $original_logo_id ); + } + } + } + // @todo Save contributors. // If we made it to here, we've successfully saved the pledge.