WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#30287 closed enhancement (fixed)

Private posts skipped in single post navigation

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

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 5 years ago.
Add private posts for current user to get_adjacent_post
30287-unit-tests.diff (3.5 KB) - added by bswatson 5 years ago.
Unit Tests for get_adjacent_post

Download all attachments as: .zip

Change History (8)

#1 @valendesigns
5 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
5 years ago

  • Component changed from General to Posts, Post Types
  • Keywords needs-patch needs-unit-tests good-first-bug added
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to enhancement
  • Version changed from trunk to 1.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
5 years ago

Add private posts for current user to get_adjacent_post

@bswatson
5 years ago

Unit Tests for get_adjacent_post

#3 @bswatson
5 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
5 years ago

  • Owner set to boonebgorges
  • Status changed from new to reviewing

#5 @boonebgorges
5 years ago

  • Milestone changed from Future Release to 4.2

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

#6 @boonebgorges
5 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

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.