返回介绍

get_sample_permalink()

发布于 2017-09-11 00:06:30 字数 2753 浏览 941 评论 0 收藏 0

get_sample_permalink( int $id,  string $title = null,  string $name = null )

Get a sample permalink based off of the post name.


description


参数

$id

(int) (Required) Post ID or post object.

$title

(string) (Optional) Title to override the post's current title when generating the post name.

Default value: null

$name

(string) (Optional) Name to override the post name.

Default value: null


返回值

(array) Array containing the sample permalink with placeholder for the post name, and the post name.


源代码

File: wp-admin/includes/post.php

function get_sample_permalink($id, $title = null, $name = null) {
	$post = get_post( $id );
	if ( ! $post )
		return array( '', '' );

	$ptype = get_post_type_object($post->post_type);

	$original_status = $post->post_status;
	$original_date = $post->post_date;
	$original_name = $post->post_name;

	// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
	if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
		$post->post_status = 'publish';
		$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
	}

	// If the user wants to set a new name -- override the current one
	// Note: if empty name is supplied -- use the title instead, see

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-admin/includes/post.php: get_sample_permalink
  • wp-admin/edit-tag-form.php: editable_slug
  • wp-includes/formatting.php: untrailingslashit()
  • wp-includes/formatting.php: sanitize_title()
  • wp-includes/link-template.php: get_permalink()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_page_uri()
  • wp-includes/post.php: wp_unique_post_slug()
  • wp-includes/post.php: get_post()
  • wp-includes/post.php: get_post_type_object()
  • Show 5 more uses Hide more uses

Used By

  • wp-admin/includes/post.php: get_sample_permalink_html()

User Contributed Notes

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

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

发布评论

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