Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#9180 closed defect (bug) (invalid)

Query clears posts, impossible to see public content on permalink page

Reported by: MrPeteH Owned by:
Milestone: Priority: normal
Severity: major Version:
Component: General Keywords:
Focuses: Cc:


Various tools such as wp-sentry enable public home page view of above-the-fold or excerpt portions of posts. Unfortunately, due to a bug in query.php, the same content cannot be viewed on the permalink page for the same posts. Instead, non-logged-in users are told they are visiting an invalid or invisible page... which should be incorrect.

The fix is quite simple in wp-includes/query.php line 2274.

Current code conditionally clears the posts[] array:

if ( ! is_user_logged_in() ) {
  // User must be logged in to view unpublished posts.
  $this->posts = array();
  } else {
   ... (code that deals with non-public posts for logged-in users)

This can be simplified by removing the condition and array-clearing:

  // Handle unpublished posts for all users.
   ... (code that deals with non-public posts for logged-in users)

I have tested this extensively with a variety of scenarios. It works perfectly. Essentially, the code that knows how to determine post visibility already handles private/future/draft posts correctly. There's no need to arbitrarily delete the posts information!

The benefit of this simple fix:

  • Whatever a user (logged in or not) can see on the home page is the same info they see on a post-specific page.
  • MUCH less confusing than the current situation, where a non-logged in user following a link is given a message that there's NOTHING to see (when they know there IS something to see -- it's available right on the home page!)

This is a killer for significant users of public/private content.

Attachments (1)

posts.9180.diff (2.1 KB) - added by filosofo 9 years ago.

Download all attachments as: .zip

Change History (4)

9 years ago

#1 @filosofo
9 years ago

You're right about that check's being unnecessary, but I don't see how it's any more helpful to remove it. A user who's not logged in and who tries to view a future post will get the same result as before: the posts array is made empty, so it will return a WP 404.

#2 @MrPeteH
9 years ago

Why bother? Because the outcome can be modified via a plugin such as wp-sentry.

Sure, a future post should always be hidden. Good.

But how about, for example, private posts with public excerpt or public above-the-fold content. That's a VERY handy result.

Without this patch, it is impossible to properly configure such things.

With this patch in place, I can configure my blog in a variety of ways.

#3 @Denis-de-Bernardy
9 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed

This is the plugin's job to fix, by filtering on posts_results to get the raw posts, and the_posts to reinsert them.

Note: See TracTickets for help on using tickets.