Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#30287 closed enhancement (fixed)

Private posts skipped in single post navigation

Reported by: blogan Owned by: boonebgorges
Priority: normal Milestone: 4.2
Component: Posts, Post Types Version: 1.5
Severity: normal Keywords: good-first-bug has-patch
Cc: Focuses:

Description

A private post that appears on my main page when logged in does not appear in the next/previous navigation of a single post.

Attachments (2)

30287.diff (1.9 KB ) - added by bswatson 12 years ago.
Add private posts for current user to get_adjacent_post
30287-unit-tests.diff (3.5 KB ) - added by bswatson 12 years ago.
Unit Tests for get_adjacent_post

Download all attachments as: .zip

Change History (8)

#1 @valendesigns
12 years ago

The issue is with the query in the get_adjacent_post() functions that only allows for published posts.

WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish'

Changing it to the following could solve this, but I don't know if it's as straight forward as that because there's no logged in check and I'm fairly certain we don't want to run this altered query for every user.

WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = IN ('publish', 'private')

#2 @boonebgorges
12 years ago

  • Component GeneralPosts, Post Types
  • Keywords needs-patch needs-unit-tests good-first-bug added
  • Milestone Awaiting ReviewFuture Release
  • Type defect (bug)enhancement
  • Version trunk1.5

The issue is with the query in the get_adjacent_post() functions that only allows for published posts.

Correct. The post_status = 'publish' clause has been hardcoded since at least 1.5. See [1557].

I don't know if it's as straight forward as that because there's no logged in check and I'm fairly certain we don't want to run this altered query for every user.

It definitely is not this straightforward, for these very reasons :) The purpose of the 'private' post status is to hide a post from all members but the author of the post. WP_Query accounts for this, but get_adjacent_post() does not use WP_Query (see #26937). I suppose mirroring the logic here too would be fine, but I'd like to see a patch + unit tests.

@bswatson
12 years ago

Add private posts for current user to get_adjacent_post

@bswatson
12 years ago

Unit Tests for get_adjacent_post

#3 @bswatson
12 years ago

  • Keywords has-patch added; needs-patch needs-unit-tests removed

Patch and unit tests added to include private posts in get_adjacent_post

#4 @boonebgorges
12 years ago

  • Owner set to boonebgorges
  • Status newreviewing

#5 @boonebgorges
12 years ago

  • Milestone Future Release4.2

bswatson - Thanks! This looks great. I'm going to do some minor cleanup.

#6 @boonebgorges
12 years ago

  • Resolutionfixed
  • Status reviewingclosed

In 31302:

In get_adjacent_post(), return private post if the current user has the capacity to read it.

This mirrors the check that happens post-query in WP_Query. See #30911.

Props bswatson.
Fixes #30287.

Note: See TracTickets for help on using tickets.