Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r59508 r59508  
    137137
    138138    if ( $post->post_type == 'page' )
    139         return get_page_link($post, $leavename, $sample);
     139        return get_page_link($post->ID, $leavename, $sample);
    140140    elseif ( $post->post_type == 'attachment' )
    141         return get_attachment_link( $post, $leavename );
     141        return get_attachment_link( $post->ID, $leavename );
    142142    elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
    143         return get_post_permalink($post, $leavename, $sample);
     143        return get_post_permalink($post->ID, $leavename, $sample);
    144144
    145145    $permalink = get_option('permalink_structure');
     
    291291 * @since 1.0.0
    292292 *
    293  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     293 * @param int $post_id Optional. Post ID.
    294294 * @param mixed $deprecated Not used.
    295295 * @return string
     
    11971197 * @since 1.0.0
    11981198 *
    1199  * @param string $text Optional. Anchor text.
     1199 * @param string $link 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( $text = null, $before = '', $after = '', $id = 0 ) {
    1205     if ( ! $post = get_post( $id ) ) {
     1204function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
     1205    if ( !$post = get_post( $id ) )
    12061206        return;
    1207     }
    1208 
    1209     if ( ! $url = get_edit_post_link( $post->ID ) ) {
     1207
     1208    if ( !$url = get_edit_post_link( $post->ID ) )
    12101209        return;
    1211     }
    1212 
    1213     if ( null === $text ) {
    1214         $text = __( 'Edit This' );
    1215     }
    1216 
    1217     $link = '<a class="post-edit-link" href="' . $url . '">' . $text . '</a>';
     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>';
    12181216
    12191217    /**
     
    12241222     * @param string $link    Anchor tag for the edit link.
    12251223     * @param int    $post_id Post ID.
    1226      * @param string $text    Anchor text.
    1227      */
    1228     echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after;
     1224     */
     1225    echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
    12291226}
    12301227
     
    13021299 * @since 1.0.0
    13031300 *
    1304  * @param string $text Optional. Anchor text.
     1301 * @param string $link Optional. Anchor text.
    13051302 * @param string $before Optional. Display before edit link.
    13061303 * @param string $after Optional. Display after edit link.
    13071304 */
    1308 function edit_comment_link( $text = null, $before = '', $after = '' ) {
     1305function edit_comment_link( $link = null, $before = '', $after = '' ) {
    13091306    global $comment;
    13101307
    1311     if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
     1308    if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
    13121309        return;
    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>';
     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>';
    13201315
    13211316    /**
     
    13261321     * @param string $link       Anchor tag for the edit link.
    13271322     * @param int    $comment_id Comment ID.
    1328      * @param string $text       Anchor text.
    1329      */
    1330     echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after;
     1323     */
     1324    echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
    13311325}
    13321326
     
    14781472
    14791473    $join = '';
    1480     $where = '';
    1481 
     1474    $posts_in_ex_terms_sql = '';
    14821475    if ( $in_same_term || ! empty( $excluded_terms ) ) {
    14831476        $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         }
    14971477
    14981478        if ( $in_same_term ) {
     
    15001480                return '';
    15011481            $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 
    15071482            if ( ! $term_array || is_wp_error( $term_array ) )
    15081483                return '';
    1509 
    1510             $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
     1484            $join .= $wpdb->prepare( " AND tt.taxonomy = %s AND tt.term_id IN (" . implode( ',', array_map( 'intval', $term_array ) ) . ")", $taxonomy );
    15111485        }
    15121486
     1487        $posts_in_ex_terms_sql = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
    15131488        if ( ! empty( $excluded_terms ) ) {
    1514             $where .= " AND p.ID NOT IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode( $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            }
    15151509        }
    15161510    }
     
    15461540     * @param array  $excluded_terms Array of excluded term IDs.
    15471541     */
    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 );
     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 );
    15491543
    15501544    /**
     
    16561650 */
    16571651function adjacent_posts_rel_link_wp_head() {
    1658     if ( ! is_single() || is_attachment() ) {
     1652    if ( !is_singular() || is_attachment() )
    16591653        return;
    1660     }
    16611654    adjacent_posts_rel_link();
    16621655}
     
    17601753 * @return string
    17611754 */
    1762 function 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 );
     1755function 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 );
    17641757}
    17651758
     
    17761769 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
    17771770 */
    1778 function 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 );
     1771function 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 );
    17801773}
    17811774
     
    17921785 * @return string
    17931786 */
    1794 function 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 );
     1787function 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 );
    17961789}
    17971790
     
    18081801 * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
    18091802 */
    1810 function 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 );
     1803function 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 );
    18121805}
    18131806
     
    18271820 * @return string
    18281821 */
    1829 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
     1822function get_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
    18301823    if ( $previous && is_attachment() )
    18311824        $post = get_post( get_post()->post_parent );
    18321825    else
    1833         $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
     1826        $post = get_adjacent_post( $in_same_cat, $excluded_terms, $previous, $taxonomy );
    18341827
    18351828    if ( ! $post ) {
     
    18831876 * @param string       $format         Link anchor format.
    18841877 * @param string       $link           Link permalink format.
    1885  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term.
     1878 * @param bool         $in_same_cat    Optional. Whether link should be in a same category.
    18861879 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs.
    18871880 * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
     
    18891882 * @return string
    18901883 */
    1891 function 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 );
     1884function 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 );
    18931886}
    18941887
     
    26272620
    26282621/**
    2629  * Retrieve a URL within the plugins or mu-plugins directory.
    2630  *
    2631  * Defaults to the plugins directory URL if no arguments are supplied.
     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.
    26322624 *
    26332625 * @since 2.6.0
    26342626 *
    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.
     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.
    26412630*/
    2642 function 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 );
     2631function 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    }
    26472638
    26482639    if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
     
    28492840function set_url_scheme( $url, $scheme = null ) {
    28502841    $orig_scheme = $scheme;
    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';
     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' );
    28582851    }
    28592852
Note: See TracChangeset for help on using the changeset viewer.