mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-22 11:03:43 +03:00
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:
parent
60b5ca5d2a
commit
286e6d55ef
|
@ -232,7 +232,29 @@ function process_form_manage( $pledge_id, $auth_token ) {
|
||||||
|
|
||||||
PledgeMeta\save_pledge_meta( $pledge_id, $submission );
|
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.
|
// @todo Save contributors.
|
||||||
|
|
||||||
// If we made it to here, we've successfully saved the pledge.
|
// If we made it to here, we've successfully saved the pledge.
|
||||||
|
|
Loading…
Reference in a new issue