*
* @since 1.0.0
*
- * @param int $id Optional. Post ID.
- * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
- * @return string
+ * @param int|WP_Post $id Optional. Post ID or post object, defaults to the current post.
+ * @param bool $leavename Optional. Whether to keep post name or page name, defaults to false.
+ * @return string|bool The permalink URL or false if post does not exist.
*/
function get_permalink( $id = 0, $leavename = false ) {
$rewritecode = array(
// show default category in permalinks, without
// having to assign it explicitly
if ( empty($category) ) {
- $default_category = get_category( get_option( 'default_category' ) );
+ $default_category = get_term( get_option( 'default_category' ), 'category' );
$category = is_wp_error( $default_category ) ? '' : $default_category->slug;
}
}
* @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
+ * @param object $tag Tag object.
* @return string HTML content.
*/
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
- $link = edit_term_link( $link, '', '', false, $tag );
+ $link = edit_term_link( $link, '', '', $tag, false );
echo $before . apply_filters( 'edit_tag_link', $link ) . $after;
}
* @param string $link Optional. Anchor text.
* @param string $before Optional. Display before edit link.
* @param string $after Optional. Display after edit link.
- * @param object $term Term object
+ * @param object $term Term object.
* @return string HTML content.
*/
function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
- if ( is_null( $term ) ) {
+ if ( is_null( $term ) )
$term = get_queried_object();
- }
+
+ if ( ! $term )
+ return;
$tax = get_taxonomy( $term->taxonomy );
- if ( !current_user_can($tax->cap->edit_terms) )
+ if ( ! current_user_can( $tax->cap->edit_terms ) )
return;
if ( empty( $link ) )
$link = __('Edit This');
- $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>';
+ $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';
$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
if ( $echo )
$link = __('Edit This');
$post_type_obj = get_post_type_object( $post->post_type );
- $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>';
+ $link = '<a class="post-edit-link" href="' . $url . '">' . $link . '</a>';
echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
}
if ( null === $link )
$link = __('Edit This');
- $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . esc_attr__( 'Edit comment' ) . '">' . $link . '</a>';
+ $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '">' . $link . '</a>';
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
}
if ( empty($link) )
$link = __('Edit This');
- $link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>';
+ $link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '">' . $link . '</a>';
echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
}
return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) );
}
+/*
+ * Get previous post link that is adjacent to the current post.
+ *
+ * @since 3.7.0
+ *
+ * @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.
+ * @return string
+ */
+function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_cat = false, $excluded_categories = '' ) {
+ return get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_categories, true );
+}
+
/**
* Display previous post link that is adjacent to the current post.
*
* @since 1.5.0
+ * @uses get_previous_post_link()
*
* @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 a same category.
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
*/
-function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
- adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
+function previous_post_link( $format = '« %link', $link = '%title', $in_same_cat = false, $excluded_categories = '' ) {
+ echo get_previous_post_link( $format, $link, $in_same_cat, $excluded_categories );
+}
+
+/**
+ * Get previous post link that is adjacent to the current post.
+ *
+ * @since 3.7.0
+ * @uses get_next_post_link()
+ *
+ * @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.
+ * @return string
+ */
+function get_next_post_link( $format = '« %link', $link = '%title', $in_same_cat = false, $excluded_categories = '' ) {
+ return get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_categories, false );
}
/**
* @param bool $in_same_cat Optional. Whether link should be in a same category.
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
*/
-function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
- adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
+function next_post_link( $format = '%link »', $link = '%title', $in_same_cat = false, $excluded_categories = '' ) {
+ echo get_next_post_link( $format, $link, $in_same_cat, $excluded_categories );
}
/**
- * Display adjacent post link.
+ * Get adjacent post link.
*
* Can be either next post link or previous.
*
- * @since 2.5.0
+ * @since 3.7.0
*
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param bool $in_same_cat Optional. Whether link should be in a same category.
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
* @param bool $previous Optional, default is true. Whether to display link to previous or next post.
+ * @return string
*/
-function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
+function get_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
if ( $previous && is_attachment() )
$post = get_post( get_post()->post_parent );
else
if ( empty( $post->post_title ) )
$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
+ /** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( 'the_title', $title, $post->ID );
$date = mysql2date( get_option( 'date_format' ), $post->post_date );
$rel = $previous ? 'prev' : 'next';
$adjacent = $previous ? 'previous' : 'next';
- echo apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );
+ 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()
+ *
+ * @param string $format Link anchor format.
+ * @param string $link Link permalink format.
+ * @param bool $in_same_cat Optional. Whether link should be in a same category.
+ * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
+ * @return string
+ */
+function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
+ echo get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_categories, $previous );
}
/**
}
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
- if ( is_ssl() && ! is_admin() )
+ if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] )
$scheme = 'https';
else
$scheme = parse_url( $url, PHP_URL_SCHEME );
global $wp_query;
$post_id = 0;
- if ( 'query' == $context && is_single() ) {
+ if ( 'query' == $context && is_singular() ) {
$post_id = $wp_query->get_queried_object_id();
+ $post = get_post( $post_id );
} elseif ( 'post' == $context ) {
- $post = get_post($id);
- $post_id = $post->ID;
+ $post = get_post( $id );
+ if ( ! empty( $post->ID ) )
+ $post_id = $post->ID;
}
$shortlink = '';
- // Return p= link for posts.
- if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
- $post = get_post($post_id);
- if ( isset($post->post_type) && 'post' == $post->post_type )
- $shortlink = home_url('?p=' . $post->ID);
+ // Return p= link for all public post types.
+ if ( ! empty( $post_id ) ) {
+ $post_type = get_post_type_object( $post->post_type );
+ if ( $post_type->public )
+ $shortlink = home_url('?p=' . $post_id);
}
return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs);