mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-06 18:55:44 +03:00
Move where image handling happens so we can pass back errors
This commit is contained in:
parent
1094dc3e89
commit
66772080a5
2 changed files with 28 additions and 27 deletions
|
@ -69,12 +69,6 @@ function get_pledge_meta_config( $context = '' ) {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'show_in_rest' => false,
|
||||
),
|
||||
'org-logo' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
'show_in_rest' => true,
|
||||
'php_filter' => FILTER_VALIDATE_URL,
|
||||
),
|
||||
'pledge-email-confirmed' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'wp_validate_boolean',
|
||||
|
@ -230,27 +224,6 @@ function save_pledge( $pledge_id, $pledge ) {
|
|||
function save_pledge_meta( $pledge_id, $new_values ) {
|
||||
$config = get_pledge_meta_config();
|
||||
|
||||
// Process image.
|
||||
if ( ! function_exists('media_handle_upload') ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
||||
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
||||
require_once( ABSPATH . 'wp-admin/includes/media.php' );
|
||||
}
|
||||
|
||||
$logo = isset( $_FILES['org-logo'] ) ? $_FILES['org-logo'] : false;
|
||||
if (
|
||||
$logo &&
|
||||
in_array( $logo['type'], [ 'image/png', 'image/jpg' ] ) &&
|
||||
( $logo['size'] < 5 * MB_IN_BYTES )
|
||||
) {
|
||||
$result = \media_handle_sideload( $logo, $pledge_id );
|
||||
|
||||
if ( ! is_wp_error( $result ) ) {
|
||||
$new_values['org-logo'] = wp_get_attachment_url( $result );
|
||||
set_post_thumbnail( $pledge_id, $result );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $new_values as $key => $value ) {
|
||||
if ( array_key_exists( $key, $config ) ) {
|
||||
$meta_key = META_PREFIX . $key;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue