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
/**
2008-10-21 23:08:33 -04:00
* Display the permalink for the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.2 . 0
*/
2004-04-21 00:12:55 -04:00
function the_permalink () {
2014-04-13 22:13:16 -04:00
/**
* Filter the display of the permalink for the current post .
*
* @ since 1.5 . 0
*
* @ param string $permalink The permalink for the current post .
*/
2013-02-28 13:56:39 -05:00
echo esc_url ( apply_filters ( 'the_permalink' , get_permalink () ) );
2004-05-18 04:36:53 -04:00
}
2007-02-15 02:07:12 -05:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve trailing slash string , if blog 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
* 'user_trailingslashit' filter . Will remove trailing slash from string , if
* blog is not set to have them .
2008-10-13 18:00:07 -04:00
*
* @ since 2.2 . 0
* @ uses $wp_rewrite
*
2010-09-07 07:21:11 -04:00
* @ param string $string URL with or without a trailing slash .
* @ param string $type_of_url The type of URL being considered ( e . g . single , category , etc ) for use in the filter .
2007-02-15 02:07:12 -05:00
* @ return string
*/
2007-03-10 01:18:43 -05:00
function user_trailingslashit ( $string , $type_of_url = '' ) {
2007-02-15 02:07:12 -05:00
global $wp_rewrite ;
if ( $wp_rewrite -> use_trailing_slashes )
$string = trailingslashit ( $string );
else
2007-03-10 01:25:33 -05:00
$string = untrailingslashit ( $string );
2007-03-10 01:18:43 -05:00
2014-04-13 22:13:16 -04:00
/**
* Filter the trailing slashed string , depending on whether the site is set
* to use training slashes .
*
* @ since 2.2 . 0
*
* @ param string $string URL with or without a trailing slash .
* @ param string $type_of_url The type of URL being considered . Accepts 'single' , 'single_trackback' ,
* 'single_feed' , 'single_paged' , 'feed' , 'category' , 'page' , 'year' ,
* 'month' , 'day' , 'paged' , 'post_type_archive' .
*/
$string = apply_filters ( 'user_trailingslashit' , $string , $type_of_url );
2007-02-15 02:07:12 -05:00
return $string ;
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Display permalink anchor for 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
*
2008-10-21 23:08:33 -04:00
* @ param string $mode Permalink mode can be either 'title' , 'id' , or default , which is '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 ;
2005-10-17 19:41:28 -04:00
echo '<a id="' . $title . '"></a>' ;
break ;
case 'id' :
default :
echo '<a id="post-' . $post -> ID . '"></a>' ;
break ;
}
2004-01-27 04:58:01 -05:00
}
2014-03-05 02:24:14 -05:00
/**
2014-04-07 16:22:15 -04:00
* Retrieve full permalink for current post or post ID .
*
* 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 ()
*
2014-04-07 16:22:15 -04:00
* @ param int | WP_Post $id Optional . Post ID or post object . Default is the current post .
2014-03-05 02:24:14 -05:00
* @ param bool $leavename Optional . Whether to keep post name or page name . Default false .
* @ return string | bool The permalink URL or false if post does not exist .
*/
function get_the_permalink ( $id = 0 , $leavename = false ) {
return get_permalink ( $id , $leavename );
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve full permalink for current post or post ID .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2014-03-05 02:24:14 -05:00
* @ param int | WP_Post $id Optional . Post ID or post object . Default current post .
* @ param bool $leavename Optional . Whether to keep post name or page name . Default false .
2013-08-21 18:12:10 -04:00
* @ return string | bool The permalink URL or false if post does not exist .
2008-10-13 18:00:07 -04:00
*/
2012-09-04 12:29:28 -04:00
function get_permalink ( $id = 0 , $leavename = false ) {
2004-09-04 22:41:01 -04:00
$rewritecode = array (
'%year%' ,
'%monthnum%' ,
'%day%' ,
'%hour%' ,
'%minute%' ,
'%second%' ,
2008-01-17 11:51:32 -05:00
$leavename ? '' : '%postname%' ,
2004-09-04 22:41:01 -04:00
'%post_id%' ,
'%category%' ,
'%author%' ,
2008-01-17 11:51:32 -05:00
$leavename ? '' : '%pagename%' ,
2004-09-04 22:41:01 -04:00
);
2004-08-10 01:35:59 -04:00
2009-02-08 08:38:02 -05:00
if ( is_object ( $id ) && isset ( $id -> filter ) && 'sample' == $id -> filter ) {
2008-12-16 18:50:39 -05:00
$post = $id ;
2009-02-08 08:38:02 -05:00
$sample = true ;
} else {
2012-08-23 16:01:10 -04:00
$post = get_post ( $id );
2009-02-08 08:38:02 -05:00
$sample = false ;
}
2007-08-28 14:58:54 -04:00
2010-03-02 06:57:32 -05:00
if ( empty ( $post -> ID ) )
return false ;
2007-08-28 14:58:54 -04:00
2006-02-09 05:03:48 -05:00
if ( $post -> post_type == 'page' )
2014-07-08 11:48:17 -04:00
return get_page_link ( $post , $leavename , $sample );
2010-02-01 18:12:26 -05:00
elseif ( $post -> post_type == 'attachment' )
2014-07-08 11:48:17 -04:00
return get_attachment_link ( $post , $leavename );
2010-02-01 18:12:26 -05:00
elseif ( in_array ( $post -> post_type , get_post_types ( array ( '_builtin' => false ) ) ) )
2014-07-08 11:48:17 -04:00
return get_post_permalink ( $post , $leavename , $sample );
2004-11-12 18:08:51 -05:00
2006-08-30 17:46:31 -04:00
$permalink = get_option ( 'permalink_structure' );
2004-08-10 01:35:59 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the permalink structure for a post before token replacement occurs .
*
* 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
2010-02-06 05:07:57 -05:00
if ( '' != $permalink && ! in_array ( $post -> post_status , array ( 'draft' , 'pending' , 'auto-draft' )) ) {
2005-03-27 15:45:01 -05:00
$unixtime = strtotime ( $post -> post_date );
2004-06-03 22:36:46 -04:00
2005-02-16 10:49:02 -05:00
$category = '' ;
2007-12-03 19:40:00 -05:00
if ( strpos ( $permalink , '%category%' ) !== false ) {
2010-11-12 16:53:15 -05:00
$cats = get_the_category ( $post -> ID );
2008-11-30 14:29:46 -05:00
if ( $cats ) {
2007-05-29 00:54:45 -04:00
usort ( $cats , '_usort_terms_by_ID' ); // order by ID
2014-04-13 22:13:16 -04:00
/**
* Filter the category that gets used in the % category % permalink token .
*
* @ since 3.5 . 0
*
* @ param stdClass $cat The category to use in the permalink .
* @ param array $cats Array of all categories associated with the post .
* @ 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' );
$category = $category_object -> slug ;
if ( $parent = $category_object -> parent )
2008-11-30 14:29:46 -05:00
$category = get_category_parents ( $parent , false , '/' , true ) . $category ;
}
2008-04-07 21:55:04 -04:00
// show default category in permalinks, without
// having to assign it explicitly
if ( empty ( $category ) ) {
2013-10-02 15:59:10 -04:00
$default_category = get_term ( get_option ( 'default_category' ), 'category' );
2008-08-09 01:36:14 -04:00
$category = is_wp_error ( $default_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 = '' ;
if ( strpos ( $permalink , '%author%' ) !== false ) {
$authordata = get_userdata ( $post -> post_author );
$author = $authordata -> user_nicename ;
}
2006-02-16 20:04:20 -05:00
$date = explode ( " " , date ( 'Y m d H i s' , $unixtime ));
2006-11-19 02:56:05 -05:00
$rewritereplace =
2004-09-04 22:41:01 -04:00
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
);
2010-01-04 12:23:29 -05:00
$permalink = home_url ( str_replace ( $rewritecode , $rewritereplace , $permalink ) );
2007-03-10 01:18:43 -05:00
$permalink = user_trailingslashit ( $permalink , 'single' );
2004-09-04 22:41:01 -04:00
} else { // if they're not using the fancy permalink option
2010-01-04 12:23:29 -05:00
$permalink = home_url ( '?p=' . $post -> ID );
2004-09-04 22:41:01 -04:00
}
2014-04-13 22:13:16 -04:00
/**
* Filter the permalink for a post .
*
* 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
/**
* Retrieve the permalink for a post with a custom post type .
*
* @ since 3.0 . 0
*
* @ param int $id Optional . Post ID .
* @ param bool $leavename Optional , defaults to false . Whether to keep post name .
* @ param bool $sample Optional , defaults to false . Is it a sample permalink .
* @ return string
*/
2010-02-08 11:23:32 -05:00
function get_post_permalink ( $id = 0 , $leavename = false , $sample = false ) {
2010-02-01 18:12:26 -05:00
global $wp_rewrite ;
2012-08-23 16:01:10 -04:00
$post = get_post ( $id );
2010-02-01 18:12:26 -05:00
if ( is_wp_error ( $post ) )
return $post ;
$post_link = $wp_rewrite -> get_extra_permastruct ( $post -> post_type );
$slug = $post -> post_name ;
2010-12-20 06:41:08 -05:00
$draft_or_pending = isset ( $post -> post_status ) && in_array ( $post -> post_status , array ( 'draft' , 'pending' , 'auto-draft' ) );
2010-02-08 11:23:32 -05:00
2010-03-19 22:23:52 -04:00
$post_type = get_post_type_object ( $post -> post_type );
2014-11-06 03:22:35 -05:00
if ( $post_type -> hierarchical ) {
$slug = get_page_uri ( $id );
}
2010-12-20 06:41:08 -05:00
if ( ! empty ( $post_link ) && ( ! $draft_or_pending || $sample ) ) {
2010-03-19 22:23:52 -04:00
if ( ! $leavename ) {
$post_link = str_replace ( " % $post->post_type % " , $slug , $post_link );
}
2010-02-01 18:12:26 -05:00
$post_link = home_url ( user_trailingslashit ( $post_link ) );
} else {
2010-02-08 11:23:32 -05:00
if ( $post_type -> query_var && ( isset ( $post -> post_status ) && ! $draft_or_pending ) )
$post_link = add_query_arg ( $post_type -> query_var , $slug , '' );
2010-02-01 18:12:26 -05:00
else
2010-02-08 11:23:32 -05:00
$post_link = add_query_arg ( array ( 'post_type' => $post -> post_type , 'p' => $post -> ID ), '' );
2010-02-01 18:12:26 -05:00
$post_link = home_url ( $post_link );
}
2014-04-13 22:13:16 -04:00
/**
* Filter the permalink for a post with a custom post type .
*
* @ 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
/**
* Retrieve permalink from post ID .
*
* @ since 1.0 . 0
*
2014-07-03 15:28:14 -04:00
* @ param int | WP_Post $post_id Optional . Post ID or WP_Post object . Default is global $post .
2008-10-21 23:08:33 -04:00
* @ param mixed $deprecated Not used .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2009-12-30 11:23:39 -05:00
function post_permalink ( $post_id = 0 , $deprecated = '' ) {
if ( ! empty ( $deprecated ) )
2010-01-09 05:03:55 -05:00
_deprecated_argument ( __FUNCTION__ , '1.3' );
2009-12-30 11:23:39 -05:00
2006-06-07 19:17:59 -04:00
return get_permalink ( $post_id );
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for 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
*
2013-06-21 08:45:11 -04:00
* @ param int | object $post Optional . Post ID or object .
2009-02-08 08:38:02 -05:00
* @ param bool $leavename Optional , defaults to false . Whether to keep page name .
* @ param bool $sample Optional , defaults to false . Is it a sample permalink .
2008-10-21 23:08:33 -04:00
* @ return string
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
2012-09-04 12:29:28 -04:00
if ( 'page' == get_option ( 'show_on_front' ) && $post -> ID == get_option ( 'page_on_front' ) )
2010-02-05 22:40:24 -05:00
$link = home_url ( '/' );
2006-11-17 15:00:11 -05:00
else
2012-09-04 12:29:28 -04:00
$link = _get_page_link ( $post , $leavename , $sample );
2006-11-17 15:00:11 -05:00
2014-04-13 22:13:16 -04:00
/**
* Filter the permalink for a page .
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Retrieve the page permalink .
2008-10-13 18:00:07 -04:00
*
* Ignores page_on_front . Internal use only .
*
* @ since 2.1 . 0
* @ access private
*
2013-06-21 08:45:11 -04:00
* @ param int | object $post Optional . Post ID or object .
2008-10-21 23:08:33 -04:00
* @ param bool $leavename Optional . Leave name .
2009-02-08 08:38:02 -05:00
* @ param bool $sample Optional . Sample permalink .
2008-10-21 23:08:33 -04:00
* @ return string
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
2010-12-19 09:42:17 -05:00
$draft_or_pending = in_array ( $post -> post_status , array ( 'draft' , 'pending' , 'auto-draft' ) );
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
if ( ! empty ( $link ) && ( ( isset ( $post -> post_status ) && ! $draft_or_pending ) || $sample ) ) {
2010-12-19 09:42:17 -05:00
if ( ! $leavename ) {
2012-09-04 12:29:28 -04:00
$link = str_replace ( '%pagename%' , get_page_uri ( $post ), $link );
2010-12-19 09:42:17 -05:00
}
2010-01-04 12:23:29 -05:00
$link = home_url ( $link );
2007-03-10 01:18:43 -05:00
$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
/**
* Filter the permalink for a non - page_on_front page .
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Retrieve permalink for 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
*
2013-06-21 08:45:11 -04:00
* @ param int | object $post Optional . Post ID or object .
2012-09-21 18:52:54 -04:00
* @ param bool $leavename Optional . Leave name .
2008-10-21 23:08:33 -04:00
* @ return string
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 ;
2012-09-04 12:29:28 -04:00
$post = get_post ( $post );
2013-05-07 07:46:35 -04:00
$parent = ( $post -> post_parent > 0 && $post -> post_parent != $post -> ID ) ? get_post ( $post -> post_parent ) : false ;
2005-10-20 16:48:32 -04:00
2013-05-07 07:46:35 -04:00
if ( $wp_rewrite -> using_permalinks () && $parent ) {
2006-11-17 15:00:11 -05:00
if ( 'page' == $parent -> post_type )
2012-09-04 12:29:28 -04:00
$parentlink = _get_page_link ( $post -> post_parent ); // Ignores page_on_front
2006-11-17 15:00:11 -05:00
else
2012-09-04 12:29:28 -04:00
$parentlink = get_permalink ( $post -> post_parent );
2010-03-19 22:23:52 -04:00
2012-09-04 12:29:28 -04:00
if ( is_numeric ( $post -> post_name ) || false !== strpos ( get_option ( 'permalink_structure' ), '%category%' ) )
$name = 'attachment/' . $post -> post_name ; // <permalink>/<int>/ is paged so we use the explicit attachment marker
2008-03-20 23:08:22 -04:00
else
2012-09-04 12:29:28 -04:00
$name = $post -> post_name ;
2010-03-19 22:23:52 -04:00
if ( strpos ( $parentlink , '?' ) === false )
2012-09-21 18:52:54 -04:00
$link = user_trailingslashit ( trailingslashit ( $parentlink ) . '%postname%' );
if ( ! $leavename )
$link = str_replace ( '%postname%' , $name , $link );
2005-10-20 16:48:32 -04:00
}
2010-03-19 22:23:52 -04:00
if ( ! $link )
2012-09-04 12:29:28 -04:00
$link = home_url ( '/?attachment_id=' . $post -> ID );
2005-10-20 16:48:32 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the permalink for an attachment .
*
* @ since 2.0 . 0
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the year archives .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2008-10-21 23:08:33 -04:00
* @ param int | bool $year False for current year or year for permalink .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2004-11-19 15:54:16 -05:00
function get_year_link ( $year ) {
2005-02-07 02:37:53 -05:00
global $wp_rewrite ;
2005-10-17 19:41:28 -04:00
if ( ! $year )
2009-12-30 12:56:09 -05:00
$year = gmdate ( 'Y' , current_time ( 'timestamp' ));
2005-10-17 19:41:28 -04:00
$yearlink = $wp_rewrite -> get_year_permastruct ();
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
/**
* Filter the year archive permalink .
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the month archives with year .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2008-10-21 23:08:33 -04:00
* @ param bool | int $year False for current year . Integer of year .
* @ param bool | int $month False for current month . Integer of month .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2004-01-27 04:58:01 -05:00
function get_month_link ( $year , $month ) {
2005-10-17 19:41:28 -04:00
global $wp_rewrite ;
if ( ! $year )
2009-12-30 12:56:09 -05:00
$year = gmdate ( 'Y' , current_time ( 'timestamp' ));
2005-10-17 19:41:28 -04:00
if ( ! $month )
2009-12-30 12:56:09 -05:00
$month = gmdate ( 'm' , current_time ( 'timestamp' ));
2005-10-17 19:41:28 -04:00
$monthlink = $wp_rewrite -> get_month_permastruct ();
if ( ! empty ( $monthlink ) ) {
$monthlink = str_replace ( '%year%' , $year , $monthlink );
$monthlink = str_replace ( '%monthnum%' , zeroise ( intval ( $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
/**
* Filter the month archive permalink .
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the day archives with year and month .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2008-10-21 23:08:33 -04:00
* @ param bool | int $year False for current year . Integer of year .
* @ param bool | int $month False for current month . Integer of month .
* @ param bool | int $day False for current day . Integer of day .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2004-01-27 04:58:01 -05:00
function get_day_link ( $year , $month , $day ) {
2005-10-17 19:41:28 -04:00
global $wp_rewrite ;
if ( ! $year )
2009-12-30 12:56:09 -05:00
$year = gmdate ( 'Y' , current_time ( 'timestamp' ));
2005-10-17 19:41:28 -04:00
if ( ! $month )
2009-12-30 12:56:09 -05:00
$month = gmdate ( 'm' , current_time ( 'timestamp' ));
2005-10-17 19:41:28 -04:00
if ( ! $day )
2009-12-30 12:56:09 -05:00
$day = gmdate ( 'j' , current_time ( 'timestamp' ));
2005-10-17 19:41:28 -04:00
$daylink = $wp_rewrite -> get_day_permastruct ();
if ( ! empty ( $daylink ) ) {
$daylink = str_replace ( '%year%' , $year , $daylink );
$daylink = str_replace ( '%monthnum%' , zeroise ( intval ( $month ), 2 ), $daylink );
$daylink = str_replace ( '%day%' , zeroise ( intval ( $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
/**
* Filter the day archive permalink .
*
* @ 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
/**
* Display the permalink for the feed type .
*
* @ since 3.0 . 0
*
* @ param string $anchor The link ' s anchor text .
* @ param string $feed Optional , defaults to default feed . Feed type .
*/
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
/**
* Filter the feed link anchor tag .
*
* @ since 3.0 . 0
*
* @ param string $link The complete anchor tag for a feed link .
* @ param string $feed The feed type , or an empty string for the
* default feed type .
*/
2010-03-02 14:00:21 -05:00
echo apply_filters ( 'the_feed_link' , $link , $feed );
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the feed type .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2008-10-21 23:08:33 -04:00
* @ param string $feed Optional , defaults to default feed . Feed type .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2007-12-06 14:58:15 -05: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 ();
2005-10-17 19:41:28 -04:00
if ( '' != $permalink ) {
2005-01-26 17:46:40 -05:00
if ( false !== strpos ( $feed , 'comments_' ) ) {
$feed = str_replace ( 'comments_' , '' , $feed );
$permalink = $wp_rewrite -> get_comment_feed_permastruct ();
}
2007-12-06 14:58:15 -05:00
if ( get_default_feed () == $feed )
2005-01-26 17:46:40 -05:00
$feed = '' ;
$permalink = str_replace ( '%feed%' , $feed , $permalink );
2007-02-15 02:07:12 -05:00
$permalink = preg_replace ( '#/+#' , '/' , " / $permalink " );
2010-01-04 12:23:29 -05:00
$output = home_url ( user_trailingslashit ( $permalink , 'feed' ) );
2005-01-26 17:46:40 -05:00
} else {
2007-12-06 14:58:15 -05:00
if ( empty ( $feed ) )
$feed = get_default_feed ();
2005-01-26 17:46:40 -05:00
if ( false !== strpos ( $feed , 'comments_' ) )
2005-02-26 01:12:16 -05:00
$feed = str_replace ( 'comments_' , 'comments-' , $feed );
2005-01-26 17:46:40 -05:00
2010-01-04 12:23:29 -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
/**
* Filter the feed type permalink .
*
* @ since 1.5 . 0
*
* @ param string $output The feed permalink .
* @ param string $feed Feed type .
*/
return apply_filters ( 'feed_link' , $output , $feed );
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the post comments feed .
2008-10-13 18:00:07 -04:00
*
* @ since 2.2 . 0
*
2008-10-21 23:08:33 -04:00
* @ param int $post_id Optional . Post ID .
* @ param string $feed Optional . Feed type .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2010-09-04 11:51:04 -04:00
function get_post_comments_feed_link ( $post_id = 0 , $feed = '' ) {
$post_id = absint ( $post_id );
2007-02-23 03:31:07 -05:00
2010-09-04 11:51:04 -04:00
if ( ! $post_id )
$post_id = get_the_ID ();
2007-02-23 03:31:07 -05:00
2010-09-04 11:51:04 -04:00
if ( empty ( $feed ) )
2007-12-06 14:58:15 -05:00
$feed = get_default_feed ();
2007-02-23 03:31:07 -05:00
if ( '' != get_option ( 'permalink_structure' ) ) {
2010-04-18 02:51:16 -04:00
if ( 'page' == get_option ( 'show_on_front' ) && $post_id == get_option ( 'page_on_front' ) )
$url = _get_page_link ( $post_id );
else
$url = get_permalink ( $post_id );
$url = trailingslashit ( $url ) . 'feed' ;
2007-12-06 14:58:15 -05:00
if ( $feed != get_default_feed () )
2007-02-23 03:31:07 -05:00
$url .= " / $feed " ;
2007-03-10 01:18:43 -05:00
$url = user_trailingslashit ( $url , 'single_feed' );
2007-02-23 03:31:07 -05:00
} else {
2007-08-22 18:42:57 -04:00
$type = get_post_field ( 'post_type' , $post_id );
if ( 'page' == $type )
2012-11-07 14:56:10 -05:00
$url = add_query_arg ( array ( 'feed' => $feed , 'page_id' => $post_id ), home_url ( '/' ) );
2007-08-22 18:42:57 -04:00
else
2012-11-07 14:56:10 -05:00
$url = add_query_arg ( array ( 'feed' => $feed , 'p' => $post_id ), home_url ( '/' ) );
2007-02-23 03:31:07 -05:00
}
2014-04-13 22:13:16 -04:00
/**
* Filter the post comments feed permalink .
*
* @ 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
/**
* Display 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
*
2008-10-18 16:46:30 -04:00
* @ param string $link_text Descriptive text .
2011-12-13 18:45:31 -05:00
* @ param int $post_id Optional post ID . Default to current post .
2008-10-18 16:46:30 -04:00
* @ param string $feed Optional . Feed format .
* @ return string Link to the comment feed for the current post .
2007-12-06 14:58:15 -05:00
*/
function post_comments_feed_link ( $link_text = '' , $post_id = '' , $feed = '' ) {
2012-11-07 14:56:10 -05:00
$url = esc_url ( get_post_comments_feed_link ( $post_id , $feed ) );
2007-12-06 14:58:15 -05:00
if ( empty ( $link_text ) )
$link_text = __ ( 'Comments Feed' );
2014-04-13 22:13:16 -04:00
/**
* Filter the post comment feed link anchor tag .
*
* @ since 2.8 . 0
*
* @ param string $link The complete anchor tag for the comment feed link .
* @ param int $post_id Post ID .
* @ param string $feed The feed type , or an empty string for the default feed type .
*/
2009-05-12 02:19:36 -04:00
echo apply_filters ( 'post_comments_feed_link_html' , " <a href=' $url '> $link_text </a> " , $post_id , $feed );
2007-12-06 14:58:15 -05:00
}
2008-10-13 18:00:07 -04:00
/**
* Retrieve 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
*
2008-10-13 18:00:07 -04:00
* @ param int $author_id ID of an author .
2008-10-21 23:08:33 -04:00
* @ param string $feed Optional . Feed type .
2008-10-13 18:00:07 -04:00
* @ return string Link to the feed for the author specified by $author_id .
2008-08-21 22:21:37 -04:00
*/
2007-12-06 14:58:15 -05:00
function get_author_feed_link ( $author_id , $feed = '' ) {
$author_id = ( int ) $author_id ;
$permalink_structure = get_option ( 'permalink_structure' );
if ( empty ( $feed ) )
$feed = get_default_feed ();
if ( '' == $permalink_structure ) {
2010-01-04 12:23:29 -05:00
$link = home_url ( " ?feed= $feed &author= " . $author_id );
2007-12-06 14:58:15 -05:00
} else {
2008-01-04 14:36:34 -05:00
$link = get_author_posts_url ( $author_id );
2008-08-21 22:21:37 -04:00
if ( $feed == get_default_feed () )
$feed_link = 'feed' ;
else
$feed_link = " feed/ $feed " ;
$link = trailingslashit ( $link ) . user_trailingslashit ( $feed_link , 'feed' );
2007-12-06 14:58:15 -05:00
}
2014-04-13 22:13:16 -04:00
/**
* Filter the feed link for a given author .
*
* @ since 1.5 . 1
*
* @ param string $link The author feed link .
* @ param string $feed Feed type .
*/
$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
/**
* Retrieve 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
*
2008-10-13 18:00:07 -04:00
* @ param int $cat_id ID of a category .
2008-10-21 23:08:33 -04:00
* @ param string $feed Optional . Feed type .
2008-10-13 18:00:07 -04:00
* @ return string Link to the feed for the category specified by $cat_id .
2007-12-06 14:58:15 -05:00
*/
function get_category_feed_link ( $cat_id , $feed = '' ) {
2010-05-17 12:21:12 -04:00
return get_term_feed_link ( $cat_id , 'category' , $feed );
}
2008-02-05 01:47:27 -05:00
2010-05-17 12:21:12 -04:00
/**
2011-09-29 18:57:43 -04:00
* Retrieve 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
*
* @ param int $term_id ID of a category .
* @ param string $taxonomy Optional . Taxonomy of $term_id
* @ param string $feed Optional . Feed type .
2011-09-29 18:57:43 -04:00
* @ return string Link to the feed for the term specified by $term_id and $taxonomy .
2010-05-17 12:21:12 -04:00
*/
function get_term_feed_link ( $term_id , $taxonomy = 'category' , $feed = '' ) {
$term_id = ( int ) $term_id ;
2008-02-05 01:47:27 -05:00
2010-05-17 12:21:12 -04:00
$term = get_term ( $term_id , $taxonomy );
2010-05-25 22:42:15 -04:00
2010-05-17 12:21:12 -04:00
if ( empty ( $term ) || is_wp_error ( $term ) )
2007-12-06 14:58:15 -05:00
return false ;
2010-05-17 12:21:12 -04:00
if ( empty ( $feed ) )
2007-12-06 14:58:15 -05:00
$feed = get_default_feed ();
2010-05-17 12:21:12 -04:00
$permalink_structure = get_option ( 'permalink_structure' );
2007-12-06 14:58:15 -05:00
if ( '' == $permalink_structure ) {
2010-05-17 12:21:12 -04:00
if ( 'category' == $taxonomy ) {
2010-05-25 22:42:15 -04:00
$link = home_url ( " ?feed= $feed &cat= $term_id " );
2010-05-17 12:21:12 -04:00
}
elseif ( 'post_tag' == $taxonomy ) {
2010-05-25 22:42:15 -04:00
$link = home_url ( " ?feed= $feed &tag= $term->slug " );
2010-05-17 12:21:12 -04:00
} else {
$t = get_taxonomy ( $taxonomy );
$link = home_url ( " ?feed= $feed & $t->query_var = $term->slug " );
}
2007-12-06 14:58:15 -05:00
} else {
2010-05-17 12:21:12 -04:00
$link = get_term_link ( $term_id , $term -> taxonomy );
if ( $feed == get_default_feed () )
2007-12-06 14:58:15 -05:00
$feed_link = 'feed' ;
else
$feed_link = " feed/ $feed " ;
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
}
2014-04-13 22:13:16 -04:00
if ( 'category' == $taxonomy ) {
/**
* Filter the category feed link .
*
* @ since 1.5 . 1
*
* @ param string $link The category feed link .
* @ param string $feed Feed type .
*/
2010-05-17 12:21:12 -04:00
$link = apply_filters ( 'category_feed_link' , $link , $feed );
2014-04-13 22:13:16 -04:00
} elseif ( 'post_tag' == $taxonomy ) {
/**
* Filter the post tag feed link .
*
* @ since 2.3 . 0
*
* @ param string $link The tag feed link .
* @ param string $feed Feed type .
*/
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 {
/**
* Filter the feed link for a taxonomy other than 'category' or 'post_tag' .
*
* @ since 3.0 . 0
*
* @ param string $link The taxonomy feed link .
* @ param string $feed Feed type .
* @ param string $feed The taxonomy name .
*/
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
/**
2008-10-21 23:08:33 -04:00
* Retrieve permalink for feed of tag .
2008-10-13 18:00:07 -04:00
*
* @ since 2.3 . 0
*
2008-10-21 23:08:33 -04:00
* @ param int $tag_id Tag ID .
* @ param string $feed Optional . Feed type .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2007-12-06 14:58:15 -05:00
function get_tag_feed_link ( $tag_id , $feed = '' ) {
2010-05-17 12:21:12 -04:00
return get_term_feed_link ( $tag_id , 'post_tag' , $feed );
2007-12-06 14:58:15 -05:00
}
2008-10-25 14:19:42 -04:00
/**
* Retrieve edit tag link .
*
* @ since 2.7 . 0
*
* @ param int $tag_id Tag ID
2010-10-14 03:35:13 -04:00
* @ param string $taxonomy Taxonomy
2008-10-25 14:19:42 -04:00
* @ return string
*/
2010-10-14 03:35:13 -04:00
function get_edit_tag_link ( $tag_id , $taxonomy = 'post_tag' ) {
2014-04-13 22:13:16 -04:00
/**
* Filter the edit link for a tag ( or term in another taxonomy ) .
*
* @ since 2.7 . 0
*
* @ param string $link The term edit link .
*/
2010-10-14 04:47:41 -04:00
return apply_filters ( 'get_edit_tag_link' , get_edit_term_link ( $tag_id , $taxonomy ) );
2008-10-25 14:19:42 -04:00
}
/**
* Display or retrieve edit tag link with formatting .
*
* @ since 2.7 . 0
*
* @ param string $link Optional . Anchor text .
* @ param string $before Optional . Display before edit link .
* @ param string $after Optional . Display after edit link .
2013-08-21 20:49:09 -04:00
* @ param object $tag Tag object .
2010-10-13 10:54:21 -04:00
* @ return string HTML content .
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
/**
* Filter the anchor tag for the edit link for a tag ( or term in another taxonomy ) .
*
* @ 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 ;
}
/**
* Retrieve edit term url .
*
2010-10-19 03:38:42 -04:00
* @ since 3.1 . 0
2010-10-13 10:54:21 -04:00
*
* @ param int $term_id Term ID
2010-10-14 03:35:13 -04:00
* @ param string $taxonomy Taxonomy
* @ param string $object_type The object type
2010-10-13 10:54:21 -04:00
* @ return string
*/
2010-10-14 04:47:41 -04:00
function get_edit_term_link ( $term_id , $taxonomy , $object_type = '' ) {
2010-10-14 03:35:13 -04:00
$tax = get_taxonomy ( $taxonomy );
if ( ! current_user_can ( $tax -> cap -> edit_terms ) )
2008-10-25 14:19:42 -04:00
return ;
2010-10-14 03:35:13 -04:00
$term = get_term ( $term_id , $taxonomy );
$args = array (
'action' => 'edit' ,
'taxonomy' => $taxonomy ,
'tag_ID' => $term -> term_id ,
);
if ( $object_type )
$args [ 'post_type' ] = $object_type ;
2010-10-13 10:54:21 -04:00
2010-10-14 03:35:13 -04:00
$location = add_query_arg ( $args , admin_url ( 'edit-tags.php' ) );
2010-10-13 10:54:21 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the edit link for a term .
*
* @ since 3.1 . 0
*
* @ param string $location The edit link .
* @ param int $term_id Term ID .
* @ param string $taxonomy Taxonomy name .
* @ param string $object_type The object type ( eg . the post type ) .
*/
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
}
/**
* Display or retrieve edit term link with formatting .
*
2010-10-19 03:38:42 -04:00
* @ since 3.1 . 0
2010-10-13 10:54:21 -04:00
*
* @ param string $link Optional . Anchor text .
* @ param string $before Optional . Display before edit link .
* @ param string $after Optional . Display after edit link .
2013-08-21 20:49:09 -04:00
* @ param object $term Term object .
2010-10-13 10:54:21 -04:00
* @ return string HTML content .
*/
function edit_term_link ( $link = '' , $before = '' , $after = '' , $term = null , $echo = true ) {
2013-09-09 22:28:11 -04:00
if ( is_null ( $term ) )
2010-10-31 07:02:17 -04:00
$term = get_queried_object ();
2013-09-09 22:28:11 -04:00
if ( ! $term )
return ;
2010-10-14 03:35:13 -04:00
2010-10-13 10:54:21 -04:00
$tax = get_taxonomy ( $term -> taxonomy );
2013-09-09 22:28:11 -04:00
if ( ! current_user_can ( $tax -> cap -> edit_terms ) )
2010-10-13 10:54:21 -04:00
return ;
2010-02-19 04:33:50 -05:00
2010-10-14 03:35:13 -04:00
if ( empty ( $link ) )
2008-10-25 14:19:42 -04:00
$link = __ ( 'Edit This' );
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
/**
* Filter the anchor tag for the edit link of a term .
*
* @ 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
2010-10-13 10:54:21 -04:00
if ( $echo )
echo $link ;
else
return $link ;
2008-10-25 14:19:42 -04:00
}
2010-02-27 23:15:02 -05:00
/**
2013-11-11 08:32:10 -05:00
* Retrieve permalink for search .
*
* @ since 3.0 . 0
*
* @ param string $query Optional . The query string to use . If empty the current query is used .
* @ return string
*/
2010-02-27 23:15:02 -05:00
function get_search_link ( $query = '' ) {
global $wp_rewrite ;
if ( empty ( $query ) )
2010-04-03 19:38:38 -04:00
$search = get_search_query ( false );
2010-02-27 23:15:02 -05:00
else
2013-03-01 11:28:40 -05:00
$search = stripslashes ( $query );
2010-02-27 23:15:02 -05:00
$permastruct = $wp_rewrite -> get_search_permastruct ();
if ( empty ( $permastruct ) ) {
$link = home_url ( '?s=' . urlencode ( $search ) );
} else {
$search = urlencode ( $search );
$search = str_replace ( '%2F' , '/' , $search ); // %2F(/) is not valid within a URL, send it unencoded.
$link = str_replace ( '%search%' , $search , $permastruct );
$link = home_url ( user_trailingslashit ( $link , 'search' ) );
}
2014-04-13 22:13:16 -04:00
/**
* Filter the search permalink .
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the feed of the search results .
2008-10-13 18:00:07 -04:00
*
* @ since 2.5 . 0
*
2008-10-21 23:08:33 -04:00
* @ param string $search_query Optional . Search query .
* @ param string $feed Optional . Feed type .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2007-12-19 13:05:21 -05:00
function get_search_feed_link ( $search_query = '' , $feed = '' ) {
2010-02-27 23:15:02 -05:00
global $wp_rewrite ;
$link = get_search_link ( $search_query );
2008-02-05 01:47:27 -05:00
2007-12-19 13:05:21 -05:00
if ( empty ( $feed ) )
$feed = get_default_feed ();
2008-02-05 01:47:27 -05:00
2010-02-27 23:15:02 -05:00
$permastruct = $wp_rewrite -> get_search_permastruct ();
if ( empty ( $permastruct ) ) {
$link = add_query_arg ( 'feed' , $feed , $link );
} else {
$link = trailingslashit ( $link );
$link .= " feed/ $feed / " ;
}
2008-02-05 01:47:27 -05:00
2014-04-13 22:13:16 -04:00
/**
* Filter the search feed link .
*
* @ since 2.5 . 0
*
* @ param string $link Search feed link .
* @ param string $feed Feed type .
* @ param string $type The search type . One of 'posts' or 'comments' .
*/
$link = apply_filters ( 'search_feed_link' , $link , $feed , 'posts' );
2008-02-05 01:47:27 -05:00
2007-12-19 13:05:21 -05:00
return $link ;
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve the permalink for the comments feed of the search results .
2008-10-13 18:00:07 -04:00
*
* @ since 2.5 . 0
*
2008-10-21 23:08:33 -04:00
* @ param string $search_query Optional . Search query .
* @ param string $feed Optional . Feed type .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2007-12-19 13:05:21 -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
2007-12-19 13:05:21 -05:00
if ( empty ( $feed ) )
$feed = get_default_feed ();
2008-02-05 01:47:27 -05:00
2010-02-27 23:15:02 -05:00
$link = get_search_feed_link ( $search_query , $feed );
$permastruct = $wp_rewrite -> get_search_permastruct ();
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 */
2010-02-27 23:15:02 -05:00
$link = apply_filters ( 'search_feed_link' , $link , $feed , 'comments' );
2008-02-05 01:47:27 -05:00
2007-12-19 13:05:21 -05:00
return $link ;
}
2010-10-15 15:44:57 -04:00
/**
* Retrieve the permalink for a post type archive .
*
* @ since 3.1 . 0
*
* @ param string $post_type Post type
* @ return string
*/
function get_post_type_archive_link ( $post_type ) {
global $wp_rewrite ;
if ( ! $post_type_obj = get_post_type_object ( $post_type ) )
return false ;
2010-12-08 02:51:40 -05:00
if ( ! $post_type_obj -> has_archive )
2010-10-15 15:44:57 -04:00
return false ;
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 ;
2010-10-15 15:44:57 -04:00
if ( $post_type_obj -> rewrite [ 'with_front' ] )
$struct = $wp_rewrite -> front . $struct ;
2011-03-09 23:24:48 -05:00
else
$struct = $wp_rewrite -> root . $struct ;
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
/**
* Filter the post type archive permalink .
*
* @ 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 );
}
/**
* Retrieve the permalink for a post type archive feed .
*
* @ since 3.1 . 0
*
* @ param string $post_type Post type
2010-10-19 03:48:22 -04:00
* @ param string $feed Optional . Feed type
2010-10-15 15:44:57 -04:00
* @ return string
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 ();
if ( empty ( $feed ) )
$feed = $default_feed ;
if ( ! $link = get_post_type_archive_link ( $post_type ) )
return false ;
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' ] ) {
$link = trailingslashit ( $link );
2010-10-15 15:44:57 -04:00
$link .= 'feed/' ;
if ( $feed != $default_feed )
$link .= " $feed / " ;
} else {
$link = add_query_arg ( 'feed' , $feed , $link );
}
2014-04-13 22:13:16 -04:00
/**
* Filter the post type archive feed link .
*
* @ since 3.1 . 0
*
* @ param string $link The post type archive feed link .
* @ param string $feed Feed type .
*/
2010-10-15 15:44:57 -04:00
return apply_filters ( 'post_type_archive_feed_link' , $link , $feed );
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Retrieve edit posts 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
* pages , posts , attachments , and revisions .
2008-10-13 18:00:07 -04:00
*
* @ since 2.3 . 0
*
2008-10-21 23:08:33 -04:00
* @ param int $id Optional . Post ID .
2011-09-29 18:57:43 -04:00
* @ param string $context Optional , defaults to display . How to write the '&' , defaults to '&' .
2008-10-21 23:08:33 -04:00
* @ return string
2008-10-13 18:00:07 -04:00
*/
2008-04-18 19:38:21 -04:00
function get_edit_post_link ( $id = 0 , $context = 'display' ) {
2012-09-04 12:29:28 -04:00
if ( ! $post = get_post ( $id ) )
2008-03-12 01:50:07 -04:00
return ;
2007-06-13 22:25:30 -04:00
2013-07-11 18:56:48 -04:00
if ( 'revision' === $post -> post_type )
$action = '' ;
elseif ( 'display' == $context )
2010-05-03 14:16:22 -04:00
$action = '&action=edit' ;
else
$action = '&action=edit' ;
2010-01-15 17:11:12 -05:00
$post_type_object = get_post_type_object ( $post -> post_type );
2010-01-04 11:58:43 -05:00
if ( ! $post_type_object )
return ;
2013-07-08 16:05:42 -04:00
if ( ! current_user_can ( 'edit_post' , $post -> ID ) )
2010-01-04 11:58:43 -05:00
return ;
2014-04-13 22:13:16 -04:00
/**
* Filter the post edit link .
*
* @ 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 .
*/
return apply_filters ( 'get_edit_post_link' , admin_url ( sprintf ( $post_type_object -> _edit_link . $action , $post -> ID ) ), $post -> ID , $context );
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2009-05-21 14:43:04 -04:00
* Display edit post link for post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2014-05-27 09:43:14 -04:00
* @ param string $text Optional . Anchor text .
2008-10-21 23:08:33 -04:00
* @ param string $before Optional . Display before edit link .
* @ param string $after Optional . Display after edit link .
2009-05-21 14:43:04 -04:00
* @ param int $id Optional . Post ID .
2008-10-13 18:00:07 -04:00
*/
2014-05-27 09:43:14 -04:00
function edit_post_link ( $text = null , $before = '' , $after = '' , $id = 0 ) {
if ( ! $post = get_post ( $id ) ) {
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
2014-05-27 09:43:14 -04:00
if ( ! $url = get_edit_post_link ( $post -> ID ) ) {
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
2014-05-27 09:43:14 -04:00
$link = '<a class="post-edit-link" href="' . $url . '">' . $text . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
* Filter the post edit link anchor tag .
*
* @ 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
/**
* Retrieve delete posts link for post .
*
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
*
* @ param int $id Optional . Post ID .
2010-04-15 22:29:10 -04:00
* @ param string $deprecated Not used .
* @ param bool $force_delete Whether to bypass trash and force deletion . Default is false .
2009-09-21 17:33:00 -04:00
* @ return string
*/
2010-04-15 22:29:10 -04:00
function get_delete_post_link ( $id = 0 , $deprecated = '' , $force_delete = false ) {
if ( ! empty ( $deprecated ) )
2010-12-15 06:27:38 -05:00
_deprecated_argument ( __FUNCTION__ , '3.0' );
2010-04-15 22:29:10 -04:00
2012-08-23 16:01:10 -04:00
if ( ! $post = get_post ( $id ) )
2009-09-21 17:33:00 -04:00
return ;
2010-01-21 01:53:33 -05:00
$post_type_object = get_post_type_object ( $post -> post_type );
if ( ! $post_type_object )
return ;
2013-07-08 16:05:42 -04:00
if ( ! current_user_can ( 'delete_post' , $post -> ID ) )
2010-01-21 01:53:33 -05:00
return ;
2009-09-21 17:33:00 -04:00
2010-04-15 22:29:10 -04:00
$action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash' ;
$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
/**
* Filter the post delete link .
*
* @ since 2.9 . 0
*
* @ param string $link The delete link .
* @ param int $post_id Post ID .
* @ param bool $force_delete Whether to bypass the trash and force deletion . Default false .
*/
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
/**
2008-10-21 23:08:33 -04:00
* Retrieve edit comment link .
2008-10-13 18:00:07 -04:00
*
* @ since 2.3 . 0
*
2008-10-21 23:08:33 -04:00
* @ param int $comment_id Optional . Comment ID .
* @ return string
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
2010-09-07 19:35:28 -04:00
if ( ! current_user_can ( 'edit_comment' , $comment -> comment_ID ) )
return ;
2007-04-28 12:45:47 -04:00
2008-07-20 00:46:59 -04:00
$location = admin_url ( 'comment.php?action=editcomment&c=' ) . $comment -> comment_ID ;
2014-04-13 22:13:16 -04:00
/**
* Filter the comment edit link .
*
* @ 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
/**
2014-01-24 02:17:36 -05:00
* Display edit comment link with formatting .
2008-10-13 18:00:07 -04:00
*
* @ since 1.0 . 0
*
2014-05-27 09:43:14 -04:00
* @ param string $text Optional . Anchor text .
2008-10-21 23:08:33 -04:00
* @ param string $before Optional . Display before edit link .
* @ param string $after Optional . Display after edit link .
2008-10-13 18:00:07 -04:00
*/
2014-05-27 09:43:14 -04:00
function edit_comment_link ( $text = null , $before = '' , $after = '' ) {
2010-09-07 19:35:28 -04:00
global $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
2014-05-27 09:43:14 -04:00
$link = '<a class="comment-edit-link" href="' . get_edit_comment_link ( $comment -> comment_ID ) . '">' . $text . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
* Filter the comment edit link anchor tag .
*
* @ since 2.3 . 0
*
* @ param string $link Anchor tag for the edit link .
* @ param int $comment_id Comment 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_comment_link' , $link , $comment -> comment_ID , $text ) . $after ;
2004-01-27 04:58:01 -05:00
}
2008-10-13 18:00:07 -04:00
/**
2008-10-21 23:08:33 -04:00
* Display edit bookmark ( literally a URL external to blog ) 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
*
2008-10-21 23:08:33 -04:00
* @ param int $link Optional . Bookmark ID .
* @ return string
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
if ( ! current_user_can ( 'manage_links' ) )
return ;
$location = admin_url ( 'link.php?action=edit&link_id=' ) . $link -> link_id ;
2014-04-13 22:13:16 -04:00
/**
* Filter the bookmark ( link ) edit link .
*
* @ 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
/**
2008-10-21 23:08:33 -04:00
* Display edit bookmark ( literally a URL external to blog ) 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
*
2008-10-21 23:08:33 -04:00
* @ param string $link Optional . Anchor text .
* @ param string $before Optional . Display before edit link .
* @ param string $after Optional . Display after edit link .
* @ param int $bookmark Optional . Bookmark ID .
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 ) {
$bookmark = get_bookmark ( $bookmark );
if ( ! current_user_can ( 'manage_links' ) )
return ;
if ( empty ( $link ) )
$link = __ ( 'Edit This' );
2013-09-23 10:51:10 -04:00
$link = '<a href="' . get_edit_bookmark_link ( $bookmark ) . '">' . $link . '</a>' ;
2014-04-13 22:13:16 -04:00
/**
* Filter the bookmark edit link anchor tag .
*
* @ 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
/**
* Retrieve edit user link
*
* @ 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 ) {
if ( ! $user_id )
$user_id = get_current_user_id ();
if ( empty ( $user_id ) || ! current_user_can ( 'edit_user' , $user_id ) )
return '' ;
2012-08-02 21:06:05 -04:00
$user = get_userdata ( $user_id );
2012-07-30 14:30:03 -04:00
2012-08-02 21:06:05 -04:00
if ( ! $user )
2012-07-30 14:30:03 -04:00
return '' ;
if ( get_current_user_id () == $user -> ID )
$link = get_edit_profile_url ( $user -> ID );
else
$link = add_query_arg ( 'user_id' , $user -> ID , self_admin_url ( 'user-edit.php' ) );
2014-04-13 22:13:16 -04:00
/**
* Filter the user edit link .
*
* @ 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 );
}
2004-06-02 03:44:43 -04:00
// Navigation links
2008-10-13 18:00:07 -04:00
/**
2010-12-15 11:45:14 -05:00
* Retrieve previous post that is adjacent to current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.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 bool $in_same_term Optional . Whether post should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ param string $taxonomy Optional . Taxonomy , if $in_same_term is true . Default 'category' .
* @ return mixed 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
/**
2010-12-15 11:45:14 -05:00
* Retrieve next post that is adjacent to current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.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 bool $in_same_term Optional . Whether post should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ param string $taxonomy Optional . Taxonomy , if $in_same_term is true . Default 'category' .
* @ return mixed 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
/**
2010-12-15 11:45:14 -05:00
* Retrieve 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
*
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 bool $in_same_term Optional . Whether post should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ param bool $previous Optional . Whether to retrieve previous post .
* @ param string $taxonomy Optional . Taxonomy , if $in_same_term is true . Default '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
* @ return mixed 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
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 ( ( ! $post = get_post () ) || ! taxonomy_exists ( $taxonomy ) )
return null ;
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
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
$join = '' ;
2014-07-19 18:27:14 -04:00
$where = '' ;
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 ) ) {
$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id " ;
2014-07-19 18:27:14 -04:00
$where = $wpdb -> prepare ( " AND tt.taxonomy = %s " , $taxonomy );
if ( ! empty ( $excluded_terms ) && ! is_array ( $excluded_terms ) ) {
// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
if ( false !== strpos ( $excluded_terms , ' and ' ) ) {
_deprecated_argument ( __FUNCTION__ , '3.3' , sprintf ( __ ( 'Use commas instead of %s to separate excluded terms.' ), " 'and' " ) );
$excluded_terms = explode ( ' and ' , $excluded_terms );
} else {
$excluded_terms = explode ( ',' , $excluded_terms );
}
$excluded_terms = array_map ( 'intval' , $excluded_terms );
}
2006-02-12 02:53:23 -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 ( $in_same_term ) {
if ( ! is_object_in_taxonomy ( $post -> post_type , $taxonomy ) )
return '' ;
$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 );
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 ( ! $term_array || is_wp_error ( $term_array ) )
return '' ;
2014-07-19 18:27:14 -04: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 ) ) {
2014-11-20 05:59:35 -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 ( $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
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
$adjacent = $previous ? 'previous' : 'next' ;
$op = $previous ? '<' : '>' ;
$order = $previous ? 'DESC' : 'ASC' ;
2014-04-13 22:13:16 -04:00
/**
* Filter the JOIN clause in the SQL for an adjacent post query .
*
* The dynamic portion of the hook name , $adjacent , refers to the type
* of adjacency , 'next' or 'previous' .
*
* @ since 2.5 . 0
*
* @ param string $join The JOIN clause in the SQL .
* @ param bool $in_same_term Whether post should be in a same taxonomy term .
* @ param array $excluded_terms Array of excluded term IDs .
*/
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
$join = apply_filters ( " get_ { $adjacent } _post_join " , $join , $in_same_term , $excluded_terms );
2014-04-13 22:13:16 -04:00
/**
* Filter the WHERE clause in the SQL for an adjacent post query .
*
* The dynamic portion of the hook name , $adjacent , refers to the type
* of adjacency , 'next' or 'previous' .
*
* @ since 2.5 . 0
*
* @ param string $where The WHERE clause in the SQL .
* @ param bool $in_same_term Whether post should be in a same taxonomy term .
* @ param array $excluded_terms Array of excluded term IDs .
*/
2014-07-19 18:27:14 -04:00
$where = apply_filters ( " get_ { $adjacent } _post_where " , $wpdb -> prepare ( " WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $where " , $current_post_date , $post -> post_type ), $in_same_term , $excluded_terms );
2014-04-13 22:13:16 -04:00
/**
* Filter the ORDER BY clause in the SQL for an adjacent post query .
*
* The dynamic portion of the hook name , $adjacent , refers to the type
* of adjacency , 'next' or 'previous' .
*
* @ since 2.5 . 0
*
* @ param string $order_by The ORDER BY clause in the SQL .
*/
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
$sort = apply_filters ( " get_ { $adjacent } _post_sort " , " ORDER BY p.post_date $order LIMIT 1 " );
$query = " SELECT p.ID FROM $wpdb->posts AS p $join $where $sort " ;
$query_key = 'adjacent_post_' . md5 ( $query );
$result = wp_cache_get ( $query_key , 'counts' );
if ( false !== $result ) {
if ( $result )
$result = get_post ( $result );
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 );
if ( null === $result )
$result = '' ;
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
wp_cache_set ( $query_key , $result , 'counts' );
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
if ( $result )
$result = get_post ( $result );
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
/**
* Get adjacent post relational link .
*
* Can either be next or previous post relational link .
*
* @ since 2.8 . 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 $title Optional . Link title format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ 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' .
2009-03-18 17:56:03 -04:00
* @ return string
*/
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' ) {
2012-09-04 12:29:28 -04:00
if ( $previous && is_attachment () && $post = get_post () )
$post = get_post ( $post -> post_parent );
2009-03-18 17:56:03 -04: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 );
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 ( $post ) )
2009-03-18 17:56:03 -04:00
return ;
2013-07-23 12:05:40 -04:00
$post_title = the_title_attribute ( array ( 'echo' => false , 'post' => $post ) );
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' );
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
$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
/**
* Filter the adjacent post relational link .
*
* The dynamic portion of the hook name , $adjacent , refers to the type
* of adjacency , 'next' or 'previous' .
*
* @ 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
}
/**
* Display relational links for the posts adjacent to the current post .
*
* @ since 2.8 . 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 $title Optional . Link title format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ 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
/**
* Display relational links for the posts adjacent to the current post for single post pages .
*
2011-09-29 18:57:43 -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
*
*/
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
/**
* Display relational link for the next post adjacent to the current post .
*
* @ since 2.8 . 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 $title Optional . Link title format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ 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
}
/**
* Display relational link for the previous post adjacent to the current post .
*
* @ since 2.8 . 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 $title Optional . Link title format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | 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
}
/**
* Retrieve boundary post .
*
2010-09-26 04:31:16 -04:00
* Boundary being either the first or last post by publish date within the constraints specified
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
* by $in_same_term or $excluded_terms .
2009-03-18 17:56:03 -04:00
*
* @ since 2.8 . 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 bool $in_same_term Optional . Whether returned post should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ param bool $start Optional . Whether to retrieve first or last post .
* @ param string $taxonomy Optional . Taxonomy , if $in_same_term is true . Default 'category' .
2014-02-22 17:28:13 -05:00
* @ return mixed 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 ();
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 ( ! $post || ! is_single () || is_attachment () || ! taxonomy_exists ( $taxonomy ) )
2009-04-22 18:56:52 -04:00
return null ;
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 (
'posts_per_page' => 1 ,
'order' => $start ? 'ASC' : 'DESC' ,
'update_post_term_cache' => false ,
'update_post_meta_cache' => false
);
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 ) ) {
if ( ! empty ( $excluded_terms ) )
$excluded_terms = explode ( ',' , $excluded_terms );
else
$excluded_terms = array ();
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 ) ) {
if ( $in_same_term )
$term_array = wp_get_object_terms ( $post -> ID , $taxonomy , array ( 'fields' => 'ids' ) );
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 ();
foreach ( $excluded_terms as $excluded_term )
$inverse_terms [] = $excluded_term * - 1 ;
$excluded_terms = $inverse_terms ;
}
$query_args [ 'tax_query' ] = array ( array (
'taxonomy' => $taxonomy ,
'terms' => array_merge ( $term_array , $excluded_terms )
) );
}
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
}
2013-09-10 18:12:10 -04:00
/*
* Get previous post link that is adjacent to the current post .
*
* @ since 3.7 . 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 Optional . Link anchor format .
* @ param string $link Optional . Link permalink format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ param string $taxonomy Optional . Taxonomy , if $in_same_term is true . Default 'category' .
2013-09-10 18:12:10 -04:00
* @ return string
*/
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
/**
2008-10-21 23:08:33 -04:00
* Display previous post link that is adjacent to the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
2013-10-30 10:39:10 -04:00
* @ see get_previous_post_link ()
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 Optional . Link anchor format .
* @ param string $link Optional . Link permalink format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ 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
}
/**
2013-10-30 10:39:10 -04:00
* Get next post link that is adjacent to the current post .
2013-09-10 18:12:10 -04:00
*
* @ since 3.7 . 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 Optional . Link anchor format .
* @ param string $link Optional . Link permalink format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ param string $taxonomy Optional . Taxonomy , if $in_same_term is true . Default 'category' .
2013-09-10 18:12:10 -04:00
* @ return string
*/
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
/**
2008-10-21 23:08:33 -04:00
* Display next post link that is adjacent to the current post .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
2013-10-30 10:39:10 -04:00
* @ see get_next_post_link ()
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 Optional . Link anchor format .
* @ param string $link Optional . Link permalink format .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded term IDs .
* @ 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' ) {
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
/**
2013-09-10 18:12:10 -04:00
* Get 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 .
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy term .
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded terms IDs .
* @ 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
* @ return string
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' ) {
2007-12-05 04:25:45 -05:00
if ( $previous && is_attachment () )
2012-09-04 12:29:28 -04:00
$post = get_post ( get_post () -> post_parent );
2007-12-05 04:25:45 -05:00
else
2014-05-25 12:10:13 -04:00
$post = get_adjacent_post ( $in_same_term , $excluded_terms , $previous , $taxonomy );
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
2012-09-10 17:36:06 -04:00
if ( empty ( $post -> post_title ) )
$title = $previous ? __ ( 'Previous Post' ) : __ ( 'Next Post' );
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 );
$rel = $previous ? 'prev' : 'next' ;
2007-09-11 16:05:52 -04:00
2012-09-10 17:36:06 -04:00
$string = '<a href="' . get_permalink ( $post ) . '" rel="' . $rel . '">' ;
$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
/**
* Filter the adjacent post link .
*
* The dynamic portion of the hook name , $adjacent , refers to the type
* of adjacency , 'next' or 'previous' .
*
* @ since 2.6 . 0
*
* @ param string $output The adjacent post link .
* @ param string $format Link anchor format .
* @ param string $link Link permalink format .
* @ param WP_Post $post The adjacent post .
*/
2013-09-10 18:12:10 -04:00
return apply_filters ( " { $adjacent } _post_link " , $output , $format , $link , $post );
}
/**
* Display adjacent post link .
*
* Can be either next post link or previous .
*
* @ since 2.5 . 0
* @ uses get_adjacent_post_link ()
*
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 .
2014-05-25 12:12:14 -04:00
* @ param bool $in_same_term Optional . Whether link should be in a same taxonomy 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
* @ param array | string $excluded_terms Optional . Array or comma - separated list of excluded category IDs .
* @ 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
* @ return string
*/
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
/**
2011-09-29 18:57:43 -04:00
* Retrieve links for page numbers .
2008-10-13 18:00:07 -04:00
*
* @ since 1.5 . 0
*
2008-10-21 23:08:33 -04:00
* @ param int $pagenum Optional . Page ID .
2012-05-02 12:29:39 -04:00
* @ param bool $escape Optional . Whether to escape the URL for display , with esc_url () . Defaults to true .
* Otherwise , prepares the URL with esc_url_raw () .
2008-10-21 23:08:33 -04:00
* @ return string
2008-10-13 18:00:07 -04:00
*/
2012-05-02 12:29:39 -04: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
2010-01-04 12:23:29 -05:00
$home_root = parse_url ( home_url ());
2008-01-10 15:51:07 -05:00
$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
2012-10-25 16:09:54 -04:00
$request = preg_replace ( '|^' . $home_root . '|i' , '' , $request );
2007-05-15 22:47:24 -04:00
$request = preg_replace ( '|^/+|' , '' , $request );
2007-06-13 22:25:30 -04:00
2007-05-28 14:34:06 -04: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
2008-02-02 13:42:09 -05:00
if ( ! empty ( $qs_match [ 0 ] ) ) {
2007-05-11 20:17:34 -04:00
$query_string = $qs_match [ 0 ];
$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
2010-09-06 21:18:42 -04:00
$request = preg_replace ( " | $wp_rewrite->pagination_base / \ d+/? $ | " , '' , $request );
2013-01-18 08:44:22 -05:00
$request = preg_replace ( '|^' . preg_quote ( $wp_rewrite -> index , '|' ) . '|i' , '' , $request );
2007-09-20 16:56:22 -04:00
$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
2007-09-22 02:07:03 -04:00
if ( $wp_rewrite -> using_index_permalinks () && ( $pagenum > 1 || '' != $request ) )
2013-01-18 08:44:22 -05:00
$base .= $wp_rewrite -> index . '/' ;
2007-06-13 22:25:30 -04:00
2007-05-15 22:47:24 -04:00
if ( $pagenum > 1 ) {
2010-09-06 21:18:42 -04: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
/**
* Filter the page number link for the current request .
*
* @ since 2.5 . 0
*
* @ param string $result The page number link .
*/
$result = apply_filters ( 'get_pagenum_link' , $result );
2008-02-25 13:40:46 -05:00
2012-05-02 12:29:39 -04:00
if ( $escape )
return esc_url ( $result );
else
return esc_url_raw ( $result );
2004-06-02 03:44:43 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2011-09-29 18:57:43 -04:00
* Retrieve 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
*
2008-10-21 23:08:33 -04:00
* @ param int $max_page Optional . Max pages .
* @ return string
2008-10-13 18:00:07 -04:00
*/
2007-03-16 04:04:24 -04: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
if ( ! is_single () ) {
if ( ! $paged )
$paged = 1 ;
$nextpage = intval ( $paged ) + 1 ;
if ( ! $max_page || $max_page >= $nextpage )
2007-03-16 04:04:24 -04:00
return get_pagenum_link ( $nextpage );
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2011-09-29 18:57:43 -04:00
* Display or return the next posts page link .
2008-10-13 18:00:07 -04:00
*
* @ since 0.71
*
2008-10-21 23:08:33 -04:00
* @ param int $max_page Optional . Max pages .
2008-11-12 05:13:50 -05:00
* @ param boolean $echo Optional . Echo or return ;
2008-10-13 18:00:07 -04:00
*/
2008-11-12 05:13:50 -05:00
function next_posts ( $max_page = 0 , $echo = 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
if ( $echo )
echo $output ;
else
return $output ;
2007-03-16 04:04:24 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2011-09-29 18:57:43 -04:00
* Return 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
*
2008-10-21 23:08:33 -04:00
* @ param string $label Content for link text .
* @ param int $max_page Optional . Max pages .
2008-11-12 05:13:50 -05:00
* @ return string | null
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
2010-04-01 20:07:59 -04:00
if ( ! $max_page )
2006-11-08 16:22:35 -05:00
$max_page = $wp_query -> max_num_pages ;
2008-11-12 05:13:50 -05:00
2005-10-17 19:41:28 -04:00
if ( ! $paged )
$paged = 1 ;
2008-11-12 05:13:50 -05:00
2005-10-17 19:41:28 -04:00
$nextpage = intval ( $paged ) + 1 ;
2011-06-10 19:01:45 -04:00
2011-04-27 17:25:09 -04:00
if ( null === $label )
$label = __ ( 'Next Page »' );
2008-11-12 05:13:50 -05:00
2010-10-15 10:43:31 -04:00
if ( ! is_single () && ( $nextpage <= $max_page ) ) {
2014-04-13 22:13:16 -04:00
/**
* Filter the anchor tag attributes for the next posts page link .
*
* @ 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
2010-04-01 20:07:59 -04:00
return '<a href="' . next_posts ( $max_page , false ) . " \" $attr > " . preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label ) . '</a>' ;
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-11-12 05:13:50 -05:00
/**
2011-09-29 18:57:43 -04:00
* Display the next posts page link .
2008-11-12 05:13:50 -05:00
*
* @ since 0.71
* @ uses get_next_posts_link ()
*
* @ param string $label Content for link text .
* @ param int $max_page Optional . Max pages .
*/
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
/**
2011-09-29 18:57:43 -04:00
* Retrieve 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
*
2008-10-21 23:08:33 -04:00
* @ return string | null
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
2005-10-17 19:41:28 -04:00
if ( ! is_single () ) {
$nextpage = intval ( $paged ) - 1 ;
if ( $nextpage < 1 )
$nextpage = 1 ;
2007-03-16 04:04:24 -04:00
return get_pagenum_link ( $nextpage );
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2011-09-29 18:57:43 -04:00
* Display or return the previous posts page link .
2008-10-13 18:00:07 -04:00
*
* @ since 0.71
2008-11-12 05:13:50 -05:00
*
* @ param boolean $echo Optional . Echo or return ;
2008-10-13 18:00:07 -04:00
*/
2008-11-12 05:13:50 -05:00
function previous_posts ( $echo = 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
if ( $echo )
echo $output ;
else
return $output ;
2007-03-16 04:04:24 -04:00
}
2005-10-17 19:41:28 -04:00
2008-10-13 18:00:07 -04:00
/**
2011-09-29 18:57:43 -04:00
* Return 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
*
2008-10-21 23:08:33 -04:00
* @ param string $label Optional . Previous page link text .
2008-11-12 05:13:50 -05:00
* @ return string | null
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
2011-04-27 17:25:09 -04:00
if ( null === $label )
$label = __ ( '« Previous Page' );
2008-11-12 05:13:50 -05:00
if ( ! is_single () && $paged > 1 ) {
2014-04-13 22:13:16 -04:00
/**
* Filter the anchor tag attributes for the previous posts page link .
*
* @ 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' , '' );
2012-04-19 11:08:06 -04:00
return '<a href="' . previous_posts ( false ) . " \" $attr > " . preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label ) . '</a>' ;
2005-10-17 19:41:28 -04:00
}
2004-06-02 03:44:43 -04:00
}
2008-11-12 05:13:50 -05:00
/**
* Display the previous posts page link .
*
* @ since 0.71
* @ uses get_previous_posts_link ()
*
* @ 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
/**
2009-04-22 04:44:37 -04:00
* Return 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
*
2009-04-22 04:44:37 -04:00
* @ param string | array $args Optional args .
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 = '' ;
2006-11-08 16:22:35 -05:00
if ( ! is_singular () ) {
2009-04-22 04:44:37 -04:00
$defaults = array (
2009-05-24 19:47:49 -04:00
'sep' => ' — ' ,
'prelabel' => __ ( '« Previous Page' ),
2009-04-22 04:44:37 -04:00
'nxtlabel' => __ ( 'Next Page »' ),
);
$args = wp_parse_args ( $args , $defaults );
2006-11-08 16:22:35 -05:00
$max_num_pages = $wp_query -> max_num_pages ;
2006-03-20 14:43:57 -05:00
$paged = get_query_var ( 'paged' );
2006-11-19 02:56:05 -05:00
2006-03-20 14:43:57 -05:00
//only have sep if there's both prev and next results
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 ) {
2009-04-22 04:44:37 -04:00
$return = get_previous_posts_link ( $args [ 'prelabel' ]);
2010-04-01 20:07:59 -04:00
$return .= preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $args [ 'sep' ]);
2009-04-22 04:44:37 -04:00
$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 ;
}
/**
* Display post pages link navigation for previous and next pages .
*
* @ since 0.71
*
* @ param string $sep Optional . Separator for posts navigation links .
* @ param string $prelabel Optional . Label for previous pages .
* @ param string $nxtlabel Optional Label for next pages .
*/
function posts_nav_link ( $sep = '' , $prelabel = '' , $nxtlabel = '' ) {
$args = array_filter ( compact ( 'sep' , 'prelabel' , 'nxtlabel' ) );
echo get_posts_nav_link ( $args );
2004-06-02 03:44:43 -04:00
}
2008-10-21 23:08:33 -04:00
/**
2011-09-29 18:57:43 -04:00
* Retrieve comments page number link .
2008-10-21 23:08:33 -04:00
*
* @ since 2.7 . 0
*
* @ param int $pagenum Optional . Page number .
* @ return string
*/
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
2008-10-23 12:08:47 -04:00
if ( 'newest' == get_option ( 'default_comments_page' ) ) {
2008-10-24 03:36:43 -04:00
if ( $pagenum != $max_page ) {
if ( $wp_rewrite -> using_permalinks () )
2008-11-21 12:33:05 -05:00
$result = user_trailingslashit ( trailingslashit ( $result ) . 'comment-page-' . $pagenum , 'commentpaged' );
2008-10-24 03:36:43 -04:00
else
2008-11-21 12:33:05 -05:00
$result = add_query_arg ( 'cpage' , $pagenum , $result );
2008-10-24 03:36:43 -04:00
}
} elseif ( $pagenum > 1 ) {
if ( $wp_rewrite -> using_permalinks () )
2008-11-21 12:33:05 -05:00
$result = user_trailingslashit ( trailingslashit ( $result ) . 'comment-page-' . $pagenum , 'commentpaged' );
2008-10-24 03:36:43 -04:00
else
2008-11-21 12:33:05 -05:00
$result = add_query_arg ( 'cpage' , $pagenum , $result );
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
/**
* Filter the comments page number link for the current request .
*
* @ since 2.7 . 0
*
* @ param string $result The comments page number link .
*/
$result = apply_filters ( 'get_comments_pagenum_link' , $result );
2008-09-23 17:11:27 -04:00
return $result ;
}
2008-10-21 23:08:33 -04:00
/**
2011-09-29 18:57:43 -04:00
* Return the link to 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
*
* @ param string $label Optional . Label for link text .
* @ param int $max_page Optional . Max page .
2008-12-22 14:33:09 -05:00
* @ return string | null
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 ;
2009-01-14 18:06:46 -05:00
if ( ! is_singular () || ! get_option ( 'page_comments' ) )
2008-09-23 17:11:27 -04:00
return ;
$page = get_query_var ( 'cpage' );
2008-10-24 03:36:43 -04:00
2008-09-23 17:11:27 -04:00
$nextpage = intval ( $page ) + 1 ;
if ( empty ( $max_page ) )
$max_page = $wp_query -> max_num_comment_pages ;
2008-12-06 23:49:22 -05:00
if ( empty ( $max_page ) )
$max_page = get_comment_pages_count ();
2008-09-23 17:11:27 -04:00
if ( $nextpage > $max_page )
return ;
if ( empty ( $label ) )
2008-11-18 17:46:56 -05:00
$label = __ ( 'Newer Comments »' );
2008-09-23 17:11:27 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the anchor tag attributes for the next comments page link .
*
* @ since 2.7 . 0
*
* @ param string $attributes Attributes for the anchor tag .
*/
2010-04-01 20:07:59 -04:00
return '<a href="' . esc_url ( get_comments_pagenum_link ( $nextpage , $max_page ) ) . '" ' . apply_filters ( 'next_comments_link_attributes' , '' ) . '>' . preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label ) . '</a>' ;
2008-09-23 17:11:27 -04:00
}
2008-10-21 23:08:33 -04:00
/**
2011-09-29 18:57:43 -04:00
* Display the link to next comments page .
2008-10-21 23:08:33 -04:00
*
* @ since 2.7 . 0
*
2008-12-22 14:33:09 -05:00
* @ param string $label Optional . Label for link text .
* @ param int $max_page Optional . Max page .
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
/**
* Return the previous comments page link .
*
* @ since 2.7 . 1
*
* @ param string $label Optional . Label for comments link text .
* @ return string | null
*/
function get_previous_comments_link ( $label = '' ) {
2009-01-14 18:06:46 -05:00
if ( ! is_singular () || ! get_option ( 'page_comments' ) )
2008-09-23 17:11:27 -04:00
return ;
$page = get_query_var ( 'cpage' );
2008-12-30 17:32:43 -05:00
if ( intval ( $page ) <= 1 )
2008-09-23 17:11:27 -04:00
return ;
2008-10-24 03:36:43 -04:00
$prevpage = intval ( $page ) - 1 ;
2008-09-23 17:11:27 -04:00
if ( empty ( $label ) )
$label = __ ( '« Older Comments' );
2014-04-13 22:13:16 -04:00
/**
* Filter the anchor tag attributes for the previous comments page link .
*
* @ since 2.7 . 0
*
* @ param string $attributes Attributes for the anchor tag .
*/
2010-04-01 20:07:59 -04:00
return '<a href="' . esc_url ( get_comments_pagenum_link ( $prevpage ) ) . '" ' . apply_filters ( 'previous_comments_link_attributes' , '' ) . '>' . preg_replace ( '/&([^#])(?![a-z]{1,8};)/i' , '&$1' , $label ) . '</a>' ;
2008-12-22 14:33:09 -05:00
}
/**
* Display the previous comments page link .
*
* @ since 2.7 . 0
*
* @ param string $label Optional . Label for comments link text .
*/
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
/**
* Create 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
*
2011-09-29 18:57:43 -04:00
* @ param string | array $args Optional args . See paginate_links () .
2008-10-21 23:08:33 -04:00
* @ return string Markup for pagination links .
2008-10-07 18:41:51 -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
2009-01-14 18:06:46 -05:00
if ( ! is_singular () || ! get_option ( 'page_comments' ) )
2008-10-07 18:41:51 -04:00
return ;
$page = get_query_var ( 'cpage' );
if ( ! $page )
$page = 1 ;
2008-12-06 23:49:22 -05:00
$max_page = get_comment_pages_count ();
2008-10-07 18:41:51 -04:00
$defaults = array (
'base' => add_query_arg ( 'cpage' , '%#%' ),
'format' => '' ,
'total' => $max_page ,
'current' => $page ,
'echo' => true ,
'add_fragment' => '#comments'
);
2008-10-23 14:55:22 -04:00
if ( $wp_rewrite -> using_permalinks () )
2009-01-08 13:26:52 -05:00
$defaults [ 'base' ] = user_trailingslashit ( trailingslashit ( get_permalink ()) . 'comment-page-%#%' , 'commentpaged' );
2008-10-23 14:55:22 -04:00
2008-10-07 18:41:51 -04:00
$args = wp_parse_args ( $args , $defaults );
$page_links = paginate_links ( $args );
if ( $args [ 'echo' ] )
echo $page_links ;
else
return $page_links ;
}
2008-10-13 18:00:07 -04:00
/**
2012-02-18 13:46:15 -05:00
* Retrieve the Press This bookmarklet link .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* Use this in 'a' element 'href' attribute .
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* @ since 2.6 . 0
2008-10-13 18:00:07 -04:00
*
2008-10-21 23:08:33 -04:00
* @ return string
2008-10-13 18:00:07 -04:00
*/
2008-05-12 15:08:39 -04:00
function get_shortcut_link () {
2012-02-18 13:46:15 -05:00
// In case of breaking changes, version this. #WP20071
2008-05-12 15:08:39 -04:00
$link = " javascript:
2009-09-14 10:03:32 -04:00
var d = document ,
w = window ,
e = w . getSelection ,
k = d . getSelection ,
2008-07-13 00:57:01 -04:00
x = d . selection ,
s = ( e ? e () : ( k ) ? k () : ( x ? x . createRange () . text : 0 )),
f = '" . admin_url(' press - this . php ') . "' ,
l = d . location ,
e = encodeURIComponent ,
2009-09-08 16:06:52 -04:00
u = f + '?u=' + e ( l . href ) + '&t=' + e ( d . title ) + '&s=' + e ( s ) + '&v=4' ;
2009-10-23 00:32:56 -04:00
a = function (){ if ( ! w . open ( u , 't' , 'toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570' )) l . href = u ;};
2009-09-08 16:06:52 -04:00
if ( / Firefox /. test ( navigator . userAgent )) setTimeout ( a , 0 ); else a ();
void ( 0 ) " ;
2008-05-13 12:02:12 -04:00
$link = str_replace ( array ( " \r " , " \n " , " \t " ), '' , $link );
2008-05-12 15:08:39 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the Press This bookmarklet link .
*
* @ since 2.6 . 0
*
* @ param string $link The Press This bookmarklet link .
*/
return apply_filters ( 'shortcut_link' , $link );
2008-05-12 15:08:39 -04:00
}
2008-05-27 13:46:01 -04:00
2010-01-04 12:23:29 -05:00
/**
2010-02-05 16:49:19 -05:00
* Retrieve the home url for the current site .
2010-01-04 12:23:29 -05:00
*
2011-09-29 18:57:43 -04:00
* Returns the 'home' option with the appropriate protocol , 'https' if
2010-01-04 12:23:29 -05:00
* is_ssl () and 'http' otherwise . If $scheme is 'http' or 'https' , is_ssl () is
* overridden .
*
2010-02-05 16:49:19 -05:00
* @ since 3.0 . 0
*
* @ uses get_home_url ()
2010-01-04 12:23:29 -05:00
*
* @ param string $path ( optional ) Path relative to the home url .
2012-02-08 11:09:41 -05:00
* @ param string $scheme ( optional ) Scheme to give the home url context . Currently 'http' , 'https' , or 'relative' .
2010-01-04 12:23:29 -05:00
* @ return string Home url link with optional path appended .
*/
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
}
/**
* Retrieve the home url for a given site .
*
2011-09-29 18:57:43 -04:00
* Returns the 'home' option with the appropriate protocol , 'https' if
2010-02-05 16:49:19 -05:00
* is_ssl () and 'http' otherwise . If $scheme is 'http' or 'https' , is_ssl () is
* overridden .
*
* @ since 3.0 . 0
*
* @ param int $blog_id ( optional ) Blog ID . Defaults to current blog .
* @ param string $path ( optional ) Path relative to the home url .
2012-02-08 11:09:41 -05:00
* @ param string $scheme ( optional ) Scheme to give the home url context . Currently 'http' , 'https' , or 'relative' .
2010-02-05 16:49:19 -05:00
* @ return string Home url link with optional path appended .
*/
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
2012-08-03 13:51:42 -04: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
2012-09-21 08:36:50 -04:00
if ( ! in_array ( $scheme , array ( 'http' , 'https' , 'relative' ) ) ) {
2013-07-28 21:21:27 -04:00
if ( is_ssl () && ! is_admin () && 'wp-login.php' !== $GLOBALS [ 'pagenow' ] )
2012-09-21 08:36:50 -04:00
$scheme = 'https' ;
else
$scheme = parse_url ( $url , PHP_URL_SCHEME );
}
2012-09-04 10:44:17 -04:00
$url = set_url_scheme ( $url , $scheme );
2010-01-04 12:23:29 -05:00
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2010-01-04 12:23:29 -05:00
$url .= '/' . ltrim ( $path , '/' );
2014-04-13 22:13:16 -04:00
/**
* Filter the home URL .
*
* @ 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 .
* @ param string | null $orig_scheme Scheme to give the home URL context . Accepts 'http' , 'https' , 'relative' or null .
* @ param int | null $blog_id Blog ID , or null for the current blog .
*/
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
/**
2010-02-05 16:49:19 -05:00
* Retrieve the site url for the current site .
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
*
2010-02-05 16:49:19 -05:00
* @ uses get_site_url ()
*
* @ param string $path Optional . Path relative to the site url .
2012-09-04 10:44:17 -04:00
* @ param string $scheme Optional . Scheme to give the site url context . See set_url_scheme () .
2010-02-05 16:49:19 -05:00
* @ return string Site url link with optional path appended .
*/
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
}
/**
* Retrieve the site url for a given site .
*
2011-09-29 18:57:43 -04:00
* Returns the 'site_url' option with the appropriate protocol , 'https' if
2010-02-05 16:49:19 -05:00
* is_ssl () and 'http' otherwise . If $scheme is 'http' or 'https' , is_ssl () is
* overridden .
*
* @ since 3.0 . 0
*
* @ param int $blog_id ( optional ) Blog ID . Defaults to current blog .
2008-10-13 18:00:07 -04:00
* @ param string $path Optional . Path relative to the site url .
2012-02-08 11:09:41 -05:00
* @ param string $scheme Optional . Scheme to give the site url context . Currently 'http' , 'https' , 'login' , 'login_post' , 'admin' , or 'relative' .
2008-10-13 18:00:07 -04:00
* @ return string Site url link with optional path appended .
2008-07-14 19:39:11 -04:00
*/
2010-05-03 14:16:22 -04:00
function get_site_url ( $blog_id = null , $path = '' , $scheme = null ) {
2012-08-03 13:51:42 -04: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
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2010-05-16 17:58:31 -04:00
$url .= '/' . ltrim ( $path , '/' );
2008-05-27 13:46:01 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the site URL .
*
* @ 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 .
* @ param int | null $blog_id Blog ID , or null for the current blog .
*/
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
/**
2010-02-05 16:49:19 -05:00
* Retrieve 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
*
2011-09-29 18:57:43 -04:00
* @ param string $path Optional path relative to the admin url .
2010-03-25 18:00:36 -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 .
2011-09-29 18:57:43 -04:00
* @ return string Admin url link with optional path appended .
2008-07-14 19:39:11 -04: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
}
/**
* Retrieve the url to the admin area for a given site .
*
* @ since 3.0 . 0
*
* @ param int $blog_id ( optional ) Blog ID . Defaults to current blog .
2011-09-29 18:57:43 -04:00
* @ param string $path Optional path relative to the admin url .
2010-03-25 18:00:36 -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 .
2011-09-29 18:57:43 -04:00
* @ return string Admin url link with optional path appended .
2010-02-05 16:49:19 -05:00
*/
2010-05-03 14:16:22 -04:00
function get_admin_url ( $blog_id = null , $path = '' , $scheme = 'admin' ) {
2010-03-25 18:00:36 -04:00
$url = get_site_url ( $blog_id , 'wp-admin/' , $scheme );
2008-05-27 13:46:01 -04:00
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2012-09-04 10:44:17 -04:00
$url .= ltrim ( $path , '/' );
2008-05-27 13:46:01 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the admin area URL .
*
* @ since 2.8 . 0
*
* @ 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 Blog ID , or null for the current blog .
*/
2012-09-04 10:44:17 -04:00
return apply_filters ( 'admin_url' , $url , $path , $blog_id );
2008-05-27 13:46:01 -04:00
}
2008-10-13 18:00:07 -04:00
/**
* Retrieve 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
*
2008-10-13 18:00:07 -04:00
* @ param string $path Optional . Path relative to the includes url .
2013-08-01 09:15:14 -04:00
* @ param string $scheme Optional . Scheme to give the includes url context .
2008-10-13 18:00:07 -04:00
* @ return string Includes url link with optional path appended .
2008-07-14 19:39:11 -04: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
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2008-05-27 13:46:01 -04:00
$url .= ltrim ( $path , '/' );
2014-04-13 22:13:16 -04:00
/**
* Filter the URL to the includes directory .
*
* @ since 2.8 . 0
*
* @ 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 .
*/
return apply_filters ( 'includes_url' , $url , $path );
2008-05-27 13:46:01 -04:00
}
2008-10-13 18:00:07 -04:00
/**
* Retrieve 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
*
2008-10-13 18:00:07 -04:00
* @ param string $path Optional . Path relative to the content url .
* @ return string Content url link with optional path appended .
2008-07-14 19:39:11 -04:00
*/
2010-05-03 14:16:22 -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
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2008-07-09 13:24:36 -04:00
$url .= '/' . ltrim ( $path , '/' );
2014-04-13 22:13:16 -04:00
/**
* Filter the URL to the content directory .
*
* @ 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 .
*/
return apply_filters ( 'content_url' , $url , $path );
2008-07-09 13:24:36 -04:00
}
2008-10-13 18:00:07 -04:00
/**
2014-07-03 15:42:15 -04:00
* Retrieve a URL within the plugins or mu - plugins directory .
*
* 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
*
2014-07-03 15:42:15 -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 .
* @ return string Plugins URL link with optional paths appended .
2008-07-14 20:10:07 -04:00
*/
2014-07-03 15:42:15 -04:00
function plugins_url ( $path = '' , $plugin = '' ) {
2009-04-23 04:16:06 -04:00
2014-08-04 21:31:16 -04:00
$path = wp_normalize_path ( $path );
$plugin = wp_normalize_path ( $plugin );
$mu_plugin_dir = wp_normalize_path ( WPMU_PLUGIN_DIR );
2010-02-05 07:39:04 -05:00
if ( ! empty ( $plugin ) && 0 === strpos ( $plugin , $mu_plugin_dir ) )
2009-04-23 04:16:06 -04:00
$url = WPMU_PLUGIN_URL ;
2010-02-05 07:39:04 -05:00
else
2009-04-23 04:16:06 -04:00
$url = WP_PLUGIN_URL ;
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
2009-04-23 04:16:06 -04:00
if ( ! empty ( $plugin ) && is_string ( $plugin ) ) {
2009-02-15 11:50:45 -05:00
$folder = dirname ( plugin_basename ( $plugin ));
2010-02-05 07:39:04 -05:00
if ( '.' != $folder )
2009-02-15 11:50:45 -05:00
$url .= '/' . ltrim ( $folder , '/' );
}
2009-03-17 22:43:45 -04:00
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2008-07-14 20:10:07 -04:00
$url .= '/' . ltrim ( $path , '/' );
2014-04-13 22:13:16 -04:00
/**
* Filter the URL to the plugins directory .
*
* @ 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
/**
* Retrieve the site url for the current network .
*
2011-09-29 18:57:43 -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
*
* @ param string $path Optional . Path relative to the site url .
2012-09-04 10:44:17 -04:00
* @ param string $scheme Optional . Scheme to give the site url context . See set_url_scheme () .
2010-03-29 13:53:03 -04:00
* @ return string Site url link with optional path appended .
*/
2010-05-03 14:16:22 -04:00
function network_site_url ( $path = '' , $scheme = null ) {
2012-09-04 10:44:17 -04:00
if ( ! is_multisite () )
2010-03-29 17:45:31 -04:00
return site_url ( $path , $scheme );
2013-11-12 22:23:10 -05:00
$current_site = get_current_site ();
2012-02-08 11:09:41 -05:00
if ( 'relative' == $scheme )
$url = $current_site -> path ;
else
2012-09-04 10:44:17 -04:00
$url = set_url_scheme ( 'http://' . $current_site -> domain . $current_site -> path , $scheme );
2010-03-29 13:53:03 -04:00
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2012-09-04 10:44:17 -04:00
$url .= ltrim ( $path , '/' );
2010-03-29 13:53:03 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the network site URL .
*
* @ 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
}
/**
* Retrieve the home url for the current network .
*
2011-09-29 18:57:43 -04:00
* Returns the home 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
*
* @ param string $path ( optional ) Path relative to the home url .
2012-02-08 11:09:41 -05:00
* @ param string $scheme ( optional ) Scheme to give the home url context . Currently 'http' , 'https' , or 'relative' .
2010-03-29 13:53:03 -04:00
* @ return string Home url link with optional path appended .
*/
2010-05-03 14:16:22 -04:00
function network_home_url ( $path = '' , $scheme = null ) {
2012-09-04 10:44:17 -04:00
if ( ! is_multisite () )
2010-03-29 17:45:31 -04:00
return home_url ( $path , $scheme );
2013-11-12 22:23:10 -05:00
$current_site = get_current_site ();
2010-03-29 13:53:03 -04:00
$orig_scheme = $scheme ;
2010-03-29 16:25:30 -04:00
2012-09-04 10:44:17 -04:00
if ( ! in_array ( $scheme , array ( 'http' , 'https' , 'relative' ) ) )
$scheme = is_ssl () && ! is_admin () ? 'https' : 'http' ;
2010-03-29 13:53:03 -04:00
2012-02-08 11:09:41 -05:00
if ( 'relative' == $scheme )
$url = $current_site -> path ;
else
2012-09-04 10:44:17 -04:00
$url = set_url_scheme ( 'http://' . $current_site -> domain . $current_site -> path , $scheme );
2010-03-29 13:53:03 -04:00
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2010-03-29 15:57:17 -04:00
$url .= ltrim ( $path , '/' );
2010-03-29 13:53:03 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the network home URL .
*
* @ 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 .
*/
2010-05-03 14:16:22 -04:00
return apply_filters ( 'network_home_url' , $url , $path , $orig_scheme );
2010-03-29 13:53:03 -04:00
}
/**
* Retrieve the url to the admin area for the network .
*
* @ since 3.0 . 0
*
2011-09-29 18:57:43 -04:00
* @ param string $path Optional path relative to the admin url .
2010-03-29 13:53:03 -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 .
2011-09-29 18:57:43 -04:00
* @ return string Admin url link with optional path appended .
2010-03-29 13:53:03 -04:00
*/
2010-05-03 14:16:22 -04:00
function network_admin_url ( $path = '' , $scheme = 'admin' ) {
2010-12-16 04:31:42 -05:00
if ( ! is_multisite () )
return admin_url ( $path , $scheme );
2010-07-30 16:34:54 -04:00
$url = network_site_url ( 'wp-admin/network/' , $scheme );
2010-03-29 13:53:03 -04:00
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2010-03-29 13:53:03 -04:00
$url .= ltrim ( $path , '/' );
2014-04-13 22:13:16 -04:00
/**
* Filter the network admin URL .
*
* @ since 3.0 . 0
*
* @ 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 .
*/
return apply_filters ( 'network_admin_url' , $url , $path );
2010-03-29 13:53:03 -04:00
}
2010-10-07 15:34:18 -04:00
/**
* Retrieve the url to the admin area for the current user .
*
* @ since 3.0 . 0
*
2011-09-29 18:57:43 -04:00
* @ param string $path Optional path relative to the admin url .
2010-10-07 15:34:18 -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 .
2011-09-29 18:57:43 -04:00
* @ return string Admin url link with optional path appended .
2010-10-07 15:34:18 -04:00
*/
function user_admin_url ( $path = '' , $scheme = 'admin' ) {
$url = network_site_url ( 'wp-admin/user/' , $scheme );
2013-02-28 16:04:26 -05:00
if ( $path && is_string ( $path ) )
2010-10-07 15:34:18 -04:00
$url .= ltrim ( $path , '/' );
2014-04-13 22:13:16 -04:00
/**
* Filter the user admin URL for the current user .
*
* @ since 3.1 . 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 .
*/
return apply_filters ( 'user_admin_url' , $url , $path );
2010-10-07 15:34:18 -04:00
}
2010-07-30 16:34:54 -04:00
/**
* Retrieve the url to the admin area for either the current blog or the network depending on context .
*
* @ since 3.1 . 0
*
2011-09-29 18:57:43 -04:00
* @ param string $path Optional path relative to the admin url .
2010-07-30 16:34:54 -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 .
2011-09-29 18:57:43 -04:00
* @ return string Admin url link with optional path appended .
2010-07-30 16:34:54 -04:00
*/
function self_admin_url ( $path = '' , $scheme = 'admin' ) {
if ( is_network_admin () )
return network_admin_url ( $path , $scheme );
2010-10-07 15:34:18 -04:00
elseif ( is_user_admin () )
return user_admin_url ( $path , $scheme );
2010-07-30 16:34:54 -04:00
else
return admin_url ( $path , $scheme );
}
2012-05-18 16:04:59 -04:00
/**
* Set the scheme for a URL
*
* @ since 3.4 . 0
2012-05-27 12:25:43 -04:00
*
2012-05-18 16:04:59 -04:00
* @ param string $url Absolute url that includes a scheme
* @ param string $scheme Optional . Scheme to give $url . Currently 'http' , 'https' , 'login' , 'login_post' , 'admin' , or 'relative' .
* @ return string $url URL with chosen scheme .
*/
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' ;
} elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) {
$scheme = is_ssl () || force_ssl_admin () ? 'https' : 'http' ;
} elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
$scheme = is_ssl () ? 'https' : 'http' ;
2012-05-18 16:04:59 -04:00
}
2013-09-10 14:08:11 -04:00
$url = trim ( $url );
2013-09-10 23:57:09 -04:00
if ( substr ( $url , 0 , 2 ) === '//' )
2013-09-10 14:08:11 -04:00
$url = 'http:' . $url ;
if ( 'relative' == $scheme ) {
$url = ltrim ( preg_replace ( '#^\w+://[^/]*#' , '' , $url ) );
2013-09-10 23:57:09 -04:00
if ( $url !== '' && $url [ 0 ] === '/' )
2013-09-10 14:08:11 -04:00
$url = '/' . ltrim ( $url , " / \t \n \r \0 \x0B " );
} else {
$url = preg_replace ( '#^\w+://#' , $scheme . '://' , $url );
}
2012-05-18 16:04:59 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the resulting URL after setting the scheme .
*
* @ since 3.4 . 0
*
* @ 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 $orig_scheme Scheme requested for the URL . One of 'http' , 'https' , 'login' ,
* 'login_post' , 'admin' , 'rpc' , or 'relative' .
*/
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
/**
* Get the URL to the user ' s dashboard .
*
2011-12-13 18:45:31 -05:00
* If a user does not belong to any site , the global user dashboard is used . If the user belongs to the current site ,
2011-09-29 18:57:43 -04:00
* the dashboard for the current site is returned . If the user cannot edit the current site , the dashboard to the user ' s
2010-10-29 13:48:53 -04:00
* primary blog is returned .
*
* @ since 3.1 . 0
*
2014-02-25 12:08:13 -05:00
* @ param int $user_id Optional . User ID . Defaults to current user .
2011-09-29 18:57:43 -04:00
* @ param string $path Optional path relative to the dashboard . Use only paths known to both blog and user admins .
2010-10-29 13:48:53 -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 .
2011-09-29 18:57:43 -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 );
2011-06-22 15:45:28 -04:00
if ( ! is_super_admin () && 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 ();
2011-06-22 15:45:28 -04:00
if ( $current_blog && ( is_super_admin ( $user_id ) || in_array ( $current_blog , array_keys ( $blogs ) ) ) ) {
2010-10-29 13:48:53 -04:00
$url = admin_url ( $path , $scheme );
} else {
$active = get_active_blog_for_user ( $user_id );
if ( $active )
$url = get_admin_url ( $active -> blog_id , $path , $scheme );
else
$url = user_admin_url ( $path , $scheme );
}
}
2014-04-13 22:13:16 -04:00
/**
* Filter the dashboard URL for a user .
*
* @ 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 .
*/
2010-10-29 13:48:53 -04:00
return apply_filters ( 'user_dashboard_url' , $url , $user_id , $path , $scheme );
}
/**
* Get the URL to the user ' s profile editor .
*
* @ since 3.1 . 0
*
2014-02-25 12:08:13 -05:00
* @ param int $user_id Optional . User ID . Defaults to current user .
* @ 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 .
2011-09-29 18:57:43 -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
2010-11-18 18:07:59 -05:00
if ( is_user_admin () )
$url = user_admin_url ( 'profile.php' , $scheme );
elseif ( is_network_admin () )
$url = network_admin_url ( 'profile.php' , $scheme );
else
2014-02-25 12:08:13 -05:00
$url = get_dashboard_url ( $user_id , 'profile.php' , $scheme );
2010-10-29 13:48:53 -04:00
2014-04-13 22:13:16 -04:00
/**
* Filter the URL for a user ' s profile editor .
*
* @ 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 .
*/
2014-02-25 12:08:13 -05:00
return apply_filters ( 'edit_profile_url' , $url , $user_id , $scheme );
2010-10-29 13:48:53 -04:00
}
2009-08-05 12:43:51 -04:00
/**
2011-09-29 18:57:43 -04:00
* Output rel = canonical for singular queries .
2009-08-05 12:43:51 -04:00
*
* @ since 2.9 . 0
*/
function rel_canonical () {
if ( ! is_singular () )
return ;
global $wp_the_query ;
if ( ! $id = $wp_the_query -> get_queried_object_id () )
return ;
$link = get_permalink ( $id );
2012-08-21 08:53:54 -04:00
if ( $page = get_query_var ( 'cpage' ) )
$link = get_comments_pagenum_link ( $page );
2009-08-05 12:43:51 -04:00
echo " <link rel='canonical' href=' $link ' /> \n " ;
}
2010-03-09 14:36:38 -05:00
/**
* Return a shortlink for a post , page , attachment , or blog .
*
2011-09-29 18:57:43 -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 via the pre_get_shortlink filter or filter the output
2010-03-09 14:36:38 -05:00
* via the get_shortlink filter .
*
* @ since 3.0 . 0.
2010-03-17 12:27:25 -04:00
*
2011-09-29 18:57:43 -04:00
* @ param int $id A post or blog id . Default is 0 , which means the current post or blog .
2010-09-07 07:21:11 -04:00
* @ param string $context Whether the id is a 'blog' id , 'post' id , or 'media' id . If 'post' , the post_type of the post is consulted . If 'query' , the current query is consulted to determine the id and context . Default is 'post' .
2010-03-09 14:36:38 -05:00
* @ param bool $allow_slugs Whether to allow post slugs in the shortlink . It is up to the plugin how and whether to honor this .
* @ return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled .
*/
function wp_get_shortlink ( $id = 0 , $context = 'post' , $allow_slugs = true ) {
2014-04-13 22:13:16 -04:00
/**
* Filter whether to preempt generating a shortlink for the given post .
*
* Passing a truthy value to the filter will effectively short - circuit the
* shortlink - generation process , returning that value instead .
*
* @ since 3.0 . 0
*
* @ param bool | 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 .
*/
$shortlink = apply_filters ( 'pre_get_shortlink' , false , $id , $context , $allow_slugs );
2010-03-09 14:36:38 -05:00
if ( false !== $shortlink )
return $shortlink ;
global $wp_query ;
$post_id = 0 ;
2013-08-22 11:56:08 -04:00
if ( 'query' == $context && is_singular () ) {
2010-03-09 14:36:38 -05:00
$post_id = $wp_query -> get_queried_object_id ();
2013-08-15 16:09:09 -04:00
$post = get_post ( $post_id );
2010-05-06 17:20:17 -04:00
} elseif ( 'post' == $context ) {
2013-08-15 16:09:09 -04:00
$post = get_post ( $id );
2013-09-12 13:30:10 -04:00
if ( ! empty ( $post -> ID ) )
$post_id = $post -> ID ;
2010-05-06 17:20:17 -04:00
}
2010-03-09 14:36:38 -05:00
$shortlink = '' ;
2013-08-15 16:09:09 -04:00
// Return p= link for all public post types.
if ( ! empty ( $post_id ) ) {
$post_type = get_post_type_object ( $post -> post_type );
2014-03-27 22:59:14 -04:00
if ( 'page' === $post -> post_type && $post -> ID == get_option ( 'page_on_front' ) && 'page' == get_option ( 'show_on_front' ) ) {
$shortlink = home_url ( '/' );
} elseif ( $post_type -> public ) {
$shortlink = home_url ( '?p=' . $post_id );
}
2010-03-09 14:36:38 -05:00
}
2014-04-13 22:13:16 -04:00
/**
* Filter the shortlink for a post .
*
* @ 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
}
/**
2011-09-05 15:08:15 -04:00
* Inject rel = shortlink into head if a shortlink is defined for the current page .
2010-03-09 14:36:38 -05:00
*
* Attached to the wp_head action .
*
* @ since 3.0 . 0
*
* @ uses wp_get_shortlink ()
*/
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
2010-04-23 17:20:16 -04:00
if ( empty ( $shortlink ) )
2010-03-09 14:36:38 -05:00
return ;
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
}
/**
* Send a Link : rel = shortlink header if a shortlink is defined for the current page .
*
* Attached to the wp action .
*
* @ since 3.0 . 0
*
* @ uses wp_get_shortlink ()
*/
function wp_shortlink_header () {
2010-06-29 20:05:18 -04:00
if ( headers_sent () )
2010-03-09 14:36:38 -05:00
return ;
$shortlink = wp_get_shortlink ( 0 , 'query' );
if ( empty ( $shortlink ) )
return ;
2010-03-10 15:10:32 -05:00
header ( 'Link: <' . $shortlink . '>; rel=shortlink' , false );
2010-03-09 14:36:38 -05:00
}
2010-03-12 11:08:37 -05:00
/**
* Display the Short Link for a Post
*
* Must be called from inside " The Loop "
*
* Call like the_shortlink ( __ ( 'Shortlinkage FTW' ))
*
* @ since 3.0 . 0
*
2011-09-29 18:57:43 -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 .
2010-03-12 11:08:37 -05:00
* @ param string $before Optional HTML to display before the link .
2011-09-29 18:57:43 -04:00
* @ param string $after Optional HTML to display after the link .
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 ();
2010-04-23 17:20:16 -04:00
if ( empty ( $text ) )
2010-03-12 11:08:37 -05:00
$text = __ ( 'This is the short link.' );
2010-04-23 17:20:16 -04:00
if ( empty ( $title ) )
2012-01-05 15:50:54 -05:00
$title = the_title_attribute ( array ( 'echo' => false ) );
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
2010-04-23 17:20:16 -04: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
/**
* Filter the shortlink anchor tag for a post .
*
* @ 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
}