2004-01-27 04:58:01 -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
|
2008-10-21 23:08:33 -04:00
|
|
|
* @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2004-04-21 00:12:55 -04:00
|
|
|
function the_permalink() {
|
2005-01-14 18:43:20 -05:00
|
|
|
echo 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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param $string String a URL with or without a trailing slash.
|
|
|
|
* @param $type_of_url String 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
|
|
|
|
|
|
|
// Note that $type_of_url can be one of following:
|
|
|
|
// single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
|
|
|
|
$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
|
|
|
*/
|
2004-01-27 04:58:01 -05:00
|
|
|
function permalink_anchor($mode = 'id') {
|
2005-10-17 19:41:28 -04:00
|
|
|
global $post;
|
|
|
|
switch ( strtolower($mode) ) {
|
|
|
|
case 'title':
|
2008-01-04 14:36:34 -05: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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param int $id Optional. Post ID.
|
|
|
|
* @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
|
|
|
|
* @return string
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2008-10-21 23:08:33 -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 {
|
2008-12-16 18:50:39 -05:00
|
|
|
$post = &get_post($id);
|
2009-02-08 08:38:02 -05:00
|
|
|
$sample = false;
|
|
|
|
}
|
2007-08-28 14:58:54 -04:00
|
|
|
|
2008-10-21 23:08:33 -04: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' )
|
2009-02-08 08:38:02 -05:00
|
|
|
return get_page_link($post->ID, $leavename, $sample);
|
2006-02-09 05:03:48 -05:00
|
|
|
elseif ($post->post_type == 'attachment')
|
2005-11-15 17:55:24 -05:00
|
|
|
return get_attachment_link($post->ID);
|
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
|
|
|
|
2007-06-15 18:11:01 -04:00
|
|
|
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
|
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 ) {
|
2005-03-27 15:45:01 -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
|
2008-11-30 14:29:46 -05:00
|
|
|
$category = $cats[0]->slug;
|
|
|
|
if ( $parent = $cats[0]->parent )
|
|
|
|
$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) ) {
|
|
|
|
$default_category = get_category( get_option( 'default_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');
|
2008-07-29 15:52:44 -04:00
|
|
|
return apply_filters('post_link', $permalink, $post, $leavename);
|
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);
|
2008-07-29 15:52:44 -04:00
|
|
|
return apply_filters('post_link', $permalink, $post, $leavename);
|
2004-09-04 22:41:01 -04:00
|
|
|
}
|
2004-01-27 04:58:01 -05:00
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* Retrieve permalink from post ID.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param int $post_id Optional. Post ID.
|
|
|
|
* @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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param int $id Optional. Post ID.
|
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
|
|
|
*/
|
2009-02-08 08:38:02 -05:00
|
|
|
function get_page_link( $id = false, $leavename = false, $sample = false ) {
|
2006-11-17 15:00:11 -05:00
|
|
|
global $post;
|
|
|
|
|
2007-03-21 21:04:19 -04:00
|
|
|
$id = (int) $id;
|
2006-11-17 15:00:11 -05:00
|
|
|
if ( !$id )
|
2007-03-22 20:59:21 -04:00
|
|
|
$id = (int) $post->ID;
|
2006-11-17 15:00:11 -05:00
|
|
|
|
|
|
|
if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
|
2010-01-04 12:23:29 -05:00
|
|
|
$link = home_url();
|
2006-11-17 15:00:11 -05:00
|
|
|
else
|
2009-02-08 08:38:02 -05:00
|
|
|
$link = _get_page_link( $id , $leavename, $sample );
|
2006-11-17 15:00:11 -05:00
|
|
|
|
|
|
|
return apply_filters('page_link', $link, $id);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param int $id Optional. Post ID.
|
|
|
|
* @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
|
|
|
*/
|
2009-02-08 08:38:02 -05:00
|
|
|
function _get_page_link( $id = false, $leavename = false, $sample = false ) {
|
2004-12-02 21:38:11 -05:00
|
|
|
global $post, $wp_rewrite;
|
2004-10-05 22:18:37 -04:00
|
|
|
|
2005-10-17 19:41:28 -04:00
|
|
|
if ( !$id )
|
2007-03-22 20:59:21 -04:00
|
|
|
$id = (int) $post->ID;
|
2008-02-06 13:11:49 -05:00
|
|
|
else
|
|
|
|
$post = &get_post($id);
|
2004-10-05 22:18:37 -04:00
|
|
|
|
2005-01-26 17:46:40 -05:00
|
|
|
$pagestruct = $wp_rewrite->get_page_permastruct();
|
2004-10-05 22:18:37 -04:00
|
|
|
|
2009-11-20 12:47:25 -05:00
|
|
|
if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status ) || $sample ) ) {
|
2004-10-05 22:18:37 -04:00
|
|
|
$link = get_page_uri($id);
|
2008-02-21 15:19:34 -05:00
|
|
|
$link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
|
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 {
|
2010-01-04 12:23:29 -05:00
|
|
|
$link = home_url("?page_id=$id");
|
2004-10-05 22:18:37 -04:00
|
|
|
}
|
|
|
|
|
2006-11-17 15:00:11 -05:00
|
|
|
return apply_filters( '_get_page_link', $link, $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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param int $id Optional. Post ID.
|
|
|
|
* @return string
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2005-11-15 17:55:24 -05:00
|
|
|
function get_attachment_link($id = false) {
|
2005-10-20 16:48:32 -04:00
|
|
|
global $post, $wp_rewrite;
|
|
|
|
|
|
|
|
$link = false;
|
|
|
|
|
|
|
|
if (! $id) {
|
2007-03-22 20:59:21 -04:00
|
|
|
$id = (int) $post->ID;
|
2005-10-20 16:48:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$object = get_post($id);
|
2006-12-12 17:50:54 -05:00
|
|
|
if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
|
2005-10-20 16:48:32 -04:00
|
|
|
$parent = get_post($object->post_parent);
|
2006-11-17 15:00:11 -05:00
|
|
|
if ( 'page' == $parent->post_type )
|
|
|
|
$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
|
|
|
|
else
|
|
|
|
$parentlink = get_permalink( $object->post_parent );
|
2008-04-02 12:18:11 -04:00
|
|
|
if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
|
2008-03-20 23:08:22 -04:00
|
|
|
$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
|
|
|
|
else
|
|
|
|
$name = $object->post_name;
|
2007-03-07 00:29:15 -05:00
|
|
|
if (strpos($parentlink, '?') === false)
|
2008-05-19 14:51:28 -04:00
|
|
|
$link = user_trailingslashit( trailingslashit($parentlink) . $name );
|
2005-10-20 16:48:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $link ) {
|
2009-05-16 13:22:19 -04:00
|
|
|
$link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id";
|
2005-10-20 16:48:32 -04:00
|
|
|
}
|
|
|
|
|
2005-11-15 17:55:24 -05:00
|
|
|
return apply_filters('attachment_link', $link, $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);
|
2010-01-04 12:23:29 -05:00
|
|
|
return apply_filters('year_link', home_url( user_trailingslashit($yearlink, 'year') ), $year);
|
2005-10-17 19:41:28 -04:00
|
|
|
} else {
|
2010-01-04 12:23:29 -05:00
|
|
|
return apply_filters('year_link', home_url('?m=' . $year), $year);
|
2005-10-17 19:41:28 -04:00
|
|
|
}
|
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);
|
2010-01-04 12:23:29 -05:00
|
|
|
return apply_filters('month_link', home_url( user_trailingslashit($monthlink, 'month') ), $year, $month);
|
2005-10-17 19:41:28 -04:00
|
|
|
} else {
|
2010-01-04 12:23:29 -05:00
|
|
|
return apply_filters('month_link', home_url( '?m=' . $year . zeroise($month, 2) ), $year, $month);
|
2005-10-17 19:41:28 -04:00
|
|
|
}
|
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);
|
2010-01-04 12:23:29 -05:00
|
|
|
return apply_filters('day_link', home_url( user_trailingslashit($daylink, 'day') ), $year, $month, $day);
|
2005-10-17 19:41:28 -04:00
|
|
|
} else {
|
2010-01-04 12:23:29 -05:00
|
|
|
return apply_filters('day_link', home_url( '?m=' . $year . zeroise($month, 2) . zeroise($day, 2) ), $year, $month, $day);
|
2005-10-17 19:41:28 -04:00
|
|
|
}
|
2004-06-02 03:14:03 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2005-02-05 22:40:08 -05:00
|
|
|
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
|
|
|
*/
|
2007-12-06 14:58:15 -05:00
|
|
|
function get_post_comments_feed_link($post_id = '', $feed = '') {
|
2007-02-23 03:31:07 -05:00
|
|
|
global $id;
|
|
|
|
|
|
|
|
if ( empty($post_id) )
|
2007-03-22 20:59:21 -04:00
|
|
|
$post_id = (int) $id;
|
2007-02-23 03:31:07 -05:00
|
|
|
|
2007-12-06 14:58:15 -05:00
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
2007-02-23 03:31:07 -05:00
|
|
|
if ( '' != get_option('permalink_structure') ) {
|
2007-08-22 18:42:57 -04:00
|
|
|
$url = trailingslashit( get_permalink($post_id) ) . '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 )
|
2010-01-04 12:23:29 -05:00
|
|
|
$url = home_url("?feed=$feed&page_id=$post_id");
|
2007-08-22 18:42:57 -04:00
|
|
|
else
|
2010-01-04 12:23:29 -05:00
|
|
|
$url = home_url("?feed=$feed&p=$post_id");
|
2007-02-23 03:31:07 -05:00
|
|
|
}
|
|
|
|
|
2007-02-27 10:24:54 -05:00
|
|
|
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
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
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.
|
2008-10-13 18:00:07 -04: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 = '' ) {
|
|
|
|
$url = get_post_comments_feed_link($post_id, $feed);
|
|
|
|
if ( empty($link_text) )
|
|
|
|
$link_text = __('Comments Feed');
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
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
|
|
|
}
|
|
|
|
|
2008-08-21 22:21:37 -04:00
|
|
|
$link = apply_filters('author_feed_link', $link, $feed);
|
2007-12-06 14:58:15 -05:00
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* Retrieve the feed link for a category.
|
2007-12-06 14:58:15 -05:00
|
|
|
*
|
2008-10-13 18:00:07 -04:00
|
|
|
* Returns a link to the feed for all post in a given category. A specific feed
|
|
|
|
* can be requested or left blank to get the default feed.
|
2007-12-06 14:58:15 -05:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Feed
|
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 = '') {
|
|
|
|
$cat_id = (int) $cat_id;
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-06 14:58:15 -05:00
|
|
|
$category = get_category($cat_id);
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-06 14:58:15 -05:00
|
|
|
if ( empty($category) || is_wp_error($category) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( empty($feed) )
|
|
|
|
$feed = get_default_feed();
|
|
|
|
|
|
|
|
$permalink_structure = get_option('permalink_structure');
|
|
|
|
|
|
|
|
if ( '' == $permalink_structure ) {
|
2010-01-04 12:23:29 -05:00
|
|
|
$link = home_url("?feed=$feed&cat=" . $cat_id);
|
2007-12-06 14:58:15 -05:00
|
|
|
} else {
|
|
|
|
$link = get_category_link($cat_id);
|
|
|
|
if( $feed == get_default_feed() )
|
|
|
|
$feed_link = 'feed';
|
|
|
|
else
|
|
|
|
$feed_link = "feed/$feed";
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-06 14:58:15 -05:00
|
|
|
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = apply_filters('category_feed_link', $link, $feed);
|
2008-02-05 01:47:27 -05: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 = '') {
|
|
|
|
$tag_id = (int) $tag_id;
|
|
|
|
|
|
|
|
$tag = get_tag($tag_id);
|
|
|
|
|
|
|
|
if ( empty($tag) || is_wp_error($tag) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$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&tag=" . $tag->slug);
|
2007-12-06 14:58:15 -05:00
|
|
|
} else {
|
|
|
|
$link = get_tag_link($tag->term_id);
|
|
|
|
if ( $feed == get_default_feed() )
|
|
|
|
$feed_link = 'feed';
|
|
|
|
else
|
|
|
|
$feed_link = "feed/$feed";
|
2008-05-27 13:56:46 -04:00
|
|
|
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
|
2007-12-06 14:58:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$link = apply_filters('tag_feed_link', $link, $feed);
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-25 14:19:42 -04:00
|
|
|
/**
|
|
|
|
* Retrieve edit tag link.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
|
|
|
* @param int $tag_id Tag ID
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-12-22 14:33:09 -05:00
|
|
|
function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) {
|
2009-02-11 18:41:29 -05:00
|
|
|
$tag = get_term($tag_id, $taxonomy);
|
2008-10-25 14:19:42 -04:00
|
|
|
|
|
|
|
if ( !current_user_can('manage_categories') )
|
|
|
|
return;
|
|
|
|
|
2008-12-22 14:33:09 -05:00
|
|
|
$location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&tag_ID=' . $tag->term_id);
|
2008-10-25 14:19:42 -04:00
|
|
|
return apply_filters( 'get_edit_tag_link', $location );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param int|object $tag Tag object or ID
|
|
|
|
* @return string|null HTML content, if $echo is set to false.
|
|
|
|
*/
|
|
|
|
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
|
|
|
|
$tag = get_term($tag, 'post_tag');
|
|
|
|
|
|
|
|
if ( !current_user_can('manage_categories') )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( empty($link) )
|
|
|
|
$link = __('Edit This');
|
|
|
|
|
|
|
|
$link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
|
|
|
|
echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
|
|
|
|
}
|
|
|
|
|
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 = '') {
|
|
|
|
if ( empty($search_query) )
|
2009-12-14 05:09:55 -05:00
|
|
|
$search = esc_attr( urlencode(get_search_query()) );
|
2007-12-19 13:05:21 -05:00
|
|
|
else
|
2009-12-14 05:09:55 -05:00
|
|
|
$search = esc_attr( urlencode(stripslashes($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-01-04 12:23:29 -05:00
|
|
|
$link = home_url("?s=$search&feed=$feed");
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-19 13:05:21 -05:00
|
|
|
$link = apply_filters('search_feed_link', $link);
|
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 = '') {
|
|
|
|
if ( empty($search_query) )
|
2009-12-14 05:09:55 -05:00
|
|
|
$search = esc_attr( urlencode(get_search_query()) );
|
2007-12-19 13:05:21 -05:00
|
|
|
else
|
2009-12-14 05:09:55 -05:00
|
|
|
$search = esc_attr( urlencode(stripslashes($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-01-04 12:23:29 -05:00
|
|
|
$link = home_url("?s=$search&feed=comments-$feed");
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-19 13:05:21 -05:00
|
|
|
$link = apply_filters('search_feed_link', $link);
|
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 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.
|
|
|
|
* @param string $context Optional, default to display. How to write the '&', defaults to '&'.
|
|
|
|
* @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' ) {
|
2008-03-12 01:50:07 -04:00
|
|
|
if ( !$post = &get_post( $id ) )
|
|
|
|
return;
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2008-04-18 19:38:21 -04:00
|
|
|
if ( 'display' == $context )
|
2010-01-04 11:58:43 -05:00
|
|
|
$action = '&action=edit';
|
2008-04-18 19:38:21 -04:00
|
|
|
else
|
2010-01-04 11:58:43 -05:00
|
|
|
$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;
|
|
|
|
|
|
|
|
if ( !current_user_can( $post_type_object->edit_cap, $post->ID ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
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.
|
2009-05-21 14:43:04 -04:00
|
|
|
* @param int $id Optional. Post ID.
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2009-10-01 13:41:09 -04:00
|
|
|
function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
|
2009-05-21 14:43:04 -04:00
|
|
|
if ( !$post = &get_post( $id ) )
|
|
|
|
return;
|
2007-04-26 23:51:36 -04:00
|
|
|
|
2009-05-21 14:55:00 -04:00
|
|
|
if ( !$url = get_edit_post_link( $post->ID ) )
|
|
|
|
return;
|
2007-04-26 23:51:36 -04:00
|
|
|
|
2009-10-01 13:41:09 -04:00
|
|
|
if ( null === $link )
|
|
|
|
$link = __('Edit This');
|
|
|
|
|
2009-05-21 14:55:00 -04:00
|
|
|
$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( __( 'Edit post' ) ) . '">' . $link . '</a>';
|
2007-04-24 19:21:56 -04:00
|
|
|
echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
|
|
|
|
}
|
2007-04-17 19:00:35 -04:00
|
|
|
|
2009-09-21 17:33:00 -04:00
|
|
|
/**
|
|
|
|
* Retrieve delete posts link for post.
|
|
|
|
*
|
|
|
|
* Can be used within the WordPress loop or outside of it. Can be used with
|
|
|
|
* pages, posts, attachments, and revisions.
|
|
|
|
*
|
|
|
|
* @since 2.9.0
|
|
|
|
*
|
|
|
|
* @param int $id Optional. Post ID.
|
|
|
|
* @param string $context Optional, default to display. How to write the '&', defaults to '&'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_delete_post_link($id = 0, $context = 'display') {
|
|
|
|
if ( !$post = &get_post( $id ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( 'display' == $context )
|
|
|
|
$action = 'action=trash&';
|
|
|
|
else
|
|
|
|
$action = 'action=trash&';
|
|
|
|
|
|
|
|
switch ( $post->post_type ) :
|
|
|
|
case 'page' :
|
|
|
|
if ( !current_user_can( 'delete_page', $post->ID ) )
|
|
|
|
return;
|
|
|
|
$file = 'page';
|
|
|
|
$var = 'post';
|
|
|
|
break;
|
|
|
|
case 'attachment' :
|
|
|
|
if ( !current_user_can( 'delete_post', $post->ID ) )
|
|
|
|
return;
|
|
|
|
$file = 'media';
|
|
|
|
$var = 'attachment_id';
|
|
|
|
break;
|
|
|
|
case 'revision' :
|
|
|
|
if ( !current_user_can( 'delete_post', $post->ID ) )
|
|
|
|
return;
|
|
|
|
$file = 'revision';
|
|
|
|
$var = 'revision';
|
|
|
|
$action = '';
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
2009-12-26 11:53:17 -05:00
|
|
|
return apply_filters( 'get_delete_post_link', '', $post->ID, $context );
|
2009-09-21 17:33:00 -04:00
|
|
|
$file = 'post';
|
|
|
|
$var = 'post';
|
|
|
|
break;
|
|
|
|
endswitch;
|
|
|
|
|
|
|
|
return apply_filters( 'get_delete_post_link', wp_nonce_url( admin_url("$file.php?{$action}$var=$post->ID"), "trash-{$file}_" . $post->ID ), $context );
|
|
|
|
}
|
|
|
|
|
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 ) {
|
|
|
|
$comment = &get_comment( $comment_id );
|
|
|
|
$post = &get_post( $comment->comment_post_ID );
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2008-03-11 17:08:09 -04:00
|
|
|
if ( $post->post_type == 'page' ) {
|
2007-04-24 19:21:56 -04:00
|
|
|
if ( !current_user_can( 'edit_page', $post->ID ) )
|
2006-02-22 14:17:28 -05:00
|
|
|
return;
|
2007-04-28 12:45:47 -04:00
|
|
|
} else {
|
2007-04-24 19:21:56 -04:00
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
2006-02-22 14:17:28 -05:00
|
|
|
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;
|
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
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Display or retrieve edit comment link with formatting.
|
2008-10-13 18:00:07 -04:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
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.
|
|
|
|
* @return string|null HTML content, if $echo is set to false.
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2009-10-01 13:41:09 -04:00
|
|
|
function edit_comment_link( $link = null, $before = '', $after = '' ) {
|
2007-04-26 23:51:36 -04:00
|
|
|
global $comment, $post;
|
|
|
|
|
2009-07-30 11:43:04 -04:00
|
|
|
if ( $post->post_type == 'page' ) {
|
2007-04-26 23:51:36 -04:00
|
|
|
if ( !current_user_can( 'edit_page', $post->ID ) )
|
|
|
|
return;
|
2007-04-28 12:45:47 -04:00
|
|
|
} else {
|
2007-04-26 23:51:36 -04:00
|
|
|
if ( !current_user_can( 'edit_post', $post->ID ) )
|
|
|
|
return;
|
2007-04-28 12:45:47 -04:00
|
|
|
}
|
2007-04-26 23:51:36 -04:00
|
|
|
|
2009-10-01 13:41:09 -04:00
|
|
|
if ( null === $link )
|
|
|
|
$link = __('Edit This');
|
|
|
|
|
2009-01-24 04:35:12 -05:00
|
|
|
$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
|
2008-10-25 14:19:42 -04:00
|
|
|
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $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;
|
|
|
|
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');
|
|
|
|
|
|
|
|
$link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
|
|
|
|
echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
|
|
|
|
}
|
|
|
|
|
2004-06-02 03:44:43 -04:00
|
|
|
// Navigation links
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve previous post link that is adjacent to current post.
|
2008-10-13 18:00:07 -04:00
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @return string
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2004-08-23 21:35:57 -04:00
|
|
|
function get_previous_post($in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 04:25:45 -05:00
|
|
|
return get_adjacent_post($in_same_cat, $excluded_categories);
|
2004-08-23 21:35:57 -04:00
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve next post link that is adjacent to current post.
|
2008-10-13 18:00:07 -04:00
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @return string
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2004-08-23 21:35:57 -04:00
|
|
|
function get_next_post($in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 04:25:45 -05:00
|
|
|
return get_adjacent_post($in_same_cat, $excluded_categories, false);
|
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve adjacent post link.
|
2008-10-13 18:00:07 -04:00
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* Can either be next or previous post link.
|
2008-10-13 18:00:07 -04:00
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @param bool $previous Optional. Whether to retrieve previous post.
|
|
|
|
* @return string
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2007-12-05 04:25:45 -05:00
|
|
|
function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
|
2005-04-18 17:47:35 -04:00
|
|
|
global $post, $wpdb;
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2009-05-08 14:04:13 -04:00
|
|
|
if ( empty($post) || !is_single() || is_attachment() )
|
2005-04-18 17:47:35 -04:00
|
|
|
return null;
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2005-04-18 17:47:35 -04:00
|
|
|
$current_post_date = $post->post_date;
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-04-18 17:47:35 -04:00
|
|
|
$join = '';
|
2008-02-02 13:42:09 -05:00
|
|
|
$posts_in_ex_cats_sql = '';
|
2007-12-05 04:25:45 -05:00
|
|
|
if ( $in_same_cat || !empty($excluded_categories) ) {
|
|
|
|
$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";
|
|
|
|
|
|
|
|
if ( $in_same_cat ) {
|
2009-12-23 10:31:02 -05:00
|
|
|
$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
|
2008-09-15 07:08:47 -04:00
|
|
|
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
|
2005-04-18 17:47:35 -04:00
|
|
|
}
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2007-12-05 04:25:45 -05:00
|
|
|
$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
|
|
|
|
if ( !empty($excluded_categories) ) {
|
|
|
|
$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
|
|
|
|
if ( !empty($cat_array) ) {
|
|
|
|
$excluded_categories = array_diff($excluded_categories, $cat_array);
|
|
|
|
$posts_in_ex_cats_sql = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($excluded_categories) ) {
|
2008-04-14 13:56:58 -04:00
|
|
|
$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
|
2007-12-05 04:25:45 -05:00
|
|
|
}
|
|
|
|
}
|
2005-04-18 17:47:35 -04:00
|
|
|
}
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2007-12-05 04:25:45 -05:00
|
|
|
$adjacent = $previous ? 'previous' : 'next';
|
|
|
|
$op = $previous ? '<' : '>';
|
|
|
|
$order = $previous ? 'DESC' : 'ASC';
|
2007-01-10 23:30:44 -05:00
|
|
|
|
2007-12-05 04:25:45 -05:00
|
|
|
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
|
2009-10-19 12:31:20 -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' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
|
2007-12-05 04:25:45 -05:00
|
|
|
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2009-05-08 14:04:13 -04:00
|
|
|
$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
|
|
|
|
$query_key = 'adjacent_post_' . md5($query);
|
|
|
|
$result = wp_cache_get($query_key, 'counts');
|
|
|
|
if ( false !== $result )
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
$result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
|
2009-05-08 15:47:30 -04:00
|
|
|
if ( null === $result )
|
|
|
|
$result = '';
|
|
|
|
|
2009-05-08 14:04:13 -04:00
|
|
|
wp_cache_set($query_key, $result, 'counts');
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @param bool $previous Optional, default is true. Whether display link to previous post.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
|
2009-12-24 04:30:12 -05:00
|
|
|
if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )
|
2009-03-18 17:56:03 -04:00
|
|
|
$post = & get_post($GLOBALS['post']->post_parent);
|
|
|
|
else
|
|
|
|
$post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
|
|
|
|
|
|
|
|
if ( empty($post) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( empty($post->post_title) )
|
|
|
|
$post->post_title = $previous ? __('Previous Post') : __('Next Post');
|
|
|
|
|
|
|
|
$date = mysql2date(get_option('date_format'), $post->post_date);
|
2009-04-20 14:18:39 -04:00
|
|
|
|
2009-03-18 17:56:03 -04:00
|
|
|
$title = str_replace('%title', $post->post_title, $title);
|
|
|
|
$title = str_replace('%date', $date, $title);
|
|
|
|
$title = apply_filters('the_title', $title, $post);
|
|
|
|
|
|
|
|
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
|
2009-05-05 15:43:53 -04:00
|
|
|
$link .= esc_attr( $title );
|
2009-03-18 17:56:03 -04:00
|
|
|
$link .= "' href='" . get_permalink($post) . "' />\n";
|
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$adjacent = $previous ? 'previous' : 'next';
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
*/
|
|
|
|
function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
|
|
|
|
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
|
|
|
|
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display relational link for the next post adjacent to the current post.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
*/
|
|
|
|
function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
|
|
|
|
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display relational link for the previous post adjacent to the current post.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
*/
|
|
|
|
function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
|
|
|
|
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve boundary post.
|
|
|
|
*
|
|
|
|
* Boundary being either the first or last post by publish date within the contraitns specified
|
|
|
|
* by in same category or excluded categories.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param bool $in_same_cat Optional. Whether returned post should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @param bool $previous Optional. Whether to retrieve first post.
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) {
|
2009-04-22 18:56:52 -04:00
|
|
|
global $post, $wpdb;
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
if ( empty($post) || !is_single() || is_attachment() )
|
|
|
|
return null;
|
2009-03-18 17:56:03 -04:00
|
|
|
|
|
|
|
$cat_array = array();
|
|
|
|
$excluded_categories = array();
|
2009-04-22 18:56:52 -04:00
|
|
|
if ( !empty($in_same_cat) || !empty($excluded_categories) ) {
|
|
|
|
if ( !empty($in_same_cat) ) {
|
2009-12-23 10:31:02 -05:00
|
|
|
$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
|
2009-04-22 18:56:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($excluded_categories) ) {
|
|
|
|
$excluded_categories = array_map('intval', explode(',', $excluded_categories));
|
|
|
|
|
|
|
|
if ( !empty($cat_array) )
|
|
|
|
$excluded_categories = array_diff($excluded_categories, $cat_array);
|
|
|
|
|
|
|
|
$inverse_cats = array();
|
|
|
|
foreach ( $excluded_categories as $excluded_category)
|
|
|
|
$inverse_cats[] = $excluded_category * -1;
|
|
|
|
$excluded_categories = $inverse_cats;
|
|
|
|
}
|
|
|
|
}
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-06-09 17:48:58 -04:00
|
|
|
$categories = implode(',', array_merge($cat_array, $excluded_categories) );
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$order = $start ? 'ASC' : 'DESC';
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-06-06 10:44:38 -04:00
|
|
|
return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) );
|
2009-03-18 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get boundary post relational link.
|
|
|
|
*
|
|
|
|
* Can either be start or end post relational link.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @param bool $start Optional, default is true. Whether display link to first post.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) {
|
2009-04-22 18:56:52 -04:00
|
|
|
$posts = get_boundary_post($in_same_cat,$excluded_categories,$start);
|
2009-12-19 04:21:00 -05:00
|
|
|
// If there is no post stop.
|
|
|
|
if ( empty($posts) )
|
|
|
|
return;
|
2010-01-15 17:11:12 -05:00
|
|
|
|
2009-04-20 14:18:39 -04:00
|
|
|
// Even though we limited get_posts to return only 1 item it still returns an array of objects.
|
|
|
|
$post = $posts[0];
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-12-19 04:21:00 -05:00
|
|
|
if ( empty($post->post_title) )
|
|
|
|
$post->post_title = $start ? __('First Post') : __('Last Post');
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$date = mysql2date(get_option('date_format'), $post->post_date);
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$title = str_replace('%title', $post->post_title, $title);
|
|
|
|
$title = str_replace('%date', $date, $title);
|
|
|
|
$title = apply_filters('the_title', $title, $post);
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$link = $start ? "<link rel='start' title='" : "<link rel='end' title='";
|
2009-05-05 15:43:53 -04:00
|
|
|
$link .= esc_attr($title);
|
2009-04-22 18:56:52 -04:00
|
|
|
$link .= "' href='" . get_permalink($post) . "' />\n";
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$boundary = $start ? 'start' : 'end';
|
|
|
|
return apply_filters( "{$boundary}_post_rel_link", $link );
|
2009-03-18 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display relational link for the first post.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
*/
|
|
|
|
function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
|
|
|
|
echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get site index relational link.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_index_rel_link() {
|
2009-12-30 12:08:23 -05:00
|
|
|
$link = "<link rel='index' title='" . esc_attr( get_bloginfo( 'name', 'display' ) ) . "' href='" . esc_url( user_trailingslashit( get_bloginfo( 'url', 'display' ) ) ) . "' />\n";
|
2009-03-18 17:56:03 -04:00
|
|
|
return apply_filters( "index_rel_link", $link );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display relational link for the site index.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*/
|
|
|
|
function index_rel_link() {
|
2009-04-20 14:18:39 -04:00
|
|
|
echo get_index_rel_link();
|
2009-03-18 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get parent post relational link.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param string $title Optional. Link title format.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_parent_post_rel_link($title = '%title') {
|
|
|
|
if ( ! empty( $GLOBALS['post'] ) && ! empty( $GLOBALS['post']->post_parent ) )
|
|
|
|
$post = & get_post($GLOBALS['post']->post_parent);
|
|
|
|
|
|
|
|
if ( empty($post) )
|
|
|
|
return;
|
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$date = mysql2date(get_option('date_format'), $post->post_date);
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$title = str_replace('%title', $post->post_title, $title);
|
|
|
|
$title = str_replace('%date', $date, $title);
|
|
|
|
$title = apply_filters('the_title', $title, $post);
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
$link = "<link rel='up' title='";
|
2009-05-05 15:43:53 -04:00
|
|
|
$link .= esc_attr( $title );
|
2009-04-22 18:56:52 -04:00
|
|
|
$link .= "' href='" . get_permalink($post) . "' />\n";
|
2009-03-18 17:56:03 -04:00
|
|
|
|
2009-04-22 18:56:52 -04:00
|
|
|
return apply_filters( "parent_post_rel_link", $link );
|
2009-03-18 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display relational link for parent item
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*/
|
|
|
|
function parent_post_rel_link($title = '%title') {
|
|
|
|
echo get_parent_post_rel_link($title);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param string $format Optional. Link anchor format.
|
|
|
|
* @param string $link Optional. Link permalink format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2005-10-17 19:41:28 -04:00
|
|
|
function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 04:25:45 -05:00
|
|
|
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
|
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
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param string $format Optional. Link anchor format.
|
|
|
|
* @param string $link Optional. Link permalink format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2004-08-23 21:35:57 -04:00
|
|
|
function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
|
2007-12-05 04:25:45 -05:00
|
|
|
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
|
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Display 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
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @param string $format Link anchor format.
|
|
|
|
* @param string $link Link permalink format.
|
|
|
|
* @param bool $in_same_cat Optional. Whether link should be in same category.
|
|
|
|
* @param string $excluded_categories Optional. Excluded categories IDs.
|
|
|
|
* @param bool $previous Optional, default is true. Whether display link to previous post.
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2007-12-05 04:25:45 -05:00
|
|
|
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
|
|
|
|
if ( $previous && is_attachment() )
|
|
|
|
$post = & get_post($GLOBALS['post']->post_parent);
|
|
|
|
else
|
|
|
|
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2005-10-17 19:41:28 -04:00
|
|
|
if ( !$post )
|
|
|
|
return;
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2007-09-11 16:05:52 -04:00
|
|
|
$title = $post->post_title;
|
|
|
|
|
|
|
|
if ( empty($post->post_title) )
|
2007-12-05 04:25:45 -05:00
|
|
|
$title = $previous ? __('Previous Post') : __('Next Post');
|
2007-09-11 16:05:52 -04:00
|
|
|
|
|
|
|
$title = apply_filters('the_title', $title, $post);
|
2008-09-15 19:48:24 -04:00
|
|
|
$date = mysql2date(get_option('date_format'), $post->post_date);
|
2009-08-21 13:12:25 -04:00
|
|
|
$rel = $previous ? 'prev' : 'next';
|
2008-12-09 13:03:31 -05:00
|
|
|
|
2009-08-21 13:12:25 -04:00
|
|
|
$string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">';
|
2005-10-17 19:41:28 -04:00
|
|
|
$link = str_replace('%title', $title, $link);
|
2008-09-15 19:48:24 -04:00
|
|
|
$link = str_replace('%date', $date, $link);
|
2005-10-17 19:41:28 -04:00
|
|
|
$link = $string . $link . '</a>';
|
2007-12-05 04:25:45 -05:00
|
|
|
|
2005-10-17 19:41:28 -04:00
|
|
|
$format = str_replace('%link', $link, $format);
|
2004-08-23 21:35:57 -04:00
|
|
|
|
2008-06-16 18:27:07 -04:00
|
|
|
$adjacent = $previous ? 'previous' : 'next';
|
|
|
|
echo apply_filters( "{$adjacent}_post_link", $format, $link );
|
2004-08-23 21:35:57 -04:00
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve get 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.
|
|
|
|
* @return string
|
2008-10-13 18:00:07 -04:00
|
|
|
*/
|
2005-03-27 21:34:16 -05:00
|
|
|
function get_pagenum_link($pagenum = 1) {
|
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'] : '';
|
2007-05-11 20:17:34 -04:00
|
|
|
$home_root = preg_quote( trailingslashit( $home_root ), '|' );
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2007-05-15 22:47:24 -04:00
|
|
|
$request = preg_replace('|^'. $home_root . '|', '', $request);
|
|
|
|
$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
|
|
|
|
2007-12-19 14:27:14 -05:00
|
|
|
$request = preg_replace( '|page/\d+/?$|', '', $request);
|
2007-09-20 16:56:22 -04:00
|
|
|
$request = preg_replace( '|^index\.php|', '', $request);
|
|
|
|
$request = ltrim($request, '/');
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2007-05-15 22:47:24 -04:00
|
|
|
$base = trailingslashit( get_bloginfo( 'url' ) );
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2007-09-22 02:07:03 -04:00
|
|
|
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
|
2007-05-11 20:17:34 -04:00
|
|
|
$base .= 'index.php/';
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2007-05-15 22:47:24 -04:00
|
|
|
if ( $pagenum > 1 ) {
|
|
|
|
$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
|
|
|
|
}
|
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
|
|
|
|
2008-02-25 13:40:46 -05:00
|
|
|
$result = apply_filters('get_pagenum_link', $result);
|
|
|
|
|
2007-05-11 20:17:34 -04:00
|
|
|
return $result;
|
2004-06-02 03:44:43 -04:00
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve next posts pages 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
|
|
|
/**
|
2008-11-12 05:13:50 -05:00
|
|
|
* Display or return the next posts pages 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
|
|
|
/**
|
2008-11-12 05:13:50 -05:00
|
|
|
* Return the next posts pages 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
|
|
|
*/
|
2008-11-12 05:13:50 -05:00
|
|
|
function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
|
2007-12-06 14:49:33 -05:00
|
|
|
global $paged, $wp_query;
|
2008-11-12 05:13:50 -05:00
|
|
|
|
2005-10-17 19:41:28 -04:00
|
|
|
if ( !$max_page ) {
|
2006-11-08 16:22:35 -05:00
|
|
|
$max_page = $wp_query->max_num_pages;
|
2005-10-17 19:41:28 -04:00
|
|
|
}
|
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;
|
2008-11-12 05:13:50 -05:00
|
|
|
|
|
|
|
if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
|
2008-07-30 03:01:03 -04:00
|
|
|
$attr = apply_filters( 'next_posts_link_attributes', '' );
|
2008-11-12 05:13:50 -05:00
|
|
|
return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$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 next posts pages link.
|
|
|
|
*
|
|
|
|
* @since 0.71
|
|
|
|
* @uses get_next_posts_link()
|
|
|
|
*
|
|
|
|
* @param string $label Content for link text.
|
|
|
|
* @param int $max_page Optional. Max pages.
|
|
|
|
*/
|
|
|
|
function next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
|
|
|
|
echo get_next_posts_link( $label, $max_page );
|
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve previous post pages link.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
/**
|
2008-11-12 05:13:50 -05:00
|
|
|
* Display or return the previous posts pages 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
|
|
|
/**
|
2008-11-12 05:13:50 -05:00
|
|
|
* Return the previous posts pages 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
|
|
|
*/
|
2008-11-12 05:13:50 -05:00
|
|
|
function get_previous_posts_link( $label = '« Previous Page' ) {
|
2005-10-17 19:41:28 -04:00
|
|
|
global $paged;
|
2008-11-12 05:13:50 -05:00
|
|
|
|
|
|
|
if ( !is_single() && $paged > 1 ) {
|
2008-07-30 03:01:03 -04:00
|
|
|
$attr = apply_filters( 'previous_posts_link_attributes', '' );
|
2008-11-12 05:13:50 -05:00
|
|
|
return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$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.
|
|
|
|
*/
|
|
|
|
function previous_posts_link( $label = '« Previous Page' ) {
|
|
|
|
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
|
|
|
*
|
2009-04-22 04:44:37 -04:00
|
|
|
* @since 2.8
|
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']);
|
|
|
|
$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']);
|
|
|
|
$return .= get_next_posts_link($args['nxtlabel']);
|
2005-10-17 19:41:28 -04:00
|
|
|
}
|
|
|
|
}
|
2009-04-22 04:44:37 -04:00
|
|
|
return $return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
/**
|
|
|
|
* Retrieve page numbers links.
|
|
|
|
*
|
|
|
|
* @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 ) {
|
2008-12-04 14:11:53 -05:00
|
|
|
global $post, $wp_rewrite;
|
2008-09-23 17:11:27 -04:00
|
|
|
|
|
|
|
$pagenum = (int) $pagenum;
|
|
|
|
|
2008-12-04 14:11:53 -05:00
|
|
|
$result = get_permalink( $post->ID );
|
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';
|
|
|
|
|
2008-09-23 17:11:27 -04:00
|
|
|
$result = apply_filters('get_comments_pagenum_link', $result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2008-10-21 23:08:33 -04:00
|
|
|
/**
|
2008-12-22 14:33:09 -05:00
|
|
|
* Return the link to next comments pages.
|
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
|
|
|
|
2009-05-18 12:00:33 -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};)/', '&$1', $label) .'</a>';
|
2008-09-23 17:11:27 -04:00
|
|
|
}
|
|
|
|
|
2008-10-21 23:08:33 -04:00
|
|
|
/**
|
2008-12-22 14:33:09 -05:00
|
|
|
* Display the link to next comments pages.
|
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');
|
|
|
|
|
2009-05-18 12:00:33 -04:00
|
|
|
return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$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
|
|
|
*
|
|
|
|
* @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()) {
|
2008-10-23 14:55:22 -04:00
|
|
|
global $wp_query, $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
|
|
|
/**
|
2008-10-21 23:08:33 -04:00
|
|
|
* Retrieve shortcut 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() {
|
|
|
|
$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
|
|
|
|
|
|
|
return apply_filters('shortcut_link', $link);
|
|
|
|
}
|
2008-05-27 13:46:01 -04:00
|
|
|
|
2010-01-04 12:23:29 -05:00
|
|
|
/**
|
|
|
|
* Retrieve the home url.
|
|
|
|
*
|
|
|
|
* Returns the 'home' option with the appropriate protocol, 'https' if
|
|
|
|
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
|
|
|
|
* overridden.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 3.0
|
|
|
|
*
|
|
|
|
* @param string $path (optional) Path relative to the home url.
|
|
|
|
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
|
|
|
|
* @return string Home url link with optional path appended.
|
|
|
|
*/
|
|
|
|
function home_url( $path = '', $scheme = null ) {
|
|
|
|
$orig_scheme = $scheme;
|
|
|
|
$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
|
|
|
|
$url = str_replace( 'http://', "$scheme://", get_option('home') );
|
|
|
|
|
|
|
|
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
|
|
|
|
$url .= '/' . ltrim( $path, '/' );
|
|
|
|
|
|
|
|
return apply_filters( 'home_url', $url, $path, $orig_scheme );
|
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* Retrieve the site url.
|
2008-07-14 19:39:11 -04:00
|
|
|
*
|
2008-10-13 18:00:07 -04:00
|
|
|
* Returns the 'site_url' option with the appropriate protocol, 'https' if
|
|
|
|
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
|
|
|
|
* overridden.
|
2008-07-14 19:39:11 -04:00
|
|
|
*
|
2008-10-21 23:08:33 -04:00
|
|
|
* @package WordPress
|
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 site url.
|
|
|
|
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
|
|
|
|
* @return string Site url link with optional path appended.
|
2008-07-14 19:39:11 -04:00
|
|
|
*/
|
2008-05-27 13:46:01 -04:00
|
|
|
function site_url($path = '', $scheme = null) {
|
|
|
|
// should the list of allowed schemes be maintained elsewhere?
|
2008-08-19 15:41:11 -04:00
|
|
|
$orig_scheme = $scheme;
|
2008-06-06 03:39:11 -04:00
|
|
|
if ( !in_array($scheme, array('http', 'https')) ) {
|
2009-07-03 22:48:22 -04:00
|
|
|
if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
|
2008-06-26 12:40:04 -04:00
|
|
|
$scheme = 'https';
|
|
|
|
elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
|
2008-06-11 13:25:55 -04:00
|
|
|
$scheme = 'https';
|
|
|
|
elseif ( ('admin' == $scheme) && force_ssl_admin() )
|
2008-06-06 03:39:11 -04:00
|
|
|
$scheme = 'https';
|
|
|
|
else
|
|
|
|
$scheme = ( is_ssl() ? 'https' : 'http' );
|
|
|
|
}
|
2008-05-27 13:46:01 -04:00
|
|
|
|
|
|
|
$url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= '/' . ltrim($path, '/');
|
|
|
|
|
2008-08-19 15:41:11 -04:00
|
|
|
return apply_filters('site_url', $url, $path, $orig_scheme);
|
2008-05-27 13:46:01 -04:00
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* Retrieve the url to the admin area.
|
2008-07-14 19:39:11 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2008-10-13 18:00:07 -04:00
|
|
|
* @since 2.6.0
|
2008-07-14 19:39:11 -04:00
|
|
|
*
|
|
|
|
* @param string $path Optional path relative to the admin url
|
|
|
|
* @return string Admin url link with optional path appended
|
|
|
|
*/
|
2008-05-27 13:46:01 -04:00
|
|
|
function admin_url($path = '') {
|
2008-06-11 13:25:55 -04:00
|
|
|
$url = site_url('wp-admin/', 'admin');
|
2008-05-27 13:46:01 -04:00
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= ltrim($path, '/');
|
|
|
|
|
2009-04-17 03:05:41 -04:00
|
|
|
return apply_filters('admin_url', $url, $path);
|
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
|
|
|
*
|
|
|
|
* @package WordPress
|
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.
|
|
|
|
* @return string Includes url link with optional path appended.
|
2008-07-14 19:39:11 -04:00
|
|
|
*/
|
2008-05-27 13:46:01 -04:00
|
|
|
function includes_url($path = '') {
|
|
|
|
$url = site_url() . '/' . WPINC . '/';
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= ltrim($path, '/');
|
|
|
|
|
2009-04-17 03:05:41 -04:00
|
|
|
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
|
|
|
*
|
|
|
|
* @package WordPress
|
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
|
|
|
*/
|
2008-07-09 13:24:36 -04:00
|
|
|
function content_url($path = '') {
|
|
|
|
$scheme = ( is_ssl() ? 'https' : 'http' );
|
|
|
|
$url = WP_CONTENT_URL;
|
|
|
|
if ( 0 === strpos($url, 'http') ) {
|
|
|
|
if ( is_ssl() )
|
|
|
|
$url = str_replace( 'http://', "{$scheme}://", $url );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= '/' . ltrim($path, '/');
|
|
|
|
|
2009-04-17 03:05:41 -04:00
|
|
|
return apply_filters('content_url', $url, $path);
|
2008-07-09 13:24:36 -04:00
|
|
|
}
|
|
|
|
|
2008-10-13 18:00:07 -04:00
|
|
|
/**
|
2009-02-15 11:50:45 -05:00
|
|
|
* Retrieve the url to the plugins directory or to a specific file within that directory.
|
|
|
|
* You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.
|
2008-07-14 20:10:07 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
2008-10-13 18:00:07 -04:00
|
|
|
* @since 2.6.0
|
2008-07-14 20:10:07 -04:00
|
|
|
*
|
2008-10-13 18:00:07 -04:00
|
|
|
* @param string $path Optional. Path relative to the plugins url.
|
2009-02-15 11:50:45 -05:00
|
|
|
* @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__
|
2008-10-13 18:00:07 -04:00
|
|
|
* @return string Plugins url link with optional path appended.
|
2008-07-14 20:10:07 -04:00
|
|
|
*/
|
2009-02-15 11:50:45 -05:00
|
|
|
function plugins_url($path = '', $plugin = '') {
|
2008-07-14 20:10:07 -04:00
|
|
|
$scheme = ( is_ssl() ? 'https' : 'http' );
|
2009-04-23 04:16:06 -04:00
|
|
|
|
|
|
|
if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) {
|
|
|
|
$url = WPMU_PLUGIN_URL;
|
|
|
|
} else {
|
|
|
|
$url = WP_PLUGIN_URL;
|
|
|
|
}
|
|
|
|
|
2008-07-14 20:10:07 -04:00
|
|
|
if ( 0 === strpos($url, 'http') ) {
|
|
|
|
if ( is_ssl() )
|
|
|
|
$url = str_replace( 'http://', "{$scheme}://", $url );
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
if ('.' != $folder)
|
|
|
|
$url .= '/' . ltrim($folder, '/');
|
|
|
|
}
|
2009-03-17 22:43:45 -04:00
|
|
|
|
2008-07-14 20:10:07 -04:00
|
|
|
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
|
|
|
|
$url .= '/' . ltrim($path, '/');
|
|
|
|
|
2009-04-17 03:05:41 -04:00
|
|
|
return apply_filters('plugins_url', $url, $path, $plugin);
|
2008-07-14 20:10:07 -04:00
|
|
|
}
|
|
|
|
|
2009-08-05 12:43:51 -04:00
|
|
|
/**
|
|
|
|
* Output rel=canonical for singular queries
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @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 );
|
|
|
|
echo "<link rel='canonical' href='$link' />\n";
|
|
|
|
}
|
|
|
|
|
2005-10-20 16:48:32 -04:00
|
|
|
?>
|