2014-02-26 12:12:14 -05:00
< ? php
2008-10-13 18:00:07 -04:00
/**
* WordPress Link Template Functions
*
* @ package WordPress
* @ subpackage Template
*/
2004-01-27 04:58:01 -05:00
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the permalink for the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.2 . 0
2015-10-10 01:41:29 -04:00
* @ since 4.4 . 0 Added the `$post` parameter .
2015-10-09 00:34:24 -04:00
*
2015-10-10 01:41:29 -04:00
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
2008-10-13 18:00:07 -04:00
*/
2015-10-10 01:41:29 -04:00
function the_permalink ( $post = 0 ) {
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the display of the permalink for the current post .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 0
2015-10-10 01:46:24 -04:00
* @ since 4.4 . 0 Added the `$post` parameter .
2014-04-13 22:13:16 -04:00
*
2015-10-10 01:46:24 -04:00
* @ param string $permalink The permalink for the current post .
* @ param int | WP_Post $post Post ID , WP_Post object , or 0. Default 0.
2014-04-13 22:13:16 -04:00
*/
2015-10-10 01:46:24 -04:00
echo esc_url ( apply_filters ( 'the_permalink' , get_permalink ( $post ), $post ) );
2004-05-18 04:36:53 -04:00
}
2007-02-15 02:07:12 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves a trailing - slashed string if the site is set for adding trailing slashes .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* Conditionally adds a trailing slash if the permalink structure has a trailing
* slash , strips the trailing slash if not . The string is passed through the
2016-05-23 15:01:27 -04:00
* { @ see 'user_trailingslashit' } filter . Will remove trailing slash from string , if
2016-01-23 11:47:29 -05:00
* site is not set to have them .
2008-10-13 18:00:07 -04:00
*
* @ since 2.2 . 0
2016-04-15 12:58:27 -04:00
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2008-10-13 18:00:07 -04:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param string $url URL with or without a trailing slash .
2016-04-19 19:21:27 -04:00
* @ param string $type_of_url Optional . The type of URL being considered ( e . g . single , category , etc )
* for use in the filter . Default empty string .
2014-11-29 23:44:23 -05:00
* @ return string The URL with the trailing slash appended or stripped .
2007-02-15 02:07:12 -05:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
function user_trailingslashit ( $url , $type_of_url = '' ) {
2007-02-15 02:07:12 -05:00
global $wp_rewrite ;
2017-11-30 18:11:00 -05:00
if ( $wp_rewrite -> use_trailing_slashes ) {
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
$url = trailingslashit ( $url );
2017-11-30 18:11:00 -05:00
} else {
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
$url = untrailingslashit ( $url );
2017-11-30 18:11:00 -05:00
}
2007-03-10 01:18:43 -05:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the trailing - slashed string , depending on whether the site is set to use trailing slashes .
2014-04-13 22:13:16 -04:00
*
* @ since 2.2 . 0
*
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param string $url URL with or without a trailing slash .
2014-04-13 22:13:16 -04:00
* @ param string $type_of_url The type of URL being considered . Accepts 'single' , 'single_trackback' ,
2016-09-22 18:54:29 -04:00
* 'single_feed' , 'single_paged' , 'commentpaged' , 'paged' , 'home' , 'feed' ,
* 'category' , 'page' , 'year' , 'month' , 'day' , 'post_type_archive' .
2014-04-13 22:13:16 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
return apply_filters ( 'user_trailingslashit' , $url , $type_of_url );
2007-02-15 02:07:12 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the permalink anchor for the current post .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* The permalink mode title will use the post title for the 'a' element 'id'
* attribute . The id mode uses 'post-' with the post ID for the 'id' attribute .
2008-10-13 18:00:07 -04:00
*
* @ since 0.71
*
2016-04-19 19:21:27 -04:00
* @ param string $mode Optional . Permalink mode . Accepts 'title' or 'id' . Default 'id' .
2008-10-13 18:00:07 -04:00
*/
2012-09-04 12:29:28 -04:00
function permalink_anchor ( $mode = 'id' ) {
$post = get_post ();
switch ( strtolower ( $mode ) ) {
2005-10-17 19:41:28 -04:00
case 'title' :
2012-09-04 12:29:28 -04:00
$title = sanitize_title ( $post -> post_title ) . '-' . $post -> ID ;
2017-11-30 18:11:00 -05:00
echo '<a id="' . $title . '"></a>' ;
2005-10-17 19:41:28 -04:00
break ;
case 'id' :
default :
echo '<a id="post-' . $post -> ID . '"></a>' ;
break ;
}
2004-01-27 04:58:01 -05:00
}
2021-02-01 19:40:01 -05:00
/**
2021-02-10 00:40:07 -05:00
* Determine whether post should always use a plain permalink structure .
2021-02-01 19:40:01 -05:00
*
* @ since 5.7 . 0
*
* @ param WP_Post | int | null $post Optional . Post ID or post object . Defaults to global $post .
* @ param bool | null $sample Optional . Whether to force consideration based on sample links .
* If omitted , a sample link is generated if a post object is passed
* with the filter property set to 'sample' .
2021-02-10 00:40:07 -05:00
* @ return bool Whether to use a plain permalink structure .
2021-02-01 19:40:01 -05:00
*/
2021-02-10 00:40:07 -05:00
function wp_force_plain_post_permalink ( $post = null , $sample = null ) {
2021-02-01 19:40:01 -05:00
if (
null === $sample &&
is_object ( $post ) &&
isset ( $post -> filter ) &&
'sample' === $post -> filter
) {
$sample = true ;
} else {
$post = get_post ( $post );
$sample = null !== $sample ? $sample : false ;
}
if ( ! $post ) {
return true ;
}
$post_status_obj = get_post_status_object ( get_post_status ( $post ) );
$post_type_obj = get_post_type_object ( get_post_type ( $post ) );
if ( ! $post_status_obj || ! $post_type_obj ) {
return true ;
}
if (
2021-02-10 00:40:07 -05:00
// Publicly viewable links never have plain permalinks.
2021-02-01 19:40:01 -05:00
is_post_status_viewable ( $post_status_obj ) ||
(
2021-02-10 00:40:07 -05:00
// Private posts don't have plain permalinks if the user can read them.
2021-02-01 19:40:01 -05:00
$post_status_obj -> private &&
current_user_can ( 'read_post' , $post -> ID )
) ||
2021-02-10 00:40:07 -05:00
// Protected posts don't have plain links if getting a sample URL.
2021-02-01 19:40:01 -05:00
( $post_status_obj -> protected && $sample )
) {
return false ;
}
return true ;
}
2014-03-05 02:24:14 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the full permalink for the current post or post ID .
2014-04-07 16:22:15 -04:00
*
* This function is an alias for get_permalink () .
2014-03-05 02:24:14 -05:00
*
* @ since 3.9 . 0
2014-04-07 16:22:15 -04:00
*
2014-03-05 02:24:14 -05:00
* @ see get_permalink ()
*
2015-10-10 01:41:29 -04:00
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
2014-03-05 02:24:14 -05:00
* @ param bool $leavename Optional . Whether to keep post name or page name . Default false .
Posts, Post Types: Correct the check for non-existing post in `get_post_permalink()`.
The function was erroneously calling `is_wp_error()` on the result of a `get_post()` call, which returns `null` on failure, and never returns a `WP_Error` object.
Previously, passing a non-existing post ID to the function would result in a home URL being returned and a few `Attempt to read property "post_type, post_name, hierarchical..." on null` PHP warnings.
This commit ensures `get_post_permalink()` returns `false` on failure, which brings parity with `get_permalink()`.
Includes a unit test to confirm the correct behavior.
Follow-up to [12923], [13023], [32606].
Props renegeuze, manzoorwani.jk.
Fixes #45329.
Built from https://develop.svn.wordpress.org/trunk@53733
git-svn-id: http://core.svn.wordpress.org/trunk@53292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-20 11:41:09 -04:00
* @ return string | false The permalink URL . False if the post does not exist .
2014-03-05 02:24:14 -05:00
*/
2015-10-10 01:41:29 -04:00
function get_the_permalink ( $post = 0 , $leavename = false ) {
return get_permalink ( $post , $leavename );
2014-03-05 02:24:14 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the full permalink for the current post or post ID .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2015-10-10 01:41:29 -04:00
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
2014-03-05 02:24:14 -05:00
* @ param bool $leavename Optional . Whether to keep post name or page name . Default false .
Posts, Post Types: Correct the check for non-existing post in `get_post_permalink()`.
The function was erroneously calling `is_wp_error()` on the result of a `get_post()` call, which returns `null` on failure, and never returns a `WP_Error` object.
Previously, passing a non-existing post ID to the function would result in a home URL being returned and a few `Attempt to read property "post_type, post_name, hierarchical..." on null` PHP warnings.
This commit ensures `get_post_permalink()` returns `false` on failure, which brings parity with `get_permalink()`.
Includes a unit test to confirm the correct behavior.
Follow-up to [12923], [13023], [32606].
Props renegeuze, manzoorwani.jk.
Fixes #45329.
Built from https://develop.svn.wordpress.org/trunk@53733
git-svn-id: http://core.svn.wordpress.org/trunk@53292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-20 11:41:09 -04:00
* @ return string | false The permalink URL . False if the post does not exist .
2008-10-13 18:00:07 -04:00
*/
2015-10-10 01:41:29 -04:00
function get_permalink ( $post = 0 , $leavename = false ) {
2004-09-04 22:41:01 -04:00
$rewritecode = array (
'%year%' ,
'%monthnum%' ,
'%day%' ,
'%hour%' ,
'%minute%' ,
'%second%' ,
2017-11-30 18:11:00 -05:00
$leavename ? '' : '%postname%' ,
2004-09-04 22:41:01 -04:00
'%post_id%' ,
'%category%' ,
'%author%' ,
2017-11-30 18:11:00 -05:00
$leavename ? '' : '%pagename%' ,
2004-09-04 22:41:01 -04:00
);
2004-08-10 01:35:59 -04:00
2020-05-16 14:42:12 -04:00
if ( is_object ( $post ) && isset ( $post -> filter ) && 'sample' === $post -> filter ) {
2009-02-08 08:38:02 -05:00
$sample = true ;
} else {
2017-11-30 18:11:00 -05:00
$post = get_post ( $post );
2009-02-08 08:38:02 -05:00
$sample = false ;
}
2007-08-28 14:58:54 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $post -> ID ) ) {
2010-03-02 06:57:32 -05:00
return false ;
2017-11-30 18:11:00 -05:00
}
2007-08-28 14:58:54 -04:00
2020-02-09 11:55:09 -05:00
if ( 'page' === $post -> post_type ) {
2017-11-30 18:11:00 -05:00
return get_page_link ( $post , $leavename , $sample );
2020-02-09 11:55:09 -05:00
} elseif ( 'attachment' === $post -> post_type ) {
2014-07-08 11:48:17 -04:00
return get_attachment_link ( $post , $leavename );
2020-04-04 23:02:11 -04:00
} elseif ( in_array ( $post -> post_type , get_post_types ( array ( '_builtin' => false ) ), true ) ) {
2017-11-30 18:11:00 -05:00
return get_post_permalink ( $post , $leavename , $sample );
}
2004-11-12 18:08:51 -05:00
2017-11-30 18:11:00 -05:00
$permalink = get_option ( 'permalink_structure' );
2004-08-10 01:35:59 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the permalink structure for a post before token replacement occurs .
2014-04-13 22:13:16 -04:00
*
* Only applies to posts with post_type of 'post' .
*
* @ since 3.0 . 0
*
* @ param string $permalink The site ' s permalink structure .
* @ param WP_Post $post The post in question .
* @ param bool $leavename Whether to keep the post name .
*/
$permalink = apply_filters ( 'pre_post_link' , $permalink , $post , $leavename );
2010-03-02 06:57:32 -05:00
2020-11-16 22:29:12 -05:00
if (
$permalink &&
2021-02-10 00:40:07 -05:00
! wp_force_plain_post_permalink ( $post )
2020-11-16 22:29:12 -05:00
) {
2004-06-03 22:36:46 -04:00
2005-02-16 10:49:02 -05:00
$category = '' ;
2023-06-25 06:50:24 -04:00
if ( str_contains ( $permalink , '%category%' ) ) {
2017-11-30 18:11:00 -05:00
$cats = get_the_category ( $post -> ID );
2008-11-30 14:29:46 -05:00
if ( $cats ) {
2017-11-30 18:11:00 -05:00
$cats = wp_list_sort (
2018-08-16 21:51:36 -04:00
$cats ,
array (
2017-11-30 18:11:00 -05:00
'term_id' => 'ASC' ,
)
);
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the category that gets used in the % category % permalink token .
2014-04-13 22:13:16 -04:00
*
* @ since 3.5 . 0
*
2016-08-26 12:49:45 -04:00
* @ param WP_Term $cat The category to use in the permalink .
* @ param array $cats Array of all categories ( WP_Term objects ) associated with the post .
2014-04-13 22:13:16 -04:00
* @ param WP_Post $post The post in question .
*/
2012-06-28 16:28:57 -04:00
$category_object = apply_filters ( 'post_link_category' , $cats [ 0 ], $cats , $post );
2014-04-13 22:13:16 -04:00
2012-06-28 16:28:57 -04:00
$category_object = get_term ( $category_object , 'category' );
2017-11-30 18:11:00 -05:00
$category = $category_object -> slug ;
2017-12-07 09:50:46 -05:00
if ( $category_object -> parent ) {
$category = get_category_parents ( $category_object -> parent , false , '/' , true ) . $category ;
2017-11-30 18:11:00 -05:00
}
2008-11-30 14:29:46 -05:00
}
2020-01-28 19:45:18 -05:00
// Show default category in permalinks,
// without having to assign it explicitly.
2017-11-30 18:11:00 -05:00
if ( empty ( $category ) ) {
2013-10-02 15:59:10 -04:00
$default_category = get_term ( get_option ( 'default_category' ), 'category' );
2016-06-14 19:12:28 -04:00
if ( $default_category && ! is_wp_error ( $default_category ) ) {
$category = $default_category -> slug ;
}
2008-04-07 21:55:04 -04:00
}
2008-03-10 03:15:01 -04:00
}
2007-12-03 19:40:00 -05:00
$author = '' ;
2023-06-25 06:50:24 -04:00
if ( str_contains ( $permalink , '%author%' ) ) {
2017-11-30 18:11:00 -05:00
$authordata = get_userdata ( $post -> post_author );
$author = $authordata -> user_nicename ;
2007-12-03 19:40:00 -05:00
}
Date/Time: Make `get_permalink()` more resilient against PHP timezone changes.
Overriding default PHP timezone with `date_default_timezone_set()`, while not recommended, should not inadvertently result in changing existing permalinks.
Add a unit test.
Props Rarst, steevithak, archon810, maciejmackowiak, Ov3rfly, Cybr, hometowntrailers, scvleon, miette49.
Fixes #48623.
Built from https://develop.svn.wordpress.org/trunk@46795
git-svn-id: http://core.svn.wordpress.org/trunk@46595 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-11-28 08:42:00 -05:00
// This is not an API call because the permalink is based on the stored post_date value,
// which should be parsed as local time regardless of the default PHP timezone.
$date = explode ( ' ' , str_replace ( array ( '-' , ':' ), ' ' , $post -> post_date ) );
$rewritereplace = array (
2006-02-16 20:04:20 -05:00
$date [ 0 ],
$date [ 1 ],
$date [ 2 ],
$date [ 3 ],
$date [ 4 ],
$date [ 5 ],
2005-03-27 15:45:01 -05:00
$post -> post_name ,
$post -> ID ,
2004-09-04 22:41:01 -04:00
$category ,
$author ,
2005-03-27 15:45:01 -05:00
$post -> post_name ,
2004-09-04 22:41:01 -04:00
);
Date/Time: Make `get_permalink()` more resilient against PHP timezone changes.
Overriding default PHP timezone with `date_default_timezone_set()`, while not recommended, should not inadvertently result in changing existing permalinks.
Add a unit test.
Props Rarst, steevithak, archon810, maciejmackowiak, Ov3rfly, Cybr, hometowntrailers, scvleon, miette49.
Fixes #48623.
Built from https://develop.svn.wordpress.org/trunk@46795
git-svn-id: http://core.svn.wordpress.org/trunk@46595 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-11-28 08:42:00 -05:00
$permalink = home_url ( str_replace ( $rewritecode , $rewritereplace , $permalink ) );
$permalink = user_trailingslashit ( $permalink , 'single' );
2020-01-28 19:45:18 -05:00
} else { // If they're not using the fancy permalink option.
2017-11-30 18:11:00 -05:00
$permalink = home_url ( '?p=' . $post -> ID );
2004-09-04 22:41:01 -04:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the permalink for a post .
2014-04-13 22:13:16 -04:00
*
* Only applies to posts with post_type of 'post' .
*
* @ since 1.5 . 0
*
* @ param string $permalink The post ' s permalink .
* @ param WP_Post $post The post in question .
* @ param bool $leavename Whether to keep the post name .
*/
return apply_filters ( 'post_link' , $permalink , $post , $leavename );
2004-01-27 04:58:01 -05:00
}
2010-02-01 18:12:26 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for a post of a custom post type .
2010-02-01 18:12:26 -05:00
*
* @ since 3.0 . 0
2022-07-20 11:46:09 -04:00
* @ since 6.1 . 0 Returns false if the post does not exist .
2010-02-01 18:12:26 -05:00
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
2020-06-28 07:49:02 -04:00
* @ param bool $leavename Optional . Whether to keep post name . Default false .
* @ param bool $sample Optional . Is it a sample permalink . Default false .
Posts, Post Types: Correct the check for non-existing post in `get_post_permalink()`.
The function was erroneously calling `is_wp_error()` on the result of a `get_post()` call, which returns `null` on failure, and never returns a `WP_Error` object.
Previously, passing a non-existing post ID to the function would result in a home URL being returned and a few `Attempt to read property "post_type, post_name, hierarchical..." on null` PHP warnings.
This commit ensures `get_post_permalink()` returns `false` on failure, which brings parity with `get_permalink()`.
Includes a unit test to confirm the correct behavior.
Follow-up to [12923], [13023], [32606].
Props renegeuze, manzoorwani.jk.
Fixes #45329.
Built from https://develop.svn.wordpress.org/trunk@53733
git-svn-id: http://core.svn.wordpress.org/trunk@53292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-20 11:41:09 -04:00
* @ return string | false The post permalink URL . False if the post does not exist .
2010-02-01 18:12:26 -05:00
*/
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
function get_post_permalink ( $post = 0 , $leavename = false , $sample = false ) {
2010-02-01 18:12:26 -05:00
global $wp_rewrite ;
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
$post = get_post ( $post );
2010-02-01 18:12:26 -05:00
Posts, Post Types: Correct the check for non-existing post in `get_post_permalink()`.
The function was erroneously calling `is_wp_error()` on the result of a `get_post()` call, which returns `null` on failure, and never returns a `WP_Error` object.
Previously, passing a non-existing post ID to the function would result in a home URL being returned and a few `Attempt to read property "post_type, post_name, hierarchical..." on null` PHP warnings.
This commit ensures `get_post_permalink()` returns `false` on failure, which brings parity with `get_permalink()`.
Includes a unit test to confirm the correct behavior.
Follow-up to [12923], [13023], [32606].
Props renegeuze, manzoorwani.jk.
Fixes #45329.
Built from https://develop.svn.wordpress.org/trunk@53733
git-svn-id: http://core.svn.wordpress.org/trunk@53292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-20 11:41:09 -04:00
if ( ! $post ) {
return false ;
2017-11-30 18:11:00 -05:00
}
2010-02-01 18:12:26 -05:00
2017-11-30 18:11:00 -05:00
$post_link = $wp_rewrite -> get_extra_permastruct ( $post -> post_type );
2010-02-01 18:12:26 -05:00
$slug = $post -> post_name ;
2021-02-10 00:40:07 -05:00
$force_plain_link = wp_force_plain_post_permalink ( $post );
2010-02-08 11:23:32 -05:00
2017-11-30 18:11:00 -05:00
$post_type = get_post_type_object ( $post -> post_type );
2010-03-19 22:23:52 -04:00
2014-09-24 17:30:19 -04:00
if ( $post_type -> hierarchical ) {
2017-06-30 23:29:42 -04:00
$slug = get_page_uri ( $post );
2014-09-24 17:30:19 -04:00
}
2021-02-10 00:40:07 -05:00
if ( ! empty ( $post_link ) && ( ! $force_plain_link || $sample ) ) {
2010-03-19 22:23:52 -04:00
if ( ! $leavename ) {
2017-11-30 18:11:00 -05:00
$post_link = str_replace ( " % $post->post_type % " , $slug , $post_link );
2010-03-19 22:23:52 -04:00
}
2017-11-30 18:11:00 -05:00
$post_link = home_url ( user_trailingslashit ( $post_link ) );
2010-02-01 18:12:26 -05:00
} else {
2021-02-10 00:40:07 -05:00
if ( $post_type -> query_var && ( isset ( $post -> post_status ) && ! $force_plain_link ) ) {
2017-11-30 18:11:00 -05:00
$post_link = add_query_arg ( $post_type -> query_var , $slug , '' );
} else {
$post_link = add_query_arg (
array (
'post_type' => $post -> post_type ,
'p' => $post -> ID ,
2018-08-16 21:51:36 -04:00
),
''
2017-11-30 18:11:00 -05:00
);
}
$post_link = home_url ( $post_link );
2010-02-01 18:12:26 -05:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the permalink for a post of a custom post type .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $post_link The post ' s permalink .
* @ param WP_Post $post The post in question .
* @ param bool $leavename Whether to keep the post name .
* @ param bool $sample Is it a sample permalink .
*/
return apply_filters ( 'post_type_link' , $post_link , $post , $leavename , $sample );
2010-02-01 18:12:26 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the current page or page ID .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* Respects page_on_front . Use this one .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2016-04-19 19:21:27 -04:00
* @ param int | WP_Post $post Optional . Post ID or object . Default uses the global `$post` .
* @ param bool $leavename Optional . Whether to keep the page name . Default false .
* @ param bool $sample Optional . Whether it should be treated as a sample permalink .
* Default false .
2014-11-29 23:44:23 -05:00
* @ return string The page permalink .
2008-10-13 18:00:07 -04:00
*/
2012-09-04 12:29:28 -04:00
function get_page_link ( $post = false , $leavename = false , $sample = false ) {
$post = get_post ( $post );
2006-11-17 15:00:11 -05:00
2020-02-09 11:55:09 -05:00
if ( 'page' === get_option ( 'show_on_front' ) && get_option ( 'page_on_front' ) == $post -> ID ) {
2017-11-30 18:11:00 -05:00
$link = home_url ( '/' );
} else {
2012-09-04 12:29:28 -04:00
$link = _get_page_link ( $post , $leavename , $sample );
2017-11-30 18:11:00 -05:00
}
2006-11-17 15:00:11 -05:00
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the permalink for a page .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 0
*
* @ param string $link The page ' s permalink .
* @ param int $post_id The ID of the page .
* @ param bool $sample Is it a sample permalink .
*/
2012-09-04 12:29:28 -04:00
return apply_filters ( 'page_link' , $link , $post -> ID , $sample );
2006-11-17 15:00:11 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the page permalink .
2008-10-13 18:00:07 -04:00
*
* Ignores page_on_front . Internal use only .
*
* @ since 2.1 . 0
* @ access private
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-19 19:21:27 -04:00
* @ param int | WP_Post $post Optional . Post ID or object . Default uses the global `$post` .
* @ param bool $leavename Optional . Whether to keep the page name . Default false .
* @ param bool $sample Optional . Whether it should be treated as a sample permalink .
* Default false .
2014-11-29 23:44:23 -05:00
* @ return string The page permalink .
2008-10-13 18:00:07 -04:00
*/
2012-09-04 12:29:28 -04:00
function _get_page_link ( $post = false , $leavename = false , $sample = false ) {
2012-08-23 15:28:58 -04:00
global $wp_rewrite ;
2004-10-05 22:18:37 -04:00
2012-09-04 12:29:28 -04:00
$post = get_post ( $post );
2004-10-05 22:18:37 -04:00
2021-02-10 00:40:07 -05:00
$force_plain_link = wp_force_plain_post_permalink ( $post );
2004-10-05 22:18:37 -04:00
2010-12-19 09:42:17 -05:00
$link = $wp_rewrite -> get_page_permastruct ();
2011-01-05 23:11:14 -05:00
2021-02-10 00:40:07 -05:00
if ( ! empty ( $link ) && ( ( isset ( $post -> post_status ) && ! $force_plain_link ) || $sample ) ) {
2010-12-19 09:42:17 -05:00
if ( ! $leavename ) {
2017-11-30 18:11:00 -05:00
$link = str_replace ( '%pagename%' , get_page_uri ( $post ), $link );
2010-12-19 09:42:17 -05:00
}
2017-11-30 18:11:00 -05:00
$link = home_url ( $link );
$link = user_trailingslashit ( $link , 'page' );
2004-10-05 22:18:37 -04:00
} else {
2012-09-04 12:29:28 -04:00
$link = home_url ( '?page_id=' . $post -> ID );
2004-10-05 22:18:37 -04:00
}
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the permalink for a non - page_on_front page .
2014-04-13 22:13:16 -04:00
*
* @ since 2.1 . 0
*
* @ param string $link The page ' s permalink .
* @ param int $post_id The ID of the page .
*/
2012-09-04 12:29:28 -04:00
return apply_filters ( '_get_page_link' , $link , $post -> ID );
2004-10-05 22:18:37 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for an attachment .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* This can be used in the WordPress Loop or outside of it .
2008-10-13 18:00:07 -04:00
*
* @ since 2.0 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-19 19:21:27 -04:00
* @ param int | object $post Optional . Post ID or object . Default uses the global `$post` .
* @ param bool $leavename Optional . Whether to keep the page name . Default false .
2014-11-29 23:44:23 -05:00
* @ return string The attachment permalink .
2008-10-13 18:00:07 -04:00
*/
2012-09-21 18:52:54 -04:00
function get_attachment_link ( $post = null , $leavename = false ) {
2012-09-04 12:29:28 -04:00
global $wp_rewrite ;
2005-10-20 16:48:32 -04:00
$link = false ;
2021-02-10 00:40:07 -05:00
$post = get_post ( $post );
$force_plain_link = wp_force_plain_post_permalink ( $post );
$parent_id = $post -> post_parent ;
$parent = $parent_id ? get_post ( $parent_id ) : false ;
$parent_valid = true ; // Default for no parent.
2021-02-01 19:40:01 -05:00
if (
$parent_id &&
(
$post -> post_parent === $post -> ID ||
! $parent ||
! is_post_type_viewable ( get_post_type ( $parent ) )
)
) {
// Post is either its own parent or parent post unavailable.
$parent_valid = false ;
2015-09-29 05:42:26 -04:00
}
2005-10-20 16:48:32 -04:00
2021-02-10 00:40:07 -05:00
if ( $force_plain_link || ! $parent_valid ) {
2021-02-01 19:40:01 -05:00
$link = false ;
} elseif ( $wp_rewrite -> using_permalinks () && $parent ) {
2020-02-09 11:55:09 -05:00
if ( 'page' === $parent -> post_type ) {
2020-01-28 19:45:18 -05:00
$parentlink = _get_page_link ( $post -> post_parent ); // Ignores page_on_front.
2017-11-30 18:11:00 -05:00
} else {
2012-09-04 12:29:28 -04:00
$parentlink = get_permalink ( $post -> post_parent );
2017-11-30 18:11:00 -05:00
}
2010-03-19 22:23:52 -04:00
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 10:36:26 -04:00
if ( is_numeric ( $post -> post_name ) || str_contains ( get_option ( 'permalink_structure' ), '%category%' ) ) {
2020-01-28 19:45:18 -05:00
$name = 'attachment/' . $post -> post_name ; // <permalink>/<int>/ is paged so we use the explicit attachment marker.
2017-11-30 18:11:00 -05:00
} else {
2012-09-04 12:29:28 -04:00
$name = $post -> post_name ;
2017-11-30 18:11:00 -05:00
}
2010-03-19 22:23:52 -04:00
2023-06-25 06:50:24 -04:00
if ( ! str_contains ( $parentlink , '?' ) ) {
2017-11-30 18:11:00 -05:00
$link = user_trailingslashit ( trailingslashit ( $parentlink ) . '%postname%' );
}
2012-09-21 18:52:54 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $leavename ) {
2012-09-21 18:52:54 -04:00
$link = str_replace ( '%postname%' , $name , $link );
2017-11-30 18:11:00 -05:00
}
2015-09-29 05:42:26 -04:00
} elseif ( $wp_rewrite -> using_permalinks () && ! $leavename ) {
$link = home_url ( user_trailingslashit ( $post -> post_name ) );
2005-10-20 16:48:32 -04:00
}
2017-11-30 18:11:00 -05:00
if ( ! $link ) {
2012-09-04 12:29:28 -04:00
$link = home_url ( '/?attachment_id=' . $post -> ID );
2017-11-30 18:11:00 -05:00
}
2005-10-20 16:48:32 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the permalink for an attachment .
2014-04-13 22:13:16 -04:00
*
* @ since 2.0 . 0
2020-10-19 22:29:06 -04:00
* @ since 5.6 . 0 Providing an empty string will now disable
* the view attachment page link on the media modal .
2014-04-13 22:13:16 -04:00
*
* @ param string $link The attachment ' s permalink .
* @ param int $post_id Attachment ID .
*/
2012-09-04 12:29:28 -04:00
return apply_filters ( 'attachment_link' , $link , $post -> ID );
2005-10-20 16:48:32 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the year archives .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2020-01-11 13:32:05 -05:00
* @ param int | false $year Integer of year . False for current year .
2014-11-29 23:44:23 -05:00
* @ return string The permalink for the specified year archive .
2008-10-13 18:00:07 -04:00
*/
2016-04-19 19:21:27 -04:00
function get_year_link ( $year ) {
2005-02-07 02:37:53 -05:00
global $wp_rewrite ;
2017-11-30 18:11:00 -05:00
if ( ! $year ) {
2019-03-07 04:12:51 -05:00
$year = current_time ( 'Y' );
2017-11-30 18:11:00 -05:00
}
2005-10-17 19:41:28 -04:00
$yearlink = $wp_rewrite -> get_year_permastruct ();
2017-11-30 18:11:00 -05:00
if ( ! empty ( $yearlink ) ) {
$yearlink = str_replace ( '%year%' , $year , $yearlink );
2014-04-13 22:13:16 -04:00
$yearlink = home_url ( user_trailingslashit ( $yearlink , 'year' ) );
2005-10-17 19:41:28 -04:00
} else {
2014-04-13 22:13:16 -04:00
$yearlink = home_url ( '?m=' . $year );
2005-10-17 19:41:28 -04:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the year archive permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 0
*
* @ param string $yearlink Permalink for the year archive .
* @ param int $year Year for the archive .
*/
return apply_filters ( 'year_link' , $yearlink , $year );
2004-11-19 15:54:16 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the month archives with year .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2020-01-11 13:32:05 -05:00
* @ param int | false $year Integer of year . False for current year .
* @ param int | false $month Integer of month . False for current month .
2014-11-29 23:44:23 -05:00
* @ return string The permalink for the specified month and year archive .
2008-10-13 18:00:07 -04:00
*/
2017-11-30 18:11:00 -05:00
function get_month_link ( $year , $month ) {
2005-10-17 19:41:28 -04:00
global $wp_rewrite ;
2017-11-30 18:11:00 -05:00
if ( ! $year ) {
2019-03-07 04:12:51 -05:00
$year = current_time ( 'Y' );
2017-11-30 18:11:00 -05:00
}
if ( ! $month ) {
2019-03-07 04:12:51 -05:00
$month = current_time ( 'm' );
2017-11-30 18:11:00 -05:00
}
2005-10-17 19:41:28 -04:00
$monthlink = $wp_rewrite -> get_month_permastruct ();
2017-11-30 18:11:00 -05:00
if ( ! empty ( $monthlink ) ) {
$monthlink = str_replace ( '%year%' , $year , $monthlink );
2020-10-08 17:15:13 -04:00
$monthlink = str_replace ( '%monthnum%' , zeroise ( ( int ) $month , 2 ), $monthlink );
2014-04-13 22:13:16 -04:00
$monthlink = home_url ( user_trailingslashit ( $monthlink , 'month' ) );
2005-10-17 19:41:28 -04:00
} else {
2014-04-13 22:13:16 -04:00
$monthlink = home_url ( '?m=' . $year . zeroise ( $month , 2 ) );
2005-10-17 19:41:28 -04:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the month archive permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 0
*
* @ param string $monthlink Permalink for the month archive .
* @ param int $year Year for the archive .
* @ param int $month The month for the archive .
*/
return apply_filters ( 'month_link' , $monthlink , $year , $month );
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the day archives with year and month .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2020-01-11 13:32:05 -05:00
* @ param int | false $year Integer of year . False for current year .
* @ param int | false $month Integer of month . False for current month .
* @ param int | false $day Integer of day . False for current day .
2014-11-29 23:44:23 -05:00
* @ return string The permalink for the specified day , month , and year archive .
2008-10-13 18:00:07 -04:00
*/
2017-11-30 18:11:00 -05:00
function get_day_link ( $year , $month , $day ) {
2005-10-17 19:41:28 -04:00
global $wp_rewrite ;
2017-11-30 18:11:00 -05:00
if ( ! $year ) {
2019-03-07 04:12:51 -05:00
$year = current_time ( 'Y' );
2017-11-30 18:11:00 -05:00
}
if ( ! $month ) {
2019-03-07 04:12:51 -05:00
$month = current_time ( 'm' );
2017-11-30 18:11:00 -05:00
}
if ( ! $day ) {
2019-03-07 04:12:51 -05:00
$day = current_time ( 'j' );
2017-11-30 18:11:00 -05:00
}
2005-10-17 19:41:28 -04:00
$daylink = $wp_rewrite -> get_day_permastruct ();
2017-11-30 18:11:00 -05:00
if ( ! empty ( $daylink ) ) {
$daylink = str_replace ( '%year%' , $year , $daylink );
2020-10-08 17:15:13 -04:00
$daylink = str_replace ( '%monthnum%' , zeroise ( ( int ) $month , 2 ), $daylink );
$daylink = str_replace ( '%day%' , zeroise ( ( int ) $day , 2 ), $daylink );
2014-04-13 22:13:16 -04:00
$daylink = home_url ( user_trailingslashit ( $daylink , 'day' ) );
2005-10-17 19:41:28 -04:00
} else {
2014-04-13 22:13:16 -04:00
$daylink = home_url ( '?m=' . $year . zeroise ( $month , 2 ) . zeroise ( $day , 2 ) );
2005-10-17 19:41:28 -04:00
}
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the day archive permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 0
*
* @ param string $daylink Permalink for the day archive .
* @ param int $year Year for the archive .
* @ param int $month Month for the archive .
* @ param int $day The day for the archive .
*/
return apply_filters ( 'day_link' , $daylink , $year , $month , $day );
2004-06-02 03:14:03 -04:00
}
2010-03-02 14:00:21 -05:00
/**
2016-04-15 12:58:27 -04:00
* Displays the permalink for the feed type .
2010-03-02 14:00:21 -05:00
*
* @ since 3.0 . 0
*
* @ param string $anchor The link ' s anchor text .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2010-03-02 14:00:21 -05:00
*/
function the_feed_link ( $anchor , $feed = '' ) {
$link = '<a href="' . esc_url ( get_feed_link ( $feed ) ) . '">' . $anchor . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the feed link anchor tag .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $link The complete anchor tag for a feed link .
2019-08-11 13:21:57 -04:00
* @ param string $feed The feed type . Possible values include 'rss2' , 'atom' ,
* or an empty string for the default feed type .
2014-04-13 22:13:16 -04:00
*/
2010-03-02 14:00:21 -05:00
echo apply_filters ( 'the_feed_link' , $link , $feed );
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the feed type .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2014-11-29 23:44:23 -05:00
* @ return string The feed permalink .
2008-10-13 18:00:07 -04:00
*/
2016-04-19 19:21:27 -04:00
function get_feed_link ( $feed = '' ) {
2004-12-02 21:38:11 -05:00
global $wp_rewrite ;
2004-06-02 03:14:03 -04:00
2005-01-26 17:46:40 -05:00
$permalink = $wp_rewrite -> get_feed_permastruct ();
2020-05-16 14:42:12 -04:00
2021-02-16 12:34:04 -05:00
if ( $permalink ) {
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 10:36:26 -04:00
if ( str_contains ( $feed , 'comments_' ) ) {
2017-11-30 18:11:00 -05:00
$feed = str_replace ( 'comments_' , '' , $feed );
2005-01-26 17:46:40 -05:00
$permalink = $wp_rewrite -> get_comment_feed_permastruct ();
}
2017-11-30 18:11:00 -05:00
if ( get_default_feed () == $feed ) {
2005-01-26 17:46:40 -05:00
$feed = '' ;
2017-11-30 18:11:00 -05:00
}
2005-01-26 17:46:40 -05:00
2017-11-30 18:11:00 -05:00
$permalink = str_replace ( '%feed%' , $feed , $permalink );
$permalink = preg_replace ( '#/+#' , '/' , " / $permalink " );
$output = home_url ( user_trailingslashit ( $permalink , 'feed' ) );
2005-01-26 17:46:40 -05:00
} else {
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2007-12-06 14:58:15 -05:00
$feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
}
2007-12-06 14:58:15 -05:00
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 10:36:26 -04:00
if ( str_contains ( $feed , 'comments_' ) ) {
2017-11-30 18:11:00 -05:00
$feed = str_replace ( 'comments_' , 'comments-' , $feed );
}
2005-01-26 17:46:40 -05:00
2017-11-30 18:11:00 -05:00
$output = home_url ( " ?feed= { $feed } " );
2005-01-26 17:46:40 -05:00
}
2004-06-02 03:14:03 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the feed type permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 0
*
* @ param string $output The feed permalink .
2019-08-11 13:21:57 -04:00
* @ param string $feed The feed type . Possible values include 'rss2' , 'atom' ,
* or an empty string for the default feed type .
2014-04-13 22:13:16 -04:00
*/
return apply_filters ( 'feed_link' , $output , $feed );
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the post comments feed .
2008-10-13 18:00:07 -04:00
*
* @ since 2.2 . 0
*
2016-04-19 19:21:27 -04:00
* @ param int $post_id Optional . Post ID . Default is the ID of the global `$post` .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2021-06-08 19:00:59 -04:00
* @ return string The permalink for the comments feed for the given post on success , empty string on failure .
2008-10-13 18:00:07 -04:00
*/
2016-04-19 19:21:27 -04:00
function get_post_comments_feed_link ( $post_id = 0 , $feed = '' ) {
2010-09-04 11:51:04 -04:00
$post_id = absint ( $post_id );
2007-02-23 03:31:07 -05:00
2017-11-30 18:11:00 -05:00
if ( ! $post_id ) {
2010-09-04 11:51:04 -04:00
$post_id = get_the_ID ();
2017-11-30 18:11:00 -05:00
}
2007-02-23 03:31:07 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2007-12-06 14:58:15 -05:00
$feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
}
2007-12-06 14:58:15 -05:00
2021-06-08 19:00:59 -04:00
$post = get_post ( $post_id );
// Bail out if the post does not exist.
if ( ! $post instanceof WP_Post ) {
return '' ;
}
2015-09-19 16:10:24 -04:00
$unattached = 'attachment' === $post -> post_type && 0 === ( int ) $post -> post_parent ;
2020-05-16 14:42:12 -04:00
if ( get_option ( 'permalink_structure' ) ) {
2020-02-09 11:55:09 -05:00
if ( 'page' === get_option ( 'show_on_front' ) && get_option ( 'page_on_front' ) == $post_id ) {
2010-04-18 02:51:16 -04:00
$url = _get_page_link ( $post_id );
2017-11-30 18:11:00 -05:00
} else {
$url = get_permalink ( $post_id );
}
2010-04-18 02:51:16 -04:00
2015-09-19 16:10:24 -04:00
if ( $unattached ) {
2017-11-30 18:11:00 -05:00
$url = home_url ( '/feed/' );
2020-02-09 11:55:09 -05:00
if ( get_default_feed () !== $feed ) {
2015-09-19 16:10:24 -04:00
$url .= " $feed / " ;
}
$url = add_query_arg ( 'attachment_id' , $post_id , $url );
} else {
2017-11-30 18:11:00 -05:00
$url = trailingslashit ( $url ) . 'feed' ;
2020-02-09 11:55:09 -05:00
if ( get_default_feed () != $feed ) {
2015-09-19 16:10:24 -04:00
$url .= " / $feed " ;
2017-11-30 18:11:00 -05:00
}
$url = user_trailingslashit ( $url , 'single_feed' );
2015-09-19 16:10:24 -04:00
}
2007-02-23 03:31:07 -05:00
} else {
2015-09-19 16:10:24 -04:00
if ( $unattached ) {
2017-11-30 18:11:00 -05:00
$url = add_query_arg (
array (
'feed' => $feed ,
'attachment_id' => $post_id ,
2018-08-16 21:51:36 -04:00
),
home_url ( '/' )
2017-11-30 18:11:00 -05:00
);
2020-02-09 11:55:09 -05:00
} elseif ( 'page' === $post -> post_type ) {
2017-11-30 18:11:00 -05:00
$url = add_query_arg (
array (
'feed' => $feed ,
'page_id' => $post_id ,
2018-08-16 21:51:36 -04:00
),
home_url ( '/' )
2017-11-30 18:11:00 -05:00
);
2015-09-19 16:10:24 -04:00
} else {
2017-11-30 18:11:00 -05:00
$url = add_query_arg (
array (
'feed' => $feed ,
'p' => $post_id ,
2018-08-16 21:51:36 -04:00
),
home_url ( '/' )
2017-11-30 18:11:00 -05:00
);
2015-09-19 16:10:24 -04:00
}
2007-02-23 03:31:07 -05:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post comments feed permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 1
*
* @ param string $url Post comments feed permalink .
*/
return apply_filters ( 'post_comments_feed_link' , $url );
2007-02-23 03:31:07 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the comment feed link for a post .
2007-12-06 14:58:15 -05:00
*
2008-10-13 18:00:07 -04:00
* Prints out the comment feed link for a post . Link text is placed in the
* anchor . If no link text is specified , default text is used . If no post ID is
* specified , the current post is used .
2007-12-06 14:58:15 -05:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.5 . 0
2007-12-06 14:58:15 -05:00
*
2016-04-19 19:21:27 -04:00
* @ param string $link_text Optional . Descriptive link text . Default 'Comments Feed' .
* @ param int $post_id Optional . Post ID . Default is the ID of the global `$post` .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2015-12-12 10:37:28 -05:00
*/
2007-12-06 14:58:15 -05:00
function post_comments_feed_link ( $link_text = '' , $post_id = '' , $feed = '' ) {
2015-09-22 16:06:24 -04:00
$url = get_post_comments_feed_link ( $post_id , $feed );
if ( empty ( $link_text ) ) {
2017-11-30 18:11:00 -05:00
$link_text = __ ( 'Comments Feed' );
2015-09-22 16:06:24 -04:00
}
2007-12-06 14:58:15 -05:00
2015-09-23 00:26:27 -04:00
$link = '<a href="' . esc_url ( $url ) . '">' . $link_text . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post comment feed link anchor tag .
2014-04-13 22:13:16 -04:00
*
* @ since 2.8 . 0
*
* @ param string $link The complete anchor tag for the comment feed link .
* @ param int $post_id Post ID .
2019-08-11 13:21:57 -04:00
* @ param string $feed The feed type . Possible values include 'rss2' , 'atom' ,
* or an empty string for the default feed type .
2014-04-13 22:13:16 -04:00
*/
2015-09-22 16:06:24 -04:00
echo apply_filters ( 'post_comments_feed_link_html' , $link , $post_id , $feed );
2007-12-06 14:58:15 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the feed link for a given author .
2008-08-21 22:21:37 -04:00
*
2008-10-13 18:00:07 -04:00
* Returns a link to the feed for all posts by a given author . A specific feed
* can be requested or left blank to get the default feed .
2008-08-21 22:21:37 -04:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.5 . 0
2008-08-21 22:21:37 -04:00
*
2016-04-19 19:21:27 -04:00
* @ param int $author_id Author ID .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2008-10-13 18:00:07 -04:00
* @ return string Link to the feed for the author specified by $author_id .
2015-12-12 10:37:28 -05:00
*/
2007-12-06 14:58:15 -05:00
function get_author_feed_link ( $author_id , $feed = '' ) {
2017-11-30 18:11:00 -05:00
$author_id = ( int ) $author_id ;
$permalink_structure = get_option ( 'permalink_structure' );
2007-12-06 14:58:15 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2007-12-06 14:58:15 -05:00
$feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
}
2007-12-06 14:58:15 -05:00
2020-05-16 14:42:12 -04:00
if ( ! $permalink_structure ) {
2017-11-30 18:11:00 -05:00
$link = home_url ( " ?feed= $feed &author= " . $author_id );
2007-12-06 14:58:15 -05:00
} else {
2017-11-30 18:11:00 -05:00
$link = get_author_posts_url ( $author_id );
2020-02-09 11:55:09 -05:00
if ( get_default_feed () == $feed ) {
2008-08-21 22:21:37 -04:00
$feed_link = 'feed' ;
2017-11-30 18:11:00 -05:00
} else {
2008-08-21 22:21:37 -04:00
$feed_link = " feed/ $feed " ;
2017-11-30 18:11:00 -05:00
}
2008-08-21 22:21:37 -04:00
2017-11-30 18:11:00 -05:00
$link = trailingslashit ( $link ) . user_trailingslashit ( $feed_link , 'feed' );
2007-12-06 14:58:15 -05:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the feed link for a given author .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 1
*
* @ param string $link The author feed link .
2019-08-11 13:21:57 -04:00
* @ param string $feed Feed type . Possible values include 'rss2' , 'atom' .
2014-04-13 22:13:16 -04:00
*/
$link = apply_filters ( 'author_feed_link' , $link , $feed );
2007-12-06 14:58:15 -05:00
return $link ;
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the feed link for a category .
2007-12-06 14:58:15 -05:00
*
2011-09-29 18:57:43 -04:00
* Returns a link to the feed for all posts in a given category . A specific feed
2008-10-13 18:00:07 -04:00
* can be requested or left blank to get the default feed .
2007-12-06 14:58:15 -05:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.5 . 0
2007-12-06 14:58:15 -05:00
*
2022-03-20 11:05:05 -04:00
* @ param int | WP_Term | object $cat The ID or category object whose feed link will be retrieved .
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2022-03-20 11:05:05 -04:00
* @ return string Link to the feed for the category specified by `$cat` .
2015-12-12 10:37:28 -05:00
*/
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
function get_category_feed_link ( $cat , $feed = '' ) {
return get_term_feed_link ( $cat , 'category' , $feed );
2010-05-17 12:21:12 -04:00
}
2008-02-05 01:47:27 -05:00
2010-05-17 12:21:12 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the feed link for a term .
2010-05-17 12:21:12 -04:00
*
2011-09-29 18:57:43 -04:00
* Returns a link to the feed for all posts in a given term . A specific feed
2010-05-17 12:21:12 -04:00
* can be requested or left blank to get the default feed .
*
2013-12-24 13:57:12 -05:00
* @ since 3.0 . 0
2010-05-17 12:21:12 -04:00
*
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
* @ param int | WP_Term | object $term The ID or term object whose feed link will be retrieved .
* @ param string $taxonomy Optional . Taxonomy of `$term_id` .
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2022-03-20 11:05:05 -04:00
* @ return string | false Link to the feed for the term specified by `$term` and `$taxonomy` .
2015-12-12 10:37:28 -05:00
*/
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
function get_term_feed_link ( $term , $taxonomy = '' , $feed = '' ) {
if ( ! is_object ( $term ) ) {
2021-11-26 06:43:03 -05:00
$term = ( int ) $term ;
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
}
2008-02-05 01:47:27 -05:00
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
$term = get_term ( $term , $taxonomy );
2010-05-25 22:42:15 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $term ) || is_wp_error ( $term ) ) {
2007-12-06 14:58:15 -05:00
return false ;
2017-11-30 18:11:00 -05:00
}
2007-12-06 14:58:15 -05:00
2021-11-27 10:23:59 -05:00
$taxonomy = $term -> taxonomy ;
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2007-12-06 14:58:15 -05:00
$feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
}
2007-12-06 14:58:15 -05:00
2010-05-17 12:21:12 -04:00
$permalink_structure = get_option ( 'permalink_structure' );
2007-12-06 14:58:15 -05:00
2020-05-16 14:42:12 -04:00
if ( ! $permalink_structure ) {
if ( 'category' === $taxonomy ) {
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
$link = home_url ( " ?feed= $feed &cat= $term->term_id " );
2020-05-16 14:42:12 -04:00
} elseif ( 'post_tag' === $taxonomy ) {
2017-11-30 18:11:00 -05:00
$link = home_url ( " ?feed= $feed &tag= $term->slug " );
2010-05-17 12:21:12 -04:00
} else {
2017-11-30 18:11:00 -05:00
$t = get_taxonomy ( $taxonomy );
$link = home_url ( " ?feed= $feed & $t->query_var = $term->slug " );
2010-05-17 12:21:12 -04:00
}
2007-12-06 14:58:15 -05:00
} else {
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
$link = get_term_link ( $term , $term -> taxonomy );
2020-02-09 11:55:09 -05:00
if ( get_default_feed () == $feed ) {
2007-12-06 14:58:15 -05:00
$feed_link = 'feed' ;
2017-11-30 18:11:00 -05:00
} else {
2007-12-06 14:58:15 -05:00
$feed_link = " feed/ $feed " ;
2017-11-30 18:11:00 -05:00
}
2008-02-05 01:47:27 -05:00
2010-05-17 12:21:12 -04:00
$link = trailingslashit ( $link ) . user_trailingslashit ( $feed_link , 'feed' );
2007-12-06 14:58:15 -05:00
}
2020-05-16 14:42:12 -04:00
if ( 'category' === $taxonomy ) {
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the category feed link .
2014-04-13 22:13:16 -04:00
*
* @ since 1.5 . 1
*
* @ param string $link The category feed link .
2019-08-11 13:21:57 -04:00
* @ param string $feed Feed type . Possible values include 'rss2' , 'atom' .
2014-04-13 22:13:16 -04:00
*/
2010-05-17 12:21:12 -04:00
$link = apply_filters ( 'category_feed_link' , $link , $feed );
2020-05-16 14:42:12 -04:00
} elseif ( 'post_tag' === $taxonomy ) {
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the post tag feed link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.3 . 0
*
* @ param string $link The tag feed link .
2019-08-11 13:21:57 -04:00
* @ param string $feed Feed type . Possible values include 'rss2' , 'atom' .
2014-04-13 22:13:16 -04:00
*/
2012-08-29 23:49:44 -04:00
$link = apply_filters ( 'tag_feed_link' , $link , $feed );
2014-04-13 22:13:16 -04:00
} else {
/**
2016-05-22 14:27:27 -04:00
* Filters the feed link for a taxonomy other than 'category' or 'post_tag' .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
2019-08-11 13:21:57 -04:00
* @ param string $link The taxonomy feed link .
* @ param string $feed Feed type . Possible values include 'rss2' , 'atom' .
2016-12-27 04:28:40 -05:00
* @ param string $taxonomy The taxonomy name .
2014-04-13 22:13:16 -04:00
*/
2010-05-17 12:21:12 -04:00
$link = apply_filters ( 'taxonomy_feed_link' , $link , $feed , $taxonomy );
2014-04-13 22:13:16 -04:00
}
2010-05-25 22:42:15 -04:00
2007-12-06 14:58:15 -05:00
return $link ;
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for a tag feed .
2008-10-13 18:00:07 -04:00
*
* @ since 2.3 . 0
*
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
* @ param int | WP_Term | object $tag The ID or term object whose feed link will be retrieved .
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
* @ return string The feed permalink for the given tag .
2008-10-13 18:00:07 -04:00
*/
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
function get_tag_feed_link ( $tag , $feed = '' ) {
return get_term_feed_link ( $tag , 'post_tag' , $feed );
2007-12-06 14:58:15 -05:00
}
2008-10-25 14:19:42 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the edit link for a tag .
2008-10-25 14:19:42 -04:00
*
* @ since 2.7 . 0
*
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
* @ param int | WP_Term | object $tag The ID or term object whose edit link will be retrieved .
* @ param string $taxonomy Optional . Taxonomy slug . Default 'post_tag' .
2014-11-29 23:44:23 -05:00
* @ return string The edit tag link URL for the given tag .
2008-10-25 14:19:42 -04:00
*/
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
function get_edit_tag_link ( $tag , $taxonomy = 'post_tag' ) {
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the edit link for a tag ( or term in another taxonomy ) .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $link The term edit link .
*/
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
return apply_filters ( 'get_edit_tag_link' , get_edit_term_link ( $tag , $taxonomy ) );
2008-10-25 14:19:42 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Displays or retrieves the edit link for a tag with formatting .
2008-10-25 14:19:42 -04:00
*
* @ since 2.7 . 0
*
2019-10-03 19:12:57 -04:00
* @ param string $link Optional . Anchor text . If empty , default is 'Edit This' . Default empty .
2016-04-19 19:21:27 -04:00
* @ param string $before Optional . Display before edit link . Default empty .
* @ param string $after Optional . Display after edit link . Default empty .
* @ param WP_Term $tag Optional . Term object . If null , the queried object will be inspected .
* Default null .
2008-10-25 14:19:42 -04:00
*/
function edit_tag_link ( $link = '' , $before = '' , $after = '' , $tag = null ) {
2013-08-21 20:49:09 -04:00
$link = edit_term_link ( $link , '' , '' , $tag , false );
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the anchor tag for the edit link for a tag ( or term in another taxonomy ) .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $link The anchor tag for the edit link .
*/
2010-10-13 10:54:21 -04:00
echo $before . apply_filters ( 'edit_tag_link' , $link ) . $after ;
}
/**
2016-03-10 12:48:26 -05:00
* Retrieves the URL for editing a given term .
2010-10-13 10:54:21 -04:00
*
2010-10-19 03:38:42 -04:00
* @ since 3.1 . 0
2019-09-24 08:54:57 -04:00
* @ since 4.5 . 0 The `$taxonomy` parameter was made optional .
2010-10-13 10:54:21 -04:00
*
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
* @ param int | WP_Term | object $term The ID or term object whose edit link will be retrieved .
* @ param string $taxonomy Optional . Taxonomy . Defaults to the taxonomy of the term identified
* by `$term` .
* @ param string $object_type Optional . The object type . Used to highlight the proper post type
* menu on the linked page . Defaults to the first object_type associated
* with the taxonomy .
2015-06-26 10:13:24 -04:00
* @ return string | null The edit term link URL for the given term , or null on failure .
2010-10-13 10:54:21 -04:00
*/
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
function get_edit_term_link ( $term , $taxonomy = '' , $object_type = '' ) {
$term = get_term ( $term , $taxonomy );
2016-02-23 15:07:28 -05:00
if ( ! $term || is_wp_error ( $term ) ) {
2008-10-25 14:19:42 -04:00
return ;
2015-06-26 10:13:24 -04:00
}
2008-10-25 14:19:42 -04:00
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
$tax = get_taxonomy ( $term -> taxonomy );
$term_id = $term -> term_id ;
if ( ! $tax || ! current_user_can ( 'edit_term' , $term_id ) ) {
2015-06-26 10:13:24 -04:00
return ;
}
2010-10-14 03:35:13 -04:00
$args = array (
'taxonomy' => $taxonomy ,
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
'tag_ID' => $term_id ,
2010-10-14 03:35:13 -04:00
);
2015-01-16 16:37:23 -05:00
if ( $object_type ) {
2010-10-14 03:35:13 -04:00
$args [ 'post_type' ] = $object_type ;
2015-06-19 18:01:25 -04:00
} elseif ( ! empty ( $tax -> object_type ) ) {
2015-01-16 16:37:23 -05:00
$args [ 'post_type' ] = reset ( $tax -> object_type );
}
2010-10-13 10:54:21 -04:00
2015-11-19 11:25:26 -05:00
if ( $tax -> show_ui ) {
2016-01-15 03:27:27 -05:00
$location = add_query_arg ( $args , admin_url ( 'term.php' ) );
2015-11-19 11:25:26 -05:00
} else {
$location = '' ;
}
2010-10-13 10:54:21 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the edit link for a term .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
*
* @ param string $location The edit link .
* @ param int $term_id Term ID .
* @ param string $taxonomy Taxonomy name .
2021-11-19 09:44:01 -05:00
* @ param string $object_type The object type .
2014-04-13 22:13:16 -04:00
*/
2010-10-14 04:47:41 -04:00
return apply_filters ( 'get_edit_term_link' , $location , $term_id , $taxonomy , $object_type );
2010-10-13 10:54:21 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Displays or retrieves the edit term link with formatting .
2010-10-13 10:54:21 -04:00
*
2010-10-19 03:38:42 -04:00
* @ since 3.1 . 0
2010-10-13 10:54:21 -04:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param string $link Optional . Anchor text . If empty , default is 'Edit This' . Default empty .
* @ param string $before Optional . Display before edit link . Default empty .
* @ param string $after Optional . Display after edit link . Default empty .
* @ param int | WP_Term | null $term Optional . Term ID or object . If null , the queried object will be inspected . Default null .
* @ param bool $display Optional . Whether or not to echo the return . Default true .
2015-05-26 14:44:25 -04:00
* @ return string | void HTML content .
2010-10-13 10:54:21 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
function edit_term_link ( $link = '' , $before = '' , $after = '' , $term = null , $display = true ) {
2017-11-30 18:11:00 -05:00
if ( is_null ( $term ) ) {
2010-10-31 07:02:17 -04:00
$term = get_queried_object ();
Taxonomy: Allow `get_*_*_link()` and `edit_term_link()` functions to accept a term ID, `WP_Term`, or term object.
`get_term()` accepts a term ID, instance of `WP_Term`, or an object (i.e. `stdClass` as a result of a db query). Functions that use `get_term()` also now allow for the same data types.
Why? For consistency, removing extra processing code in consuming functions, and performance.
Functions changed in this commit are:
* `get_category_feed_link()`
* `get_term_feed_link()`
* `get_tag_feed_link()`
* `get_edit_tag_link()`
* `get_edit_term_link()`
* `edit_term_link()`
For each of consumer of these functions, changes to pass the object instead of the term ID.
Includes unit/integration tests for test coverage of these changes.
Follow-up to [6365], [9136], [9340], [14711], [15792], [15800], [18827], [32606], [36646], [37252].
Props davidbinda, johnbillion, peterwilsoncc, hellofromTonya, sergeybiryukov, mista-flo, hareesh-pillai, audrasjb, jeffpaul, chaion07.
Fixes #50225.
Built from https://develop.svn.wordpress.org/trunk@52180
git-svn-id: http://core.svn.wordpress.org/trunk@51772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 09:57:02 -05:00
} else {
$term = get_term ( $term );
2017-11-30 18:11:00 -05:00
}
2013-09-09 22:28:11 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $term ) {
2013-09-09 22:28:11 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-10-14 03:35:13 -04:00
2010-10-13 10:54:21 -04:00
$tax = get_taxonomy ( $term -> taxonomy );
Taxonomy: Introduce more fine grained capabilities for managing taxonomy terms.
This introduces the singular `edit_term`, `delete_term`, and `assign_term` meta capabilities for terms, and switches the base capability name for tags from `manage_categories` to `manage_post_tags` and the corresponding `edit_post_tags`, `delete_post_tags`, and `assign_post_tags`.
All of these capabilities ultimately map to `manage_categories` so by default there is no change in the behaviour of the capabilities for categories, tags, or custom taxonomies. The `map_meta_cap` filter and the `capabilities` argument when registering a taxonomy now allow for control over editing, deleting, and assigning individual terms, as well as a separation of capabilities for tags from those of categories.
Fixes #35614
Props johnjamesjacoby for feedback
Built from https://develop.svn.wordpress.org/trunk@38698
git-svn-id: http://core.svn.wordpress.org/trunk@38641 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-09-30 18:40:28 -04:00
if ( ! current_user_can ( 'edit_term' , $term -> term_id ) ) {
2010-10-13 10:54:21 -04:00
return ;
2016-09-08 18:54:32 -04:00
}
2010-02-19 04:33:50 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $link ) ) {
$link = __ ( 'Edit This' );
}
2008-10-25 14:19:42 -04:00
2013-09-23 10:51:10 -04:00
$link = '<a href="' . get_edit_term_link ( $term -> term_id , $term -> taxonomy ) . '">' . $link . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the anchor tag for the edit link of a term .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
*
* @ param string $link The anchor tag for the edit link .
* @ param int $term_id Term ID .
*/
2010-10-13 10:54:21 -04:00
$link = $before . apply_filters ( 'edit_term_link' , $link , $term -> term_id ) . $after ;
2010-10-14 03:35:13 -04:00
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
if ( $display ) {
2010-10-13 10:54:21 -04:00
echo $link ;
2017-11-30 18:11:00 -05:00
} else {
2010-10-13 10:54:21 -04:00
return $link ;
2017-11-30 18:11:00 -05:00
}
2008-10-25 14:19:42 -04:00
}
2010-02-27 23:15:02 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for a search .
2013-11-11 08:32:10 -05:00
*
2020-01-28 19:45:18 -05:00
* @ since 3.0 . 0
2013-11-11 08:32:10 -05:00
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-19 19:21:27 -04:00
* @ param string $query Optional . The query string to use . If empty the current query is used . Default empty .
2014-11-29 23:44:23 -05:00
* @ return string The search permalink .
2013-11-11 08:32:10 -05:00
*/
2010-02-27 23:15:02 -05:00
function get_search_link ( $query = '' ) {
global $wp_rewrite ;
2017-11-30 18:11:00 -05:00
if ( empty ( $query ) ) {
2010-04-03 19:38:38 -04:00
$search = get_search_query ( false );
2017-11-30 18:11:00 -05:00
} else {
$search = stripslashes ( $query );
}
2010-02-27 23:15:02 -05:00
$permastruct = $wp_rewrite -> get_search_permastruct ();
if ( empty ( $permastruct ) ) {
2017-11-30 18:11:00 -05:00
$link = home_url ( '?s=' . urlencode ( $search ) );
2010-02-27 23:15:02 -05:00
} else {
2017-11-30 18:11:00 -05:00
$search = urlencode ( $search );
$search = str_replace ( '%2F' , '/' , $search ); // %2F(/) is not valid within a URL, send it un-encoded.
$link = str_replace ( '%search%' , $search , $permastruct );
$link = home_url ( user_trailingslashit ( $link , 'search' ) );
2010-02-27 23:15:02 -05:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the search permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $link Search permalink .
* @ param string $search The URL - encoded search term .
*/
2010-02-27 23:15:02 -05:00
return apply_filters ( 'search_link' , $link , $search );
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the search results feed .
2008-10-13 18:00:07 -04:00
*
* @ since 2.5 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-19 19:21:27 -04:00
* @ param string $search_query Optional . Search query . Default empty .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2014-11-29 23:44:23 -05:00
* @ return string The search results feed permalink .
2008-10-13 18:00:07 -04:00
*/
2017-11-30 18:11:00 -05:00
function get_search_feed_link ( $search_query = '' , $feed = '' ) {
2010-02-27 23:15:02 -05:00
global $wp_rewrite ;
2017-11-30 18:11:00 -05:00
$link = get_search_link ( $search_query );
2008-02-05 01:47:27 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2007-12-19 13:05:21 -05:00
$feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
}
2008-02-05 01:47:27 -05:00
2010-02-27 23:15:02 -05:00
$permastruct = $wp_rewrite -> get_search_permastruct ();
2017-11-30 18:11:00 -05:00
if ( empty ( $permastruct ) ) {
$link = add_query_arg ( 'feed' , $feed , $link );
2010-02-27 23:15:02 -05:00
} else {
2017-11-30 18:11:00 -05:00
$link = trailingslashit ( $link );
2010-02-27 23:15:02 -05:00
$link .= " feed/ $feed / " ;
}
2008-02-05 01:47:27 -05:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the search feed link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.5 . 0
*
* @ param string $link Search feed link .
2019-08-11 13:21:57 -04:00
* @ param string $feed Feed type . Possible values include 'rss2' , 'atom' .
2014-04-13 22:13:16 -04:00
* @ param string $type The search type . One of 'posts' or 'comments' .
*/
2015-05-26 14:44:25 -04:00
return apply_filters ( 'search_feed_link' , $link , $feed , 'posts' );
2007-12-19 13:05:21 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for the search results comments feed .
2008-10-13 18:00:07 -04:00
*
* @ since 2.5 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-19 19:21:27 -04:00
* @ param string $search_query Optional . Search query . Default empty .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2014-11-29 23:44:23 -05:00
* @ return string The comments feed search results permalink .
2008-10-13 18:00:07 -04:00
*/
2017-11-30 18:11:00 -05:00
function get_search_comments_feed_link ( $search_query = '' , $feed = '' ) {
2010-02-27 23:15:02 -05:00
global $wp_rewrite ;
2008-02-05 01:47:27 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2007-12-19 13:05:21 -05:00
$feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
}
2008-02-05 01:47:27 -05:00
2017-11-30 18:11:00 -05:00
$link = get_search_feed_link ( $search_query , $feed );
2010-02-27 23:15:02 -05:00
$permastruct = $wp_rewrite -> get_search_permastruct ();
2017-11-30 18:11:00 -05:00
if ( empty ( $permastruct ) ) {
$link = add_query_arg ( 'feed' , 'comments-' . $feed , $link );
} else {
$link = add_query_arg ( 'withcomments' , 1 , $link );
}
2008-02-05 01:47:27 -05:00
2014-04-13 22:13:16 -04:00
/** This filter is documented in wp-includes/link-template.php */
2015-05-26 14:44:25 -04:00
return apply_filters ( 'search_feed_link' , $link , $feed , 'comments' );
2007-12-19 13:05:21 -05:00
}
2010-10-15 15:44:57 -04:00
/**
2016-01-14 12:56:27 -05:00
* Retrieves the permalink for a post type archive .
2010-10-15 15:44:57 -04:00
*
* @ since 3.1 . 0
2016-01-14 12:56:27 -05:00
* @ since 4.5 . 0 Support for posts was added .
2010-10-15 15:44:57 -04:00
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-01-14 12:56:27 -05:00
* @ param string $post_type Post type .
2020-09-28 07:12:03 -04:00
* @ return string | false The post type archive permalink . False if the post type
* does not exist or does not have an archive .
2010-10-15 15:44:57 -04:00
*/
function get_post_type_archive_link ( $post_type ) {
global $wp_rewrite ;
2019-07-02 19:42:58 -04:00
$post_type_obj = get_post_type_object ( $post_type );
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2019-07-02 19:42:58 -04:00
if ( ! $post_type_obj ) {
2010-10-15 15:44:57 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2010-10-15 15:44:57 -04:00
2016-01-08 17:01:26 -05:00
if ( 'post' === $post_type ) {
2017-11-30 18:11:00 -05:00
$show_on_front = get_option ( 'show_on_front' );
$page_for_posts = get_option ( 'page_for_posts' );
2016-01-08 17:01:26 -05:00
2020-02-09 11:55:09 -05:00
if ( 'page' === $show_on_front && $page_for_posts ) {
2016-01-08 17:01:26 -05:00
$link = get_permalink ( $page_for_posts );
} else {
$link = get_home_url ();
}
/** This filter is documented in wp-includes/link-template.php */
return apply_filters ( 'post_type_archive_link' , $link , $post_type );
}
2017-11-30 18:11:00 -05:00
if ( ! $post_type_obj -> has_archive ) {
2010-10-15 15:44:57 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2010-10-15 15:44:57 -04:00
2010-12-08 02:51:40 -05:00
if ( get_option ( 'permalink_structure' ) && is_array ( $post_type_obj -> rewrite ) ) {
2010-12-08 04:15:09 -05:00
$struct = ( true === $post_type_obj -> has_archive ) ? $post_type_obj -> rewrite [ 'slug' ] : $post_type_obj -> has_archive ;
2017-11-30 18:11:00 -05:00
if ( $post_type_obj -> rewrite [ 'with_front' ] ) {
2010-10-15 15:44:57 -04:00
$struct = $wp_rewrite -> front . $struct ;
2017-11-30 18:11:00 -05:00
} else {
2011-03-09 23:24:48 -05:00
$struct = $wp_rewrite -> root . $struct ;
2017-11-30 18:11:00 -05:00
}
2010-10-15 15:44:57 -04:00
$link = home_url ( user_trailingslashit ( $struct , 'post_type_archive' ) );
} else {
$link = home_url ( '?post_type=' . $post_type );
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post type archive permalink .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
*
* @ param string $link The post type archive permalink .
* @ param string $post_type Post type name .
*/
2010-10-15 15:44:57 -04:00
return apply_filters ( 'post_type_archive_link' , $link , $post_type );
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the permalink for a post type archive feed .
2010-10-15 15:44:57 -04:00
*
* @ since 3.1 . 0
*
2020-09-28 07:12:03 -04:00
* @ param string $post_type Post type .
2019-08-11 13:21:57 -04:00
* @ param string $feed Optional . Feed type . Possible values include 'rss2' , 'atom' .
* Default is the value of get_default_feed () .
2020-09-28 07:12:03 -04:00
* @ return string | false The post type feed permalink . False if the post type
* does not exist or does not have an archive .
2010-10-19 03:48:22 -04:00
*/
2010-10-15 15:44:57 -04:00
function get_post_type_archive_feed_link ( $post_type , $feed = '' ) {
$default_feed = get_default_feed ();
2017-11-30 18:11:00 -05:00
if ( empty ( $feed ) ) {
2010-10-15 15:44:57 -04:00
$feed = $default_feed ;
2017-11-30 18:11:00 -05:00
}
2010-10-15 15:44:57 -04:00
2019-07-02 19:42:58 -04:00
$link = get_post_type_archive_link ( $post_type );
if ( ! $link ) {
2010-10-15 15:44:57 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2013-03-11 21:50:46 -04:00
2010-10-15 15:44:57 -04:00
$post_type_obj = get_post_type_object ( $post_type );
2013-03-11 21:50:46 -04:00
if ( get_option ( 'permalink_structure' ) && is_array ( $post_type_obj -> rewrite ) && $post_type_obj -> rewrite [ 'feeds' ] ) {
2017-11-30 18:11:00 -05:00
$link = trailingslashit ( $link );
2010-10-15 15:44:57 -04:00
$link .= 'feed/' ;
2017-11-30 18:11:00 -05:00
if ( $feed != $default_feed ) {
2010-10-15 15:44:57 -04:00
$link .= " $feed / " ;
2017-11-30 18:11:00 -05:00
}
2010-10-15 15:44:57 -04:00
} else {
$link = add_query_arg ( 'feed' , $feed , $link );
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post type archive feed link .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
*
* @ param string $link The post type archive feed link .
2019-08-11 13:21:57 -04:00
* @ param string $feed Feed type . Possible values include 'rss2' , 'atom' .
2014-04-13 22:13:16 -04:00
*/
2010-10-15 15:44:57 -04:00
return apply_filters ( 'post_type_archive_feed_link' , $link , $feed );
}
2015-09-15 00:15:25 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL used for the post preview .
2015-09-15 00:15:25 -04:00
*
2016-05-25 14:25:28 -04:00
* Allows additional query args to be appended .
2015-09-15 00:15:25 -04:00
*
* @ since 4.4 . 0
*
2016-04-19 19:21:27 -04:00
* @ param int | WP_Post $post Optional . Post ID or `WP_Post` object . Defaults to global `$post` .
2015-09-15 04:25:25 -04:00
* @ param array $query_args Optional . Array of additional query args to be appended to the link .
2016-04-19 19:21:27 -04:00
* Default empty array .
* @ param string $preview_link Optional . Base preview link to be used if it should differ from the
* post permalink . Default empty .
2016-05-25 14:25:28 -04:00
* @ return string | null URL used for the post preview , or null if the post does not exist .
2015-09-15 00:15:25 -04:00
*/
function get_preview_post_link ( $post = null , $query_args = array (), $preview_link = '' ) {
$post = get_post ( $post );
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2015-09-15 00:15:25 -04:00
if ( ! $post ) {
return ;
}
$post_type_object = get_post_type_object ( $post -> post_type );
if ( is_post_type_viewable ( $post_type_object ) ) {
if ( ! $preview_link ) {
2016-03-10 00:37:27 -05:00
$preview_link = set_url_scheme ( get_permalink ( $post ) );
2015-09-15 00:15:25 -04:00
}
2015-09-15 04:16:24 -04:00
$query_args [ 'preview' ] = 'true' ;
2017-11-30 18:11:00 -05:00
$preview_link = add_query_arg ( $query_args , $preview_link );
2015-09-15 00:15:25 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Filters the URL used for a post preview .
2015-09-15 00:15:25 -04:00
*
* @ since 2.0 . 5
2015-09-21 09:17:26 -04:00
* @ since 4.0 . 0 Added the `$post` parameter .
2015-09-15 00:15:25 -04:00
*
2015-09-15 04:25:25 -04:00
* @ param string $preview_link URL used for the post preview .
2015-09-15 00:15:25 -04:00
* @ param WP_Post $post Post object .
*/
return apply_filters ( 'preview_post_link' , $preview_link , $post );
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the edit post link for post .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* Can be used within the WordPress loop or outside of it . Can be used with
Revisions: Add edit link functionality for the `wp_template` and `wp_template_part` post types.
In preparation for viewing revisions of templates and template parts in the editor, this set changes adds the `_edit_link` argument when registering the `wp_template` and `wp_template_part` post types. This commit also updates `get_edit_post_link` to account for the unique edit URLs for these post types.
Finally, this commit also adds new unit tests for the `get_edit_post_link` function, including tests for the `post`, `wp_template`, and `wp_template_part` post types.
Fixes #57709.
Props andraganescu, spacedmonkey, antonvlasenko, youknowriad, ramonopoly, ironprogrammer, annezazu.
Built from https://develop.svn.wordpress.org/trunk@55743
git-svn-id: http://core.svn.wordpress.org/trunk@55255 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-10 13:36:21 -04:00
* pages , posts , attachments , revisions , global styles , templates , and template parts .
2008-10-13 18:00:07 -04:00
*
* @ since 2.3 . 0
*
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
2017-06-30 23:29:42 -04:00
* @ param string $context Optional . How to output the '&' character . Default '&' .
2020-09-28 07:12:03 -04:00
* @ return string | null The edit post link for the given post . Null if the post type does not exist
* or does not allow an editing UI .
2008-10-13 18:00:07 -04:00
*/
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
function get_edit_post_link ( $post = 0 , $context = 'display' ) {
$post = get_post ( $post );
2019-07-02 19:42:58 -04:00
if ( ! $post ) {
2008-03-12 01:50:07 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
if ( 'revision' === $post -> post_type ) {
2013-07-11 18:56:48 -04:00
$action = '' ;
2020-05-16 14:42:12 -04:00
} elseif ( 'display' === $context ) {
2010-05-03 14:16:22 -04:00
$action = '&action=edit' ;
2017-11-30 18:11:00 -05:00
} else {
2010-05-03 14:16:22 -04:00
$action = '&action=edit' ;
2017-11-30 18:11:00 -05:00
}
2010-05-03 14:16:22 -04:00
2010-01-15 17:11:12 -05:00
$post_type_object = get_post_type_object ( $post -> post_type );
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $post_type_object ) {
2010-01-04 11:58:43 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-01-04 11:58:43 -05:00
2017-11-30 18:11:00 -05:00
if ( ! current_user_can ( 'edit_post' , $post -> ID ) ) {
2010-01-04 11:58:43 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-01-04 11:58:43 -05:00
Revisions: Add edit link functionality for the `wp_template` and `wp_template_part` post types.
In preparation for viewing revisions of templates and template parts in the editor, this set changes adds the `_edit_link` argument when registering the `wp_template` and `wp_template_part` post types. This commit also updates `get_edit_post_link` to account for the unique edit URLs for these post types.
Finally, this commit also adds new unit tests for the `get_edit_post_link` function, including tests for the `post`, `wp_template`, and `wp_template_part` post types.
Fixes #57709.
Props andraganescu, spacedmonkey, antonvlasenko, youknowriad, ramonopoly, ironprogrammer, annezazu.
Built from https://develop.svn.wordpress.org/trunk@55743
git-svn-id: http://core.svn.wordpress.org/trunk@55255 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-10 13:36:21 -04:00
$link = '' ;
if ( 'wp_template' === $post -> post_type || 'wp_template_part' === $post -> post_type ) {
$slug = urlencode ( get_stylesheet () . '//' . $post -> post_name );
$link = admin_url ( sprintf ( $post_type_object -> _edit_link , $post -> post_type , $slug ) );
} elseif ( $post_type_object -> _edit_link ) {
2015-11-19 11:25:26 -05:00
$link = admin_url ( sprintf ( $post_type_object -> _edit_link . $action , $post -> ID ) );
2015-09-15 06:27:29 -04:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post edit link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.3 . 0
*
* @ param string $link The edit link .
* @ param int $post_id Post ID .
* @ param string $context The link context . If set to 'display' then ampersands
* are encoded .
*/
2015-11-19 11:25:26 -05:00
return apply_filters ( 'get_edit_post_link' , $link , $post -> ID , $context );
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the edit post link for post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ since 4.4 . 0 The `$css_class` argument was added .
2008-10-13 18:00:07 -04:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ 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 $after Optional . Display after edit link . Default empty .
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
* @ param string $css_class Optional . Add custom class to link . Default 'post-edit-link' .
2008-10-13 18:00:07 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
function edit_post_link ( $text = null , $before = '' , $after = '' , $post = 0 , $css_class = 'post-edit-link' ) {
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
$post = get_post ( $post );
2019-07-02 19:42:58 -04:00
if ( ! $post ) {
2009-05-21 14:43:04 -04:00
return ;
2014-05-27 09:43:14 -04:00
}
2007-04-26 23:51:36 -04:00
2019-07-02 19:42:58 -04:00
$url = get_edit_post_link ( $post -> ID );
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2019-07-02 19:42:58 -04:00
if ( ! $url ) {
2009-05-21 14:55:00 -04:00
return ;
2014-05-27 09:43:14 -04:00
}
2007-04-26 23:51:36 -04:00
2014-05-27 09:43:14 -04:00
if ( null === $text ) {
$text = __ ( 'Edit This' );
}
2009-10-01 13:41:09 -04:00
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
$link = '<a class="' . esc_attr ( $css_class ) . '" href="' . esc_url ( $url ) . '">' . $text . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post edit link anchor tag .
2014-04-13 22:13:16 -04:00
*
* @ since 2.3 . 0
*
* @ param string $link Anchor tag for the edit link .
* @ param int $post_id Post ID .
2014-05-27 09:43:14 -04:00
* @ param string $text Anchor text .
2014-04-13 22:13:16 -04:00
*/
2014-05-27 09:43:14 -04:00
echo $before . apply_filters ( 'edit_post_link' , $link , $post -> ID , $text ) . $after ;
2007-04-24 19:21:56 -04:00
}
2007-04-17 19:00:35 -04:00
2009-09-21 17:33:00 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the delete posts link for post .
2009-09-21 17:33:00 -04:00
*
2010-04-15 22:29:10 -04:00
* Can be used within the WordPress loop or outside of it , with any post type .
2009-09-21 17:33:00 -04:00
*
* @ since 2.9 . 0
*
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
* @ param int | WP_Post $post Optional . Post ID or post object . Default is the global `$post` .
2017-06-30 23:29:42 -04:00
* @ param string $deprecated Not used .
2020-02-09 23:12:07 -05:00
* @ param bool $force_delete Optional . Whether to bypass Trash and force deletion . Default false .
2015-05-26 14:44:25 -04:00
* @ return string | void The delete post link URL for the given post .
2009-09-21 17:33:00 -04:00
*/
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
function get_delete_post_link ( $post = 0 , $deprecated = '' , $force_delete = false ) {
2017-11-30 18:11:00 -05:00
if ( ! empty ( $deprecated ) ) {
2016-07-06 08:40:29 -04:00
_deprecated_argument ( __FUNCTION__ , '3.0.0' );
2017-11-30 18:11:00 -05:00
}
2010-04-15 22:29:10 -04:00
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
$post = get_post ( $post );
2019-07-02 19:42:58 -04:00
if ( ! $post ) {
2009-09-21 17:33:00 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2009-09-21 17:33:00 -04:00
2010-01-21 01:53:33 -05:00
$post_type_object = get_post_type_object ( $post -> post_type );
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $post_type_object ) {
2010-01-21 01:53:33 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-01-21 01:53:33 -05:00
2017-11-30 18:11:00 -05:00
if ( ! current_user_can ( 'delete_post' , $post -> ID ) ) {
2010-01-21 01:53:33 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2009-09-21 17:33:00 -04:00
2017-11-30 18:11:00 -05:00
$action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash' ;
2010-04-15 22:29:10 -04:00
$delete_link = add_query_arg ( 'action' , $action , admin_url ( sprintf ( $post_type_object -> _edit_link , $post -> ID ) ) );
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the post delete link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.9 . 0
*
* @ param string $link The delete link .
* @ param int $post_id Post ID .
2020-02-09 23:12:07 -05:00
* @ param bool $force_delete Whether to bypass the Trash and force deletion . Default false .
2014-04-13 22:13:16 -04:00
*/
2012-08-14 14:39:15 -04:00
return apply_filters ( 'get_delete_post_link' , wp_nonce_url ( $delete_link , " $action -post_ { $post -> ID } " ), $post -> ID , $force_delete );
2009-09-21 17:33:00 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the edit comment link .
2008-10-13 18:00:07 -04:00
*
* @ since 2.3 . 0
*
2015-09-11 02:21:25 -04:00
* @ param int | WP_Comment $comment_id Optional . Comment ID or WP_Comment object .
2015-05-26 14:44:25 -04:00
* @ return string | void The edit comment link URL for the given comment .
2008-10-13 18:00:07 -04:00
*/
2007-04-24 19:21:56 -04:00
function get_edit_comment_link ( $comment_id = 0 ) {
2012-10-04 14:21:47 -04:00
$comment = get_comment ( $comment_id );
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
if ( ! current_user_can ( 'edit_comment' , $comment -> comment_ID ) ) {
2010-09-07 19:35:28 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2007-04-28 12:45:47 -04:00
2017-11-30 18:11:00 -05:00
$location = admin_url ( 'comment.php?action=editcomment&c=' ) . $comment -> comment_ID ;
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the comment edit link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.3 . 0
*
* @ param string $location The edit link .
*/
2007-04-24 19:21:56 -04:00
return apply_filters ( 'get_edit_comment_link' , $location );
}
2004-01-27 04:58:01 -05:00
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the edit comment link with formatting .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2016-04-20 02:32:29 -04:00
* @ 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 $after Optional . Display after edit link . Default empty .
2008-10-13 18:00:07 -04:00
*/
2016-04-19 19:21:27 -04:00
function edit_comment_link ( $text = null , $before = '' , $after = '' ) {
$comment = get_comment ();
2007-04-26 23:51:36 -04:00
2014-05-27 09:43:14 -04:00
if ( ! current_user_can ( 'edit_comment' , $comment -> comment_ID ) ) {
2010-09-07 19:35:28 -04:00
return ;
2014-05-27 09:43:14 -04:00
}
2007-04-26 23:51:36 -04:00
2014-05-27 09:43:14 -04:00
if ( null === $text ) {
$text = __ ( 'Edit This' );
}
2009-10-01 13:41:09 -04:00
2016-04-19 19:21:27 -04:00
$link = '<a class="comment-edit-link" href="' . esc_url ( get_edit_comment_link ( $comment ) ) . '">' . $text . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the comment edit link anchor tag .
2014-04-13 22:13:16 -04:00
*
* @ since 2.3 . 0
*
* @ param string $link Anchor tag for the edit link .
2021-11-18 08:57:01 -05:00
* @ param string $comment_id Comment ID as a numeric string .
2014-05-27 09:43:14 -04:00
* @ param string $text Anchor text .
2014-04-13 22:13:16 -04:00
*/
2014-05-27 09:43:14 -04:00
echo $before . apply_filters ( 'edit_comment_link' , $link , $comment -> comment_ID , $text ) . $after ;
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the edit bookmark link .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* @ since 2.7 . 0
2008-10-13 18:00:07 -04:00
*
2020-06-20 08:02:12 -04:00
* @ param int | stdClass $link Optional . Bookmark ID . Default is the ID of the current bookmark .
2015-05-26 14:44:25 -04:00
* @ return string | void The edit bookmark link URL .
2008-10-13 18:00:07 -04:00
*/
2008-08-27 18:04:12 -04:00
function get_edit_bookmark_link ( $link = 0 ) {
2008-11-17 13:21:20 -05:00
$link = get_bookmark ( $link );
2008-08-27 18:04:12 -04:00
2017-11-30 18:11:00 -05:00
if ( ! current_user_can ( 'manage_links' ) ) {
2008-08-27 18:04:12 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-08-27 18:04:12 -04:00
2017-11-30 18:11:00 -05:00
$location = admin_url ( 'link.php?action=edit&link_id=' ) . $link -> link_id ;
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the bookmark edit link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $location The edit link .
* @ param int $link_id Bookmark ID .
*/
2008-08-27 18:04:12 -04:00
return apply_filters ( 'get_edit_bookmark_link' , $location , $link -> link_id );
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the edit bookmark link anchor content .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* @ since 2.7 . 0
2008-10-13 18:00:07 -04:00
*
2019-10-03 19:12:57 -04:00
* @ param string $link Optional . Anchor text . If empty , default is 'Edit This' . Default empty .
2016-04-20 02:32:29 -04:00
* @ param string $before Optional . Display before edit link . Default empty .
* @ param string $after Optional . Display after edit link . Default empty .
* @ param int $bookmark Optional . Bookmark ID . Default is the current bookmark .
2008-10-13 18:00:07 -04:00
*/
2008-08-27 18:04:12 -04:00
function edit_bookmark_link ( $link = '' , $before = '' , $after = '' , $bookmark = null ) {
2017-11-30 18:11:00 -05:00
$bookmark = get_bookmark ( $bookmark );
2008-08-27 18:04:12 -04:00
2017-11-30 18:11:00 -05:00
if ( ! current_user_can ( 'manage_links' ) ) {
2008-08-27 18:04:12 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-08-27 18:04:12 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $link ) ) {
$link = __ ( 'Edit This' );
}
2008-08-27 18:04:12 -04:00
2015-09-23 00:26:27 -04:00
$link = '<a href="' . esc_url ( get_edit_bookmark_link ( $bookmark ) ) . '">' . $link . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the bookmark edit link anchor tag .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $link Anchor tag for the edit link .
* @ param int $link_id Bookmark ID .
*/
2008-08-27 18:04:12 -04:00
echo $before . apply_filters ( 'edit_bookmark_link' , $link , $bookmark -> link_id ) . $after ;
}
2012-07-30 14:30:03 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the edit user link .
2012-07-30 14:30:03 -04:00
*
* @ since 3.5 . 0
*
* @ param int $user_id Optional . User ID . Defaults to the current user .
* @ return string URL to edit user page or empty string .
*/
function get_edit_user_link ( $user_id = null ) {
2017-11-30 18:11:00 -05:00
if ( ! $user_id ) {
2012-07-30 14:30:03 -04:00
$user_id = get_current_user_id ();
2017-11-30 18:11:00 -05:00
}
2012-07-30 14:30:03 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $user_id ) || ! current_user_can ( 'edit_user' , $user_id ) ) {
2012-07-30 14:30:03 -04:00
return '' ;
2017-11-30 18:11:00 -05:00
}
2012-07-30 14:30:03 -04:00
2012-08-02 21:06:05 -04:00
$user = get_userdata ( $user_id );
2012-07-30 14:30:03 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $user ) {
2012-07-30 14:30:03 -04:00
return '' ;
2017-11-30 18:11:00 -05:00
}
2012-07-30 14:30:03 -04:00
2017-11-30 18:11:00 -05:00
if ( get_current_user_id () == $user -> ID ) {
2012-07-30 14:30:03 -04:00
$link = get_edit_profile_url ( $user -> ID );
2017-11-30 18:11:00 -05:00
} else {
2012-07-30 14:30:03 -04:00
$link = add_query_arg ( 'user_id' , $user -> ID , self_admin_url ( 'user-edit.php' ) );
2017-11-30 18:11:00 -05:00
}
2012-07-30 14:30:03 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the user edit link .
2014-04-13 22:13:16 -04:00
*
* @ since 3.5 . 0
*
* @ param string $link The edit link .
* @ param int $user_id User ID .
*/
2012-07-30 14:30:03 -04:00
return apply_filters ( 'get_edit_user_link' , $link , $user -> ID );
}
2020-01-28 19:45:18 -05:00
//
// Navigation links.
//
2004-06-02 03:44:43 -04:00
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the previous post that is adjacent to the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether post should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
* @ return WP_Post | null | string Post object if successful . Null if global `$post` is not set .
* Empty string if no corresponding post exists .
2008-10-13 18:00:07 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function get_previous_post ( $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
return get_adjacent_post ( $in_same_term , $excluded_terms , true , $taxonomy );
2004-08-23 21:35:57 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the next post that is adjacent to the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether post should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
* @ return WP_Post | null | string Post object if successful . Null if global `$post` is not set .
* Empty string if no corresponding post exists .
2008-10-13 18:00:07 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function get_next_post ( $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
return get_adjacent_post ( $in_same_term , $excluded_terms , false , $taxonomy );
2007-12-05 04:25:45 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the adjacent post .
2008-10-13 18:00:07 -04:00
*
2010-12-15 11:45:14 -05:00
* Can either be next or previous post .
2008-10-13 18:00:07 -04:00
*
* @ since 2.5 . 0
*
2015-10-14 19:44:25 -04:00
* @ global wpdb $wpdb WordPress database abstraction object .
2015-05-26 14:44:25 -04:00
*
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether post should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty string .
* @ param bool $previous Optional . Whether to retrieve previous post .
* Default true .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
* @ return WP_Post | null | string Post object if successful . Null if global `$post` is not set .
* Empty string if no corresponding post exists .
2008-10-13 18:00:07 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function get_adjacent_post ( $in_same_term = false , $excluded_terms = '' , $previous = true , $taxonomy = 'category' ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
global $wpdb ;
2014-02-26 12:10:13 -05:00
2019-07-02 19:42:58 -04:00
$post = get_post ();
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2019-07-02 19:42:58 -04:00
if ( ! $post || ! taxonomy_exists ( $taxonomy ) ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
return null ;
2017-11-30 18:11:00 -05:00
}
2004-08-23 21:35:57 -04:00
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$current_post_date = $post -> post_date ;
2014-02-26 12:10:13 -05:00
2017-11-30 18:11:00 -05:00
$join = '' ;
$where = '' ;
2015-12-23 14:57:27 -05:00
$adjacent = $previous ? 'previous' : 'next' ;
2014-07-19 18:27:14 -04:00
2019-01-14 20:54:49 -05:00
if ( ! empty ( $excluded_terms ) && ! is_array ( $excluded_terms ) ) {
2019-03-27 10:45:51 -04:00
// Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ".
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 10:36:26 -04:00
if ( str_contains ( $excluded_terms , ' and ' ) ) {
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
_deprecated_argument (
__FUNCTION__ ,
'3.3.0' ,
sprintf (
2019-09-02 20:41:05 -04:00
/* translators: %s: The word 'and'. */
I18N: Improve translator comments.
* Add missing translator comments.
* Fix placement of some translator comments. Translator comments should be on the line directly above the line containing the translation function call for optimal compatibility with various `.pot` file generation tools. The CS auto-fixing, which changed some inconsistent function calls to multi-line function calls, is part of the reason why this was no longer the case for a select group of translator comments.
Includes minor code layout fixes.
Polyglots, rejoice! All WordPress core files now have translator comments for all strings with placeholders!
Props jrf, subrataemfluence, GaryJ, webdados, Dency, swissspidy, alvarogois, marcomartins, mihaiiceyro, vladwtz, niq1982, flipkeijzer, michielatyoast, chandrapatel, thrijith, joshuanoyce, FesoVik, tessak22, bhaktirajdev, cleancoded, dhavalkasvala, garrett-eclipse, bibliofille, socalchristina, priyankkpatel, 5hel2l2y, adamsilverstein, JeffPaul, pierlo, SergeyBiryukov.
Fixes #44360.
Built from https://develop.svn.wordpress.org/trunk@45926
git-svn-id: http://core.svn.wordpress.org/trunk@45737 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-01 13:13:59 -04:00
__ ( 'Use commas instead of %s to separate excluded terms.' ),
" 'and' "
)
);
2019-01-14 20:54:49 -05:00
$excluded_terms = explode ( ' and ' , $excluded_terms );
} else {
$excluded_terms = explode ( ',' , $excluded_terms );
}
$excluded_terms = array_map ( 'intval' , $excluded_terms );
}
2018-03-11 13:32:31 -04:00
/**
* Filters the IDs of terms excluded from adjacent post queries .
*
* The dynamic portion of the hook name , `$adjacent` , refers to the type
* of adjacency , 'next' or 'previous' .
*
2021-03-07 07:32:09 -05:00
* Possible hook names include :
*
* - `get_next_post_excluded_terms`
* - `get_previous_post_excluded_terms`
*
2018-03-11 13:32:31 -04:00
* @ since 4.4 . 0
*
2022-08-09 06:31:09 -04:00
* @ param int [] | string $excluded_terms Array of excluded term IDs . Empty string if none were provided .
2018-03-11 13:32:31 -04:00
*/
$excluded_terms = apply_filters ( " get_ { $adjacent } _post_excluded_terms " , $excluded_terms );
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
if ( $in_same_term || ! empty ( $excluded_terms ) ) {
if ( $in_same_term ) {
2022-01-10 23:12:05 -05:00
$join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id " ;
2017-11-30 18:11:00 -05:00
$where .= $wpdb -> prepare ( 'AND tt.taxonomy = %s' , $taxonomy );
2015-09-12 16:34:24 -04:00
2017-11-30 18:11:00 -05:00
if ( ! is_object_in_taxonomy ( $post -> post_type , $taxonomy ) ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
return '' ;
2017-11-30 18:11:00 -05:00
}
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$term_array = wp_get_object_terms ( $post -> ID , $taxonomy , array ( 'fields' => 'ids' ) );
2014-07-19 18:27:14 -04:00
// Remove any exclusions from the term array to include.
$term_array = array_diff ( $term_array , ( array ) $excluded_terms );
$term_array = array_map ( 'intval' , $term_array );
2017-11-30 18:11:00 -05:00
if ( ! $term_array || is_wp_error ( $term_array ) ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
return '' ;
2017-11-30 18:11:00 -05:00
}
2014-07-19 18:27:14 -04:00
2017-11-30 18:11:00 -05:00
$where .= ' AND tt.term_id IN (' . implode ( ',' , $term_array ) . ')' ;
2014-02-26 12:10:13 -05:00
}
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
if ( ! empty ( $excluded_terms ) ) {
2015-12-23 15:15:25 -05:00
$where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN ( " . implode ( ',' , array_map ( 'intval' , $excluded_terms ) ) . ') )' ;
2007-12-05 04:25:45 -05:00
}
2005-04-18 17:47:35 -04:00
}
2004-08-23 21:35:57 -04:00
2015-01-29 21:20:23 -05:00
// 'post_status' clause depends on the current user.
if ( is_user_logged_in () ) {
$user_id = get_current_user_id ();
$post_type_object = get_post_type_object ( $post -> post_type );
if ( empty ( $post_type_object ) ) {
$post_type_cap = $post -> post_type ;
$read_private_cap = 'read_private_' . $post_type_cap . 's' ;
} else {
$read_private_cap = $post_type_object -> cap -> read_private_posts ;
}
/*
* Results should include private posts belonging to the current user , or private posts where the
* current user has the 'read_private_posts' cap .
*/
$private_states = get_post_stati ( array ( 'private' => true ) );
2017-11-30 18:11:00 -05:00
$where .= " AND ( p.post_status = 'publish' " ;
2021-06-30 13:44:58 -04:00
foreach ( $private_states as $state ) {
2015-01-29 21:20:23 -05:00
if ( current_user_can ( $read_private_cap ) ) {
2017-11-30 18:11:00 -05:00
$where .= $wpdb -> prepare ( ' OR p.post_status = %s' , $state );
2015-01-29 21:20:23 -05:00
} else {
2017-11-30 18:11:00 -05:00
$where .= $wpdb -> prepare ( ' OR (p.post_author = %d AND p.post_status = %s)' , $user_id , $state );
2015-01-29 21:20:23 -05:00
}
}
2017-11-30 18:11:00 -05:00
$where .= ' )' ;
2015-01-29 21:20:23 -05:00
} else {
$where .= " AND p.post_status = 'publish' " ;
}
2017-11-30 18:11:00 -05:00
$op = $previous ? '<' : '>' ;
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$order = $previous ? 'DESC' : 'ASC' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the JOIN clause in the SQL for an adjacent post query .
2014-04-13 22:13:16 -04:00
*
2014-11-30 07:10:23 -05:00
* The dynamic portion of the hook name , `$adjacent` , refers to the type
2014-04-13 22:13:16 -04:00
* of adjacency , 'next' or 'previous' .
*
2021-03-07 07:32:09 -05:00
* Possible hook names include :
*
* - `get_next_post_join`
* - `get_previous_post_join`
*
2014-04-13 22:13:16 -04:00
* @ since 2.5 . 0
2015-09-08 23:49:24 -04:00
* @ since 4.4 . 0 Added the `$taxonomy` and `$post` parameters .
2014-04-13 22:13:16 -04:00
*
2022-08-09 06:31:09 -04:00
* @ param string $join The JOIN clause in the SQL .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Whether post should be in the same taxonomy term .
2022-08-09 06:31:09 -04:00
* @ param int [] | string $excluded_terms Array of excluded term IDs . Empty string if none were provided .
* @ param string $taxonomy Taxonomy . Used to identify the term used when `$in_same_term` is true .
* @ param WP_Post $post WP_Post object .
2014-04-13 22:13:16 -04:00
*/
2015-09-08 23:49:24 -04:00
$join = apply_filters ( " get_ { $adjacent } _post_join " , $join , $in_same_term , $excluded_terms , $taxonomy , $post );
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the WHERE clause in the SQL for an adjacent post query .
2014-04-13 22:13:16 -04:00
*
2014-11-30 07:10:23 -05:00
* The dynamic portion of the hook name , `$adjacent` , refers to the type
2014-04-13 22:13:16 -04:00
* of adjacency , 'next' or 'previous' .
*
2021-03-07 07:32:09 -05:00
* Possible hook names include :
*
* - `get_next_post_where`
* - `get_previous_post_where`
*
2014-04-13 22:13:16 -04:00
* @ since 2.5 . 0
2015-09-08 23:49:24 -04:00
* @ since 4.4 . 0 Added the `$taxonomy` and `$post` parameters .
2014-04-13 22:13:16 -04:00
*
2022-08-09 06:31:09 -04:00
* @ param string $where The `WHERE` clause in the SQL .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Whether post should be in the same taxonomy term .
2022-08-09 06:31:09 -04:00
* @ param int [] | string $excluded_terms Array of excluded term IDs . Empty string if none were provided .
* @ param string $taxonomy Taxonomy . Used to identify the term used when `$in_same_term` is true .
* @ param WP_Post $post WP_Post object .
2014-04-13 22:13:16 -04:00
*/
2015-09-08 23:49:24 -04:00
$where = apply_filters ( " get_ { $adjacent } _post_where " , $wpdb -> prepare ( " WHERE p.post_date $op %s AND p.post_type = %s $where " , $current_post_date , $post -> post_type ), $in_same_term , $excluded_terms , $taxonomy , $post );
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the ORDER BY clause in the SQL for an adjacent post query .
2014-04-13 22:13:16 -04:00
*
2014-11-30 07:10:23 -05:00
* The dynamic portion of the hook name , `$adjacent` , refers to the type
2014-04-13 22:13:16 -04:00
* of adjacency , 'next' or 'previous' .
*
2021-03-07 07:32:09 -05:00
* Possible hook names include :
*
* - `get_next_post_sort`
* - `get_previous_post_sort`
*
2014-04-13 22:13:16 -04:00
* @ since 2.5 . 0
2015-09-08 23:49:24 -04:00
* @ since 4.4 . 0 Added the `$post` parameter .
2017-09-24 19:01:44 -04:00
* @ since 4.9 . 0 Added the `$order` parameter .
2014-04-13 22:13:16 -04:00
*
2014-11-30 07:10:23 -05:00
* @ param string $order_by The `ORDER BY` clause in the SQL .
2015-09-08 23:49:24 -04:00
* @ param WP_Post $post WP_Post object .
2017-09-24 19:01:44 -04:00
* @ param string $order Sort order . 'DESC' for previous post , 'ASC' for next .
2014-04-13 22:13:16 -04:00
*/
2017-11-30 18:11:00 -05:00
$sort = apply_filters ( " get_ { $adjacent } _post_sort " , " ORDER BY p.post_date $order LIMIT 1 " , $post , $order );
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
2023-01-18 06:20:13 -05:00
$query = " SELECT p.ID FROM $wpdb->posts AS p $join $where $sort " ;
$key = md5 ( $query );
$last_changed = wp_cache_get_last_changed ( 'posts' );
if ( $in_same_term || ! empty ( $excluded_terms ) ) {
$last_changed .= wp_cache_get_last_changed ( 'terms' );
}
$cache_key = " adjacent_post: $key : $last_changed " ;
2023-03-10 11:30:03 -05:00
$result = wp_cache_get ( $cache_key , 'post-queries' );
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
if ( false !== $result ) {
2017-11-30 18:11:00 -05:00
if ( $result ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$result = get_post ( $result );
2017-11-30 18:11:00 -05:00
}
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
return $result ;
2012-08-27 09:13:40 -04:00
}
2009-05-08 14:04:13 -04:00
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$result = $wpdb -> get_var ( $query );
2017-11-30 18:11:00 -05:00
if ( null === $result ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$result = '' ;
2017-11-30 18:11:00 -05:00
}
2014-03-19 22:59:15 -04:00
2023-03-10 11:30:03 -05:00
wp_cache_set ( $cache_key , $result , 'post-queries' );
2014-03-19 22:59:15 -04:00
2017-11-30 18:11:00 -05:00
if ( $result ) {
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
$result = get_post ( $result );
2017-11-30 18:11:00 -05:00
}
2014-03-19 22:59:15 -04:00
Revert the conversion of adjacent post queries to WP_Query. Explanation on the ticket.
Reverts [27285], [27286], [27287], [27288], [27291], [27292], [27293], [27296], [27633], [27634], [27635], and [27692].
see #26937.
Built from https://develop.svn.wordpress.org/trunk@27836
git-svn-id: http://core.svn.wordpress.org/trunk@27670 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-03-29 02:03:15 -04:00
return $result ;
2007-12-05 04:25:45 -05:00
}
2004-08-23 21:35:57 -04:00
2009-03-18 17:56:03 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the adjacent post relational link .
2009-03-18 17:56:03 -04:00
*
* Can either be next or previous post relational link .
*
* @ since 2.8 . 0
*
2016-04-20 02:32:29 -04:00
* @ param string $title Optional . Link title format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param bool $previous Optional . Whether to display link to previous or next post .
* Default true .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2015-05-26 14:44:25 -04:00
* @ return string | void The adjacent post relational link URL .
2009-03-18 17:56:03 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function get_adjacent_post_rel_link ( $title = '%title' , $in_same_term = false , $excluded_terms = '' , $previous = true , $taxonomy = 'category' ) {
2019-07-02 19:42:58 -04:00
$post = get_post ();
if ( $previous && is_attachment () && $post ) {
2012-09-04 12:29:28 -04:00
$post = get_post ( $post -> post_parent );
2017-11-30 18:11:00 -05:00
} else {
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$post = get_adjacent_post ( $in_same_term , $excluded_terms , $previous , $taxonomy );
2017-11-30 18:11:00 -05:00
}
2009-03-18 17:56:03 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $post ) ) {
2009-03-18 17:56:03 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2009-03-18 17:56:03 -04:00
2017-11-30 18:11:00 -05:00
$post_title = the_title_attribute (
array (
'echo' => false ,
'post' => $post ,
)
);
2013-07-23 12:05:40 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $post_title ) ) {
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$post_title = $previous ? __ ( 'Previous Post' ) : __ ( 'Next Post' );
2017-11-30 18:11:00 -05:00
}
2009-03-18 17:56:03 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$date = mysql2date ( get_option ( 'date_format' ), $post -> post_date );
2009-04-20 14:18:39 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$title = str_replace ( '%title' , $post_title , $title );
$title = str_replace ( '%date' , $date , $title );
2009-03-18 17:56:03 -04:00
2017-11-30 18:11:00 -05:00
$link = $previous ? " <link rel='prev' title=' " : " <link rel='next' title=' " ;
2009-05-05 15:43:53 -04:00
$link .= esc_attr ( $title );
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$link .= " ' href=' " . get_permalink ( $post ) . " ' /> \n " ;
2009-03-18 17:56:03 -04:00
2009-04-22 18:56:52 -04:00
$adjacent = $previous ? 'previous' : 'next' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the adjacent post relational link .
2014-04-13 22:13:16 -04:00
*
2014-11-30 07:10:23 -05:00
* The dynamic portion of the hook name , `$adjacent` , refers to the type
2014-04-13 22:13:16 -04:00
* of adjacency , 'next' or 'previous' .
*
2021-03-07 07:32:09 -05:00
* Possible hook names include :
*
* - `next_post_rel_link`
* - `previous_post_rel_link`
*
2014-04-13 22:13:16 -04:00
* @ since 2.8 . 0
*
* @ param string $link The relational link .
*/
2009-04-22 18:56:52 -04:00
return apply_filters ( " { $adjacent } _post_rel_link " , $link );
2009-03-18 17:56:03 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Displays the relational links for the posts adjacent to the current post .
2009-03-18 17:56:03 -04:00
*
* @ since 2.8 . 0
*
2016-04-20 02:32:29 -04:00
* @ param string $title Optional . Link title format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2009-03-18 17:56:03 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function adjacent_posts_rel_link ( $title = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
2014-03-26 18:32:15 -04:00
echo get_adjacent_post_rel_link ( $title , $in_same_term , $excluded_terms , true , $taxonomy );
echo get_adjacent_post_rel_link ( $title , $in_same_term , $excluded_terms , false , $taxonomy );
2009-03-18 17:56:03 -04:00
}
2010-04-06 11:06:42 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays relational links for the posts adjacent to the current post for single post pages .
2010-04-06 11:06:42 -04:00
*
2016-04-20 02:32:29 -04:00
* This is meant to be attached to actions like 'wp_head' . Do not call this directly in plugins
* or theme templates .
*
2010-04-06 11:06:42 -04:00
* @ since 3.0 . 0
2020-09-18 07:06:04 -04:00
* @ since 5.6 . 0 No longer used in core .
2010-04-06 11:06:42 -04:00
*
2016-04-20 02:32:29 -04:00
* @ see adjacent_posts_rel_link ()
2010-04-06 11:06:42 -04:00
*/
function adjacent_posts_rel_link_wp_head () {
2014-06-17 20:05:16 -04:00
if ( ! is_single () || is_attachment () ) {
2010-04-06 11:06:42 -04:00
return ;
2014-05-30 17:20:14 -04:00
}
2010-04-06 11:06:42 -04:00
adjacent_posts_rel_link ();
}
2009-03-18 17:56:03 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the relational link for the next post adjacent to the current post .
2009-03-18 17:56:03 -04:00
*
* @ since 2.8 . 0
*
2016-04-20 02:32:29 -04:00
* @ see get_adjacent_post_rel_link ()
*
* @ param string $title Optional . Link title format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2009-03-18 17:56:03 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function next_post_rel_link ( $title = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
2014-03-26 18:32:15 -04:00
echo get_adjacent_post_rel_link ( $title , $in_same_term , $excluded_terms , false , $taxonomy );
2009-03-18 17:56:03 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Displays the relational link for the previous post adjacent to the current post .
2009-03-18 17:56:03 -04:00
*
* @ since 2.8 . 0
*
2016-04-20 02:32:29 -04:00
* @ see get_adjacent_post_rel_link ()
*
* @ param string $title Optional . Link title format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default true .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2009-03-18 17:56:03 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function prev_post_rel_link ( $title = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
2014-03-26 18:32:15 -04:00
echo get_adjacent_post_rel_link ( $title , $in_same_term , $excluded_terms , true , $taxonomy );
2009-03-18 17:56:03 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the boundary post .
2009-03-18 17:56:03 -04:00
*
2010-09-26 04:31:16 -04:00
* Boundary being either the first or last post by publish date within the constraints specified
2022-11-14 19:34:12 -05:00
* by `$in_same_term` or `$excluded_terms` .
2009-03-18 17:56:03 -04:00
*
* @ since 2.8 . 0
*
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether returned post should be in the same taxonomy term .
2016-04-20 02:32:29 -04:00
* Default false .
2020-11-19 13:24:09 -05:00
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
2016-04-20 02:32:29 -04:00
* Default empty .
2022-11-14 19:34:12 -05:00
* @ param bool $start Optional . Whether to retrieve first or last post .
* Default true .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
* @ return array | null Array containing the boundary post object if successful , null otherwise .
2009-03-18 17:56:03 -04:00
*/
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
function get_boundary_post ( $in_same_term = false , $excluded_terms = '' , $start = true , $taxonomy = 'category' ) {
2012-09-04 12:29:28 -04:00
$post = get_post ();
Posts, Post Types: Standardize on `$post` parameter name where appropriate.
This renames the `$post_id` or `$id` parameters to `$post` for functions that accept a post ID or post object:
* `get_sample_permalink()`
* `get_sample_permalink_html()`
* `wp_check_post_lock()`
* `wp_set_post_lock()`
* `get_the_tags()`
* `comment_class()`
* `get_comment_class()`
* `get_comments_link()`
* `get_comments_number()`
* `comments_number()`
* `get_comments_number_text()`
* `comments_open()`
* `pings_open()`
* `comment_form()`
* `do_trackbacks()`
* `pingback()`
* `post_permalink()`
* `get_post_permalink()`
* `get_edit_post_link()`
* `edit_post_link()`
* `get_delete_post_link()`
* `post_class()`
* `get_post_class()`
* `the_attachment_link()`
* `wp_get_attachment_link()`
* `wp_list_post_revisions()`
* `check_and_publish_future_post()`
* `add_ping()`
* `get_pung()`
* `get_to_ping()`
* `wp_get_post_revisions()`
* `wp_get_post_revisions_url()`
Additionally, `$revision_id` is renamed to `$revision` in:
* `wp_restore_post_revision()`
* `wp_delete_post_revision()`
Includes minor documentation improvements for consistency and code layout fixes for better readability.
Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].
See #56243, #55647.
Built from https://develop.svn.wordpress.org/trunk@53715
git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-18 13:37:17 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $post || ! is_single () || is_attachment () || ! taxonomy_exists ( $taxonomy ) ) {
2009-04-22 18:56:52 -04:00
return null ;
2017-11-30 18:11:00 -05:00
}
2009-03-18 17:56:03 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$query_args = array (
2017-11-30 18:11:00 -05:00
'posts_per_page' => 1 ,
'order' => $start ? 'ASC' : 'DESC' ,
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
'update_post_term_cache' => false ,
2017-11-30 18:11:00 -05:00
'update_post_meta_cache' => false ,
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
);
2009-04-22 18:56:52 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$term_array = array ();
2009-04-22 18:56:52 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
if ( ! is_array ( $excluded_terms ) ) {
2017-11-30 18:11:00 -05:00
if ( ! empty ( $excluded_terms ) ) {
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$excluded_terms = explode ( ',' , $excluded_terms );
2017-11-30 18:11:00 -05:00
} else {
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$excluded_terms = array ();
2017-11-30 18:11:00 -05:00
}
2009-04-22 18:56:52 -04:00
}
2009-03-18 17:56:03 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
if ( $in_same_term || ! empty ( $excluded_terms ) ) {
2017-11-30 18:11:00 -05:00
if ( $in_same_term ) {
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$term_array = wp_get_object_terms ( $post -> ID , $taxonomy , array ( 'fields' => 'ids' ) );
2017-11-30 18:11:00 -05:00
}
2009-03-18 17:56:03 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
if ( ! empty ( $excluded_terms ) ) {
$excluded_terms = array_map ( 'intval' , $excluded_terms );
$excluded_terms = array_diff ( $excluded_terms , $term_array );
$inverse_terms = array ();
2017-11-30 18:11:00 -05:00
foreach ( $excluded_terms as $excluded_term ) {
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$inverse_terms [] = $excluded_term * - 1 ;
2017-11-30 18:11:00 -05:00
}
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
$excluded_terms = $inverse_terms ;
}
2017-11-30 18:11:00 -05:00
$query_args [ 'tax_query' ] = array (
array (
'taxonomy' => $taxonomy ,
'terms' => array_merge ( $term_array , $excluded_terms ),
),
);
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
}
2009-03-18 17:56:03 -04:00
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
return get_posts ( $query_args );
2009-03-18 17:56:03 -04:00
}
2015-12-18 18:14:26 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the previous post link that is adjacent to the current post .
2013-09-10 18:12:10 -04:00
*
* @ since 3.7 . 0
*
2016-04-20 02:32:29 -04:00
* @ param string $format Optional . Link anchor format . Default '« %link' .
2017-06-25 02:20:43 -04:00
* @ param string $link Optional . Link permalink format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2014-11-29 23:44:23 -05:00
* @ return string The link URL of the previous post in relation to the current post .
2013-09-10 18:12:10 -04:00
*/
2014-05-25 12:10:13 -04:00
function get_previous_post_link ( $format = '« %link' , $link = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
return get_adjacent_post_link ( $format , $link , $in_same_term , $excluded_terms , true , $taxonomy );
2013-09-10 18:12:10 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the previous post link that is adjacent to the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
2016-04-15 12:58:27 -04:00
*
2013-10-30 10:39:10 -04:00
* @ see get_previous_post_link ()
2008-10-13 18:00:07 -04:00
*
2016-04-20 02:32:29 -04:00
* @ param string $format Optional . Link anchor format . Default '« %link' .
* @ param string $link Optional . Link permalink format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2008-10-13 18:00:07 -04:00
*/
2014-05-25 12:10:13 -04:00
function previous_post_link ( $format = '« %link' , $link = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
echo get_previous_post_link ( $format , $link , $in_same_term , $excluded_terms , $taxonomy );
2013-09-10 18:12:10 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the next post link that is adjacent to the current post .
2013-09-10 18:12:10 -04:00
*
* @ since 3.7 . 0
*
2016-04-20 02:32:29 -04:00
* @ param string $format Optional . Link anchor format . Default '« %link' .
* @ param string $link Optional . Link permalink format . Default '%title' .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2014-11-29 23:44:23 -05:00
* @ return string The link URL of the next post in relation to the current post .
2013-09-10 18:12:10 -04:00
*/
2014-05-25 12:10:13 -04:00
function get_next_post_link ( $format = '%link »' , $link = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
return get_adjacent_post_link ( $format , $link , $in_same_term , $excluded_terms , false , $taxonomy );
2004-08-23 21:35:57 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the next post link that is adjacent to the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
2020-06-16 17:07:14 -04:00
*
2013-10-30 10:39:10 -04:00
* @ see get_next_post_link ()
2008-10-13 18:00:07 -04:00
*
2016-04-20 02:32:29 -04:00
* @ param string $format Optional . Link anchor format . Default '« %link' .
2022-11-14 19:34:12 -05:00
* @ param string $link Optional . Link permalink format . Default '%title' .
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* Default empty .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2008-10-13 18:00:07 -04:00
*/
2014-05-25 12:10:13 -04:00
function next_post_link ( $format = '%link »' , $link = '%title' , $in_same_term = false , $excluded_terms = '' , $taxonomy = 'category' ) {
2017-11-26 18:57:55 -05:00
echo get_next_post_link ( $format , $link , $in_same_term , $excluded_terms , $taxonomy );
2007-12-05 04:25:45 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the adjacent post link .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* Can be either next post link or previous .
2008-10-13 18:00:07 -04:00
*
2013-09-10 18:12:10 -04:00
* @ since 3.7 . 0
2008-10-13 18:00:07 -04:00
*
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
* @ param string $format Link anchor format .
* @ param string $link Link permalink format .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded terms IDs .
* Default empty .
* @ param bool $previous Optional . Whether to display link to previous or next post .
* Default true .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2014-11-29 23:44:23 -05:00
* @ return string The link URL of the previous or next post in relation to the current post .
2008-10-13 18:00:07 -04:00
*/
2014-05-25 12:10:13 -04:00
function get_adjacent_post_link ( $format , $link , $in_same_term = false , $excluded_terms = '' , $previous = true , $taxonomy = 'category' ) {
2017-11-30 18:11:00 -05:00
if ( $previous && is_attachment () ) {
2012-09-04 12:29:28 -04:00
$post = get_post ( get_post () -> post_parent );
2017-11-30 18:11:00 -05:00
} else {
2014-05-25 12:10:13 -04:00
$post = get_adjacent_post ( $in_same_term , $excluded_terms , $previous , $taxonomy );
2017-11-30 18:11:00 -05:00
}
2004-08-23 21:35:57 -04:00
2012-09-10 17:36:06 -04:00
if ( ! $post ) {
$output = '' ;
} else {
$title = $post -> post_title ;
2004-08-23 21:35:57 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $post -> post_title ) ) {
2012-09-10 17:36:06 -04:00
$title = $previous ? __ ( 'Previous Post' ) : __ ( 'Next Post' );
2017-11-30 18:11:00 -05:00
}
2007-09-11 16:05:52 -04:00
2013-10-24 18:59:20 -04:00
/** This filter is documented in wp-includes/post-template.php */
2012-09-10 17:36:06 -04:00
$title = apply_filters ( 'the_title' , $title , $post -> ID );
2014-04-13 22:13:16 -04:00
2012-09-10 17:36:06 -04:00
$date = mysql2date ( get_option ( 'date_format' ), $post -> post_date );
2017-11-30 18:11:00 -05:00
$rel = $previous ? 'prev' : 'next' ;
2007-09-11 16:05:52 -04:00
2017-11-30 18:11:00 -05:00
$string = '<a href="' . get_permalink ( $post ) . '" rel="' . $rel . '">' ;
2012-09-10 17:36:06 -04:00
$inlink = str_replace ( '%title' , $title , $link );
$inlink = str_replace ( '%date' , $date , $inlink );
$inlink = $string . $inlink . '</a>' ;
2007-12-05 04:25:45 -05:00
2012-09-10 17:36:06 -04:00
$output = str_replace ( '%link' , $inlink , $format );
}
2004-08-23 21:35:57 -04:00
2008-06-16 18:27:07 -04:00
$adjacent = $previous ? 'previous' : 'next' ;
2012-09-10 17:36:06 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the adjacent post link .
2014-04-13 22:13:16 -04:00
*
2014-11-30 07:10:23 -05:00
* The dynamic portion of the hook name , `$adjacent` , refers to the type
2014-04-13 22:13:16 -04:00
* of adjacency , 'next' or 'previous' .
*
2021-03-07 07:32:09 -05:00
* Possible hook names include :
*
* - `next_post_link`
* - `previous_post_link`
*
2014-04-13 22:13:16 -04:00
* @ since 2.6 . 0
2014-12-30 01:57:23 -05:00
* @ since 4.2 . 0 Added the `$adjacent` parameter .
2014-04-13 22:13:16 -04:00
*
2022-11-14 19:19:13 -05:00
* @ param string $output The adjacent post link .
* @ param string $format Link anchor format .
* @ param string $link Link permalink format .
* @ param WP_Post | string $post The adjacent post . Empty string if no corresponding post exists .
* @ param string $adjacent Whether the post is previous or next .
2014-04-13 22:13:16 -04:00
*/
2014-12-30 01:57:23 -05:00
return apply_filters ( " { $adjacent } _post_link " , $output , $format , $link , $post , $adjacent );
2013-09-10 18:12:10 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Displays the adjacent post link .
2013-09-10 18:12:10 -04:00
*
* Can be either next post link or previous .
*
* @ since 2.5 . 0
*
Add a $taxonomy argument to each of the adjacent post functions.
Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.
Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().
props ethitter.
finally fixes #17807.
Built from https://develop.svn.wordpress.org/trunk@25959
git-svn-id: http://core.svn.wordpress.org/trunk@25918 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-10-27 17:40:09 -04:00
* @ param string $format Link anchor format .
* @ param string $link Link permalink format .
2022-11-14 19:34:12 -05:00
* @ param bool $in_same_term Optional . Whether link should be in the same taxonomy term .
* Default false .
* @ param int [] | string $excluded_terms Optional . Array or comma - separated list of excluded category IDs .
* Default empty .
* @ param bool $previous Optional . Whether to display link to previous or next post .
* Default true .
* @ param string $taxonomy Optional . Taxonomy , if `$in_same_term` is true . Default 'category' .
2013-09-10 18:12:10 -04:00
*/
2014-05-25 12:10:13 -04:00
function adjacent_post_link ( $format , $link , $in_same_term = false , $excluded_terms = '' , $previous = true , $taxonomy = 'category' ) {
echo get_adjacent_post_link ( $format , $link , $in_same_term , $excluded_terms , $previous , $taxonomy );
2004-08-23 21:35:57 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the link for a page number .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2019-03-27 10:24:52 -04:00
* @ param int $pagenum Optional . Page number . Default 1.
2022-11-14 19:34:12 -05:00
* @ param bool $escape Optional . Whether to escape the URL for display , with esc_url () .
* If set to false , prepares the URL with sanitize_url () . Default true .
2014-11-29 23:44:23 -05:00
* @ return string The link URL for the given page number .
2008-10-13 18:00:07 -04:00
*/
2017-11-30 18:11:00 -05:00
function get_pagenum_link ( $pagenum = 1 , $escape = true ) {
2004-12-02 21:38:11 -05:00
global $wp_rewrite ;
2007-06-13 22:25:30 -04:00
2007-05-11 20:17:34 -04:00
$pagenum = ( int ) $pagenum ;
2007-06-13 22:25:30 -04:00
2007-05-11 20:17:34 -04:00
$request = remove_query_arg ( 'paged' );
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
$home_root = parse_url ( home_url () );
$home_root = ( isset ( $home_root [ 'path' ] ) ) ? $home_root [ 'path' ] : '' ;
2012-06-28 16:54:20 -04:00
$home_root = preg_quote ( $home_root , '|' );
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
$request = preg_replace ( '|^' . $home_root . '|i' , '' , $request );
$request = preg_replace ( '|^/+|' , '' , $request );
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $wp_rewrite -> using_permalinks () || is_admin () ) {
2009-12-30 12:05:02 -05:00
$base = trailingslashit ( get_bloginfo ( 'url' ) );
2007-05-28 14:34:06 -04:00
2007-05-11 20:17:34 -04:00
if ( $pagenum > 1 ) {
2007-05-15 22:47:24 -04:00
$result = add_query_arg ( 'paged' , $pagenum , $base . $request );
2007-05-11 20:17:34 -04:00
} else {
$result = $base . $request ;
}
2005-03-27 21:34:16 -05:00
} else {
2007-05-11 20:17:34 -04:00
$qs_regex = '|\?.*?$|' ;
preg_match ( $qs_regex , $request , $qs_match );
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
if ( ! empty ( $qs_match [ 0 ] ) ) {
2007-05-11 20:17:34 -04:00
$query_string = $qs_match [ 0 ];
2017-11-30 18:11:00 -05:00
$request = preg_replace ( $qs_regex , '' , $request );
2005-03-27 21:34:16 -05:00
} else {
2007-05-11 20:17:34 -04:00
$query_string = '' ;
2005-03-27 21:34:16 -05:00
}
2007-06-13 22:25:30 -04:00
2017-11-30 18:11:00 -05:00
$request = preg_replace ( " | $wp_rewrite->pagination_base / \ d+/? $ | " , '' , $request );
$request = preg_replace ( '|^' . preg_quote ( $wp_rewrite -> index , '|' ) . '|i' , '' , $request );
$request = ltrim ( $request , '/' );
2007-06-13 22:25:30 -04:00
2007-05-15 22:47:24 -04:00
$base = trailingslashit ( get_bloginfo ( 'url' ) );
2007-06-13 22:25:30 -04:00
2020-05-16 14:42:12 -04:00
if ( $wp_rewrite -> using_index_permalinks () && ( $pagenum > 1 || '' !== $request ) ) {
2013-01-18 08:44:22 -05:00
$base .= $wp_rewrite -> index . '/' ;
2017-11-30 18:11:00 -05:00
}
2007-06-13 22:25:30 -04:00
2007-05-15 22:47:24 -04:00
if ( $pagenum > 1 ) {
2017-11-30 18:11:00 -05:00
$request = ( ( ! empty ( $request ) ) ? trailingslashit ( $request ) : $request ) . user_trailingslashit ( $wp_rewrite -> pagination_base . '/' . $pagenum , 'paged' );
2007-05-15 22:47:24 -04:00
}
2007-06-13 22:25:30 -04:00
2007-05-11 20:17:34 -04:00
$result = $base . $request . $query_string ;
2005-03-27 21:34:16 -05:00
}
2007-06-13 22:25:30 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the page number link for the current request .
2014-04-13 22:13:16 -04:00
*
* @ since 2.5 . 0
2019-04-13 10:17:55 -04:00
* @ since 5.2 . 0 Added the `$pagenum` argument .
2014-04-13 22:13:16 -04:00
*
2019-03-27 10:24:52 -04:00
* @ param string $result The page number link .
* @ param int $pagenum The page number .
2014-04-13 22:13:16 -04:00
*/
2019-03-27 10:24:52 -04:00
$result = apply_filters ( 'get_pagenum_link' , $result , $pagenum );
2008-02-25 13:40:46 -05:00
2017-11-30 18:11:00 -05:00
if ( $escape ) {
2012-05-02 12:29:39 -04:00
return esc_url ( $result );
2017-11-30 18:11:00 -05:00
} else {
2022-06-01 14:14:10 -04:00
return sanitize_url ( $result );
2017-11-30 18:11:00 -05:00
}
2004-06-02 03:44:43 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the next posts page link .
2008-10-13 18:00:07 -04:00
*
* Backported from 2.1 . 3 to 2.0 . 10.
*
* @ since 2.0 . 10
*
2015-05-26 14:44:25 -04:00
* @ global int $paged
*
2016-04-20 02:32:29 -04:00
* @ param int $max_page Optional . Max pages . Default 0.
2015-05-26 14:44:25 -04:00
* @ return string | void The link URL for next posts page .
2008-10-13 18:00:07 -04:00
*/
2017-11-30 18:11:00 -05:00
function get_next_posts_page_link ( $max_page = 0 ) {
2007-12-06 14:49:33 -05:00
global $paged ;
2005-10-17 19:41:28 -04:00
2017-11-30 18:11:00 -05:00
if ( ! is_single () ) {
if ( ! $paged ) {
2005-10-17 19:41:28 -04:00
$paged = 1 ;
2017-11-30 18:11:00 -05:00
}
2023-02-18 10:09:18 -05:00
$next_page = ( int ) $paged + 1 ;
if ( ! $max_page || $max_page >= $next_page ) {
return get_pagenum_link ( $next_page );
2017-11-30 18:11:00 -05:00
}
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays or retrieves the next posts page link .
2008-10-13 18:00:07 -04:00
*
* @ since 0.71
*
2020-07-23 17:11:05 -04:00
* @ param int $max_page Optional . Max pages . Default 0.
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param bool $display Optional . Whether to echo the link . Default true .
* @ return string | void The link URL for next posts page if `$display = false` .
2008-10-13 18:00:07 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
function next_posts ( $max_page = 0 , $display = true ) {
2009-05-18 12:00:33 -04:00
$output = esc_url ( get_next_posts_page_link ( $max_page ) );
2008-11-12 05:13:50 -05:00
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
if ( $display ) {
2008-11-12 05:13:50 -05:00
echo $output ;
2017-11-30 18:11:00 -05:00
} else {
2008-11-12 05:13:50 -05:00
return $output ;
2017-11-30 18:11:00 -05:00
}
2007-03-16 04:04:24 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the next posts page link .
2008-10-13 18:00:07 -04:00
*
2008-11-12 05:13:50 -05:00
* @ since 2.7 . 0
2008-10-13 18:00:07 -04:00
*
2015-05-26 14:44:25 -04:00
* @ global int $paged
2019-08-03 21:59:56 -04:00
* @ global WP_Query $wp_query WordPress Query object .
2015-05-26 14:44:25 -04:00
*
* @ param string $label Content for link text .
2016-04-20 02:32:29 -04:00
* @ param int $max_page Optional . Max pages . Default 0.
2015-05-26 14:44:25 -04:00
* @ return string | void HTML - formatted next posts page link .
2008-10-13 18:00:07 -04:00
*/
2011-04-27 17:25:09 -04:00
function get_next_posts_link ( $label = null , $max_page = 0 ) {
2007-12-06 14:49:33 -05:00
global $paged , $wp_query ;
2008-11-12 05:13:50 -05:00
2017-11-30 18:11:00 -05:00
if ( ! $max_page ) {
2006-11-08 16:22:35 -05:00
$max_page = $wp_query -> max_num_pages ;
2017-11-30 18:11:00 -05:00
}
2008-11-12 05:13:50 -05:00
2017-11-30 18:11:00 -05:00
if ( ! $paged ) {
2005-10-17 19:41:28 -04:00
$paged = 1 ;
2017-11-30 18:11:00 -05:00
}
2008-11-12 05:13:50 -05:00
2023-02-18 10:09:18 -05:00
$next_page = ( int ) $paged + 1 ;
2011-06-10 19:01:45 -04:00
2017-11-30 18:11:00 -05:00
if ( null === $label ) {
2011-04-27 17:25:09 -04:00
$label = __ ( 'Next Page »' );
2017-11-30 18:11:00 -05:00
}
2008-11-12 05:13:50 -05:00
2023-02-18 10:09:18 -05:00
if ( ! is_single () && ( $next_page <= $max_page ) ) {
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the anchor tag attributes for the next posts page link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $attributes Attributes for the anchor tag .
*/
2008-07-30 03:01:03 -04:00
$attr = apply_filters ( 'next_posts_link_attributes' , '' );
2014-04-13 22:13:16 -04:00
2023-02-18 10:09:18 -05:00
return sprintf (
'<a href="%1$s" %2$s>%3$s</a>' ,
next_posts ( $max_page , false ),
$attr ,
preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label )
);
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-11-12 05:13:50 -05:00
/**
2016-04-15 12:58:27 -04:00
* Displays the next posts page link .
2008-11-12 05:13:50 -05:00
*
* @ since 0.71
*
2015-05-26 14:44:25 -04:00
* @ param string $label Content for link text .
2016-04-20 02:32:29 -04:00
* @ param int $max_page Optional . Max pages . Default 0.
2008-11-12 05:13:50 -05:00
*/
2011-04-27 17:25:09 -04:00
function next_posts_link ( $label = null , $max_page = 0 ) {
2008-11-12 05:13:50 -05:00
echo get_next_posts_link ( $label , $max_page );
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the previous posts page link .
2008-10-21 23:08:33 -04:00
*
* Will only return string , if not on a single page or post .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* Backported to 2.0 . 10 from 2.1 . 3.
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* @ since 2.0 . 10
2008-10-13 18:00:07 -04:00
*
2015-05-26 14:44:25 -04:00
* @ global int $paged
*
* @ return string | void The link for the previous posts page .
2008-10-13 18:00:07 -04:00
*/
2007-03-16 04:04:24 -04:00
function get_previous_posts_page_link () {
2007-12-06 14:49:33 -05:00
global $paged ;
2004-06-02 03:44:43 -04:00
2017-11-30 18:11:00 -05:00
if ( ! is_single () ) {
2023-02-18 10:09:18 -05:00
$previous_page = ( int ) $paged - 1 ;
if ( $previous_page < 1 ) {
$previous_page = 1 ;
2017-11-30 18:11:00 -05:00
}
2023-02-18 10:09:18 -05:00
return get_pagenum_link ( $previous_page );
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays or retrieves the previous posts page link .
2008-10-13 18:00:07 -04:00
*
* @ since 0.71
2008-11-12 05:13:50 -05:00
*
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param bool $display Optional . Whether to echo the link . Default true .
* @ return string | void The previous posts page link if `$display = false` .
2008-10-13 18:00:07 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
function previous_posts ( $display = true ) {
2009-05-18 12:00:33 -04:00
$output = esc_url ( get_previous_posts_page_link () );
2008-11-12 05:13:50 -05:00
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
if ( $display ) {
2008-11-12 05:13:50 -05:00
echo $output ;
2017-11-30 18:11:00 -05:00
} else {
2008-11-12 05:13:50 -05:00
return $output ;
2017-11-30 18:11:00 -05:00
}
2007-03-16 04:04:24 -04:00
}
2005-10-17 19:41:28 -04:00
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the previous posts page link .
2008-10-13 18:00:07 -04:00
*
2008-11-12 05:13:50 -05:00
* @ since 2.7 . 0
2008-10-13 18:00:07 -04:00
*
2015-05-26 14:44:25 -04:00
* @ global int $paged
*
2008-10-21 23:08:33 -04:00
* @ param string $label Optional . Previous page link text .
2015-05-26 14:44:25 -04:00
* @ return string | void HTML - formatted previous page link .
2008-10-13 18:00:07 -04:00
*/
2011-04-27 17:25:09 -04:00
function get_previous_posts_link ( $label = null ) {
2005-10-17 19:41:28 -04:00
global $paged ;
2008-11-12 05:13:50 -05:00
2017-11-30 18:11:00 -05:00
if ( null === $label ) {
2011-04-27 17:25:09 -04:00
$label = __ ( '« Previous Page' );
2017-11-30 18:11:00 -05:00
}
2011-04-27 17:25:09 -04:00
2017-11-30 18:11:00 -05:00
if ( ! is_single () && $paged > 1 ) {
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the anchor tag attributes for the previous posts page link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $attributes Attributes for the anchor tag .
*/
2008-07-30 03:01:03 -04:00
$attr = apply_filters ( 'previous_posts_link_attributes' , '' );
2023-02-18 10:09:18 -05:00
return sprintf (
'<a href="%1$s" %2$s>%3$s</a>' ,
previous_posts ( false ),
$attr ,
preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label )
);
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-11-12 05:13:50 -05:00
/**
2016-04-15 12:58:27 -04:00
* Displays the previous posts page link .
2008-11-12 05:13:50 -05:00
*
* @ since 0.71
*
* @ param string $label Optional . Previous page link text .
*/
2011-04-27 17:25:09 -04:00
function previous_posts_link ( $label = null ) {
2008-11-12 05:13:50 -05:00
echo get_previous_posts_link ( $label );
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the post pages link navigation for previous and next pages .
2008-10-13 18:00:07 -04:00
*
2013-12-24 13:57:12 -05:00
* @ since 2.8 . 0
2008-10-13 18:00:07 -04:00
*
2019-08-03 21:59:56 -04:00
* @ global WP_Query $wp_query WordPress Query object .
2015-05-26 14:44:25 -04:00
*
2016-04-20 02:32:29 -04:00
* @ param string | array $args {
* Optional . Arguments to build the post pages link navigation .
*
* @ type string $sep Separator character . Default '—' .
* @ type string $prelabel Link text to display for the previous page link .
* Default '« Previous Page' .
* @ type string $nxtlabel Link text to display for the next page link .
* Default 'Next Page »' .
* }
2009-05-24 19:47:49 -04:00
* @ return string The posts link navigation .
2008-10-13 18:00:07 -04:00
*/
2009-04-22 04:44:37 -04:00
function get_posts_nav_link ( $args = array () ) {
2006-11-08 16:22:35 -05:00
global $wp_query ;
2009-05-24 19:47:49 -04:00
2009-04-22 04:44:37 -04:00
$return = '' ;
2017-11-30 18:11:00 -05:00
if ( ! is_singular () ) {
2009-04-22 04:44:37 -04:00
$defaults = array (
2017-11-30 18:11:00 -05:00
'sep' => ' — ' ,
'prelabel' => __ ( '« Previous Page' ),
'nxtlabel' => __ ( 'Next Page »' ),
2009-04-22 04:44:37 -04:00
);
2017-11-30 18:11:00 -05:00
$args = wp_parse_args ( $args , $defaults );
2009-04-22 04:44:37 -04:00
2006-11-08 16:22:35 -05:00
$max_num_pages = $wp_query -> max_num_pages ;
2017-11-30 18:11:00 -05:00
$paged = get_query_var ( 'paged' );
2006-11-19 02:56:05 -05:00
2020-01-28 19:45:18 -05:00
// Only have sep if there's both prev and next results.
2017-11-30 18:11:00 -05:00
if ( $paged < 2 || $paged >= $max_num_pages ) {
2009-04-22 04:44:37 -04:00
$args [ 'sep' ] = '' ;
2004-10-12 09:04:35 -04:00
}
2004-08-16 18:50:06 -04:00
2005-10-17 19:41:28 -04:00
if ( $max_num_pages > 1 ) {
2017-11-30 18:11:00 -05:00
$return = get_previous_posts_link ( $args [ 'prelabel' ] );
$return .= preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $args [ 'sep' ] );
$return .= get_next_posts_link ( $args [ 'nxtlabel' ] );
2005-10-17 19:41:28 -04:00
}
}
2009-04-22 04:44:37 -04:00
return $return ;
}
/**
2016-04-15 12:58:27 -04:00
* Displays the post pages link navigation for previous and next pages .
2009-04-22 04:44:37 -04:00
*
* @ since 0.71
*
2016-04-20 02:32:29 -04:00
* @ param string $sep Optional . Separator for posts navigation links . Default empty .
* @ param string $prelabel Optional . Label for previous pages . Default empty .
* @ param string $nxtlabel Optional Label for next pages . Default empty .
2009-04-22 04:44:37 -04:00
*/
function posts_nav_link ( $sep = '' , $prelabel = '' , $nxtlabel = '' ) {
2017-11-30 18:11:00 -05:00
$args = array_filter ( compact ( 'sep' , 'prelabel' , 'nxtlabel' ) );
echo get_posts_nav_link ( $args );
2004-06-02 03:44:43 -04:00
}
2014-10-28 15:39:24 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the navigation to next / previous post , when applicable .
2014-10-28 15:39:24 -04:00
*
* @ since 4.1 . 0
2015-09-29 23:41:26 -04:00
* @ since 4.4 . 0 Introduced the `in_same_term` , `excluded_terms` , and `taxonomy` arguments .
2019-09-22 18:32:59 -04:00
* @ since 5.3 . 0 Added the `aria_label` parameter .
2020-07-07 10:16:03 -04:00
* @ since 5.5 . 0 Added the `class` parameter .
2014-10-28 15:39:24 -04:00
*
* @ param array $args {
2014-11-28 06:57:24 -05:00
* Optional . Default post navigation arguments . Default empty array .
2014-10-28 15:39:24 -04:00
*
2022-11-14 19:34:12 -05:00
* @ type string $prev_text Anchor text to display in the previous post link .
* Default '%title' .
* @ type string $next_text Anchor text to display in the next post link .
* Default '%title' .
* @ type bool $in_same_term Whether link should be in the same taxonomy term .
* Default false .
* @ type int [] | string $excluded_terms Array or comma - separated list of excluded term IDs .
* Default empty .
2015-09-29 23:41:26 -04:00
* @ type string $taxonomy Taxonomy , if `$in_same_term` is true . Default 'category' .
2022-11-14 19:34:12 -05:00
* @ type string $screen_reader_text Screen reader text for the nav element .
* Default 'Post navigation' .
2019-09-22 18:32:59 -04:00
* @ type string $aria_label ARIA label text for the nav element . Default 'Posts' .
2020-07-07 10:16:03 -04:00
* @ type string $class Custom class for the nav element . Default 'post-navigation' .
2014-10-28 15:39:24 -04:00
* }
* @ return string Markup for post links .
*/
function get_the_post_navigation ( $args = array () ) {
2019-09-22 18:32:59 -04:00
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty ( $args [ 'screen_reader_text' ] ) && empty ( $args [ 'aria_label' ] ) ) {
$args [ 'aria_label' ] = $args [ 'screen_reader_text' ];
}
2017-11-30 18:11:00 -05:00
$args = wp_parse_args (
2018-08-16 21:51:36 -04:00
$args ,
array (
2017-11-30 18:11:00 -05:00
'prev_text' => '%title' ,
'next_text' => '%title' ,
'in_same_term' => false ,
'excluded_terms' => '' ,
'taxonomy' => 'category' ,
'screen_reader_text' => __ ( 'Post navigation' ),
2019-09-22 18:32:59 -04:00
'aria_label' => __ ( 'Posts' ),
2020-07-07 10:16:03 -04:00
'class' => 'post-navigation' ,
2017-11-30 18:11:00 -05:00
)
);
2014-10-28 15:39:24 -04:00
$navigation = '' ;
2015-09-29 23:41:26 -04:00
$previous = get_previous_post_link (
'<div class="nav-previous">%link</div>' ,
$args [ 'prev_text' ],
$args [ 'in_same_term' ],
$args [ 'excluded_terms' ],
$args [ 'taxonomy' ]
);
$next = get_next_post_link (
'<div class="nav-next">%link</div>' ,
$args [ 'next_text' ],
$args [ 'in_same_term' ],
$args [ 'excluded_terms' ],
$args [ 'taxonomy' ]
);
2014-10-28 15:39:24 -04:00
// Only add markup if there's somewhere to navigate to.
2014-11-20 10:19:24 -05:00
if ( $previous || $next ) {
2020-07-07 10:16:03 -04:00
$navigation = _navigation_markup ( $previous . $next , $args [ 'class' ], $args [ 'screen_reader_text' ], $args [ 'aria_label' ] );
2014-10-28 15:39:24 -04:00
}
return $navigation ;
}
/**
2016-04-15 12:58:27 -04:00
* Displays the navigation to next / previous post , when applicable .
2014-10-28 15:39:24 -04:00
*
* @ since 4.1 . 0
*
2016-04-20 02:32:29 -04:00
* @ param array $args Optional . See get_the_post_navigation () for available arguments .
* Default empty array .
2014-10-28 15:39:24 -04:00
*/
function the_post_navigation ( $args = array () ) {
echo get_the_post_navigation ( $args );
}
/**
2016-04-15 12:58:27 -04:00
* Returns the navigation to next / previous set of posts , when applicable .
2014-10-28 15:39:24 -04:00
*
* @ since 4.1 . 0
2019-09-22 18:32:59 -04:00
* @ since 5.3 . 0 Added the `aria_label` parameter .
2020-07-07 10:16:03 -04:00
* @ since 5.5 . 0 Added the `class` parameter .
2014-10-28 15:39:24 -04:00
*
* @ global WP_Query $wp_query WordPress Query object .
*
* @ param array $args {
2014-12-11 05:23:24 -05:00
* Optional . Default posts navigation arguments . Default empty array .
2014-11-28 06:57:24 -05:00
*
* @ type string $prev_text Anchor text to display in the previous posts link .
* Default 'Older posts' .
* @ type string $next_text Anchor text to display in the next posts link .
* Default 'Newer posts' .
2019-09-22 18:32:59 -04:00
* @ type string $screen_reader_text Screen reader text for the nav element .
2014-11-28 06:57:24 -05:00
* Default 'Posts navigation' .
2019-09-22 18:32:59 -04:00
* @ type string $aria_label ARIA label text for the nav element . Default 'Posts' .
2020-07-07 10:16:03 -04:00
* @ type string $class Custom class for the nav element . Default 'posts-navigation' .
2014-10-28 15:39:24 -04:00
* }
2014-12-11 05:23:24 -05:00
* @ return string Markup for posts links .
2014-10-28 15:39:24 -04:00
*/
function get_the_posts_navigation ( $args = array () ) {
2022-06-18 11:38:15 -04:00
global $wp_query ;
2014-10-28 15:39:24 -04:00
$navigation = '' ;
// Don't print empty markup if there's only one page.
2022-06-18 11:38:15 -04:00
if ( $wp_query -> max_num_pages > 1 ) {
2019-09-22 18:32:59 -04:00
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty ( $args [ 'screen_reader_text' ] ) && empty ( $args [ 'aria_label' ] ) ) {
$args [ 'aria_label' ] = $args [ 'screen_reader_text' ];
}
2017-11-30 18:11:00 -05:00
$args = wp_parse_args (
2018-08-16 21:51:36 -04:00
$args ,
array (
2017-11-30 18:11:00 -05:00
'prev_text' => __ ( 'Older posts' ),
'next_text' => __ ( 'Newer posts' ),
'screen_reader_text' => __ ( 'Posts navigation' ),
2019-09-22 18:32:59 -04:00
'aria_label' => __ ( 'Posts' ),
2020-07-07 10:16:03 -04:00
'class' => 'posts-navigation' ,
2017-11-30 18:11:00 -05:00
)
);
2014-10-28 15:39:24 -04:00
2014-11-20 10:19:24 -05:00
$next_link = get_previous_posts_link ( $args [ 'next_text' ] );
$prev_link = get_next_posts_link ( $args [ 'prev_text' ] );
2014-10-28 15:39:24 -04:00
2014-11-20 10:19:24 -05:00
if ( $prev_link ) {
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>' ;
2014-10-28 15:39:24 -04:00
}
2014-11-20 10:19:24 -05:00
if ( $next_link ) {
$navigation .= '<div class="nav-next">' . $next_link . '</div>' ;
2014-10-28 15:39:24 -04:00
}
2020-07-07 10:16:03 -04:00
$navigation = _navigation_markup ( $navigation , $args [ 'class' ], $args [ 'screen_reader_text' ], $args [ 'aria_label' ] );
2014-10-28 15:39:24 -04:00
}
return $navigation ;
}
/**
2016-04-15 12:58:27 -04:00
* Displays the navigation to next / previous set of posts , when applicable .
2014-10-28 15:39:24 -04:00
*
* @ since 4.1 . 0
*
2016-04-20 02:32:29 -04:00
* @ param array $args Optional . See get_the_posts_navigation () for available arguments .
* Default empty array .
2014-10-28 15:39:24 -04:00
*/
function the_posts_navigation ( $args = array () ) {
echo get_the_posts_navigation ( $args );
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves a paginated navigation to next / previous set of posts , when applicable .
2014-10-28 15:39:24 -04:00
*
* @ since 4.1 . 0
2019-09-22 18:32:59 -04:00
* @ since 5.3 . 0 Added the `aria_label` parameter .
2020-07-07 10:16:03 -04:00
* @ since 5.5 . 0 Added the `class` parameter .
2014-10-28 15:39:24 -04:00
*
2022-06-18 11:38:15 -04:00
* @ global WP_Query $wp_query WordPress Query object .
*
2014-10-28 15:39:24 -04:00
* @ param array $args {
2016-04-20 02:32:29 -04:00
* Optional . Default pagination arguments , see paginate_links () .
2014-11-20 10:19:24 -05:00
*
2014-11-28 06:57:24 -05:00
* @ type string $screen_reader_text Screen reader text for navigation element .
* Default 'Posts navigation' .
2019-09-22 18:32:59 -04:00
* @ type string $aria_label ARIA label text for the nav element . Default 'Posts' .
2020-07-07 10:16:03 -04:00
* @ type string $class Custom class for the nav element . Default 'pagination' .
2014-10-28 15:39:24 -04:00
* }
* @ return string Markup for pagination links .
*/
2014-12-11 05:23:24 -05:00
function get_the_posts_pagination ( $args = array () ) {
2022-06-18 11:38:15 -04:00
global $wp_query ;
2014-10-28 15:39:24 -04:00
$navigation = '' ;
// Don't print empty markup if there's only one page.
2022-06-18 11:38:15 -04:00
if ( $wp_query -> max_num_pages > 1 ) {
2019-09-22 18:32:59 -04:00
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty ( $args [ 'screen_reader_text' ] ) && empty ( $args [ 'aria_label' ] ) ) {
$args [ 'aria_label' ] = $args [ 'screen_reader_text' ];
}
2017-11-30 18:11:00 -05:00
$args = wp_parse_args (
2018-08-16 21:51:36 -04:00
$args ,
array (
2017-11-30 18:11:00 -05:00
'mid_size' => 1 ,
'prev_text' => _x ( 'Previous' , 'previous set of posts' ),
'next_text' => _x ( 'Next' , 'next set of posts' ),
'screen_reader_text' => __ ( 'Posts navigation' ),
2019-09-22 18:32:59 -04:00
'aria_label' => __ ( 'Posts' ),
2020-07-07 10:16:03 -04:00
'class' => 'pagination' ,
2017-11-30 18:11:00 -05:00
)
);
2014-12-11 04:39:23 -05:00
2022-09-13 14:05:09 -04:00
/**
* Filters the arguments for posts pagination links .
*
* @ since 6.1 . 0
*
* @ param array $args {
* Optional . Default pagination arguments , see paginate_links () .
*
* @ type string $screen_reader_text Screen reader text for navigation element .
* Default 'Posts navigation' .
* @ type string $aria_label ARIA label text for the nav element . Default 'Posts' .
* @ type string $class Custom class for the nav element . Default 'pagination' .
* }
*/
$args = apply_filters ( 'the_posts_pagination_args' , $args );
2014-12-11 04:39:23 -05:00
// Make sure we get a string back. Plain is the next best thing.
2020-05-16 14:42:12 -04:00
if ( isset ( $args [ 'type' ] ) && 'array' === $args [ 'type' ] ) {
2014-12-11 04:39:23 -05:00
$args [ 'type' ] = 'plain' ;
}
2014-10-28 15:39:24 -04:00
// Set up paginated links.
$links = paginate_links ( $args );
2014-11-20 10:19:24 -05:00
if ( $links ) {
2020-07-07 10:16:03 -04:00
$navigation = _navigation_markup ( $links , $args [ 'class' ], $args [ 'screen_reader_text' ], $args [ 'aria_label' ] );
2014-10-28 15:39:24 -04:00
}
}
return $navigation ;
}
/**
2016-04-15 12:58:27 -04:00
* Displays a paginated navigation to next / previous set of posts , when applicable .
2014-10-28 15:39:24 -04:00
*
* @ since 4.1 . 0
*
2016-04-20 02:32:29 -04:00
* @ param array $args Optional . See get_the_posts_pagination () for available arguments .
2014-11-28 06:57:24 -05:00
* Default empty array .
2014-10-28 15:39:24 -04:00
*/
2014-12-11 05:23:24 -05:00
function the_posts_pagination ( $args = array () ) {
echo get_the_posts_pagination ( $args );
2014-10-28 15:39:24 -04:00
}
/**
* Wraps passed links in navigational markup .
*
* @ since 4.1 . 0
2019-09-22 18:32:59 -04:00
* @ since 5.3 . 0 Added the `aria_label` parameter .
2014-10-28 15:39:24 -04:00
* @ access private
*
* @ param string $links Navigational links .
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param string $css_class Optional . Custom class for the nav element .
2020-07-07 10:16:03 -04:00
* Default 'posts-navigation' .
* @ param string $screen_reader_text Optional . Screen reader text for the nav element .
* Default 'Posts navigation' .
* @ param string $aria_label Optional . ARIA label for the nav element .
* Defaults to the value of `$screen_reader_text` .
2014-10-28 15:39:24 -04:00
* @ return string Navigation template tag .
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
function _navigation_markup ( $links , $css_class = 'posts-navigation' , $screen_reader_text = '' , $aria_label = '' ) {
2014-10-28 15:39:24 -04:00
if ( empty ( $screen_reader_text ) ) {
I18N: Mark screen reader strings as such with translator comments.
This aims to provide better context for translators and make it easier to determine that some strings contain hidden accessibility text and are not displayed in the UI.
Props kebbet, mercime, pavelevap, ocean90, swissspidy, Chouby, jipmoors, afercia, desrosj, costdev, audrasjb, SergeyBiryukov.
Fixes #29748.
Built from https://develop.svn.wordpress.org/trunk@55276
git-svn-id: http://core.svn.wordpress.org/trunk@54809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-07 12:10:21 -05:00
$screen_reader_text = /* translators: Hidden accessibility text. */ __ ( 'Posts navigation' );
2014-10-28 15:39:24 -04:00
}
2019-09-22 18:32:59 -04:00
if ( empty ( $aria_label ) ) {
$aria_label = $screen_reader_text ;
}
2014-10-28 15:39:24 -04:00
$template = '
2021-11-01 17:47:13 -04:00
< nav class = " navigation %1 $s " aria - label = " %4 $s " >
2014-11-20 10:19:24 -05:00
< h2 class = " screen-reader-text " >% 2 $s </ h2 >
2014-10-28 15:39:24 -04:00
< div class = " nav-links " >% 3 $s </ div >
</ nav > ' ;
2015-08-23 12:34:26 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the navigation markup template .
2015-08-23 12:34:26 -04:00
*
2015-08-23 14:08:25 -04:00
* Note : The filtered template HTML must contain specifiers for the navigation
2019-09-22 18:32:59 -04:00
* class ( % 1 $ s ), the screen - reader - text value ( % 2 $s ), placement of the navigation
* links ( % 3 $s ), and ARIA label text if screen - reader - text does not fit that ( % 4 $s ) :
2015-08-23 14:08:25 -04:00
*
2021-11-01 17:47:13 -04:00
* < nav class = " navigation %1 $s " aria - label = " %4 $s " >
2015-08-23 14:08:25 -04:00
* < h2 class = " screen-reader-text " >% 2 $s </ h2 >
* < div class = " nav-links " >% 3 $s </ div >
* </ nav >
*
2015-08-23 12:34:26 -04:00
* @ since 4.4 . 0
*
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
* @ param string $template The default template .
* @ param string $css_class The class passed by the calling function .
2015-08-23 12:34:26 -04:00
* @ return string Navigation template .
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/link-template.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$string` parameter to `$url` in `user_trailingslashit()`.
* Renames the `$echo` parameter to `$display` in:
* `edit_term_link()`
* `next_posts()`
* `previous_posts()`
* Renames the `$class` parameter to `$css_class` in:
* `edit_post_link()`
* `_navigation_markup()`
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54943
git-svn-id: http://core.svn.wordpress.org/trunk@54495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-06 16:18:15 -05:00
$template = apply_filters ( 'navigation_markup_template' , $template , $css_class );
2015-08-23 12:34:26 -04:00
2023-05-27 05:53:25 -04:00
return sprintf ( $template , sanitize_html_class ( $css_class ), esc_html ( $screen_reader_text ), $links , esc_attr ( $aria_label ) );
2014-10-28 15:39:24 -04:00
}
2008-10-21 23:08:33 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the comments page number link .
2008-10-21 23:08:33 -04:00
*
* @ since 2.7 . 0
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-20 10:37:29 -04:00
* @ param int $pagenum Optional . Page number . Default 1.
* @ param int $max_page Optional . The maximum number of comment pages . Default 0.
2014-11-29 23:44:23 -05:00
* @ return string The comments page number link URL .
2008-10-21 23:08:33 -04:00
*/
2008-10-23 12:08:47 -04:00
function get_comments_pagenum_link ( $pagenum = 1 , $max_page = 0 ) {
2012-09-04 12:29:28 -04:00
global $wp_rewrite ;
2008-09-23 17:11:27 -04:00
$pagenum = ( int ) $pagenum ;
2012-09-04 12:29:28 -04:00
$result = get_permalink ();
2008-09-23 17:11:27 -04:00
2020-05-16 14:42:12 -04:00
if ( 'newest' === get_option ( 'default_comments_page' ) ) {
2008-10-24 03:36:43 -04:00
if ( $pagenum != $max_page ) {
2017-11-30 18:11:00 -05:00
if ( $wp_rewrite -> using_permalinks () ) {
$result = user_trailingslashit ( trailingslashit ( $result ) . $wp_rewrite -> comments_pagination_base . '-' . $pagenum , 'commentpaged' );
} else {
2008-11-21 12:33:05 -05:00
$result = add_query_arg ( 'cpage' , $pagenum , $result );
2017-11-30 18:11:00 -05:00
}
2008-10-24 03:36:43 -04:00
}
} elseif ( $pagenum > 1 ) {
2017-11-30 18:11:00 -05:00
if ( $wp_rewrite -> using_permalinks () ) {
$result = user_trailingslashit ( trailingslashit ( $result ) . $wp_rewrite -> comments_pagination_base . '-' . $pagenum , 'commentpaged' );
} else {
2008-11-21 12:33:05 -05:00
$result = add_query_arg ( 'cpage' , $pagenum , $result );
2017-11-30 18:11:00 -05:00
}
2008-10-24 03:36:43 -04:00
}
2008-09-23 17:11:27 -04:00
2008-10-07 18:41:51 -04:00
$result .= '#comments' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the comments page number link for the current request .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $result The comments page number link .
*/
2015-05-26 14:44:25 -04:00
return apply_filters ( 'get_comments_pagenum_link' , $result );
2008-09-23 17:11:27 -04:00
}
2008-10-21 23:08:33 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the link to the next comments page .
2008-10-21 23:08:33 -04:00
*
2008-12-22 14:33:09 -05:00
* @ since 2.7 . 1
2008-10-21 23:08:33 -04:00
*
2019-08-03 21:59:56 -04:00
* @ global WP_Query $wp_query WordPress Query object .
2015-05-26 14:44:25 -04:00
*
2016-04-20 10:37:29 -04:00
* @ param string $label Optional . Label for link text . Default empty .
* @ param int $max_page Optional . Max page . Default 0.
2015-05-26 14:44:25 -04:00
* @ return string | void HTML - formatted link for the next page of comments .
2008-10-21 23:08:33 -04:00
*/
2008-12-22 14:33:09 -05:00
function get_next_comments_link ( $label = '' , $max_page = 0 ) {
2008-09-23 17:11:27 -04:00
global $wp_query ;
2017-11-30 18:11:00 -05:00
if ( ! is_singular () ) {
2008-09-23 17:11:27 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-09-23 17:11:27 -04:00
2017-11-30 18:11:00 -05:00
$page = get_query_var ( 'cpage' );
2008-10-24 03:36:43 -04:00
2015-03-04 22:57:24 -05:00
if ( ! $page ) {
$page = 1 ;
}
2023-02-18 10:09:18 -05:00
$next_page = ( int ) $page + 1 ;
2008-09-23 17:11:27 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $max_page ) ) {
2008-09-23 17:11:27 -04:00
$max_page = $wp_query -> max_num_comment_pages ;
2017-11-30 18:11:00 -05:00
}
2008-09-23 17:11:27 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $max_page ) ) {
2008-12-06 23:49:22 -05:00
$max_page = get_comment_pages_count ();
2017-11-30 18:11:00 -05:00
}
2008-12-06 23:49:22 -05:00
2023-02-18 10:09:18 -05:00
if ( $next_page > $max_page ) {
2008-09-23 17:11:27 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-09-23 17:11:27 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $label ) ) {
$label = __ ( 'Newer Comments »' );
}
2008-09-23 17:11:27 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the anchor tag attributes for the next comments page link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $attributes Attributes for the anchor tag .
*/
2023-02-18 10:09:18 -05:00
$attr = apply_filters ( 'next_comments_link_attributes' , '' );
return sprintf (
'<a href="%1$s" %2$s>%3$s</a>' ,
esc_url ( get_comments_pagenum_link ( $next_page , $max_page ) ),
$attr ,
preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label )
);
2008-09-23 17:11:27 -04:00
}
2008-10-21 23:08:33 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays the link to the next comments page .
2008-10-21 23:08:33 -04:00
*
* @ since 2.7 . 0
*
2016-04-20 10:37:29 -04:00
* @ param string $label Optional . Label for link text . Default empty .
* @ param int $max_page Optional . Max page . Default 0.
2008-10-21 23:08:33 -04:00
*/
2008-12-22 14:33:09 -05:00
function next_comments_link ( $label = '' , $max_page = 0 ) {
echo get_next_comments_link ( $label , $max_page );
}
2008-09-23 17:11:27 -04:00
2008-12-22 14:33:09 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the link to the previous comments page .
2008-12-22 14:33:09 -05:00
*
* @ since 2.7 . 1
*
2016-04-20 10:37:29 -04:00
* @ param string $label Optional . Label for comments link text . Default empty .
2015-05-26 14:44:25 -04:00
* @ return string | void HTML - formatted link for the previous page of comments .
2008-12-22 14:33:09 -05:00
*/
function get_previous_comments_link ( $label = '' ) {
2017-11-30 18:11:00 -05:00
if ( ! is_singular () ) {
2008-09-23 17:11:27 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-09-23 17:11:27 -04:00
2017-11-30 18:11:00 -05:00
$page = get_query_var ( 'cpage' );
2008-09-23 17:11:27 -04:00
2020-10-08 17:15:13 -04:00
if ( ( int ) $page <= 1 ) {
2008-09-23 17:11:27 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-09-23 17:11:27 -04:00
2023-02-18 10:09:18 -05:00
$previous_page = ( int ) $page - 1 ;
2008-09-23 17:11:27 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $label ) ) {
$label = __ ( '« Older Comments' );
}
2008-09-23 17:11:27 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-05-22 14:27:27 -04:00
* Filters the anchor tag attributes for the previous comments page link .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $attributes Attributes for the anchor tag .
*/
2023-02-18 10:09:18 -05:00
$attr = apply_filters ( 'previous_comments_link_attributes' , '' );
return sprintf (
'<a href="%1$s" %2$s>%3$s</a>' ,
esc_url ( get_comments_pagenum_link ( $previous_page ) ),
$attr ,
preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label )
);
2008-12-22 14:33:09 -05:00
}
/**
2016-04-15 12:58:27 -04:00
* Displays the link to the previous comments page .
2008-12-22 14:33:09 -05:00
*
* @ since 2.7 . 0
*
2016-04-20 10:37:29 -04:00
* @ param string $label Optional . Label for comments link text . Default empty .
2008-12-22 14:33:09 -05:00
*/
function previous_comments_link ( $label = '' ) {
echo get_previous_comments_link ( $label );
2008-09-23 17:11:27 -04:00
}
2008-10-21 23:08:33 -04:00
/**
2016-04-15 12:58:27 -04:00
* Displays or retrieves pagination links for the comments on the current post .
2008-10-07 18:41:51 -04:00
*
2008-10-21 23:08:33 -04:00
* @ see paginate_links ()
* @ since 2.7 . 0
2008-10-07 18:41:51 -04:00
*
2019-08-03 21:19:56 -04:00
* @ global WP_Rewrite $wp_rewrite WordPress rewrite component .
2015-05-26 14:44:25 -04:00
*
2016-04-20 10:37:29 -04:00
* @ param string | array $args Optional args . See paginate_links () . Default empty array .
2020-01-11 13:32:05 -05:00
* @ return void | string | array Void if 'echo' argument is true and 'type' is not an array ,
* or if the query is not for an existing single post of any post type .
* Otherwise , markup for comment page links or array of comment page links ,
* depending on 'type' argument .
2015-12-12 10:37:28 -05:00
*/
2016-04-20 10:37:29 -04:00
function paginate_comments_links ( $args = array () ) {
2010-02-19 21:01:46 -05:00
global $wp_rewrite ;
2008-10-07 18:41:51 -04:00
2017-11-30 18:11:00 -05:00
if ( ! is_singular () ) {
2008-10-07 18:41:51 -04:00
return ;
2017-11-30 18:11:00 -05:00
}
2008-10-07 18:41:51 -04:00
2017-11-30 18:11:00 -05:00
$page = get_query_var ( 'cpage' );
if ( ! $page ) {
2008-10-07 18:41:51 -04:00
$page = 1 ;
2017-11-30 18:11:00 -05:00
}
2008-12-06 23:49:22 -05:00
$max_page = get_comment_pages_count ();
2008-10-07 18:41:51 -04:00
$defaults = array (
2017-11-30 18:11:00 -05:00
'base' => add_query_arg ( 'cpage' , '%#%' ),
'format' => '' ,
'total' => $max_page ,
'current' => $page ,
'echo' => true ,
2018-02-25 11:08:30 -05:00
'type' => 'plain' ,
2017-11-30 18:11:00 -05:00
'add_fragment' => '#comments' ,
2008-10-07 18:41:51 -04:00
);
2017-11-30 18:11:00 -05:00
if ( $wp_rewrite -> using_permalinks () ) {
$defaults [ 'base' ] = user_trailingslashit ( trailingslashit ( get_permalink () ) . $wp_rewrite -> comments_pagination_base . '-%#%' , 'commentpaged' );
}
2008-10-23 14:55:22 -04:00
2017-11-30 18:11:00 -05:00
$args = wp_parse_args ( $args , $defaults );
2008-10-07 18:41:51 -04:00
$page_links = paginate_links ( $args );
2018-02-12 16:12:35 -05:00
if ( $args [ 'echo' ] && 'array' !== $args [ 'type' ] ) {
2008-10-07 18:41:51 -04:00
echo $page_links ;
2017-11-30 18:11:00 -05:00
} else {
2008-10-07 18:41:51 -04:00
return $page_links ;
2017-11-30 18:11:00 -05:00
}
2008-10-07 18:41:51 -04:00
}
2015-09-21 12:32:26 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves navigation to next / previous set of comments , when applicable .
2015-09-21 12:32:26 -04:00
*
* @ since 4.4 . 0
2019-09-22 18:32:59 -04:00
* @ since 5.3 . 0 Added the `aria_label` parameter .
2020-07-07 10:16:03 -04:00
* @ since 5.5 . 0 Added the `class` parameter .
2015-09-21 12:32:26 -04:00
*
* @ param array $args {
* Optional . Default comments navigation arguments .
*
2016-04-20 10:37:29 -04:00
* @ type string $prev_text Anchor text to display in the previous comments link .
* Default 'Older comments' .
* @ type string $next_text Anchor text to display in the next comments link .
* Default 'Newer comments' .
2019-09-22 18:32:59 -04:00
* @ type string $screen_reader_text Screen reader text for the nav element . Default 'Comments navigation' .
* @ type string $aria_label ARIA label text for the nav element . Default 'Comments' .
2020-07-07 10:16:03 -04:00
* @ type string $class Custom class for the nav element . Default 'comment-navigation' .
2015-09-21 12:32:26 -04:00
* }
* @ return string Markup for comments links .
*/
function get_the_comments_navigation ( $args = array () ) {
$navigation = '' ;
// Are there comments to navigate through?
Force comment pagination on single posts.
Previously, the 'page_comments' toggle allowed users to disable comment
pagination. This toggle was only superficial, however. Even with
'page_comments' turned on, `comments_template()` loaded all of a post's
comments into memory, and passed them to `wp_list_comments()` and
`Walker_Comment`, the latter of which produced markup for only the
current page of comments. In other words, it was possible to enable
'page_comments', thereby showing only a subset of a post's comments on a given
page, but all comments continued to be loaded in the background. This technique
scaled poorly. Posts with hundreds or thousands of comments would load slowly,
or not at all, even when the 'comments_per_page' setting was set to a
reasonable number.
Recent changesets have addressed this problem through more efficient tree-
walking, better descendant caching, and more selective queries for top-level
post comments. The current changeset completes the project by addressing the
root issue: that loading a post causes all of its comments to be loaded too.
Here's the breakdown:
* Comment pagination is now forced. Setting 'page_comments' to false leads to evil things when you have many comments. If you want to avoid pagination, set 'comments_per_page' to something high.
* The 'page_comments' setting has been expunged from options-discussion.php, and from places in the codebase where it was referenced. For plugins relying on 'page_comments', we now force the value to `true` with a `pre_option` filter.
* `comments_template()` now queries for an appropriately small number of comments. Usually, this means the `comments_per_page` value.
* To preserve the current (odd) behavior for comment pagination links, some unholy hacks have been inserted into `comments_template()`. The ugliness is insulated in this function for backward compatibility and to minimize collateral damage. A side-effect is that, for certain settings of 'default_comments_page', up to 2x the value of `comments_per_page` might be fetched at a time.
* In support of these changes, a `$format` parameter has been added to `WP_Comment::get_children()`. This param allows you to request a flattened array of comment children, suitable for feeding into `Walker_Comment`.
* `WP_Query` loops are now informed about total available comment counts and comment pages by the `WP_Comment_Query` (`found_comments`, `max_num_pages`), instead of by `Walker_Comment`.
Aside from radical performance improvements in the case of a post with many
comments, this changeset fixes a bug that caused the first page of comments to
be partial (`found_comments` % `comments_per_page`), rather than the last, as
you'd expect.
Props boonebgorges, wonderboymusic.
Fixes #8071.
Built from https://develop.svn.wordpress.org/trunk@34561
git-svn-id: http://core.svn.wordpress.org/trunk@34525 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 16:40:25 -04:00
if ( get_comment_pages_count () > 1 ) {
2019-09-22 18:32:59 -04:00
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty ( $args [ 'screen_reader_text' ] ) && empty ( $args [ 'aria_label' ] ) ) {
$args [ 'aria_label' ] = $args [ 'screen_reader_text' ];
}
2017-11-30 18:11:00 -05:00
$args = wp_parse_args (
2018-08-16 21:51:36 -04:00
$args ,
array (
2017-11-30 18:11:00 -05:00
'prev_text' => __ ( 'Older comments' ),
'next_text' => __ ( 'Newer comments' ),
'screen_reader_text' => __ ( 'Comments navigation' ),
2019-09-22 18:32:59 -04:00
'aria_label' => __ ( 'Comments' ),
2020-07-07 10:16:03 -04:00
'class' => 'comment-navigation' ,
2017-11-30 18:11:00 -05:00
)
);
2015-09-21 12:32:26 -04:00
$prev_link = get_previous_comments_link ( $args [ 'prev_text' ] );
$next_link = get_next_comments_link ( $args [ 'next_text' ] );
if ( $prev_link ) {
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>' ;
}
if ( $next_link ) {
$navigation .= '<div class="nav-next">' . $next_link . '</div>' ;
}
2020-07-07 10:16:03 -04:00
$navigation = _navigation_markup ( $navigation , $args [ 'class' ], $args [ 'screen_reader_text' ], $args [ 'aria_label' ] );
2015-09-21 12:32:26 -04:00
}
return $navigation ;
}
/**
2016-04-15 12:58:27 -04:00
* Displays navigation to next / previous set of comments , when applicable .
2015-09-21 12:32:26 -04:00
*
* @ since 4.4 . 0
*
2016-04-20 10:37:29 -04:00
* @ param array $args See get_the_comments_navigation () for available arguments . Default empty array .
2015-09-21 12:32:26 -04:00
*/
function the_comments_navigation ( $args = array () ) {
echo get_the_comments_navigation ( $args );
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves a paginated navigation to next / previous set of comments , when applicable .
2015-09-21 12:32:26 -04:00
*
* @ since 4.4 . 0
2019-09-22 18:32:59 -04:00
* @ since 5.3 . 0 Added the `aria_label` parameter .
2020-07-07 10:16:03 -04:00
* @ since 5.5 . 0 Added the `class` parameter .
2015-09-21 12:32:26 -04:00
*
* @ see paginate_comments_links ()
*
* @ param array $args {
* Optional . Default pagination arguments .
*
2019-09-22 18:32:59 -04:00
* @ type string $screen_reader_text Screen reader text for the nav element . Default 'Comments navigation' .
* @ type string $aria_label ARIA label text for the nav element . Default 'Comments' .
2020-07-07 10:16:03 -04:00
* @ type string $class Custom class for the nav element . Default 'comments-pagination' .
2015-09-21 12:32:26 -04:00
* }
* @ return string Markup for pagination links .
*/
function get_the_comments_pagination ( $args = array () ) {
2019-09-22 18:32:59 -04:00
$navigation = '' ;
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text.
if ( ! empty ( $args [ 'screen_reader_text' ] ) && empty ( $args [ 'aria_label' ] ) ) {
$args [ 'aria_label' ] = $args [ 'screen_reader_text' ];
}
2017-11-30 18:11:00 -05:00
$args = wp_parse_args (
2018-08-16 21:51:36 -04:00
$args ,
array (
2017-11-30 18:11:00 -05:00
'screen_reader_text' => __ ( 'Comments navigation' ),
2019-09-22 18:32:59 -04:00
'aria_label' => __ ( 'Comments' ),
2020-07-07 10:16:03 -04:00
'class' => 'comments-pagination' ,
2017-11-30 18:11:00 -05:00
)
);
2015-09-21 12:32:26 -04:00
$args [ 'echo' ] = false ;
2017-08-09 00:07:43 -04:00
// Make sure we get a string back. Plain is the next best thing.
2020-05-16 14:42:12 -04:00
if ( isset ( $args [ 'type' ] ) && 'array' === $args [ 'type' ] ) {
2017-08-09 00:07:43 -04:00
$args [ 'type' ] = 'plain' ;
}
2015-09-21 12:32:26 -04:00
$links = paginate_comments_links ( $args );
if ( $links ) {
2020-07-07 10:16:03 -04:00
$navigation = _navigation_markup ( $links , $args [ 'class' ], $args [ 'screen_reader_text' ], $args [ 'aria_label' ] );
2015-09-21 12:32:26 -04:00
}
return $navigation ;
}
/**
2016-04-15 12:58:27 -04:00
* Displays a paginated navigation to next / previous set of comments , when applicable .
2015-09-21 12:32:26 -04:00
*
* @ since 4.4 . 0
*
2016-04-20 10:37:29 -04:00
* @ param array $args See get_the_comments_pagination () for available arguments . Default empty array .
2015-09-21 12:32:26 -04:00
*/
function the_comments_pagination ( $args = array () ) {
echo get_the_comments_pagination ( $args );
}
2010-01-04 12:23:29 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL for the current site where the front end is accessible .
2010-01-04 12:23:29 -05:00
*
2016-10-31 03:06:32 -04:00
* Returns the 'home' option with the appropriate protocol . The protocol will be 'https'
* if is_ssl () evaluates to true ; otherwise , it will be the same as the 'home' option .
* If `$scheme` is 'http' or 'https' , is_ssl () is overridden .
2010-01-04 12:23:29 -05:00
*
2010-02-05 16:49:19 -05:00
* @ since 3.0 . 0
*
2020-06-20 08:58:10 -04:00
* @ param string $path Optional . Path relative to the home URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the home URL context . Accepts
* 'http' , 'https' , 'relative' , 'rest' , or null . Default null .
2016-04-20 10:47:28 -04:00
* @ return string Home URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function home_url ( $path = '' , $scheme = null ) {
2012-09-04 10:44:17 -04:00
return get_home_url ( null , $path , $scheme );
2010-02-05 16:49:19 -05:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL for a given site where the front end is accessible .
2010-02-05 16:49:19 -05:00
*
2016-10-31 03:06:32 -04:00
* Returns the 'home' option with the appropriate protocol . The protocol will be 'https'
* if is_ssl () evaluates to true ; otherwise , it will be the same as the 'home' option .
* If `$scheme` is 'http' or 'https' , is_ssl () is overridden .
2010-02-05 16:49:19 -05:00
*
* @ since 3.0 . 0
*
2021-02-13 10:16:08 -05:00
* @ param int | null $blog_id Optional . Site ID . Default null ( current site ) .
2020-06-20 08:58:10 -04:00
* @ param string $path Optional . Path relative to the home URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the home URL context . Accepts
* 'http' , 'https' , 'relative' , 'rest' , or null . Default null .
2014-12-06 16:24:45 -05:00
* @ return string Home URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function get_home_url ( $blog_id = null , $path = '' , $scheme = null ) {
2010-01-04 12:23:29 -05:00
$orig_scheme = $scheme ;
2010-03-29 16:25:30 -04:00
2017-11-30 18:11:00 -05:00
if ( empty ( $blog_id ) || ! is_multisite () ) {
2010-10-23 13:51:18 -04:00
$url = get_option ( 'home' );
2012-08-03 13:51:42 -04:00
} else {
switch_to_blog ( $blog_id );
$url = get_option ( 'home' );
restore_current_blog ();
}
2010-02-05 16:49:19 -05:00
2020-04-04 23:02:11 -04:00
if ( ! in_array ( $scheme , array ( 'http' , 'https' , 'relative' ), true ) ) {
2021-02-02 14:03:04 -05:00
if ( is_ssl () ) {
2012-09-21 08:36:50 -04:00
$scheme = 'https' ;
2017-11-30 18:11:00 -05:00
} else {
2012-09-21 08:36:50 -04:00
$scheme = parse_url ( $url , PHP_URL_SCHEME );
2017-11-30 18:11:00 -05:00
}
2012-09-21 08:36:50 -04:00
}
2012-09-04 10:44:17 -04:00
$url = set_url_scheme ( $url , $scheme );
2010-01-04 12:23:29 -05:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
2010-01-04 12:23:29 -05:00
$url .= '/' . ltrim ( $path , '/' );
2017-11-30 18:11:00 -05:00
}
2010-01-04 12:23:29 -05:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the home URL .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $url The complete home URL including scheme and path .
* @ param string $path Path relative to the home URL . Blank string if no path is specified .
2015-10-19 18:39:25 -04:00
* @ param string | null $orig_scheme Scheme to give the home URL context . Accepts 'http' , 'https' ,
* 'relative' , 'rest' , or null .
2016-01-23 11:47:29 -05:00
* @ param int | null $blog_id Site ID , or null for the current site .
2014-04-13 22:13:16 -04:00
*/
2010-05-03 14:16:22 -04:00
return apply_filters ( 'home_url' , $url , $path , $orig_scheme , $blog_id );
2010-01-04 12:23:29 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL for the current site where WordPress application files
2016-01-26 21:55:27 -05:00
* ( e . g . wp - blog - header . php or the wp - admin / folder ) are accessible .
2008-07-14 19:39:11 -04:00
*
2011-09-29 18:57:43 -04:00
* Returns the 'site_url' option with the appropriate protocol , 'https' if
2008-10-13 18:00:07 -04:00
* is_ssl () and 'http' otherwise . If $scheme is 'http' or 'https' , is_ssl () is
* overridden .
2008-07-14 19:39:11 -04:00
*
2014-04-13 22:13:16 -04:00
* @ since 3.0 . 0
2008-07-14 19:39:11 -04:00
*
2021-02-13 10:16:08 -05:00
* @ param string $path Optional . Path relative to the site URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the site URL context . See set_url_scheme () .
2016-04-20 10:47:28 -04:00
* @ return string Site URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function site_url ( $path = '' , $scheme = null ) {
2012-09-04 10:44:17 -04:00
return get_site_url ( null , $path , $scheme );
2010-02-05 16:49:19 -05:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL for a given site where WordPress application files
2016-01-26 21:55:27 -05:00
* ( e . g . wp - blog - header . php or the wp - admin / folder ) are accessible .
2010-02-05 16:49:19 -05:00
*
2011-09-29 18:57:43 -04:00
* Returns the 'site_url' option with the appropriate protocol , 'https' if
2016-05-02 00:00:28 -04:00
* is_ssl () and 'http' otherwise . If `$scheme` is 'http' or 'https' ,
2014-12-06 16:24:45 -05:00
* `is_ssl()` is overridden .
2010-02-05 16:49:19 -05:00
*
* @ since 3.0 . 0
*
2021-02-13 10:16:08 -05:00
* @ param int | null $blog_id Optional . Site ID . Default null ( current site ) .
* @ param string $path Optional . Path relative to the site URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the site URL context . Accepts
* 'http' , 'https' , 'login' , 'login_post' , 'admin' , or
* 'relative' . Default null .
2016-04-20 10:47:28 -04:00
* @ return string Site URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function get_site_url ( $blog_id = null , $path = '' , $scheme = null ) {
2017-11-30 18:11:00 -05:00
if ( empty ( $blog_id ) || ! is_multisite () ) {
2010-05-16 17:58:31 -04:00
$url = get_option ( 'siteurl' );
2012-08-03 13:51:42 -04:00
} else {
switch_to_blog ( $blog_id );
$url = get_option ( 'siteurl' );
restore_current_blog ();
}
2010-02-05 16:49:19 -05:00
2012-09-04 10:44:17 -04:00
$url = set_url_scheme ( $url , $scheme );
2008-05-27 13:46:01 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
2010-05-16 17:58:31 -04:00
$url .= '/' . ltrim ( $path , '/' );
2017-11-30 18:11:00 -05:00
}
2008-05-27 13:46:01 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the site URL .
2014-04-13 22:13:16 -04:00
*
* @ since 2.7 . 0
*
* @ param string $url The complete site URL including scheme and path .
* @ param string $path Path relative to the site URL . Blank string if no path is specified .
* @ param string | null $scheme Scheme to give the site URL context . Accepts 'http' , 'https' , 'login' ,
* 'login_post' , 'admin' , 'relative' or null .
2016-01-23 11:47:29 -05:00
* @ param int | null $blog_id Site ID , or null for the current site .
2014-04-13 22:13:16 -04:00
*/
2012-09-04 10:44:17 -04:00
return apply_filters ( 'site_url' , $url , $path , $scheme , $blog_id );
2008-05-27 13:46:01 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the admin area for the current site .
2008-07-14 19:39:11 -04:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.6 . 0
2008-07-14 19:39:11 -04:00
*
2022-08-19 15:48:15 -04:00
* @ param string $path Optional . Path relative to the admin URL . Default empty .
2016-04-20 10:37:29 -04:00
* @ param string $scheme The scheme to use . Default is 'admin' , which obeys force_ssl_admin () and is_ssl () .
* 'http' or 'https' can be passed to force those schemes .
2016-04-20 10:47:28 -04:00
* @ return string Admin URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function admin_url ( $path = '' , $scheme = 'admin' ) {
2012-09-04 10:44:17 -04:00
return get_admin_url ( null , $path , $scheme );
2010-02-05 16:49:19 -05:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the admin area for a given site .
2010-02-05 16:49:19 -05:00
*
* @ since 3.0 . 0
*
2021-02-13 10:16:08 -05:00
* @ param int | null $blog_id Optional . Site ID . Default null ( current site ) .
* @ param string $path Optional . Path relative to the admin URL . Default empty .
* @ param string $scheme Optional . The scheme to use . Accepts 'http' or 'https' ,
* to force those schemes . Default 'admin' , which obeys
* force_ssl_admin () and is_ssl () .
2016-04-20 10:47:28 -04:00
* @ return string Admin URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function get_admin_url ( $blog_id = null , $path = '' , $scheme = 'admin' ) {
2017-11-30 18:11:00 -05:00
$url = get_site_url ( $blog_id , 'wp-admin/' , $scheme );
2008-05-27 13:46:01 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
2012-09-04 10:44:17 -04:00
$url .= ltrim ( $path , '/' );
2017-11-30 18:11:00 -05:00
}
2008-05-27 13:46:01 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the admin area URL .
2014-04-13 22:13:16 -04:00
*
* @ since 2.8 . 0
2021-05-25 21:47:59 -04:00
* @ since 5.8 . 0 The `$scheme` parameter was added .
2014-04-13 22:13:16 -04:00
*
2021-05-25 21:47:59 -04:00
* @ param string $url The complete admin area URL including scheme and path .
* @ param string $path Path relative to the admin area URL . Blank string if no path is specified .
* @ param int | null $blog_id Site ID , or null for the current site .
* @ param string | null $scheme The scheme to use . Accepts 'http' , 'https' ,
* 'admin' , or null . Default 'admin' , which obeys force_ssl_admin () and is_ssl () .
2014-04-13 22:13:16 -04:00
*/
2021-05-25 21:47:59 -04:00
return apply_filters ( 'admin_url' , $url , $path , $blog_id , $scheme );
2008-05-27 13:46:01 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the includes directory .
2008-07-14 19:39:11 -04:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.6 . 0
2008-07-14 19:39:11 -04:00
*
2021-02-13 10:16:08 -05:00
* @ param string $path Optional . Path relative to the includes URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the includes URL context . Accepts
* 'http' , 'https' , or 'relative' . Default null .
2016-04-20 10:47:28 -04:00
* @ return string Includes URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2013-08-01 09:15:14 -04:00
function includes_url ( $path = '' , $scheme = null ) {
$url = site_url ( '/' . WPINC . '/' , $scheme );
2008-05-27 13:46:01 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
$url .= ltrim ( $path , '/' );
}
2008-05-27 13:46:01 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the URL to the includes directory .
2014-04-13 22:13:16 -04:00
*
* @ since 2.8 . 0
2021-05-25 21:47:59 -04:00
* @ since 5.8 . 0 The `$scheme` parameter was added .
2014-04-13 22:13:16 -04:00
*
2021-05-25 21:47:59 -04:00
* @ param string $url The complete URL to the includes directory including scheme and path .
* @ param string $path Path relative to the URL to the wp - includes directory . Blank string
* if no path is specified .
* @ param string | null $scheme Scheme to give the includes URL context . Accepts
* 'http' , 'https' , 'relative' , or null . Default null .
2014-04-13 22:13:16 -04:00
*/
2021-05-25 21:47:59 -04:00
return apply_filters ( 'includes_url' , $url , $path , $scheme );
2008-05-27 13:46:01 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the content directory .
2008-07-14 19:39:11 -04:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.6 . 0
2008-07-14 19:39:11 -04:00
*
2016-04-20 10:47:28 -04:00
* @ param string $path Optional . Path relative to the content URL . Default empty .
* @ return string Content URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2016-04-20 10:37:29 -04:00
function content_url ( $path = '' ) {
2012-08-30 09:33:00 -04:00
$url = set_url_scheme ( WP_CONTENT_URL );
2008-07-09 13:24:36 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
$url .= '/' . ltrim ( $path , '/' );
}
2008-07-09 13:24:36 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the URL to the content directory .
2014-04-13 22:13:16 -04:00
*
* @ since 2.8 . 0
*
* @ param string $url The complete URL to the content directory including scheme and path .
* @ param string $path Path relative to the URL to the content directory . Blank string
* if no path is specified .
*/
2017-11-30 18:11:00 -05:00
return apply_filters ( 'content_url' , $url , $path );
2008-07-09 13:24:36 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves a URL within the plugins or mu - plugins directory .
2014-07-03 15:42:15 -04:00
*
* Defaults to the plugins directory URL if no arguments are supplied .
2008-07-14 20:10:07 -04:00
*
2008-10-13 18:00:07 -04:00
* @ since 2.6 . 0
2008-07-14 20:10:07 -04:00
*
2020-06-20 08:58:10 -04:00
* @ param string $path Optional . Extra path appended to the end of the URL , including
* the relative directory if $plugin is supplied . Default empty .
* @ param string $plugin Optional . A full path to a file inside a plugin or mu - plugin .
* The URL will be relative to its directory . Default empty .
* Typically this is done by passing `__FILE__` as the argument .
2014-07-03 15:42:15 -04:00
* @ return string Plugins URL link with optional paths appended .
2015-12-12 10:37:28 -05:00
*/
2014-07-03 15:42:15 -04:00
function plugins_url ( $path = '' , $plugin = '' ) {
2009-04-23 04:16:06 -04:00
2017-11-30 18:11:00 -05:00
$path = wp_normalize_path ( $path );
$plugin = wp_normalize_path ( $plugin );
2014-08-04 21:31:16 -04:00
$mu_plugin_dir = wp_normalize_path ( WPMU_PLUGIN_DIR );
2010-02-05 07:39:04 -05:00
Code Modernization: Replace usage of `strpos()` with `str_starts_with()`.
`str_starts_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins with the given substring (needle).
WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `0 === strpos( ... )` with `str_starts_with()` in core files, making the code more readable and consistent, as well as improving performance.
While `strpos()` is slightly faster than the polyfill on PHP < 8.0, `str_starts_with()` is noticeably faster on PHP 8.0+, as it is optimized to avoid unnecessarily searching along the whole haystack if it does not find the needle.
Follow-up to [52039], [52040], [52326].
Props spacedmonkey, costdev, sabernhardt, mukesh27, desrosj, jorbin, TobiasBg, ayeshrajans, lgadzhev, SergeyBiryukov.
Fixes #58012.
Built from https://develop.svn.wordpress.org/trunk@55703
git-svn-id: http://core.svn.wordpress.org/trunk@55215 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-02 11:45:22 -04:00
if ( ! empty ( $plugin ) && str_starts_with ( $plugin , $mu_plugin_dir ) ) {
2009-04-23 04:16:06 -04:00
$url = WPMU_PLUGIN_URL ;
2017-11-30 18:11:00 -05:00
} else {
2009-04-23 04:16:06 -04:00
$url = WP_PLUGIN_URL ;
2017-11-30 18:11:00 -05:00
}
2012-09-19 14:11:43 -04:00
2012-08-30 09:33:00 -04:00
$url = set_url_scheme ( $url );
2008-07-14 20:10:07 -04:00
2017-11-30 18:11:00 -05:00
if ( ! empty ( $plugin ) && is_string ( $plugin ) ) {
$folder = dirname ( plugin_basename ( $plugin ) );
2020-05-16 14:42:12 -04:00
if ( '.' !== $folder ) {
2017-11-30 18:11:00 -05:00
$url .= '/' . ltrim ( $folder , '/' );
}
2009-02-15 11:50:45 -05:00
}
2009-03-17 22:43:45 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
$url .= '/' . ltrim ( $path , '/' );
}
2008-07-14 20:10:07 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the URL to the plugins directory .
2014-04-13 22:13:16 -04:00
*
* @ since 2.8 . 0
*
* @ param string $url The complete URL to the plugins directory including scheme and path .
* @ param string $path Path relative to the URL to the plugins directory . Blank string
* if no path is specified .
* @ param string $plugin The plugin file path to be relative to . Blank string if no plugin
* is specified .
*/
return apply_filters ( 'plugins_url' , $url , $path , $plugin );
2008-07-14 20:10:07 -04:00
}
2010-03-29 13:53:03 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the site URL for the current network .
2010-03-29 13:53:03 -04:00
*
2016-04-20 10:47:28 -04:00
* Returns the site URL with the appropriate protocol , 'https' if
2010-03-29 13:53:03 -04:00
* is_ssl () and 'http' otherwise . If $scheme is 'http' or 'https' , is_ssl () is
* overridden .
*
* @ since 3.0 . 0
*
2016-04-20 10:37:29 -04:00
* @ see set_url_scheme ()
*
2021-02-13 10:16:08 -05:00
* @ param string $path Optional . Path relative to the site URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the site URL context . Accepts
* 'http' , 'https' , or 'relative' . Default null .
2016-04-20 10:47:28 -04:00
* @ return string Site URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function network_site_url ( $path = '' , $scheme = null ) {
2017-11-30 18:11:00 -05:00
if ( ! is_multisite () ) {
return site_url ( $path , $scheme );
}
2010-03-29 17:45:31 -04:00
2016-10-19 00:47:30 -04:00
$current_network = get_network ();
2013-11-12 22:23:10 -05:00
2020-05-16 14:42:12 -04:00
if ( 'relative' === $scheme ) {
2016-10-19 00:47:30 -04:00
$url = $current_network -> path ;
2017-11-30 18:11:00 -05:00
} else {
2016-10-19 00:47:30 -04:00
$url = set_url_scheme ( 'http://' . $current_network -> domain . $current_network -> path , $scheme );
2017-11-30 18:11:00 -05:00
}
2010-03-29 13:53:03 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
2012-09-04 10:44:17 -04:00
$url .= ltrim ( $path , '/' );
2017-11-30 18:11:00 -05:00
}
2010-03-29 13:53:03 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the network site URL .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $url The complete network site URL including scheme and path .
* @ param string $path Path relative to the network site URL . Blank string if
* no path is specified .
* @ param string | null $scheme Scheme to give the URL context . Accepts 'http' , 'https' ,
* 'relative' or null .
*/
2012-09-04 10:44:17 -04:00
return apply_filters ( 'network_site_url' , $url , $path , $scheme );
2010-03-29 13:53:03 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the home URL for the current network .
2010-03-29 13:53:03 -04:00
*
2016-04-20 10:47:28 -04:00
* Returns the home URL with the appropriate protocol , 'https' is_ssl ()
2014-12-06 16:24:45 -05:00
* and 'http' otherwise . If `$scheme` is 'http' or 'https' , `is_ssl()` is
2010-03-29 13:53:03 -04:00
* overridden .
*
* @ since 3.0 . 0
*
2021-02-13 10:16:08 -05:00
* @ param string $path Optional . Path relative to the home URL . Default empty .
* @ param string | null $scheme Optional . Scheme to give the home URL context . Accepts
* 'http' , 'https' , or 'relative' . Default null .
2016-04-20 10:47:28 -04:00
* @ return string Home URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function network_home_url ( $path = '' , $scheme = null ) {
2017-11-30 18:11:00 -05:00
if ( ! is_multisite () ) {
return home_url ( $path , $scheme );
}
2010-03-29 17:45:31 -04:00
2016-10-19 00:47:30 -04:00
$current_network = get_network ();
2017-11-30 18:11:00 -05:00
$orig_scheme = $scheme ;
2010-03-29 16:25:30 -04:00
2020-04-04 23:02:11 -04:00
if ( ! in_array ( $scheme , array ( 'http' , 'https' , 'relative' ), true ) ) {
2021-02-02 15:59:05 -05:00
$scheme = is_ssl () ? 'https' : 'http' ;
2017-11-30 18:11:00 -05:00
}
2010-03-29 13:53:03 -04:00
2020-05-16 14:42:12 -04:00
if ( 'relative' === $scheme ) {
2016-10-19 00:47:30 -04:00
$url = $current_network -> path ;
2017-11-30 18:11:00 -05:00
} else {
2016-10-19 00:47:30 -04:00
$url = set_url_scheme ( 'http://' . $current_network -> domain . $current_network -> path , $scheme );
2017-11-30 18:11:00 -05:00
}
2010-03-29 13:53:03 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
2010-03-29 15:57:17 -04:00
$url .= ltrim ( $path , '/' );
2017-11-30 18:11:00 -05:00
}
2010-03-29 13:53:03 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the network home URL .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $url The complete network home URL including scheme and path .
* @ param string $path Path relative to the network home URL . Blank string
* if no path is specified .
* @ param string | null $orig_scheme Scheme to give the URL context . Accepts 'http' , 'https' ,
* 'relative' or null .
*/
2017-11-30 18:11:00 -05:00
return apply_filters ( 'network_home_url' , $url , $path , $orig_scheme );
2010-03-29 13:53:03 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the admin area for the network .
2010-03-29 13:53:03 -04:00
*
* @ since 3.0 . 0
*
2016-04-20 10:47:28 -04:00
* @ param string $path Optional path relative to the admin URL . Default empty .
2016-04-20 10:37:29 -04:00
* @ param string $scheme Optional . The scheme to use . Default is 'admin' , which obeys force_ssl_admin ()
* and is_ssl () . 'http' or 'https' can be passed to force those schemes .
2016-04-20 10:47:28 -04:00
* @ return string Admin URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-05-03 14:16:22 -04:00
function network_admin_url ( $path = '' , $scheme = 'admin' ) {
2017-11-30 18:11:00 -05:00
if ( ! is_multisite () ) {
2010-12-16 04:31:42 -05:00
return admin_url ( $path , $scheme );
2017-11-30 18:11:00 -05:00
}
2010-12-16 04:31:42 -05:00
2017-11-30 18:11:00 -05:00
$url = network_site_url ( 'wp-admin/network/' , $scheme );
2010-03-29 13:53:03 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
$url .= ltrim ( $path , '/' );
}
2010-03-29 13:53:03 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the network admin URL .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
2021-05-25 21:47:59 -04:00
* @ since 5.8 . 0 The `$scheme` parameter was added .
2014-04-13 22:13:16 -04:00
*
2021-05-25 21:47:59 -04:00
* @ param string $url The complete network admin URL including scheme and path .
* @ param string $path Path relative to the network admin URL . Blank string if
* no path is specified .
* @ param string | null $scheme The scheme to use . Accepts 'http' , 'https' ,
* 'admin' , or null . Default is 'admin' , which obeys force_ssl_admin () and is_ssl () .
2014-04-13 22:13:16 -04:00
*/
2021-05-25 21:47:59 -04:00
return apply_filters ( 'network_admin_url' , $url , $path , $scheme );
2010-03-29 13:53:03 -04:00
}
2010-10-07 15:34:18 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the admin area for the current user .
2010-10-07 15:34:18 -04:00
*
* @ since 3.0 . 0
*
2016-04-20 10:47:28 -04:00
* @ param string $path Optional . Path relative to the admin URL . Default empty .
2016-04-20 10:37:29 -04:00
* @ param string $scheme Optional . The scheme to use . Default is 'admin' , which obeys force_ssl_admin ()
* and is_ssl () . 'http' or 'https' can be passed to force those schemes .
2016-04-20 10:47:28 -04:00
* @ return string Admin URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2010-10-07 15:34:18 -04:00
function user_admin_url ( $path = '' , $scheme = 'admin' ) {
2017-11-30 18:11:00 -05:00
$url = network_site_url ( 'wp-admin/user/' , $scheme );
2010-10-07 15:34:18 -04:00
2017-11-30 18:11:00 -05:00
if ( $path && is_string ( $path ) ) {
$url .= ltrim ( $path , '/' );
}
2010-10-07 15:34:18 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the user admin URL for the current user .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
2021-05-25 21:47:59 -04:00
* @ since 5.8 . 0 The `$scheme` parameter was added .
2014-04-13 22:13:16 -04:00
*
2021-05-25 21:47:59 -04:00
* @ param string $url The complete URL including scheme and path .
* @ param string $path Path relative to the URL . Blank string if
* no path is specified .
* @ param string | null $scheme The scheme to use . Accepts 'http' , 'https' ,
* 'admin' , or null . Default is 'admin' , which obeys force_ssl_admin () and is_ssl () .
2014-04-13 22:13:16 -04:00
*/
2021-05-25 21:47:59 -04:00
return apply_filters ( 'user_admin_url' , $url , $path , $scheme );
2010-10-07 15:34:18 -04:00
}
2010-07-30 16:34:54 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the admin area for either the current site or the network depending on context .
2010-07-30 16:34:54 -04:00
*
* @ since 3.1 . 0
*
2016-04-20 10:47:28 -04:00
* @ param string $path Optional . Path relative to the admin URL . Default empty .
2016-04-20 10:37:29 -04:00
* @ param string $scheme Optional . The scheme to use . Default is 'admin' , which obeys force_ssl_admin ()
* and is_ssl () . 'http' or 'https' can be passed to force those schemes .
2016-04-20 10:47:28 -04:00
* @ return string Admin URL link with optional path appended .
2015-12-12 10:37:28 -05:00
*/
2016-04-20 10:37:29 -04:00
function self_admin_url ( $path = '' , $scheme = 'admin' ) {
2017-07-14 19:01:42 -04:00
if ( is_network_admin () ) {
$url = network_admin_url ( $path , $scheme );
} elseif ( is_user_admin () ) {
$url = user_admin_url ( $path , $scheme );
} else {
$url = admin_url ( $path , $scheme );
}
/**
* Filters the admin URL for the current site or network depending on context .
*
* @ since 4.9 . 0
*
* @ param string $url The complete URL including scheme and path .
* @ param string $path Path relative to the URL . Blank string if no path is specified .
* @ param string $scheme The scheme to use .
*/
return apply_filters ( 'self_admin_url' , $url , $path , $scheme );
2010-07-30 16:34:54 -04:00
}
2012-05-18 16:04:59 -04:00
/**
2015-10-19 18:39:25 -04:00
* Sets the scheme for a URL .
2012-05-18 16:04:59 -04:00
*
* @ since 3.4 . 0
2015-10-19 18:39:25 -04:00
* @ since 4.4 . 0 The 'rest' scheme was added .
2012-05-27 12:25:43 -04:00
*
2016-04-20 10:47:28 -04:00
* @ param string $url Absolute URL that includes a scheme
2015-10-19 18:39:25 -04:00
* @ param string | null $scheme Optional . Scheme to give $url . Currently 'http' , 'https' , 'login' ,
* 'login_post' , 'admin' , 'relative' , 'rest' , 'rpc' , or null . Default null .
2020-06-19 18:55:12 -04:00
* @ return string URL with chosen scheme .
2012-05-18 16:04:59 -04:00
*/
function set_url_scheme ( $url , $scheme = null ) {
$orig_scheme = $scheme ;
2014-05-28 23:59:15 -04:00
if ( ! $scheme ) {
$scheme = is_ssl () ? 'https' : 'http' ;
2020-02-09 11:55:09 -05:00
} elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) {
2014-05-28 23:59:15 -04:00
$scheme = is_ssl () || force_ssl_admin () ? 'https' : 'http' ;
2020-02-09 11:55:09 -05:00
} elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) {
2014-05-28 23:59:15 -04:00
$scheme = is_ssl () ? 'https' : 'http' ;
2012-05-18 16:04:59 -04:00
}
2013-09-10 14:08:11 -04:00
$url = trim ( $url );
2023-06-24 12:50:24 -04:00
if ( str_starts_with ( $url , '//' ) ) {
2013-09-10 14:08:11 -04:00
$url = 'http:' . $url ;
2017-11-30 18:11:00 -05:00
}
2013-09-10 14:08:11 -04:00
2020-05-16 14:42:12 -04:00
if ( 'relative' === $scheme ) {
2013-09-10 14:08:11 -04:00
$url = ltrim ( preg_replace ( '#^\w+://[^/]*#' , '' , $url ) );
2020-02-09 11:55:09 -05:00
if ( '' !== $url && '/' === $url [ 0 ] ) {
2017-11-30 18:11:00 -05:00
$url = '/' . ltrim ( $url , " / \t \n \r \0 \x0B " );
}
2013-09-10 14:08:11 -04:00
} else {
$url = preg_replace ( '#^\w+://#' , $scheme . '://' , $url );
}
2012-05-18 16:04:59 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the resulting URL after setting the scheme .
2014-04-13 22:13:16 -04:00
*
* @ since 3.4 . 0
*
2015-10-19 18:39:25 -04:00
* @ param string $url The complete URL including scheme and path .
* @ param string $scheme Scheme applied to the URL . One of 'http' , 'https' , or 'relative' .
* @ param string | null $orig_scheme Scheme requested for the URL . One of 'http' , 'https' , 'login' ,
* 'login_post' , 'admin' , 'relative' , 'rest' , 'rpc' , or null .
2014-04-13 22:13:16 -04:00
*/
2012-05-18 16:04:59 -04:00
return apply_filters ( 'set_url_scheme' , $url , $scheme , $orig_scheme );
}
2010-10-29 13:48:53 -04:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the user ' s dashboard .
2010-10-29 13:48:53 -04:00
*
2016-04-20 10:37:29 -04:00
* If a user does not belong to any site , the global user dashboard is used . If the user
* belongs to the current site , the dashboard for the current site is returned . If the user
* cannot edit the current site , the dashboard to the user ' s primary site is returned .
2010-10-29 13:48:53 -04:00
*
* @ since 3.1 . 0
*
2015-05-26 14:44:25 -04:00
* @ param int $user_id Optional . User ID . Defaults to current user .
2016-04-20 10:37:29 -04:00
* @ param string $path Optional path relative to the dashboard . Use only paths known to
* both site and user admins . Default empty .
* @ param string $scheme The scheme to use . Default is 'admin' , which obeys force_ssl_admin ()
* and is_ssl () . 'http' or 'https' can be passed to force those schemes .
2016-04-20 10:47:28 -04:00
* @ return string Dashboard URL link with optional path appended .
2010-10-29 13:48:53 -04:00
*/
2014-02-25 12:08:13 -05:00
function get_dashboard_url ( $user_id = 0 , $path = '' , $scheme = 'admin' ) {
$user_id = $user_id ? ( int ) $user_id : get_current_user_id ();
2010-10-29 13:48:53 -04:00
$blogs = get_blogs_of_user ( $user_id );
2020-04-09 11:43:10 -04:00
2017-11-30 18:11:00 -05:00
if ( is_multisite () && ! user_can ( $user_id , 'manage_network' ) && empty ( $blogs ) ) {
2010-10-29 13:48:53 -04:00
$url = user_admin_url ( $path , $scheme );
} elseif ( ! is_multisite () ) {
$url = admin_url ( $path , $scheme );
} else {
$current_blog = get_current_blog_id ();
2020-04-09 11:43:10 -04:00
if ( $current_blog && ( user_can ( $user_id , 'manage_network' ) || in_array ( $current_blog , array_keys ( $blogs ), true ) ) ) {
2010-10-29 13:48:53 -04:00
$url = admin_url ( $path , $scheme );
} else {
$active = get_active_blog_for_user ( $user_id );
2017-11-30 18:11:00 -05:00
if ( $active ) {
2010-10-29 13:48:53 -04:00
$url = get_admin_url ( $active -> blog_id , $path , $scheme );
2017-11-30 18:11:00 -05:00
} else {
2010-10-29 13:48:53 -04:00
$url = user_admin_url ( $path , $scheme );
2017-11-30 18:11:00 -05:00
}
2010-10-29 13:48:53 -04:00
}
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the dashboard URL for a user .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
*
* @ param string $url The complete URL including scheme and path .
* @ param int $user_id The user ID .
* @ param string $path Path relative to the URL . Blank string if no path is specified .
* @ param string $scheme Scheme to give the URL context . Accepts 'http' , 'https' , 'login' ,
* 'login_post' , 'admin' , 'relative' or null .
*/
2017-11-30 18:11:00 -05:00
return apply_filters ( 'user_dashboard_url' , $url , $user_id , $path , $scheme );
2010-10-29 13:48:53 -04:00
}
/**
2016-04-15 12:58:27 -04:00
* Retrieves the URL to the user ' s profile editor .
2010-10-29 13:48:53 -04:00
*
* @ since 3.1 . 0
*
2014-02-25 12:08:13 -05:00
* @ param int $user_id Optional . User ID . Defaults to current user .
2016-04-20 10:37:29 -04:00
* @ param string $scheme Optional . The scheme to use . Default is 'admin' , which obeys force_ssl_admin ()
* and is_ssl () . 'http' or 'https' can be passed to force those schemes .
2016-04-20 10:47:28 -04:00
* @ return string Dashboard URL link with optional path appended .
2010-10-29 13:48:53 -04:00
*/
2014-02-25 12:08:13 -05:00
function get_edit_profile_url ( $user_id = 0 , $scheme = 'admin' ) {
2014-02-25 12:29:13 -05:00
$user_id = $user_id ? ( int ) $user_id : get_current_user_id ();
2010-10-29 13:48:53 -04:00
2017-11-30 18:11:00 -05:00
if ( is_user_admin () ) {
2010-11-18 18:07:59 -05:00
$url = user_admin_url ( 'profile.php' , $scheme );
2017-11-30 18:11:00 -05:00
} elseif ( is_network_admin () ) {
2010-11-18 18:07:59 -05:00
$url = network_admin_url ( 'profile.php' , $scheme );
2017-11-30 18:11:00 -05:00
} else {
2014-02-25 12:08:13 -05:00
$url = get_dashboard_url ( $user_id , 'profile.php' , $scheme );
2017-11-30 18:11:00 -05:00
}
2010-10-29 13:48:53 -04:00
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the URL for a user ' s profile editor .
2014-04-13 22:13:16 -04:00
*
* @ since 3.1 . 0
*
* @ param string $url The complete URL including scheme and path .
* @ param int $user_id The user ID .
* @ param string $scheme Scheme to give the URL context . Accepts 'http' , 'https' , 'login' ,
* 'login_post' , 'admin' , 'relative' or null .
*/
2017-11-30 18:11:00 -05:00
return apply_filters ( 'edit_profile_url' , $url , $user_id , $scheme );
2010-10-29 13:48:53 -04:00
}
2016-06-11 09:31:29 -04:00
/**
* Returns the canonical URL for a post .
*
* When the post is the same as the current requested page the function will handle the
* pagination arguments too .
*
* @ since 4.6 . 0
*
* @ param int | WP_Post $post Optional . Post ID or object . Default is global `$post` .
Posts, Post Types: Correct the check for non-existing post in `get_post_permalink()`.
The function was erroneously calling `is_wp_error()` on the result of a `get_post()` call, which returns `null` on failure, and never returns a `WP_Error` object.
Previously, passing a non-existing post ID to the function would result in a home URL being returned and a few `Attempt to read property "post_type, post_name, hierarchical..." on null` PHP warnings.
This commit ensures `get_post_permalink()` returns `false` on failure, which brings parity with `get_permalink()`.
Includes a unit test to confirm the correct behavior.
Follow-up to [12923], [13023], [32606].
Props renegeuze, manzoorwani.jk.
Fixes #45329.
Built from https://develop.svn.wordpress.org/trunk@53733
git-svn-id: http://core.svn.wordpress.org/trunk@53292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-20 11:41:09 -04:00
* @ return string | false The canonical URL . False if the post does not exist
* or has not been published yet .
2016-06-11 09:31:29 -04:00
*/
function wp_get_canonical_url ( $post = null ) {
$post = get_post ( $post );
if ( ! $post ) {
return false ;
}
if ( 'publish' !== $post -> post_status ) {
return false ;
}
$canonical_url = get_permalink ( $post );
// If a canonical is being generated for the current page, make sure it has pagination if needed.
2020-02-09 11:55:09 -05:00
if ( get_queried_object_id () === $post -> ID ) {
2016-06-11 09:31:29 -04:00
$page = get_query_var ( 'page' , 0 );
if ( $page >= 2 ) {
2020-05-16 14:42:12 -04:00
if ( ! get_option ( 'permalink_structure' ) ) {
2016-06-11 09:31:29 -04:00
$canonical_url = add_query_arg ( 'page' , $page , $canonical_url );
} else {
$canonical_url = trailingslashit ( $canonical_url ) . user_trailingslashit ( $page , 'single_paged' );
}
}
$cpage = get_query_var ( 'cpage' , 0 );
if ( $cpage ) {
$canonical_url = get_comments_pagenum_link ( $cpage );
}
}
/**
* Filters the canonical URL for a post .
*
* @ since 4.6 . 0
*
2016-12-27 04:28:40 -05:00
* @ param string $canonical_url The post ' s canonical URL .
* @ param WP_Post $post Post object .
2016-06-11 09:31:29 -04:00
*/
return apply_filters ( 'get_canonical_url' , $canonical_url , $post );
}
2009-08-05 12:43:51 -04:00
/**
2016-04-15 12:58:27 -04:00
* Outputs rel = canonical for singular queries .
2009-08-05 12:43:51 -04:00
*
* @ since 2.9 . 0
2018-02-09 11:55:31 -05:00
* @ since 4.6 . 0 Adjusted to use `wp_get_canonical_url()` .
2015-12-12 10:37:28 -05:00
*/
2009-08-05 12:43:51 -04:00
function rel_canonical () {
2015-09-22 16:06:24 -04:00
if ( ! is_singular () ) {
2009-08-05 12:43:51 -04:00
return ;
2015-09-22 16:06:24 -04:00
}
2009-08-05 12:43:51 -04:00
2016-06-11 09:31:29 -04:00
$id = get_queried_object_id ();
if ( 0 === $id ) {
2009-08-05 12:43:51 -04:00
return ;
2015-09-22 16:06:24 -04:00
}
2009-08-05 12:43:51 -04:00
2016-06-11 09:31:29 -04:00
$url = wp_get_canonical_url ( $id );
2015-09-24 10:30:24 -04:00
2016-06-11 09:31:29 -04:00
if ( ! empty ( $url ) ) {
echo '<link rel="canonical" href="' . esc_url ( $url ) . '" />' . " \n " ;
2015-09-22 16:06:24 -04:00
}
2009-08-05 12:43:51 -04:00
}
2010-03-09 14:36:38 -05:00
/**
2016-04-15 12:58:27 -04:00
* Returns a shortlink for a post , page , attachment , or site .
2010-03-09 14:36:38 -05:00
*
2016-04-20 10:37:29 -04:00
* This function exists to provide a shortlink tag that all themes and plugins can target .
* A plugin must hook in to provide the actual shortlinks . Default shortlink support is
* limited to providing ? p = style links for posts . Plugins can short - circuit this function
2016-05-02 00:00:28 -04:00
* via the { @ see 'pre_get_shortlink' } filter or filter the output via the { @ see 'get_shortlink' }
* filter .
2010-03-09 14:36:38 -05:00
*
2017-12-15 00:16:47 -05:00
* @ since 3.0 . 0
2010-03-17 12:27:25 -04:00
*
2020-06-20 08:02:12 -04:00
* @ param int $id Optional . A post or site ID . Default is 0 , which means the current post or site .
2021-12-12 09:54:00 -05:00
* @ param string $context Optional . Whether the ID is a 'site' ID , 'post' ID , or 'media' ID . If 'post' ,
2016-04-20 10:37:29 -04:00
* the post_type of the post is consulted . If 'query' , the current query is consulted
2020-06-20 08:02:12 -04:00
* to determine the ID and context . Default 'post' .
2016-04-20 10:37:29 -04:00
* @ param bool $allow_slugs Optional . Whether to allow post slugs in the shortlink . It is up to the plugin how
* and whether to honor this . Default true .
* @ return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks
* are not enabled .
2010-03-09 14:36:38 -05:00
*/
2016-04-20 10:37:29 -04:00
function wp_get_shortlink ( $id = 0 , $context = 'post' , $allow_slugs = true ) {
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters whether to preempt generating a shortlink for the given post .
2014-04-13 22:13:16 -04:00
*
2022-08-04 10:52:11 -04:00
* Returning a value other than false from the filter will short - circuit
2020-06-26 14:49:09 -04:00
* the shortlink generation process , returning that value instead .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
2020-06-03 06:02:13 -04:00
* @ param false | string $return Short - circuit return value . Either false or a URL string .
* @ param int $id Post ID , or 0 for the current post .
* @ param string $context The context for the link . One of 'post' or 'query' ,
* @ param bool $allow_slugs Whether to allow post slugs in the shortlink .
2014-04-13 22:13:16 -04:00
*/
$shortlink = apply_filters ( 'pre_get_shortlink' , false , $id , $context , $allow_slugs );
2015-09-22 16:09:23 -04:00
if ( false !== $shortlink ) {
2010-03-09 14:36:38 -05:00
return $shortlink ;
2015-09-22 16:09:23 -04:00
}
2010-03-09 14:36:38 -05:00
$post_id = 0 ;
2020-05-16 14:42:12 -04:00
if ( 'query' === $context && is_singular () ) {
2015-09-22 16:09:23 -04:00
$post_id = get_queried_object_id ();
2017-11-30 18:11:00 -05:00
$post = get_post ( $post_id );
2020-05-16 14:42:12 -04:00
} elseif ( 'post' === $context ) {
2013-08-15 16:09:09 -04:00
$post = get_post ( $id );
2017-11-30 18:11:00 -05:00
if ( ! empty ( $post -> ID ) ) {
2013-09-12 13:30:10 -04:00
$post_id = $post -> ID ;
2017-11-30 18:11:00 -05:00
}
2010-05-06 17:20:17 -04:00
}
2010-03-09 14:36:38 -05:00
$shortlink = '' ;
2020-01-28 19:45:18 -05:00
// Return `?p=` link for all public post types.
2013-08-15 16:09:09 -04:00
if ( ! empty ( $post_id ) ) {
$post_type = get_post_type_object ( $post -> post_type );
2014-03-27 22:59:14 -04:00
2020-02-09 11:55:09 -05:00
if ( 'page' === $post -> post_type && get_option ( 'page_on_front' ) == $post -> ID && 'page' === get_option ( 'show_on_front' ) ) {
2014-03-27 22:59:14 -04:00
$shortlink = home_url ( '/' );
2020-09-28 07:53:08 -04:00
} elseif ( $post_type && $post_type -> public ) {
2014-03-27 22:59:14 -04:00
$shortlink = home_url ( '?p=' . $post_id );
}
2010-03-09 14:36:38 -05:00
}
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the shortlink for a post .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $shortlink Shortlink URL .
* @ param int $id Post ID , or 0 for the current post .
* @ param string $context The context for the link . One of 'post' or 'query' ,
* @ param bool $allow_slugs Whether to allow post slugs in the shortlink . Not used by default .
*/
return apply_filters ( 'get_shortlink' , $shortlink , $id , $context , $allow_slugs );
2010-03-09 14:36:38 -05:00
}
/**
2016-04-15 12:58:27 -04:00
* Injects rel = shortlink into the head if a shortlink is defined for the current page .
2010-03-09 14:36:38 -05:00
*
2016-04-20 10:37:29 -04:00
* Attached to the { @ see 'wp_head' } action .
2010-03-09 14:36:38 -05:00
*
* @ since 3.0 . 0
*/
function wp_shortlink_wp_head () {
2010-04-23 17:20:16 -04:00
$shortlink = wp_get_shortlink ( 0 , 'query' );
2010-03-09 14:36:38 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $shortlink ) ) {
2010-03-09 14:36:38 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-03-09 14:36:38 -05:00
2011-04-01 15:29:06 -04:00
echo " <link rel='shortlink' href=' " . esc_url ( $shortlink ) . " ' /> \n " ;
2010-03-09 14:36:38 -05:00
}
/**
2016-04-15 12:58:27 -04:00
* Sends a Link : rel = shortlink header if a shortlink is defined for the current page .
2010-03-09 14:36:38 -05:00
*
2016-05-23 15:01:27 -04:00
* Attached to the { @ see 'wp' } action .
2010-03-09 14:36:38 -05:00
*
* @ since 3.0 . 0
*/
function wp_shortlink_header () {
2017-11-30 18:11:00 -05:00
if ( headers_sent () ) {
2010-03-09 14:36:38 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-03-09 14:36:38 -05:00
2017-11-30 18:11:00 -05:00
$shortlink = wp_get_shortlink ( 0 , 'query' );
2010-03-09 14:36:38 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $shortlink ) ) {
2010-03-09 14:36:38 -05:00
return ;
2017-11-30 18:11:00 -05:00
}
2010-03-09 14:36:38 -05:00
2017-11-30 18:11:00 -05:00
header ( 'Link: <' . $shortlink . '>; rel=shortlink' , false );
2010-03-09 14:36:38 -05:00
}
2010-03-12 11:08:37 -05:00
/**
2016-04-15 12:58:27 -04:00
* Displays the shortlink for a post .
2010-03-12 11:08:37 -05:00
*
* Must be called from inside " The Loop "
*
2016-04-20 10:37:29 -04:00
* Call like the_shortlink ( __ ( 'Shortlinkage FTW' ) )
2010-03-12 11:08:37 -05:00
*
* @ since 3.0 . 0
*
2015-05-26 14:44:25 -04:00
* @ param string $text Optional The link text or HTML to be displayed . Defaults to 'This is the short link.'
* @ param string $title Optional The tooltip for the link . Must be sanitized . Defaults to the sanitized post title .
2016-04-20 10:37:29 -04:00
* @ param string $before Optional HTML to display before the link . Default empty .
* @ param string $after Optional HTML to display after the link . Default empty .
2010-03-12 11:08:37 -05:00
*/
2010-04-23 17:20:16 -04:00
function the_shortlink ( $text = '' , $title = '' , $before = '' , $after = '' ) {
2012-11-14 00:05:34 -05:00
$post = get_post ();
2017-11-30 18:11:00 -05:00
if ( empty ( $text ) ) {
$text = __ ( 'This is the short link.' );
}
2010-03-12 11:08:37 -05:00
2017-11-30 18:11:00 -05:00
if ( empty ( $title ) ) {
2012-01-05 15:50:54 -05:00
$title = the_title_attribute ( array ( 'echo' => false ) );
2017-11-30 18:11:00 -05:00
}
2010-03-12 11:08:37 -05:00
2012-11-14 00:05:34 -05:00
$shortlink = wp_get_shortlink ( $post -> ID );
2010-03-12 11:08:37 -05:00
2017-11-30 18:11:00 -05:00
if ( ! empty ( $shortlink ) ) {
2010-04-23 17:23:32 -04:00
$link = '<a rel="shortlink" href="' . esc_url ( $shortlink ) . '" title="' . $title . '">' . $text . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
2016-04-15 12:58:27 -04:00
* Filters the short link anchor tag for a post .
2014-04-13 22:13:16 -04:00
*
* @ since 3.0 . 0
*
* @ param string $link Shortlink anchor tag .
* @ param string $shortlink Shortlink URL .
* @ param string $text Shortlink ' s text .
* @ param string $title Shortlink ' s title attribute .
*/
2010-04-23 17:20:16 -04:00
$link = apply_filters ( 'the_shortlink' , $link , $shortlink , $text , $title );
echo $before , $link , $after ;
}
2010-03-12 11:08:37 -05:00
}
2015-01-08 23:43:23 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves the avatar URL .
2015-01-08 23:43:23 -05:00
*
* @ since 4.2 . 0
*
* @ param mixed $id_or_email The Gravatar to retrieve a URL for . Accepts a user_id , gravatar md5 hash ,
2015-09-03 14:17:24 -04:00
* user email , WP_User object , WP_Post object , or WP_Comment object .
2015-04-05 12:04:28 -04:00
* @ param array $args {
2022-08-11 10:11:08 -04:00
* Optional . Arguments to use instead of the default arguments .
2015-01-08 23:43:23 -05:00
*
* @ type int $size Height and width of the avatar in pixels . Default 96.
* @ type string $default URL for the default image or a default type . Accepts '404' ( return
2023-02-06 16:30:18 -05:00
* a 404 instead of a default image ), 'retro' ( 8 bit ), 'RoboHash' ( robohash ),
* 'monsterid' ( monster ), 'wavatar' ( cartoon face ), 'indenticon' ( the " quilt " ),
* 'mystery' , 'mm' , or 'mysteryman' ( The Oyster Man ), 'blank' ( transparent GIF ),
* or 'gravatar_default' ( the Gravatar logo ) . Default is the value of the
2015-01-08 23:43:23 -05:00
* 'avatar_default' option , with a fallback of 'mystery' .
* @ type bool $force_default Whether to always show the default image , never the Gravatar . Default false .
* @ type string $rating What rating to display avatars up to . Accepts 'G' , 'PG' , 'R' , 'X' , and are
* judged in that order . Default is the value of the 'avatar_rating' option .
2015-04-05 12:04:28 -04:00
* @ type string $scheme URL scheme to use . See set_url_scheme () for accepted values .
2015-01-08 23:43:23 -05:00
* Default null .
* @ type array $processed_args When the function returns , the value will be the processed / sanitized $args
* plus a " found_avatar " guess . Pass as a reference . Default null .
* }
2020-01-11 13:32:05 -05:00
* @ return string | false The URL of the avatar on success , false on failure .
2015-01-08 23:43:23 -05:00
*/
function get_avatar_url ( $id_or_email , $args = null ) {
$args = get_avatar_data ( $id_or_email , $args );
return $args [ 'url' ];
}
2019-01-09 01:00:51 -05:00
/**
* Check if this comment type allows avatars to be retrieved .
*
* @ since 5.1 . 0
*
* @ param string $comment_type Comment type to check .
* @ return bool Whether the comment type is allowed for retrieving avatars .
*/
function is_avatar_comment_type ( $comment_type ) {
/**
* Filters the list of allowed comment types for retrieving avatars .
*
* @ since 3.0 . 0
*
* @ param array $types An array of content types . Default only contains 'comment' .
*/
$allowed_comment_types = apply_filters ( 'get_avatar_comment_types' , array ( 'comment' ) );
return in_array ( $comment_type , ( array ) $allowed_comment_types , true );
}
2015-01-08 23:43:23 -05:00
/**
2016-04-15 12:58:27 -04:00
* Retrieves default data about the avatar .
2015-01-08 23:43:23 -05:00
*
* @ since 4.2 . 0
*
2022-08-11 10:11:08 -04:00
* @ param mixed $id_or_email The avatar to retrieve . Accepts a user ID , Gravatar MD5 hash ,
2019-09-21 13:41:57 -04:00
* user email , WP_User object , WP_Post object , or WP_Comment object .
2015-04-05 12:04:28 -04:00
* @ param array $args {
2022-08-11 10:11:08 -04:00
* Optional . Arguments to use instead of the default arguments .
2015-01-08 23:43:23 -05:00
*
2015-02-26 16:17:24 -05:00
* @ type int $size Height and width of the avatar image file in pixels . Default 96.
* @ type int $height Display height of the avatar in pixels . Defaults to $size .
* @ type int $width Display width of the avatar in pixels . Defaults to $size .
2015-01-08 23:43:23 -05:00
* @ type string $default URL for the default image or a default type . Accepts '404' ( return
* a 404 instead of a default image ), 'retro' ( 8 bit ), 'monsterid' ( monster ),
* 'wavatar' ( cartoon face ), 'indenticon' ( the " quilt " ), 'mystery' , 'mm' ,
2015-10-09 11:52:24 -04:00
* or 'mysteryman' ( The Oyster Man ), 'blank' ( transparent GIF ), or
2015-01-08 23:43:23 -05:00
* 'gravatar_default' ( the Gravatar logo ) . Default is the value of the
* 'avatar_default' option , with a fallback of 'mystery' .
* @ type bool $force_default Whether to always show the default image , never the Gravatar . Default false .
* @ type string $rating What rating to display avatars up to . Accepts 'G' , 'PG' , 'R' , 'X' , and are
* judged in that order . Default is the value of the 'avatar_rating' option .
2015-04-05 12:04:28 -04:00
* @ type string $scheme URL scheme to use . See set_url_scheme () for accepted values .
2015-01-08 23:43:23 -05:00
* Default null .
* @ type array $processed_args When the function returns , the value will be the processed / sanitized $args
* plus a " found_avatar " guess . Pass as a reference . Default null .
2015-03-01 02:19:24 -05:00
* @ type string $extra_attr HTML attributes to insert in the IMG element . Is not sanitized . Default empty .
2015-01-08 23:43:23 -05:00
* }
2019-09-21 13:41:57 -04:00
* @ return array {
2015-04-05 12:04:28 -04:00
* Along with the arguments passed in `$args` , this will contain a couple of extra arguments .
2015-01-08 23:43:23 -05:00
*
2022-08-11 10:03:09 -04:00
* @ type bool $found_avatar True if an avatar was found for this user ,
* false or not set if none was found .
* @ type string | false $url The URL of the avatar that was found , or false .
2015-01-08 23:43:23 -05:00
* }
*/
function get_avatar_data ( $id_or_email , $args = null ) {
2017-11-30 18:11:00 -05:00
$args = wp_parse_args (
2018-08-16 21:51:36 -04:00
$args ,
array (
2017-11-30 18:11:00 -05:00
'size' => 96 ,
'height' => null ,
'width' => null ,
'default' => get_option ( 'avatar_default' , 'mystery' ),
'force_default' => false ,
'rating' => get_option ( 'avatar_rating' ),
'scheme' => null ,
2020-01-28 19:45:18 -05:00
'processed_args' => null , // If used, should be a reference.
2017-11-30 18:11:00 -05:00
'extra_attr' => '' ,
)
);
2015-01-08 23:43:23 -05:00
if ( is_numeric ( $args [ 'size' ] ) ) {
$args [ 'size' ] = absint ( $args [ 'size' ] );
if ( ! $args [ 'size' ] ) {
$args [ 'size' ] = 96 ;
}
} else {
$args [ 'size' ] = 96 ;
}
2015-02-26 16:17:24 -05:00
if ( is_numeric ( $args [ 'height' ] ) ) {
$args [ 'height' ] = absint ( $args [ 'height' ] );
if ( ! $args [ 'height' ] ) {
$args [ 'height' ] = $args [ 'size' ];
}
} else {
$args [ 'height' ] = $args [ 'size' ];
}
if ( is_numeric ( $args [ 'width' ] ) ) {
$args [ 'width' ] = absint ( $args [ 'width' ] );
if ( ! $args [ 'width' ] ) {
$args [ 'width' ] = $args [ 'size' ];
}
} else {
$args [ 'width' ] = $args [ 'size' ];
}
2015-01-08 23:43:23 -05:00
if ( empty ( $args [ 'default' ] ) ) {
2015-01-11 19:23:24 -05:00
$args [ 'default' ] = get_option ( 'avatar_default' , 'mystery' );
2015-01-08 23:43:23 -05:00
}
switch ( $args [ 'default' ] ) {
2017-11-30 18:11:00 -05:00
case 'mm' :
case 'mystery' :
case 'mysteryman' :
2015-01-08 23:43:23 -05:00
$args [ 'default' ] = 'mm' ;
break ;
2017-11-30 18:11:00 -05:00
case 'gravatar_default' :
2015-01-08 23:43:23 -05:00
$args [ 'default' ] = false ;
break ;
}
$args [ 'force_default' ] = ( bool ) $args [ 'force_default' ];
$args [ 'rating' ] = strtolower ( $args [ 'rating' ] );
$args [ 'found_avatar' ] = false ;
/**
2016-04-15 12:58:27 -04:00
* Filters whether to retrieve the avatar URL early .
2015-01-08 23:43:23 -05:00
*
* Passing a non - null value in the 'url' member of the return array will
2015-04-05 12:04:28 -04:00
* effectively short circuit get_avatar_data (), passing the value through
* the { @ see 'get_avatar_data' } filter and returning early .
2015-01-08 23:43:23 -05:00
*
* @ since 4.2 . 0
*
2019-09-21 13:41:57 -04:00
* @ param array $args Arguments passed to get_avatar_data (), after processing .
2022-08-11 10:11:08 -04:00
* @ param mixed $id_or_email The avatar to retrieve . Accepts a user ID , Gravatar MD5 hash ,
2019-09-21 13:41:57 -04:00
* user email , WP_User object , WP_Post object , or WP_Comment object .
2015-01-08 23:43:23 -05:00
*/
$args = apply_filters ( 'pre_get_avatar_data' , $args , $id_or_email );
2018-12-19 21:49:48 -05:00
if ( isset ( $args [ 'url' ] ) ) {
2015-02-19 09:59:26 -05:00
/** This filter is documented in wp-includes/link-template.php */
2015-01-08 23:43:23 -05:00
return apply_filters ( 'get_avatar_data' , $args , $id_or_email );
}
$email_hash = '' ;
2019-07-02 19:42:58 -04:00
$user = false ;
$email = false ;
2015-01-08 23:43:23 -05:00
2015-09-14 21:34:25 -04:00
if ( is_object ( $id_or_email ) && isset ( $id_or_email -> comment_ID ) ) {
$id_or_email = get_comment ( $id_or_email );
}
2015-01-08 23:43:23 -05:00
// Process the user identifier.
if ( is_numeric ( $id_or_email ) ) {
$user = get_user_by ( 'id' , absint ( $id_or_email ) );
} elseif ( is_string ( $id_or_email ) ) {
if ( strpos ( $id_or_email , '@md5.gravatar.com' ) ) {
2020-01-28 19:45:18 -05:00
// MD5 hash.
2015-01-08 23:43:23 -05:00
list ( $email_hash ) = explode ( '@' , $id_or_email );
} else {
2020-01-28 19:45:18 -05:00
// Email address.
2015-01-08 23:43:23 -05:00
$email = $id_or_email ;
}
} elseif ( $id_or_email instanceof WP_User ) {
2020-01-28 19:45:18 -05:00
// User object.
2015-01-08 23:43:23 -05:00
$user = $id_or_email ;
} elseif ( $id_or_email instanceof WP_Post ) {
2020-01-28 19:45:18 -05:00
// Post object.
2015-01-08 23:43:23 -05:00
$user = get_user_by ( 'id' , ( int ) $id_or_email -> post_author );
2015-09-03 14:17:24 -04:00
} elseif ( $id_or_email instanceof WP_Comment ) {
2019-01-09 01:00:51 -05:00
if ( ! is_avatar_comment_type ( get_comment_type ( $id_or_email ) ) ) {
2015-01-08 23:43:23 -05:00
$args [ 'url' ] = false ;
2015-02-19 09:59:26 -05:00
/** This filter is documented in wp-includes/link-template.php */
2015-01-08 23:43:23 -05:00
return apply_filters ( 'get_avatar_data' , $args , $id_or_email );
}
if ( ! empty ( $id_or_email -> user_id ) ) {
$user = get_user_by ( 'id' , ( int ) $id_or_email -> user_id );
}
if ( ( ! $user || is_wp_error ( $user ) ) && ! empty ( $id_or_email -> comment_author_email ) ) {
$email = $id_or_email -> comment_author_email ;
}
}
if ( ! $email_hash ) {
if ( $user ) {
$email = $user -> user_email ;
}
if ( $email ) {
$email_hash = md5 ( strtolower ( trim ( $email ) ) );
}
}
if ( $email_hash ) {
$args [ 'found_avatar' ] = true ;
2017-11-30 18:11:00 -05:00
$gravatar_server = hexdec ( $email_hash [ 0 ] ) % 3 ;
2015-01-08 23:43:23 -05:00
} else {
$gravatar_server = rand ( 0 , 2 );
}
$url_args = array (
's' => $args [ 'size' ],
'd' => $args [ 'default' ],
'f' => $args [ 'force_default' ] ? 'y' : false ,
'r' => $args [ 'rating' ],
);
2015-06-18 14:36:25 -04:00
if ( is_ssl () ) {
$url = 'https://secure.gravatar.com/avatar/' . $email_hash ;
} else {
$url = sprintf ( 'http://%d.gravatar.com/avatar/%s' , $gravatar_server , $email_hash );
}
2015-01-08 23:43:23 -05:00
$url = add_query_arg (
rawurlencode_deep ( array_filter ( $url_args ) ),
set_url_scheme ( $url , $args [ 'scheme' ] )
);
/**
2016-04-15 12:58:27 -04:00
* Filters the avatar URL .
2015-01-08 23:43:23 -05:00
*
* @ since 4.2 . 0
*
2015-09-03 14:17:24 -04:00
* @ param string $url The URL of the avatar .
2022-08-11 10:11:08 -04:00
* @ param mixed $id_or_email The avatar to retrieve . Accepts a user ID , Gravatar MD5 hash ,
2015-09-03 14:17:24 -04:00
* user email , WP_User object , WP_Post object , or WP_Comment object .
* @ param array $args Arguments passed to get_avatar_data (), after processing .
2015-01-08 23:43:23 -05:00
*/
$args [ 'url' ] = apply_filters ( 'get_avatar_url' , $url , $id_or_email , $args );
/**
2016-04-15 12:58:27 -04:00
* Filters the avatar data .
2015-01-08 23:43:23 -05:00
*
* @ since 4.2 . 0
*
2019-09-21 13:41:57 -04:00
* @ param array $args Arguments passed to get_avatar_data (), after processing .
2022-08-11 10:11:08 -04:00
* @ param mixed $id_or_email The avatar to retrieve . Accepts a user ID , Gravatar MD5 hash ,
2019-09-21 13:41:57 -04:00
* user email , WP_User object , WP_Post object , or WP_Comment object .
2015-01-08 23:43:23 -05:00
*/
2015-01-11 19:20:24 -05:00
return apply_filters ( 'get_avatar_data' , $args , $id_or_email );
2015-01-08 23:43:23 -05:00
}
2016-09-08 18:54:32 -04:00
/**
2016-09-14 17:48:28 -04:00
* Retrieves the URL of a file in the theme .
2016-09-08 18:54:32 -04:00
*
* Searches in the stylesheet directory before the template directory so themes
* which inherit from a parent theme can just override one file .
*
* @ since 4.7 . 0
*
* @ param string $file Optional . File to search for in the stylesheet directory .
* @ return string The URL of the file .
*/
function get_theme_file_uri ( $file = '' ) {
$file = ltrim ( $file , '/' );
if ( empty ( $file ) ) {
$url = get_stylesheet_directory_uri ();
} elseif ( file_exists ( get_stylesheet_directory () . '/' . $file ) ) {
$url = get_stylesheet_directory_uri () . '/' . $file ;
} else {
$url = get_template_directory_uri () . '/' . $file ;
}
/**
2016-09-14 17:45:29 -04:00
* Filters the URL to a file in the theme .
2016-09-08 18:54:32 -04:00
*
* @ since 4.7 . 0
*
* @ param string $url The file URL .
* @ param string $file The requested file to search for .
*/
return apply_filters ( 'theme_file_uri' , $url , $file );
}
/**
2016-09-14 17:48:28 -04:00
* Retrieves the URL of a file in the parent theme .
2016-09-08 18:54:32 -04:00
*
* @ since 4.7 . 0
*
* @ param string $file Optional . File to return the URL for in the template directory .
* @ return string The URL of the file .
*/
function get_parent_theme_file_uri ( $file = '' ) {
$file = ltrim ( $file , '/' );
if ( empty ( $file ) ) {
$url = get_template_directory_uri ();
} else {
$url = get_template_directory_uri () . '/' . $file ;
}
/**
2016-09-14 17:45:29 -04:00
* Filters the URL to a file in the parent theme .
2016-09-08 18:54:32 -04:00
*
* @ since 4.7 . 0
*
* @ param string $url The file URL .
* @ param string $file The requested file to search for .
*/
return apply_filters ( 'parent_theme_file_uri' , $url , $file );
}
/**
2016-09-14 17:48:28 -04:00
* Retrieves the path of a file in the theme .
2016-09-08 18:54:32 -04:00
*
* Searches in the stylesheet directory before the template directory so themes
* which inherit from a parent theme can just override one file .
*
* @ since 4.7 . 0
*
* @ param string $file Optional . File to search for in the stylesheet directory .
* @ return string The path of the file .
*/
function get_theme_file_path ( $file = '' ) {
$file = ltrim ( $file , '/' );
if ( empty ( $file ) ) {
$path = get_stylesheet_directory ();
} elseif ( file_exists ( get_stylesheet_directory () . '/' . $file ) ) {
$path = get_stylesheet_directory () . '/' . $file ;
} else {
$path = get_template_directory () . '/' . $file ;
}
/**
2016-09-14 17:45:29 -04:00
* Filters the path to a file in the theme .
2016-09-08 18:54:32 -04:00
*
* @ since 4.7 . 0
*
* @ param string $path The file path .
* @ param string $file The requested file to search for .
*/
return apply_filters ( 'theme_file_path' , $path , $file );
}
/**
2016-09-14 17:48:28 -04:00
* Retrieves the path of a file in the parent theme .
2016-09-08 18:54:32 -04:00
*
* @ since 4.7 . 0
*
* @ param string $file Optional . File to return the path for in the template directory .
* @ return string The path of the file .
*/
function get_parent_theme_file_path ( $file = '' ) {
$file = ltrim ( $file , '/' );
if ( empty ( $file ) ) {
$path = get_template_directory ();
} else {
$path = get_template_directory () . '/' . $file ;
}
/**
2016-09-14 17:45:29 -04:00
* Filters the path to a file in the parent theme .
2016-09-08 18:54:32 -04:00
*
* @ since 4.7 . 0
*
* @ param string $path The file path .
* @ param string $file The requested file to search for .
*/
return apply_filters ( 'parent_theme_file_path' , $path , $file );
}
2018-04-16 04:53:20 -04:00
/**
* Retrieves the URL to the privacy policy page .
*
* @ since 4.9 . 6
*
* @ return string The URL to the privacy policy page . Empty string if it doesn ' t exist .
*/
function get_privacy_policy_url () {
2018-04-25 11:55:21 -04:00
$url = '' ;
2018-04-16 04:53:20 -04:00
$policy_page_id = ( int ) get_option ( 'wp_page_for_privacy_policy' );
2018-04-20 10:44:20 -04:00
if ( ! empty ( $policy_page_id ) && get_post_status ( $policy_page_id ) === 'publish' ) {
2018-04-25 11:55:21 -04:00
$url = ( string ) get_permalink ( $policy_page_id );
}
/**
* Filters the URL of the privacy policy page .
*
* @ since 4.9 . 6
*
* @ param string $url The URL to the privacy policy page . Empty string
* if it doesn ' t exist .
* @ param int $policy_page_id The ID of privacy policy page .
*/
return apply_filters ( 'privacy_policy_url' , $url , $policy_page_id );
}
/**
* Displays the privacy policy link with formatting , when applicable .
*
* @ since 4.9 . 6
*
* @ param string $before Optional . Display before privacy policy link . Default empty .
* @ param string $after Optional . Display after privacy policy link . Default empty .
*/
function the_privacy_policy_link ( $before = '' , $after = '' ) {
echo get_the_privacy_policy_link ( $before , $after );
}
/**
* Returns the privacy policy link with formatting , when applicable .
*
* @ since 4.9 . 6
2023-03-08 08:36:22 -05:00
* @ since 6.2 . 0 Added 'privacy-policy' rel attribute .
2018-04-25 11:55:21 -04:00
*
* @ param string $before Optional . Display before privacy policy link . Default empty .
* @ param string $after Optional . Display after privacy policy link . Default empty .
* @ return string Markup for the link and surrounding elements . Empty string if it
* doesn ' t exist .
*/
function get_the_privacy_policy_link ( $before = '' , $after = '' ) {
$link = '' ;
$privacy_policy_url = get_privacy_policy_url ();
2018-07-18 07:50:25 -04:00
$policy_page_id = ( int ) get_option ( 'wp_page_for_privacy_policy' );
$page_title = ( $policy_page_id ) ? get_the_title ( $policy_page_id ) : '' ;
2018-04-25 11:55:21 -04:00
2018-07-18 07:50:25 -04:00
if ( $privacy_policy_url && $page_title ) {
2018-04-25 11:55:21 -04:00
$link = sprintf (
Privacy: Add `rel="privacy-policy"` to the Privacy Policy link.
This changeset adds a `rel="privacy-policy"` attribute to user-facing links to the Privacy Policy of the website, when a privacy policy page is set and available. While this `rel` value is still a RFC of the Link Types HTML specification, this changeset helps to make Privacy Policy link more discoverable for user agents and HTML parsers.
Props dshanske, audrasjb, bhavz-10, bookwyrm, faisal03, JeffPaul, peterwilsoncc, paapst, davidbaumwald, costdev, robinwpdeveloper, kawserz.
Fixes #56345.
Built from https://develop.svn.wordpress.org/trunk@55261
git-svn-id: http://core.svn.wordpress.org/trunk@54794 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-07 09:05:20 -05:00
'<a class="privacy-policy-link" href="%s" rel="privacy-policy">%s</a>' ,
2018-04-25 11:55:21 -04:00
esc_url ( $privacy_policy_url ),
2018-07-18 07:50:25 -04:00
esc_html ( $page_title )
2018-04-25 11:55:21 -04:00
);
}
/**
* Filters the privacy policy link .
*
* @ since 4.9 . 6
*
* @ param string $link The privacy policy link . Empty string if it
* doesn ' t exist .
* @ param string $privacy_policy_url The URL of the privacy policy . Empty string
* if it doesn ' t exist .
*/
$link = apply_filters ( 'the_privacy_policy_link' , $link , $privacy_policy_url );
if ( $link ) {
return $before . $link . $after ;
2018-04-16 04:53:20 -04:00
}
2018-04-20 10:44:20 -04:00
return '' ;
2018-04-16 04:53:20 -04:00
}
2023-02-07 13:54:19 -05:00
/**
* Returns an array of URL hosts which are considered to be internal hosts .
*
2023-04-27 18:29:18 -04:00
* By default the list of internal hosts is comprised of the host name of
2023-02-07 13:54:19 -05:00
* the site ' s home_url () ( as parsed by wp_parse_url ()) .
*
* This list is used when determining if a specificed URL is a link to a page on
* the site itself or a link offsite ( to an external host ) . This is used , for
* example , when determining if the " nofollow " attribute should be applied to a
* link .
*
* @ see wp_is_internal_link
*
* @ since 6.2 . 0
*
* @ return string [] An array of URL hosts .
*/
function wp_internal_hosts () {
static $internal_hosts ;
if ( empty ( $internal_hosts ) ) {
/**
* Filters the array of URL hosts which are considered internal .
*
2023-02-27 17:55:22 -05:00
* @ since 6.2 . 0
2023-02-07 13:54:19 -05:00
*
2023-04-27 18:29:18 -04:00
* @ param string [] $internal_hosts An array of internal URL hostnames .
2023-02-07 13:54:19 -05:00
*/
$internal_hosts = apply_filters (
'wp_internal_hosts' ,
array (
wp_parse_url ( home_url (), PHP_URL_HOST ),
)
);
$internal_hosts = array_unique (
array_map ( 'strtolower' , ( array ) $internal_hosts )
);
}
return $internal_hosts ;
}
/**
* Determines whether or not the specified URL is of a host included in the internal hosts list .
*
* @ see wp_internal_hosts ()
*
* @ since 6.2 . 0
*
* @ param string $link The URL to test .
* @ return bool Returns true for internal URLs and false for all other URLs .
*/
function wp_is_internal_link ( $link ) {
$link = strtolower ( $link );
if ( in_array ( wp_parse_url ( $link , PHP_URL_SCHEME ), wp_allowed_protocols (), true ) ) {
return in_array ( wp_parse_url ( $link , PHP_URL_HOST ), wp_internal_hosts (), true );
}
return false ;
}