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. Built from https://develop.svn.wordpress.org/trunk@35001 git-svn-id: http://core.svn.wordpress.org/trunk@34966 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5399881b18
commit
c2b5aeebb0
|
@ -10,11 +10,11 @@
|
||||||
* Display the permalink for the current post.
|
* Display the permalink for the current post.
|
||||||
*
|
*
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
* @since 4.4.0 Added `$id` parameter.
|
* @since 4.4.0 Added the `$post` parameter.
|
||||||
*
|
*
|
||||||
* @param int|WP_Post $id Optional. Post ID or post object. Default current post.
|
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
|
||||||
*/
|
*/
|
||||||
function the_permalink( $id = 0 ) {
|
function the_permalink( $post = 0 ) {
|
||||||
/**
|
/**
|
||||||
* Filter the display of the permalink for the current post.
|
* Filter the display of the permalink for the current post.
|
||||||
*
|
*
|
||||||
|
@ -22,7 +22,7 @@ function the_permalink( $id = 0 ) {
|
||||||
*
|
*
|
||||||
* @param string $permalink The permalink for the current post.
|
* @param string $permalink The permalink for the current post.
|
||||||
*/
|
*/
|
||||||
echo esc_url( apply_filters( 'the_permalink', get_permalink( $id ) ) );
|
echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,12 +94,13 @@ function permalink_anchor( $mode = 'id' ) {
|
||||||
*
|
*
|
||||||
* @see get_permalink()
|
* @see get_permalink()
|
||||||
*
|
*
|
||||||
* @param int|WP_Post $id Optional. Post ID or post object. Default current post.
|
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
|
||||||
* @param bool $leavename Optional. Whether to keep post name or page name. Default false.
|
* @param bool $leavename Optional. Whether to keep post name or page name. Default false.
|
||||||
|
*
|
||||||
* @return string|false The permalink URL or false if post does not exist.
|
* @return string|false The permalink URL or false if post does not exist.
|
||||||
*/
|
*/
|
||||||
function get_the_permalink( $id = 0, $leavename = false ) {
|
function get_the_permalink( $post = 0, $leavename = false ) {
|
||||||
return get_permalink( $id, $leavename );
|
return get_permalink( $post, $leavename );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,11 +108,11 @@ function get_the_permalink( $id = 0, $leavename = false ) {
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*
|
*
|
||||||
* @param int|WP_Post $id Optional. Post ID or post object. Default current post.
|
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
|
||||||
* @param bool $leavename Optional. Whether to keep post name or page name. Default false.
|
* @param bool $leavename Optional. Whether to keep post name or page name. Default false.
|
||||||
* @return string|false The permalink URL or false if post does not exist.
|
* @return string|false The permalink URL or false if post does not exist.
|
||||||
*/
|
*/
|
||||||
function get_permalink( $id = 0, $leavename = false ) {
|
function get_permalink( $post = 0, $leavename = false ) {
|
||||||
$rewritecode = array(
|
$rewritecode = array(
|
||||||
'%year%',
|
'%year%',
|
||||||
'%monthnum%',
|
'%monthnum%',
|
||||||
|
@ -126,11 +127,10 @@ function get_permalink( $id = 0, $leavename = false ) {
|
||||||
$leavename? '' : '%pagename%',
|
$leavename? '' : '%pagename%',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
|
if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) {
|
||||||
$post = $id;
|
|
||||||
$sample = true;
|
$sample = true;
|
||||||
} else {
|
} else {
|
||||||
$post = get_post($id);
|
$post = get_post( $post );
|
||||||
$sample = false;
|
$sample = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-35000';
|
$wp_version = '4.4-alpha-35001';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
Loading…
Reference in New Issue