Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_ajax_autosave [ WordPress Function ]

wp_ajax_autosave ( No parameters )
Defined at:



No description yet.

Source


<?php
function wp_ajax_autosave() {
    global 
$login_grace_period;

    
define'DOING_AUTOSAVE'true );

    
$nonce_age check_ajax_referer'autosave''autosavenonce' );

    
$_POST['post_category'] = explode(","$_POST['catslist']);
    if ( 
$_POST['post_type'] == 'page' || empty($_POST['post_category']) )
        unset(
$_POST['post_category']);

    
$do_autosave = (bool) $_POST['autosave'];
    
$do_lock true;

    
$data $alert '';
    
/* translators: draft saved date format, see http://php.net/date */
    
$draft_saved_date_format __('g:i:s a');
    
/* translators: %s: date and time */
    
$message sprintf__('Draft saved at %s.'), date_i18n$draft_saved_date_format ) );

    
$supplemental = array();
    if ( isset(
$login_grace_period) )
        
$alert .= sprintf__('Your login has expired. Please open a new browser window and <a href="%s" target="_blank">log in again</a>. '), add_query_arg'interim-login'1wp_login_url() ) );

    
$id $revision_id 0;

    
$post_ID = (int) $_POST['post_ID'];
    
$_POST['ID'] = $post_ID;
    
$post get_post($post_ID);
    if ( 
'auto-draft' == $post->post_status )
        
$_POST['post_status'] = 'draft';

    if ( 
$last wp_check_post_lock$post->ID ) ) {
        
$do_autosave $do_lock false;

        
$last_user get_userdata$last );
        
$last_user_name $last_user $last_user->display_name __'Someone' );
        
$data __'Autosave disabled.' );

        
$supplemental['disable_autosave'] = 'disable';
        
$alert .= sprintf__'%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html$last_user_name ) );
    }

    if ( 
'page' == $post->post_type ) {
        if ( !
current_user_can('edit_page'$post_ID) )
            
wp_die__'You are not allowed to edit this page.' ) );
    } else {
        if ( !
current_user_can('edit_post'$post_ID) )
            
wp_die__'You are not allowed to edit this post.' ) );
    }

    if ( 
$do_autosave ) {
        
// Drafts and auto-drafts are just overwritten by autosave
        
if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) {
            
$id edit_post();
        } else { 
// Non drafts are not overwritten. The autosave is stored in a special post revision.
            
$revision_id wp_create_post_autosave$post->ID );
            if ( 
is_wp_error($revision_id) )
                
$id $revision_id;
            else
                
$id $post->ID;
        }
        
$data $message;
    } else {
        if ( ! empty( 
$_POST['auto_draft'] ) )
            
$id 0// This tells us it didn't actually save
        
else
            
$id $post->ID;
    }

    if ( 
$do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric$id ) ) {
        
$lock_result wp_set_post_lock$id );
        
$supplemental['active-post-lock'] = implode':'$lock_result );
    }

    if ( 
$nonce_age == ) {
        
$supplemental['replace-autosavenonce'] = wp_create_nonce('autosave');
        
$supplemental['replace-getpermalinknonce'] = wp_create_nonce('getpermalink');
        
$supplemental['replace-samplepermalinknonce'] = wp_create_nonce('samplepermalink');
        
$supplemental['replace-closedpostboxesnonce'] = wp_create_nonce('closedpostboxes');
        
$supplemental['replace-_ajax_linking_nonce'] = wp_create_nonce'internal-linking' );
        if ( 
$id ) {
            if ( 
$_POST['post_type'] == 'post' )
                
$supplemental['replace-_wpnonce'] = wp_create_nonce('update-post_' $id);
            elseif ( 
$_POST['post_type'] == 'page' )
                
$supplemental['replace-_wpnonce'] = wp_create_nonce('update-page_' $id);
        }
    }

    if ( ! empty(
$alert) )
        
$supplemental['alert'] = $alert;

    
$x = new WP_Ajax_Response( array(
        
'what' => 'autosave',
        
'id' => $id,
        
'data' => $id $data '',
        
'supplemental' => $supplemental
    
) );
    
$x->send();
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics