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)
This commit is contained in:
Kelly Dwan 2019-11-21 19:00:12 -05:00
parent 60b5ca5d2a
commit 286e6d55ef

View file

@ -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.