Changeset 12987 for trunk/wp-admin/admin-ajax.php
- Timestamp:
- 02/06/2010 10:07:57 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r12942 r12987 888 888 889 889 $id = $revision_id = 0; 890 if ( $_POST['post_ID'] < 0 ) { 890 891 $post_ID = (int) $_POST['post_ID']; 892 $_POST['ID'] = $post_ID; 893 $post = get_post($post_ID); 894 if ( 'auto-draft' == $post->post_status ) 891 895 $_POST['post_status'] = 'draft'; 892 $_POST['temp_ID'] = $_POST['post_ID']; 893 if ( $do_autosave ) { 894 $id = wp_write_post(); 895 $data = $message; 896 } 896 897 if ( $last = wp_check_post_lock( $post->ID ) ) { 898 $do_autosave = $do_lock = false; 899 900 $last_user = get_userdata( $last ); 901 $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); 902 $data = new WP_Error( 'locked', sprintf( 903 $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ), 904 esc_html( $last_user_name ) 905 ) ); 906 907 $supplemental['disable_autosave'] = 'disable'; 908 } 909 910 if ( 'page' == $post->post_type ) { 911 if ( !current_user_can('edit_page', $post_ID) ) 912 die(__('You are not allowed to edit this page.')); 897 913 } else { 898 $post_ID = (int) $_POST['post_ID']; 899 $_POST['ID'] = $post_ID; 900 $post = get_post($post_ID); 901 902 if ( $last = wp_check_post_lock( $post->ID ) ) { 903 $do_autosave = $do_lock = false; 904 905 $last_user = get_userdata( $last ); 906 $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); 907 $data = new WP_Error( 'locked', sprintf( 908 $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ), 909 esc_html( $last_user_name ) 910 ) ); 911 912 $supplemental['disable_autosave'] = 'disable'; 913 } 914 915 if ( 'page' == $post->post_type ) { 916 if ( !current_user_can('edit_page', $post_ID) ) 917 die(__('You are not allowed to edit this page.')); 918 } else { 919 if ( !current_user_can('edit_post', $post_ID) ) 920 die(__('You are not allowed to edit this post.')); 921 } 922 923 if ( $do_autosave ) { 924 // Drafts are just overwritten by autosave 925 if ( 'draft' == $post->post_status ) { 926 $id = edit_post(); 927 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 928 $revision_id = wp_create_post_autosave( $post->ID ); 929 if ( is_wp_error($revision_id) ) 930 $id = $revision_id; 931 else 932 $id = $post->ID; 933 } 934 $data = $message; 935 } else { 914 if ( !current_user_can('edit_post', $post_ID) ) 915 die(__('You are not allowed to edit this post.')); 916 } 917 918 if ( $do_autosave ) { 919 // Drafts and auto-drafts are just overwritten by autosave 920 if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) { 921 $id = edit_post(); 922 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 923 $revision_id = wp_create_post_autosave( $post->ID ); 924 if ( is_wp_error($revision_id) ) 925 $id = $revision_id; 926 else 927 $id = $post->ID; 928 } 929 $data = $message; 930 } else { 931 if ( '1' == $_POST['auto_draft'] ) 932 $id = 0; // This tells us it didn't actually save 933 else 936 934 $id = $post->ID; 937 } 938 } 939 940 if ( $do_lock && $id && is_numeric($id) ) 935 } 936 937 if ( $do_lock && $_POST['auto_draft'] != '1' && $id && is_numeric($id) ) 941 938 wp_set_post_lock( $id ); 942 939 … … 962 959 $x->send(); 963 960 break; 964 case 'autosave-generate-nonces' :965 check_ajax_referer( 'autosave', 'autosavenonce' );966 $ID = (int) $_POST['post_ID'];967 $post_type = $_POST['post_type'];968 $post_type_object = get_post_type_object($post_type);969 if ( !$post_type_object )970 die('0');971 if ( current_user_can( $post_type_object->edit_cap, $ID ) )972 die( json_encode( array( 'updateNonce' => wp_create_nonce( "update-{$post_type}_{$ID}" ), 'deleteURL' => str_replace( '&', '&', wp_nonce_url( admin_url( $post_type . '.php?action=trash&post=' . $ID ), "trash-{$post_type}_{$ID}" ) ) ) ) );973 do_action('autosave_generate_nonces');974 die('0');975 break;976 961 case 'closed-postboxes' : 977 962 check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
Note: See TracChangeset
for help on using the changeset viewer.