WordPress.org

Make WordPress Core

Ticket #17807: 17807.3.patch

File 17807.3.patch, 12.7 KB (added by billerickson, 3 years ago)
  • wp-includes/link-template.php

     
    10661066 * 
    10671067 * @param bool $in_same_cat Optional. Whether post should be in same category. 
    10681068 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1069 * @param string $taxonomy Optional. Which taxonomy to use. 
    10691070 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 
    10701071 */ 
    1071 function get_previous_post($in_same_cat = false, $excluded_categories = '') { 
    1072         return get_adjacent_post($in_same_cat, $excluded_categories); 
     1072function get_previous_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1073        return get_adjacent_post($in_same_cat, $excluded_categories, true, $taxonomy); 
    10731074} 
    10741075 
    10751076/** 
     
    10791080 * 
    10801081 * @param bool $in_same_cat Optional. Whether post should be in same category. 
    10811082 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1083 * @param string $taxonomy Optional. Which taxonomy to use. 
    10821084 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 
    10831085 */ 
    1084 function get_next_post($in_same_cat = false, $excluded_categories = '') { 
    1085         return get_adjacent_post($in_same_cat, $excluded_categories, false); 
     1086function get_next_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1087        return get_adjacent_post($in_same_cat, $excluded_categories, false, $taxonomy); 
    10861088} 
    10871089 
    10881090/** 
     
    10951097 * @param bool $in_same_cat Optional. Whether post should be in same category. 
    10961098 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
    10971099 * @param bool $previous Optional. Whether to retrieve previous post. 
     1100 * @param string $taxonomy Optional. Which taxonomy to use. 
    10981101 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 
    10991102 */ 
    1100 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) { 
     1103function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category' ) { 
    11011104        global $post, $wpdb; 
    11021105 
    11031106        if ( empty( $post ) ) 
     
    11111114                $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"; 
    11121115 
    11131116                if ( $in_same_cat ) { 
    1114                         $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); 
    1115                         $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; 
     1117                        $cat_array = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 
     1118                        $join .= " AND tt.taxonomy = '$taxonomy' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; 
    11161119                } 
    11171120 
    1118                 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; 
     1121                $posts_in_ex_cats_sql = "AND tt.taxonomy = '$taxonomy'"; 
    11191122                if ( ! empty( $excluded_categories ) ) { 
    11201123                        if ( ! is_array( $excluded_categories ) ) { 
    11211124                                // back-compat, $excluded_categories used to be IDs separated by " and " 
     
    11351138                        } 
    11361139 
    11371140                        if ( !empty($excluded_categories) ) { 
    1138                                 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; 
     1141                                $posts_in_ex_cats_sql = " AND tt.taxonomy = '$taxonomy' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; 
    11391142                        } 
    11401143                } 
    11411144        } 
     
    11731176 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    11741177 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
    11751178 * @param bool $previous Optional, default is true. Whether display link to previous post. 
     1179 * @param string $taxonomy Optional. Which taxonomy to use. 
    11761180 * @return string 
    11771181 */ 
    1178 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { 
     1182function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 
    11791183        if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) 
    11801184                $post = & get_post($GLOBALS['post']->post_parent); 
    11811185        else 
    1182                 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); 
     1186                $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous, $taxonomy ); 
    11831187 
    11841188        if ( empty($post) ) 
    11851189                return; 
     
    12091213 * @param string $title Optional. Link title format. 
    12101214 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    12111215 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1216 * @param string $taxonomy Optional. Which taxonomy to use. 
    12121217 */ 
    1213 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { 
    1214         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); 
    1215         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); 
     1218function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1219        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy); 
     1220        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy); 
    12161221} 
    12171222 
    12181223/** 
     
    12361241 * @param string $title Optional. Link title format. 
    12371242 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    12381243 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1244 * @param string $taxonomy Optional. Which taxonomy to use. 
    12391245 */ 
    1240 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { 
    1241         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); 
     1246function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1247        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy); 
    12421248} 
    12431249 
    12441250/** 
     
    12491255 * @param string $title Optional. Link title format. 
    12501256 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    12511257 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1258 * @param string $taxonomy Optional. Which taxonomy to use. 
    12521259 */ 
    1253 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { 
    1254         echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); 
     1260function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1261        echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy); 
    12551262} 
    12561263 
    12571264/** 
     
    12651272 * @param bool $in_same_cat Optional. Whether returned post should be in same category. 
    12661273 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
    12671274 * @param bool $start Optional. Whether to retrieve first or last post. 
     1275 * @param string $taxonomy Optional. Which taxonomy to use. 
    12681276 * @return object 
    12691277 */ 
    1270 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) { 
     1278function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true, $taxonomy = 'category' ) { 
    12711279        global $post; 
    12721280 
    12731281        if ( empty($post) || ! is_single() || is_attachment() ) 
     
    12791287                 
    12801288        if ( $in_same_cat || ! empty( $excluded_categories ) ) { 
    12811289                if ( $in_same_cat ) 
    1282                         $cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) ); 
     1290                        $cat_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); 
    12831291 
    12841292                if ( ! empty( $excluded_categories ) ) { 
    12851293                        $excluded_categories = array_map( 'intval', $excluded_categories ); 
     
    12951303        $categories = implode( ',', array_merge( $cat_array, $excluded_categories ) ); 
    12961304 
    12971305        $order = $start ? 'ASC' : 'DESC'; 
     1306         
     1307        $args = array( 
     1308                'posts_per_page' => '1', 
     1309                'order' => $order, 
     1310                'update_post_term_cache' => false, 
     1311                'update_post_meta_cache' => false, 
     1312                'tax_query' => array( 
     1313                        array( 
     1314                                'taxonomy' => $taxonomy, 
     1315                                'field' => 'id', 
     1316                                'terms' => $categories 
     1317                        ) 
     1318                ) 
     1319                 
     1320        ); 
    12981321 
    1299         return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) ); 
     1322        return get_posts( $args ); 
    13001323} 
    13011324 
    13021325/** 
     
    13101333 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    13111334 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
    13121335 * @param bool $start Optional, default is true. Whether display link to first or last post. 
     1336 * @param string $taxonomy Optional. Which taxonomy to use. 
    13131337 * @return string 
    13141338 */ 
    1315 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { 
    1316         $posts = get_boundary_post($in_same_cat, $excluded_categories, $start); 
     1339function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true, $taxonomy = 'category') { 
     1340        $posts = get_boundary_post($in_same_cat, $excluded_categories, $start, $taxonomy); 
    13171341        // If there is no post stop. 
    13181342        if ( empty($posts) ) 
    13191343                return; 
     
    13461370 * @param string $title Optional. Link title format. 
    13471371 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    13481372 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1373 * @param string $taxonomy Optional. Which taxonomy to use. 
    13491374 */ 
    1350 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { 
    1351         echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true); 
     1375function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1376        echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true, $taxonomy); 
    13521377} 
    13531378 
    13541379/** 
     
    14181443 * @param string $link Optional. Link permalink format. 
    14191444 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    14201445 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1446 * @param string $taxonomy Optional. Which taxonomy to use. 
    14211447 */ 
    1422 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { 
    1423         adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); 
     1448function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1449        adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true, $taxonomy); 
    14241450} 
    14251451 
    14261452/** 
     
    14321458 * @param string $link Optional. Link permalink format. 
    14331459 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    14341460 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
     1461 * @param string $taxonomy Optional. Which taxonomy to use. 
    14351462 */ 
    1436 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { 
    1437         adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); 
     1463function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 
     1464        adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false, $taxonomy); 
    14381465} 
    14391466 
    14401467/** 
     
    14491476 * @param bool $in_same_cat Optional. Whether link should be in same category. 
    14501477 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 
    14511478 * @param bool $previous Optional, default is true. Whether display link to previous post. 
     1479 * @param string $taxonomy Optional. Which taxonomy to use. 
    14521480 */ 
    1453 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { 
     1481function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 
    14541482        if ( $previous && is_attachment() ) 
    14551483                $post = & get_post($GLOBALS['post']->post_parent); 
    14561484        else 
    1457                 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); 
     1485                $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy); 
    14581486 
    14591487        if ( !$post ) 
    14601488                return; 
     
    24852513        } 
    24862514} 
    24872515 
    2488 ?> 
     2516?> 
     2517 No newline at end of file