Make WordPress Core

Ticket #30287: 30287.diff

File 30287.diff, 1.9 KB (added by bswatson, 7 years ago)

Add private posts for current user to get_adjacent_post

  • src/wp-includes/link-template.php

     
    15171517                }
    15181518        }
    15191519
     1520        if ( is_user_logged_in() ) {
     1521                $user_id = get_current_user_id();
     1522
     1523                $post_type_object = get_post_type_object( $post->post_type );
     1524                if ( empty( $post_type_object ) ) {
     1525                        $post_type_cap    = $post->post_type;
     1526                        $read_private_cap = 'read_private_' . $post_type_cap . 's';
     1527                } else {
     1528                        $read_private_cap = $post_type_object->cap->read_private_posts;
     1529                }
     1530
     1531                // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
     1532                $private_states = get_post_stati( array( 'private' => true ) );
     1533                $where .= " AND ( p.post_status = 'publish'";
     1534                foreach ( (array) $private_states as $state ) {
     1535                        $where .= current_user_can( $read_private_cap ) ? " OR p.post_status = '$state'" : " OR (p.post_author = $user_id AND p.post_status = '$state')";
     1536                }
     1537                $where .= " )";
     1538        } else {
     1539                $where .= " AND p.post_status = 'publish'";
     1540        }
     1541
    15201542        $adjacent = $previous ? 'previous' : 'next';
    15211543        $op = $previous ? '<' : '>';
    15221544        $order = $previous ? 'DESC' : 'ASC';
     
    15471569         * @param bool   $in_same_term   Whether post should be in a same taxonomy term.
    15481570         * @param array  $excluded_terms Array of excluded term IDs.
    15491571         */
    1550         $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 );
     1572        $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms );
    15511573
    15521574        /**
    15531575         * Filter the ORDER BY clause in the SQL for an adjacent post query.