@@ 2075-2085 (lines=11) @@ | ||
2072 | ||
2073 | if ( isset( $_REQUEST['post_id'] ) ) { |
|
2074 | $post_id = $_REQUEST['post_id']; |
|
2075 | if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
2076 | echo wp_json_encode( array( |
|
2077 | 'success' => false, |
|
2078 | 'data' => array( |
|
2079 | 'message' => __( 'Sorry, you are not allowed to attach files to this post.' ), |
|
2080 | 'filename' => $_FILES['async-upload']['name'], |
|
2081 | ) |
|
2082 | ) ); |
|
2083 | ||
2084 | wp_die(); |
|
2085 | } |
|
2086 | } else { |
|
2087 | $post_id = null; |
|
2088 | } |
|
@@ 2095-2105 (lines=11) @@ | ||
2092 | // If the context is custom header or background, make sure the uploaded file is an image. |
|
2093 | if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { |
|
2094 | $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); |
|
2095 | if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
|
2096 | echo wp_json_encode( array( |
|
2097 | 'success' => false, |
|
2098 | 'data' => array( |
|
2099 | 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), |
|
2100 | 'filename' => $_FILES['async-upload']['name'], |
|
2101 | ) |
|
2102 | ) ); |
|
2103 | ||
2104 | wp_die(); |
|
2105 | } |
|
2106 | } |
|
2107 | ||
2108 | $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); |