Manage Pledge: Delete the current logo when a new one is uploaded

This commit is contained in:
Kelly Dwan 2019-11-22 13:00:14 -05:00
parent a947ec259d
commit 77391b5c46
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D

View file

@ -233,17 +233,23 @@ function process_form_manage( $pledge_id, $auth_token ) {
PledgeMeta\save_pledge_meta( $pledge_id, $submission );
if ( isset( $_FILES['org-logo'], $_FILES['org-logo']['tmp_name'] ) && ! empty( $_FILES['org-logo']['tmp_name'] ) ) {
$current_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 logo to the pledge.
// Attach new logo to the pledge.
wp_update_post( array(
'ID' => $logo_attachment_id,
'post_parent' => $pledge_id,
) );
set_post_thumbnail( $pledge_id, $logo_attachment_id );
$updated = set_post_thumbnail( $pledge_id, $logo_attachment_id );
// Trash the old logo.
if ( $updated ) {
wp_delete_attachment( $current_logo_id );
}
}
// @todo Save contributors.