diff --git src/wp-admin/async-upload.php src/wp-admin/async-upload.php
index add6164..763302e 100644
|
|
if ( ! ( isset( $_REQUEST['action'] ) && 'upload-attachment' == $_REQUEST['actio |
32 | 32 | |
33 | 33 | require_once( ABSPATH . 'wp-admin/admin.php' ); |
34 | 34 | |
35 | | if ( !current_user_can('upload_files') ) |
36 | | wp_die(__('You do not have permission to upload files.')); |
37 | | |
38 | | header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
39 | | |
40 | 35 | if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) { |
41 | 36 | include( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); |
42 | 37 | |
… |
… |
if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] |
47 | 42 | die( '0' ); |
48 | 43 | } |
49 | 44 | |
| 45 | if ( !current_user_can('upload_files') ) |
| 46 | wp_die(__('You do not have permission to upload files.')); |
| 47 | |
| 48 | header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
| 49 | |
50 | 50 | // just fetch the detail form for that attachment |
51 | 51 | if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch'] ) { |
52 | 52 | $post = get_post( $id ); |
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php
index 799ef1e..c174cd3 100644
|
|
function wp_ajax_update_widget() { |
1823 | 1823 | function wp_ajax_upload_attachment() { |
1824 | 1824 | check_ajax_referer( 'media-form' ); |
1825 | 1825 | |
1826 | | if ( ! current_user_can( 'upload_files' ) ) |
1827 | | wp_die(); |
| 1826 | if ( ! current_user_can( 'upload_files' ) ) { |
| 1827 | wp_send_json_error( array( |
| 1828 | 'message' => __( "You don't have permission to upload files." ), |
| 1829 | 'filename' => $_FILES['async-upload']['name'], |
| 1830 | ) ); |
| 1831 | } |
1828 | 1832 | |
1829 | 1833 | if ( isset( $_REQUEST['post_id'] ) ) { |
1830 | 1834 | $post_id = $_REQUEST['post_id']; |
1831 | | if ( ! current_user_can( 'edit_post', $post_id ) ) |
1832 | | wp_die(); |
| 1835 | if ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 1836 | wp_send_json_error( array( |
| 1837 | 'message' => __( "You don't have permission to attach files to this post." ), |
| 1838 | 'filename' => $_FILES['async-upload']['name'], |
| 1839 | ) ); |
| 1840 | } |
1833 | 1841 | } else { |
1834 | 1842 | $post_id = null; |
1835 | 1843 | } |
… |
… |
function wp_ajax_upload_attachment() { |
1840 | 1848 | if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { |
1841 | 1849 | $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false ); |
1842 | 1850 | if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
1843 | | echo json_encode( array( |
1844 | | 'success' => false, |
1845 | | 'data' => array( |
1846 | | 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), |
1847 | | 'filename' => $_FILES['async-upload']['name'], |
1848 | | ) |
| 1851 | wp_send_json_error( array( |
| 1852 | 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), |
| 1853 | 'filename' => $_FILES['async-upload']['name'], |
1849 | 1854 | ) ); |
1850 | | |
1851 | | wp_die(); |
1852 | 1855 | } |
1853 | 1856 | } |
1854 | 1857 | |
1855 | 1858 | $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); |
1856 | 1859 | |
1857 | 1860 | if ( is_wp_error( $attachment_id ) ) { |
1858 | | echo json_encode( array( |
1859 | | 'success' => false, |
1860 | | 'data' => array( |
1861 | | 'message' => $attachment_id->get_error_message(), |
1862 | | 'filename' => $_FILES['async-upload']['name'], |
1863 | | ) |
| 1861 | wp_send_json_error( array( |
| 1862 | 'message' => $attachment_id->get_error_message(), |
| 1863 | 'filename' => $_FILES['async-upload']['name'], |
1864 | 1864 | ) ); |
1865 | 1865 | |
1866 | | wp_die(); |
1867 | 1866 | } |
1868 | 1867 | |
1869 | 1868 | if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) { |
… |
… |
function wp_ajax_upload_attachment() { |
1877 | 1876 | if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) |
1878 | 1877 | wp_die(); |
1879 | 1878 | |
1880 | | echo json_encode( array( |
1881 | | 'success' => true, |
1882 | | 'data' => $attachment, |
1883 | | ) ); |
1884 | | |
1885 | | wp_die(); |
| 1879 | wp_send_json_success( $attachment ); |
1886 | 1880 | } |
1887 | 1881 | |
1888 | 1882 | /** |