Changeset 22541 for trunk/wp-admin/includes/ajax-actions.php
- Timestamp:
- 11/11/2012 01:26:42 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ajax-actions.php
r22532 r22541 1851 1851 1852 1852 $changes = $_REQUEST['changes']; 1853 $args = array(); 1854 1855 if ( ! empty( $changes['title'] ) ) 1856 $args['post_title'] = $changes['title']; 1857 1858 if ( ! empty( $changes['caption'] ) ) 1859 $args['post_excerpt'] = $changes['caption']; 1860 1861 if ( ! empty( $changes['alt'] ) ) 1862 $args['_wp_attachment_image_alt'] = $changes['alt']; 1863 1864 if ( $args ) 1865 edit_post( array_merge( $args, array( 'post_ID' => $id ) ) ); 1866 1853 $post = get_post( $id, ARRAY_A ); 1854 1855 if ( 'attachment' != $post['post_type'] ) 1856 wp_send_json_error(); 1857 1858 if ( isset( $changes['title'] ) ) 1859 $post['post_title'] = $changes['title']; 1860 1861 if ( isset( $changes['caption'] ) ) 1862 $post['post_excerpt'] = $changes['caption']; 1863 1864 if ( isset( $changes['alt'] ) ) { 1865 $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); 1866 $new_alt = stripslashes( $changes['alt'] ); 1867 if ( $alt != $new_alt ) { 1868 $new_alt = wp_strip_all_tags( $new_alt, true ); 1869 update_post_meta( $id, '_wp_attachment_image_alt', addslashes( $new_alt ) ); 1870 } 1871 } 1872 1873 wp_update_post( $post ); 1867 1874 wp_send_json_success(); 1868 1875 } 1876 1877 /** 1878 * Save backwards compatible attachment attributes. 1879 * 1880 * @since 3.5.0 1881 */ 1882 function wp_ajax_save_attachment_compat() { 1883 if ( ! isset( $_REQUEST['id'] ) ) 1884 wp_send_json_error(); 1885 1886 if ( ! $id = absint( $_REQUEST['id'] ) ) 1887 wp_send_json_error(); 1888 1889 if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) 1890 wp_send_json_error(); 1891 $attachment_data = $_REQUEST['attachments'][ $id ]; 1892 1893 check_ajax_referer( 'save-attachment', 'nonce' ); 1894 1895 if ( ! current_user_can( 'edit_post', $id ) ) 1896 wp_send_json_error(); 1897 1898 $post = get_post( $id, ARRAY_A ); 1899 1900 if ( 'attachment' != $post['post_type'] ) 1901 wp_send_json_error(); 1902 1903 $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); 1904 1905 if ( isset( $post['errors'] ) ) { 1906 $errors = $post['errors']; // @todo return me and display me! 1907 unset( $post['errors'] ); 1908 } 1909 1910 wp_update_post( $post ); 1911 1912 foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { 1913 if ( isset( $attachment_data[ $taxonomy ] ) ) 1914 wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false ); 1915 } 1916 1917 if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) 1918 wp_send_json_error(); 1919 1920 wp_send_json_success( $attachment ); 1921 }
Note: See TracChangeset
for help on using the changeset viewer.