返回介绍

get_preview_post_link()

发布于 2017-09-11 00:00:25 字数 3462 浏览 1103 评论 0 收藏 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.


description

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 );
}

更新日志

Versiondescription
4.4.0Introduced.

相关函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文