post_preview() - WordPress 函数参考中文文档

返回介绍

post_preview()

发布于 2017-09-11 字数2876 浏览 879 评论 0

post_preview()

Save draft or manually autosave for showing preview.


描述


返回值

(str) URL to redirect to show the preview


源代码

File: wp-admin/includes/post.php

function post_preview() {

	$post_ID = (int) $_POST['post_ID'];
	$_POST['ID'] = $post_ID;

	if ( ! $post = get_post( $post_ID ) ) {
		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
	}

	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
	}

	$is_autosave = false;

	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
		$saved_post_id = edit_post();
	} else {
		$is_autosave = true;

		if ( isset( $_POST['post_status'] ) && 'auto-draft' == $_POST['post_status'] )
			$_POST['post_status'] = 'draft';

		$saved_post_id = wp_create_post_autosave( $post->ID );
	}

	if ( is_wp_error( $saved_post_id ) )
		wp_die( $saved_post_id->get_error_message() );

	$query_args = array();

	if ( $is_autosave && $saved_post_id ) {
		$query_args['preview_id'] = $post->ID;
		$query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID );

		if ( isset( $_POST['post_format'] ) ) {
			$query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] );
		}

		if ( isset( $_POST['_thumbnail_id'] ) ) {
			$query_args['_thumbnail_id'] = ( intval( $_POST['_thumbnail_id'] ) <= 0 ) ? '-1' : intval( $_POST['_thumbnail_id'] );
		}
	}

	return get_preview_post_link( $post, $query_args );
}

更新日志

Version 描述
2.7.0 Introduced.

相关函数

Uses

  • wp-includes/link-template.php:
    get_preview_post_link()
  • wp-admin/includes/post.php:
    wp_check_post_lock()
  • wp-admin/includes/post.php:
    wp_create_post_autosave()
  • wp-admin/includes/post.php:
    edit_post()
  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/l10n.php:
    __()
  • wp-includes/formatting.php:
    sanitize_key()
  • wp-includes/pluggable.php:
    wp_create_nonce()
  • wp-includes/functions.php:
    wp_die()
  • wp-includes/user.php:
    get_current_user_id()
  • wp-includes/post.php:
    get_post()
  • wp-includes/load.php:
    is_wp_error()
  • Show 7 more uses
    Hide more uses


User Contributed Notes

上一篇:post_permalink()

下一篇:post_reply_link()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!