]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/link-template.php
Wordpress 3.7
[autoinstalls/wordpress.git] / wp-includes / link-template.php
index 1029d9df53a275b9076669841165e1b2c03aef08..38a0ab6e2d08581a1fb0d9ca604378e0a4ed1f80 100644 (file)
@@ -73,9 +73,9 @@ function permalink_anchor( $mode = 'id' ) {
  *
  * @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(
@@ -131,7 +131,7 @@ function get_permalink( $id = 0, $leavename = false ) {
                        // 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;
                        }
                }
@@ -662,11 +662,11 @@ function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) {
  * @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;
 }
 
@@ -709,22 +709,24 @@ function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) {
  * @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 )
@@ -935,7 +937,7 @@ function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
                $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;
 }
 
@@ -1009,7 +1011,7 @@ function edit_comment_link( $link = null, $before = '', $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;
 }
 
@@ -1050,7 +1052,7 @@ function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark =
        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;
 }
 
@@ -1335,18 +1337,50 @@ function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $st
        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 = '&laquo; %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='&laquo; %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 = '&laquo; %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 = '&laquo; %link', $link = '%title', $in_same_cat = false, $excluded_categories = '' ) {
+       return get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_categories, false );
 }
 
 /**
@@ -1359,24 +1393,25 @@ function previous_post_link($format='&laquo; %link', $link='%title', $in_same_ca
  * @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 &raquo;', $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 &raquo;', $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
@@ -1390,6 +1425,7 @@ function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_cat
                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';
@@ -1404,7 +1440,26 @@ function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_cat
 
        $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 );
 }
 
 /**
@@ -1913,7 +1968,7 @@ function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
        }
 
        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 );
@@ -2358,20 +2413,22 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
 
        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);