WP_Customize_Manager::handle_changeset_trash_request() WordPress Method

The WP_Customize_Manager::handle_changeset_trash_request() method is responsible for handling a request to trash a changeset. This is typically done via an AJAX request.

WP_Customize_Manager::handle_changeset_trash_request() #

Handles request to trash a changeset.


Source

File: wp-includes/class-wp-customize-manager.php

	public function handle_changeset_trash_request() {
		if ( ! is_user_logged_in() ) {
			wp_send_json_error( 'unauthenticated' );
		}

		if ( ! $this->is_preview() ) {
			wp_send_json_error( 'not_preview' );
		}

		if ( ! check_ajax_referer( 'trash_customize_changeset', 'nonce', false ) ) {
			wp_send_json_error(
				array(
					'code'    => 'invalid_nonce',
					'message' => __( 'There was an authentication problem. Please reload and try again.' ),
				)
			);
		}

		$changeset_post_id = $this->changeset_post_id();

		if ( ! $changeset_post_id ) {
			wp_send_json_error(
				array(
					'message' => __( 'No changes saved yet, so there is nothing to trash.' ),
					'code'    => 'non_existent_changeset',
				)
			);
			return;
		}

		if ( $changeset_post_id ) {
			if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->delete_post, $changeset_post_id ) ) {
				wp_send_json_error(
					array(
						'code'    => 'changeset_trash_unauthorized',
						'message' => __( 'Unable to trash changes.' ),
					)
				);
			}

			$lock_user = (int) wp_check_post_lock( $changeset_post_id );

			if ( $lock_user && get_current_user_id() !== $lock_user ) {
				wp_send_json_error(
					array(
						'code'     => 'changeset_locked',
						'message'  => __( 'Changeset is being edited by other user.' ),
						'lockUser' => $this->get_lock_user_data( $lock_user ),
					)
				);
			}
		}

		if ( 'trash' === get_post_status( $changeset_post_id ) ) {
			wp_send_json_error(
				array(
					'message' => __( 'Changes have already been trashed.' ),
					'code'    => 'changeset_already_trashed',
				)
			);
			return;
		}

		$r = $this->trash_changeset_post( $changeset_post_id );
		if ( ! ( $r instanceof WP_Post ) ) {
			wp_send_json_error(
				array(
					'code'    => 'changeset_trash_failure',
					'message' => __( 'Unable to trash changes.' ),
				)
			);
		}

		wp_send_json_success(
			array(
				'message' => __( 'Changes trashed successfully.' ),
			)
		);
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More