WP_Customize_Manager::get_changeset_post_data() WordPress Method

The WP_Customize_Manager::get_changeset_post_data() method is used to get the post data for a changeset. This is useful for making changes to a changeset via the WordPress REST API.

WP_Customize_Manager::get_changeset_post_data( int $post_id ) #

Gets the data stored in a changeset post.


Parameters

$post_id

(int)(Required)Changeset post ID.


Top ↑

Return

(array|WP_Error) Changeset data or WP_Error on error.


Top ↑

Source

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

	protected function get_changeset_post_data( $post_id ) {
		if ( ! $post_id ) {
			return new WP_Error( 'empty_post_id' );
		}
		$changeset_post = get_post( $post_id );
		if ( ! $changeset_post ) {
			return new WP_Error( 'missing_post' );
		}
		if ( 'revision' === $changeset_post->post_type ) {
			if ( 'customize_changeset' !== get_post_type( $changeset_post->post_parent ) ) {
				return new WP_Error( 'wrong_post_type' );
			}
		} elseif ( 'customize_changeset' !== $changeset_post->post_type ) {
			return new WP_Error( 'wrong_post_type' );
		}
		$changeset_data = json_decode( $changeset_post->post_content, true );
		$last_error     = json_last_error();
		if ( $last_error ) {
			return new WP_Error( 'json_parse_error', '', $last_error );
		}
		if ( ! is_array( $changeset_data ) ) {
			return new WP_Error( 'expected_array' );
		}
		return $changeset_data;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.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