Changeset 31430 for branches/4.1/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 02/12/2015 01:32:26 AM (10 years ago)
- Location:
- branches/4.1
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.1
-
branches/4.1/src/wp-admin/includes/ajax-actions.php
r30895 r31430 1833 1833 function wp_ajax_upload_attachment() { 1834 1834 check_ajax_referer( 'media-form' ); 1835 /* 1836 * This function does not use wp_send_json_success() / wp_send_json_error() 1837 * as the html4 Plupload handler requires a text/html content-type for older IE. 1838 * See https://core.trac.wordpress.org/ticket/31037 1839 */ 1835 1840 1836 1841 if ( ! current_user_can( 'upload_files' ) ) { 1837 wp_send_json_error( array( 1838 'message' => __( "You don't have permission to upload files." ), 1839 'filename' => $_FILES['async-upload']['name'], 1842 echo wp_json_encode( array( 1843 'success' => false, 1844 'data' => array( 1845 'message' => __( "You don't have permission to upload files." ), 1846 'filename' => $_FILES['async-upload']['name'], 1847 ) 1840 1848 ) ); 1849 1850 wp_die(); 1841 1851 } 1842 1852 … … 1844 1854 $post_id = $_REQUEST['post_id']; 1845 1855 if ( ! current_user_can( 'edit_post', $post_id ) ) { 1846 wp_send_json_error( array( 1847 'message' => __( "You don't have permission to attach files to this post." ), 1848 'filename' => $_FILES['async-upload']['name'], 1856 echo wp_json_encode( array( 1857 'success' => false, 1858 'data' => array( 1859 'message' => __( "You don't have permission to attach files to this post." ), 1860 'filename' => $_FILES['async-upload']['name'], 1861 ) 1849 1862 ) ); 1863 1864 wp_die(); 1850 1865 } 1851 1866 } else { … … 1859 1874 $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false ); 1860 1875 if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { 1861 wp_send_json_error( array( 1862 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), 1876 echo wp_json_encode( array( 1877 'success' => false, 1878 'data' => array( 1879 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), 1880 'filename' => $_FILES['async-upload']['name'], 1881 ) 1882 ) ); 1883 1884 wp_die(); 1885 } 1886 } 1887 1888 $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); 1889 1890 if ( is_wp_error( $attachment_id ) ) { 1891 echo wp_json_encode( array( 1892 'success' => false, 1893 'data' => array( 1894 'message' => $attachment_id->get_error_message(), 1863 1895 'filename' => $_FILES['async-upload']['name'], 1864 ) ); 1865 } 1866 } 1867 1868 $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); 1869 1870 if ( is_wp_error( $attachment_id ) ) { 1871 wp_send_json_error( array( 1872 'message' => $attachment_id->get_error_message(), 1873 'filename' => $_FILES['async-upload']['name'], 1896 ) 1874 1897 ) ); 1898 1899 wp_die(); 1875 1900 } 1876 1901 … … 1886 1911 wp_die(); 1887 1912 1888 wp_send_json_success( $attachment ); 1913 echo wp_json_encode( array( 1914 'success' => true, 1915 'data' => $attachment, 1916 ) ); 1917 1918 wp_die(); 1889 1919 } 1890 1920
Note: See TracChangeset
for help on using the changeset viewer.