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

返回介绍

get_preview_post_link()

发布于 2017-09-11 字数3464 浏览 910 评论 0

get_preview_post_link( int|WP_Post $post = null,  array $query_args = array(),  string $preview_link = '' )

Retrieves the URL used for the post preview.


描述

Allows additional query args to be appended.


参数

$post

(int|WP_Post)
(Optional)
Post ID or WP_Post object. Defaults to global $post.

Default value: null

$query_args

(array)
(Optional)
Array of additional query args to be appended to the link.

Default value: array()

$preview_link

(string)
(Optional)
Base preview link to be used if it should differ from the post permalink.

Default value: ”


返回值

(string|null) URL used for the post preview, or null if the post does not exist.


源代码

File: wp-includes/link-template.php

function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) {
	$post = get_post( $post );
	if ( ! $post ) {
		return;
	}

	$post_type_object = get_post_type_object( $post->post_type );
	if ( is_post_type_viewable( $post_type_object ) ) {
		if ( ! $preview_link ) {
			$preview_link = set_url_scheme( get_permalink( $post ) );
		}

		$query_args['preview'] = 'true';
		$preview_link = add_query_arg( $query_args, $preview_link );
	}

	/**
	 * Filters the URL used for a post preview.
	 *
	 * @since 2.0.5
	 * @since 4.0.0 Added the `$post` parameter.
	 *
	 * @param string  $preview_link URL used for the post preview.
	 * @param WP_Post $post         Post object.
	 */
	return apply_filters( 'preview_post_link', $preview_link, $post );
}

更新日志

Version 描述
4.4.0 Introduced.

相关函数

Uses

  • wp-includes/post.php:
    is_post_type_viewable()
  • wp-includes/link-template.php:
    preview_post_link
  • wp-includes/functions.php:
    add_query_arg()
  • wp-includes/link-template.php:
    set_url_scheme()
  • wp-includes/link-template.php:
    get_permalink()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post.php:
    get_post()
  • wp-includes/post.php:
    get_post_type_object()
  • Show 3 more uses
    Hide more uses


Used By

  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::handle_row_actions()
  • wp-admin/includes/post.php:
    get_sample_permalink_html()
  • wp-admin/includes/post.php:
    _admin_notice_post_locked()
  • wp-admin/includes/post.php:
    post_preview()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_permalink()
  • wp-admin/includes/meta-boxes.php:
    post_submit_meta_box()
  • wp-includes/admin-bar.php:
    wp_admin_bar_edit_menu()
  • wp-includes/post-template.php:
    _wp_link_page()
  • Show 3 more used by
    Hide more used by


User Contributed Notes

发布评论

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

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