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

返回介绍

redirect_post()

发布于 2017-09-11 字数2334 浏览 961 评论 0

redirect_post( int $post_id = '' )

Redirect to previous page.


描述


参数

$post_id

(int)
(Optional)
Post ID.

Default value: ”


源代码

File: wp-admin/includes/post.php

function redirect_post($post_id = '') {
	if ( isset($_POST['save']) || isset($_POST['publish']) ) {
		$status = get_post_status( $post_id );

		if ( isset( $_POST['publish'] ) ) {
			switch ( $status ) {
				case 'pending':
					$message = 8;
					break;
				case 'future':
					$message = 9;
					break;
				default:
					$message = 6;
			}
		} else {
			$message = 'draft' == $status ? 10 : 1;
		}

		$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
	} elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
		$location = add_query_arg( 'message', 2, wp_get_referer() );
		$location = explode('#', $location);
		$location = $location[0] . '#postcustom';
	} elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
		$location = add_query_arg( 'message', 3, wp_get_referer() );
		$location = explode('#', $location);
		$location = $location[0] . '#postcustom';
	} else {
		$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
	}

	/**
	 * Filters the post redirect destination URL.
	 *
	 * @since 2.9.0
	 *
	 * @param string $location The destination URL.
	 * @param int    $post_id  The post ID.
	 */
	wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
	exit;
}

Collapse full 源代码 code

View on Trac


相关函数

Uses

  • wp-admin/includes/post.php:
    redirect_post_location
  • wp-includes/pluggable.php:
    wp_redirect()
  • wp-includes/functions.php:
    wp_get_referer()
  • wp-includes/functions.php:
    add_query_arg()
  • wp-includes/link-template.php:
    get_edit_post_link()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post.php:
    get_post_status()
  • Show 2 more uses
    Hide more uses


User Contributed Notes

发布评论

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

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