Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/4.0/src/wp-includes/link-template.php

    r59508 r59508  
    137137
    138138    if ( $post->post_type == 'page' )
    139         return get_page_link($post->ID, $leavename, $sample);
     139        return get_page_link($post, $leavename, $sample);
    140140    elseif ( $post->post_type == 'attachment' )
    141         return get_attachment_link( $post->ID, $leavename );
     141        return get_attachment_link( $post, $leavename );
    142142    elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
    143         return get_post_permalink($post->ID, $leavename, $sample);
     143        return get_post_permalink($post, $leavename, $sample);
    144144
    145145    $permalink = get_option('permalink_structure');
     
    291291 * @since 1.0.0
    292292 *
    293  * @param int $post_id Optional. Post ID.
     293 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
    294294 * @param mixed $deprecated Not used.
    295295 * @return string
     
    11971197 * @since 1.0.0
    11981198 *
    1199  * @param string $link Optional. Anchor text.
     1199 * @param string $text Optional. Anchor text.
    12001200 * @param string $before Optional. Display before edit link.
    12011201 * @param string $after Optional. Display after edit link.
    12021202 * @param int $id Optional. Post ID.
    12031203 */
    1204 function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
    1205     if ( !$post = get_post( $id ) )
     1204function edit_post_link( $text = null, $before = '', $after = '', $id = 0 ) {
     1205    if ( ! $post = get_post( $id ) ) {
    12061206        return;
    1207 
    1208     if ( !$url = get_edit_post_link( $post->ID ) )
     1207    }
     1208
     1209    if ( ! $url = get_edit_post_link( $post->ID ) ) {
    12091210        return;
    1210 
    1211     if ( null === $link )
    1212         $link = __('Edit This');
    1213 
    1214     $post_type_obj = get_post_type_object( $post->post_type );
    1215     $link = '<a class="post-edit-link" href="' . $url . '">' . $link . '</a>';
     1211    }
     1212
     1213    if ( null === $text ) {
     1214        $text = __( 'Edit This' );
     1215    }
     1216
     1217    $link = '<a class="post-edit-link" href="' . $url . '">' . $text . '</a>';
    12161218
    12171219    /**
     
    12221224     * @param string $link    Anchor tag for the edit link.
    12231225     * @param int    $post_id Post ID.
    1224      */
    1225     echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
     1226     * @param string $text    Anchor text.
     1227     */
     1228    echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;
    12261229}
    12271230
     
    12991302 * @since 1.0.0
    13001303 *
    1301  * @param string $link Optional. Anchor text.
     1304 * @param string $text Optional. Anchor text.
    13021305 * @param string $before Optional. Display before edit link.
    13031306 * @param string $after Optional. Display after edit link.
    13041307 */
    1305 function edit_comment_link( $link = null, $before = '', $after = '' ) {
     1308function edit_comment_link( $text = null, $before = '', $after = '' ) {
    13061309    global $comment;
    13071310
    1308     if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
     1311    if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
    13091312        return;
    1310 
    1311     if ( null === $link )
    1312         $link = __('Edit This');
    1313 
    1314     $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '">' . $link . '</a>';
     1313    }
     1314
     1315    if ( null === $text ) {
     1316        $text = __( 'Edit This' );
     1317    }
     1318
     1319    $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '">' . $text . '</a>';
    13151320
    13161321    /**
     
    13211326     * @param string $link       Anchor tag for the edit link.
    13221327     * @param int    $comment_id Comment ID.
    1323      */
    1324     echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
     1328     * @param string $text       Anchor text.
     1329     */
     1330    echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after;
    13251331}
    13261332
     
    14721478
    14731479    $join = '';
    1474     $posts_in_ex_terms_sql = '';
     1480    $where = '';
     1481
    14751482    if ( $in_same_term || ! empty( $excluded_terms ) ) {
    14761483        $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";
     1484        $where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
     1485
     1486        if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
     1487            // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
     1488            if ( false !== strpos( $excluded_terms, ' and ' ) ) {
     1489                _deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
     1490                $excluded_terms = explode( ' and ', $excluded_terms );
     1491            } else {
     1492                $excluded_terms = explode( ',', $excluded_terms );
     1493            }
     1494
     1495            $excluded_terms = array_map( 'intval', $excluded_terms );
     1496        }
    14771497
    14781498        if ( $in_same_term ) {
     
    14801500                return '';
    14811501            $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
     1502
     1503            // Remove any exclusions from the term array to include.
     1504            $term_array = array_diff( $term_array, (array) $excluded_terms );
     1505            $term_array = array_map( 'intval', $term_array );
     1506
    14821507            if ( ! $term_array || is_wp_error( $term_array ) )
    14831508                return '';
    1484             $join .= $wpdb->prepare( " AND tt.taxonomy = %s AND tt.term_id IN (" . implode( ',', array_map( 'intval', $term_array ) ) . ")", $taxonomy );
     1509
     1510            $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
    14851511        }
    14861512
    1487         $posts_in_ex_terms_sql = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
    14881513        if ( ! empty( $excluded_terms ) ) {
    1489             if ( ! is_array( $excluded_terms ) ) {
    1490                 // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
    1491                 if ( false !== strpos( $excluded_terms, ' and ' ) ) {
    1492                     _deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
    1493                     $excluded_terms = explode( ' and ', $excluded_terms );
    1494                 } else {
    1495                     $excluded_terms = explode( ',', $excluded_terms );
    1496                 }
    1497             }
    1498 
    1499             $excluded_terms = array_map( 'intval', $excluded_terms );
    1500 
    1501             if ( ! empty( $term_array ) ) {
    1502                 $excluded_terms = array_diff( $excluded_terms, $term_array );
    1503                 $posts_in_ex_terms_sql = '';
    1504             }
    1505 
    1506             if ( ! empty( $excluded_terms ) ) {
    1507                 $posts_in_ex_terms_sql = $wpdb->prepare( " AND tt.taxonomy = %s AND tt.term_id NOT IN (" . implode( $excluded_terms, ',' ) . ')', $taxonomy );
    1508             }
     1514            $where .= " AND p.ID NOT IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode( $excluded_terms, ',' ) . ') )';
    15091515        }
    15101516    }
     
    15401546     * @param array  $excluded_terms Array of excluded term IDs.
    15411547     */
    1542     $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_terms_sql", $current_post_date, $post->post_type), $in_same_term, $excluded_terms );
     1548    $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms );
    15431549
    15441550    /**
     
    16501656 */
    16511657function adjacent_posts_rel_link_wp_head() {
    1652     if ( !is_singular() || is_attachment() )
     1658    if ( ! is_single() || is_attachment() ) {
    16531659        return;
     1660    }
    16541661    adjacent_posts_rel_link();
    16551662}
     
    17531760 * @return string
    17541761 */
    1755 function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_cat = false, $excluded_terms = '', $taxonomy = 'category' ) {
    1756     return get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_terms, true, $taxonomy );
     1762function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
     1763    return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
    17571764}
    17581765
     
    17691776 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
    17701777 */
    1771 function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_cat = false, $excluded_terms = '', $taxonomy = 'category' ) {
    1772     echo get_previous_post_link( $format, $link, $in_same_cat, $excluded_terms, $taxonomy );
     1778function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
     1779    echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
    17731780}
    17741781
     
    17851792 * @return string
    17861793 */
    1787 function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_cat = false, $excluded_terms = '', $taxonomy = 'category' ) {
    1788     return get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_terms, false, $taxonomy );
     1794function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
     1795    return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
    17891796}
    17901797
     
    18011808 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
    18021809 */
    1803 function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_cat = false, $excluded_terms = '', $taxonomy = 'category' ) {
    1804      echo get_next_post_link( $format, $link, $in_same_cat, $excluded_terms, $taxonomy );
     1810function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
     1811     echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
    18051812}
    18061813
     
    18201827 * @return string
    18211828 */
    1822 function get_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
     1829function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
    18231830    if ( $previous && is_attachment() )
    18241831        $post = get_post( get_post()->post_parent );
    18251832    else
    1826         $post = get_adjacent_post( $in_same_cat, $excluded_terms, $previous, $taxonomy );
     1833        $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
    18271834
    18281835    if ( ! $post ) {
     
    18761883 * @param string       $format         Link anchor format.
    18771884 * @param string       $link           Link permalink format.
    1878  * @param bool         $in_same_cat    Optional. Whether link should be in a same category.
     1885 * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
    18791886 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs.
    18801887 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
     
    18821889 * @return string
    18831890 */
    1884 function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
    1885     echo get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_terms, $previous, $taxonomy );
     1891function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
     1892    echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
    18861893}
    18871894
     
    26202627
    26212628/**
    2622  * Retrieve the url to the plugins directory or to a specific file within that directory.
    2623  * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.
     2629 * Retrieve a URL within the plugins or mu-plugins directory.
     2630 *
     2631 * Defaults to the plugins directory URL if no arguments are supplied.
    26242632 *
    26252633 * @since 2.6.0
    26262634 *
    2627  * @param string $path Optional. Path relative to the plugins url.
    2628  * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__
    2629  * @return string Plugins url link with optional path appended.
     2635 * @param  string $path   Optional. Extra path appended to the end of the URL, including
     2636 *                        the relative directory if $plugin is supplied. Default empty.
     2637 * @param  string $plugin Optional. A full path to a file inside a plugin or mu-plugin.
     2638 *                        The URL will be relative to its directory. Default empty.
     2639 *                        Typically this is done by passing `__FILE__` as the argument.
     2640 * @return string Plugins URL link with optional paths appended.
    26302641*/
    2631 function plugins_url($path = '', $plugin = '') {
    2632 
    2633     $mu_plugin_dir = WPMU_PLUGIN_DIR;
    2634     foreach ( array('path', 'plugin', 'mu_plugin_dir') as $var ) {
    2635         $$var = str_replace('\\' ,'/', $$var); // sanitize for Win32 installs
    2636         $$var = preg_replace('|/+|', '/', $$var);
    2637     }
     2642function plugins_url( $path = '', $plugin = '' ) {
     2643
     2644    $path = wp_normalize_path( $path );
     2645    $plugin = wp_normalize_path( $plugin );
     2646    $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
    26382647
    26392648    if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
     
    28402849function set_url_scheme( $url, $scheme = null ) {
    28412850    $orig_scheme = $scheme;
    2842     if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
    2843         if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
    2844             $scheme = 'https';
    2845         elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
    2846             $scheme = 'https';
    2847         elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
    2848             $scheme = 'https';
    2849         else
    2850             $scheme = ( is_ssl() ? 'https' : 'http' );
     2851
     2852    if ( ! $scheme ) {
     2853        $scheme = is_ssl() ? 'https' : 'http';
     2854    } elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) {
     2855        $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
     2856    } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
     2857        $scheme = is_ssl() ? 'https' : 'http';
    28512858    }
    28522859
Note: See TracChangeset for help on using the changeset viewer.