WP_Customize_Manager::handle_dismiss_autosave_or_lock_request() WordPress Method
The WP_Customize_Manager::handle_dismiss_autosave_or_lock_request() method is used to dismiss an autosave or lock request. This method is used when a user clicks on the "Dismiss" button in the autosave or lock request dialog.
WP_Customize_Manager::handle_dismiss_autosave_or_lock_request() #
Deletes a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock.
Source
File: wp-includes/class-wp-customize-manager.php
public function handle_dismiss_autosave_or_lock_request() { // Calls to dismiss_user_auto_draft_changesets() and wp_get_post_autosave() require non-zero get_current_user_id(). if ( ! is_user_logged_in() ) { wp_send_json_error( 'unauthenticated', 401 ); } if ( ! $this->is_preview() ) { wp_send_json_error( 'not_preview', 400 ); } if ( ! check_ajax_referer( 'customize_dismiss_autosave_or_lock', 'nonce', false ) ) { wp_send_json_error( 'invalid_nonce', 403 ); } $changeset_post_id = $this->changeset_post_id(); $dismiss_lock = ! empty( $_POST['dismiss_lock'] ); $dismiss_autosave = ! empty( $_POST['dismiss_autosave'] ); if ( $dismiss_lock ) { if ( empty( $changeset_post_id ) && ! $dismiss_autosave ) { wp_send_json_error( 'no_changeset_to_dismiss_lock', 404 ); } if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $changeset_post_id ) && ! $dismiss_autosave ) { wp_send_json_error( 'cannot_remove_changeset_lock', 403 ); } delete_post_meta( $changeset_post_id, '_edit_lock' ); if ( ! $dismiss_autosave ) { wp_send_json_success( 'changeset_lock_dismissed' ); } } if ( $dismiss_autosave ) { if ( empty( $changeset_post_id ) || 'auto-draft' === get_post_status( $changeset_post_id ) ) { $dismissed = $this->dismiss_user_auto_draft_changesets(); if ( $dismissed > 0 ) { wp_send_json_success( 'auto_draft_dismissed' ); } else { wp_send_json_error( 'no_auto_draft_to_delete', 404 ); } } else { $revision = wp_get_post_autosave( $changeset_post_id, get_current_user_id() ); if ( $revision ) { if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->delete_post, $changeset_post_id ) ) { wp_send_json_error( 'cannot_delete_autosave_revision', 403 ); } if ( ! wp_delete_post( $revision->ID, true ) ) { wp_send_json_error( 'autosave_revision_deletion_failure', 500 ); } else { wp_send_json_success( 'autosave_revision_deleted' ); } } else { wp_send_json_error( 'no_autosave_revision_to_delete', 404 ); } } } wp_send_json_error( 'unknown_error', 500 ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.9.0 | Introduced. |