WordPress.org

Make WordPress Core

Changeset 35001


Ignore:
Timestamp:
10/10/2015 05:40:14 AM (4 years ago)
Author:
DrewAPicture
Message:

Template: Rename the $id parameters in the_permalink(), get_the_permalink(), and get_permalink() to $post.

In all three cases, the functions can accept a post ID, a WP_Post object, or a falsey value, which defaults to the value of the global $post. Switching to $post in this context allows the parameters to better self-document and removes ambiguity in the code they are subsequently used in.

Props chriscct7 for the initial patch.
See #34234.

File:
1 edited

Legend:

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

    r34988 r35001  
    1111 *
    1212 * @since 1.2.0
    13  * @since 4.4.0 Added `$id` parameter.
    14  *
    15  * @param int|WP_Post $id Optional. Post ID or post object. Default current post.
    16  */
    17 function the_permalink( $id = 0 ) {
     13 * @since 4.4.0 Added the `$post` parameter.
     14 *
     15 * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
     16 */
     17function the_permalink( $post = 0 ) {
    1818    /**
    1919     * Filter the display of the permalink for the current post.
     
    2323     * @param string $permalink The permalink for the current post.
    2424     */
    25     echo esc_url( apply_filters( 'the_permalink', get_permalink( $id ) ) );
     25    echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ) ) );
    2626}
    2727
     
    9595 * @see get_permalink()
    9696 *
    97  * @param int|WP_Post $id        Optional. Post ID or post object. Default current post.
     97 * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
     98 * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
     99 *
     100 * @return string|false The permalink URL or false if post does not exist.
     101 */
     102function get_the_permalink( $post = 0, $leavename = false ) {
     103    return get_permalink( $post, $leavename );
     104}
     105
     106/**
     107 * Retrieve full permalink for current post or post ID.
     108 *
     109 * @since 1.0.0
     110 *
     111 * @param int|WP_Post $post      Optional. Post ID or post object. Default is the global `$post`.
    98112 * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
    99113 * @return string|false The permalink URL or false if post does not exist.
    100114 */
    101 function get_the_permalink( $id = 0, $leavename = false ) {
    102     return get_permalink( $id, $leavename );
    103 }
    104 
    105 /**
    106  * Retrieve full permalink for current post or post ID.
    107  *
    108  * @since 1.0.0
    109  *
    110  * @param int|WP_Post $id        Optional. Post ID or post object. Default current post.
    111  * @param bool        $leavename Optional. Whether to keep post name or page name. Default false.
    112  * @return string|false The permalink URL or false if post does not exist.
    113  */
    114 function get_permalink( $id = 0, $leavename = false ) {
     115function get_permalink( $post = 0, $leavename = false ) {
    115116    $rewritecode = array(
    116117        '%year%',
     
    127128    );
    128129
    129     if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
    130         $post = $id;
     130    if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) {
    131131        $sample = true;
    132132    } else {
    133         $post = get_post($id);
     133        $post = get_post( $post );
    134134        $sample = false;
    135135    }
Note: See TracChangeset for help on using the changeset viewer.