GC_Customize_Manager::get_changeset_post_data()

最后更新于:2021-11-27 00:56:56

GC_Customize_Manager::get_changeset_post_data( int$post_id)

Get the data stored in a changeset post.

参数

$post_id

(int) (Required) Changeset post ID.

响应

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

源文件

文件: gc-includes/class-gc-customize-manager.php

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