Link Template: Clarify documentation for the $id parameter in get_post_permalink(), get_edit_post_link(), edit_post_link(), and get_delete_post_link(), to reflect that either a post ID or WP_Post object is accepted.

Separately, use `$post` for checking the post status and retrieving the page_uri in `get_post_permalink()` instead of referencing back to the original `$id` parameter.

Props GunGeekATX for the initial patch.
Fixes #40780.

Built from https://develop.svn.wordpress.org/trunk@40975


git-svn-id: http://core.svn.wordpress.org/trunk@40825 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Drew Jaynes 2017-07-01 03:29:42 +00:00
parent 903d23be34
commit 0fe9fb4a16
2 changed files with 16 additions and 16 deletions

View File

@ -247,9 +247,9 @@ function get_permalink( $post = 0, $leavename = false ) {
* *
* @global WP_Rewrite $wp_rewrite * @global WP_Rewrite $wp_rewrite
* *
* @param int $id Optional. Post ID. Default uses the global `$post`. * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`.
* @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false. * @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false.
* @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false. * @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false.
* @return string|WP_Error The post permalink. * @return string|WP_Error The post permalink.
*/ */
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
@ -264,12 +264,12 @@ function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
$slug = $post->post_name; $slug = $post->post_name;
$draft_or_pending = get_post_status( $id ) && in_array( get_post_status( $id ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
$post_type = get_post_type_object($post->post_type); $post_type = get_post_type_object($post->post_type);
if ( $post_type->hierarchical ) { if ( $post_type->hierarchical ) {
$slug = get_page_uri( $id ); $slug = get_page_uri( $post );
} }
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) { if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
@ -1262,8 +1262,8 @@ function get_preview_post_link( $post = null, $query_args = array(), $preview_li
* *
* @since 2.3.0 * @since 2.3.0
* *
* @param int $id Optional. Post ID. Default is the ID of the global `$post`. * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`.
* @param string $context Optional. How to output the '&' character. Default '&'. * @param string $context Optional. How to output the '&' character. Default '&'.
* @return string|null The edit post link for the given post. null if the post type is invalid or does * @return string|null The edit post link for the given post. null if the post type is invalid or does
* not allow an editing UI. * not allow an editing UI.
*/ */
@ -1310,11 +1310,11 @@ function get_edit_post_link( $id = 0, $context = 'display' ) {
* @since 1.0.0 * @since 1.0.0
* @since 4.4.0 The `$class` argument was added. * @since 4.4.0 The `$class` argument was added.
* *
* @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. * @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null.
* @param string $before Optional. Display before edit link. Default empty. * @param string $before Optional. Display before edit link. Default empty.
* @param string $after Optional. Display after edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty.
* @param int $id Optional. Post ID. Default is the ID of the global `$post`. * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`.
* @param string $class Optional. Add custom class to link. Default 'post-edit-link'. * @param string $class Optional. Add custom class to link. Default 'post-edit-link'.
*/ */
function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) {
if ( ! $post = get_post( $id ) ) { if ( ! $post = get_post( $id ) ) {
@ -1350,9 +1350,9 @@ function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $clas
* *
* @since 2.9.0 * @since 2.9.0
* *
* @param int $id Optional. Post ID. Default is the ID of the global `$post`. * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`.
* @param string $deprecated Not used. * @param string $deprecated Not used.
* @param bool $force_delete Optional. Whether to bypass trash and force deletion. Default false. * @param bool $force_delete Optional. Whether to bypass trash and force deletion. Default false.
* @return string|void The delete post link URL for the given post. * @return string|void The delete post link URL for the given post.
*/ */
function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-alpha-40974'; $wp_version = '4.9-alpha-40975';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.