W3cubDocs

/WordPress

_wp_post_revision_fields( array|WP_Post $post = array(), bool $deprecated = false ): string[]

Determines which fields of posts are to be saved in revisions.

Parameters

$postarray|WP_Postoptional
A post array or a WP_Post object being processed for insertion as a post revision.

Default:array()

$deprecatedbooloptional
Not used.

Default:false

Return

string[] Array of fields that can be versioned.

Source

function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
	static $fields = null;

	if ( ! is_array( $post ) ) {
		$post = get_post( $post, ARRAY_A );
	}

	if ( is_null( $fields ) ) {
		// Allow these to be versioned.
		$fields = array(
			'post_title'   => __( 'Title' ),
			'post_content' => __( 'Content' ),
			'post_excerpt' => __( 'Excerpt' ),
		);
	}

	/**
	 * Filters the list of fields saved in post revisions.
	 *
	 * Included by default: 'post_title', 'post_content' and 'post_excerpt'.
	 *
	 * Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
	 * 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
	 * and 'post_author'.
	 *
	 * @since 2.6.0
	 * @since 4.5.0 The `$post` parameter was added.
	 *
	 * @param string[] $fields List of fields to revision. Contains 'post_title',
	 *                         'post_content', and 'post_excerpt' by default.
	 * @param array    $post   A post array being processed for insertion as a post revision.
	 */
	$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );

	// WP uses these internally either in versioning or elsewhere - they cannot be versioned.
	foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
		unset( $fields[ $protect ] );
	}

	return $fields;
}

Hooks

apply_filters( ‘_wp_post_revision_fields’, string[] $fields, array $post )

Filters the list of fields saved in post revisions.

Changelog

Version Description
4.5.0 The optional $autosave parameter was deprecated and renamed to $deprecated.
2.6.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_wp_post_revision_fields