Make WordPress Core

Changeset 40975


Ignore:
Timestamp:
07/01/2017 03:28:11 AM (7 years ago)
Author:
DrewAPicture
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r40931 r40975  
    248248 * @global WP_Rewrite $wp_rewrite
    249249 *
    250  * @param int $id         Optional. Post ID. Default uses the global `$post`.
    251  * @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false.
    252  * @param bool $sample    Optional, defaults to false. Is it a sample permalink. Default false.
     250 * @param int|WP_Post $id        Optional. Post ID or post object. Default is the global `$post`.
     251 * @param bool        $leavename Optional, defaults to false. Whether to keep post name. Default false.
     252 * @param bool        $sample    Optional, defaults to false. Is it a sample permalink. Default false.
    253253 * @return string|WP_Error The post permalink.
    254254 */
     
    265265    $slug = $post->post_name;
    266266
    267     $draft_or_pending = get_post_status( $id ) && in_array( get_post_status( $id ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
     267    $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
    268268
    269269    $post_type = get_post_type_object($post->post_type);
    270270
    271271    if ( $post_type->hierarchical ) {
    272         $slug = get_page_uri( $id );
     272        $slug = get_page_uri( $post );
    273273    }
    274274
     
    12631263 * @since 2.3.0
    12641264 *
    1265  * @param int    $id      Optional. Post ID. Default is the ID of the global `$post`.
    1266  * @param string $context Optional. How to output the '&' character. Default '&'.
     1265 * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
     1266 * @param string      $context Optional. How to output the '&' character. Default '&'.
    12671267 * @return string|null The edit post link for the given post. null if the post type is invalid or does
    12681268 *                     not allow an editing UI.
     
    13111311 * @since 4.4.0 The `$class` argument was added.
    13121312 *
    1313  * @param string $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
    1314  * @param string $before Optional. Display before edit link. Default empty.
    1315  * @param string $after  Optional. Display after edit link. Default empty.
    1316  * @param int    $id     Optional. Post ID. Default is the ID of the global `$post`.
    1317  * @param string $class  Optional. Add custom class to link. Default 'post-edit-link'.
     1313 * @param string      $text   Optional. Anchor text. If null, default is 'Edit This'. Default null.
     1314 * @param string      $before Optional. Display before edit link. Default empty.
     1315 * @param string      $after  Optional. Display after edit link. Default empty.
     1316 * @param int|WP_Post $id     Optional. Post ID or post object. Default is the global `$post`.
     1317 * @param string      $class  Optional. Add custom class to link. Default 'post-edit-link'.
    13181318 */
    13191319function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) {
     
    13511351 * @since 2.9.0
    13521352 *
    1353  * @param int    $id           Optional. Post ID. Default is the ID of the global `$post`.
    1354  * @param string $deprecated   Not used.
    1355  * @param bool   $force_delete Optional. Whether to bypass trash and force deletion. Default false.
     1353 * @param int|WP_Post $id           Optional. Post ID or post object. Default is the global `$post`.
     1354 * @param string      $deprecated   Not used.
     1355 * @param bool        $force_delete Optional. Whether to bypass trash and force deletion. Default false.
    13561356 * @return string|void The delete post link URL for the given post.
    13571357 */
Note: See TracChangeset for help on using the changeset viewer.