Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_set_preview() WordPress Function

The set_preview() function allows you to enable or disable the WordPress preview feature. By default, WordPress previews are enabled. When you enable previews, WordPress will generate a preview of your post or page whenever you save it. This can be useful if you want to see what your post or page will look like before it is published. However, if you do not want WordPress to generate previews, you can disable them using this function.

_set_preview( WP_Post $post ) #

Sets up the post object for preview based on the post autosave.


Parameters

$post

(WP_Post)(Required)


Top ↑

Return

(WP_Post|false)


Top ↑

Source

File: wp-includes/revision.php

function _set_preview( $post ) {
	if ( ! is_object( $post ) ) {
		return $post;
	}

	$preview = wp_get_post_autosave( $post->ID );

	if ( is_object( $preview ) ) {
		$preview = sanitize_post( $preview );

		$post->post_content = $preview->post_content;
		$post->post_title   = $preview->post_title;
		$post->post_excerpt = $preview->post_excerpt;
	}

	add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
	add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );

	return $post;
}


Top ↑

Changelog

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