Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#8526 closed defect (bug) (fixed)

Bad Preview Link In WordPress 2.7 With object-cache.php present

Reported by: brianwhite's profile brianwhite Owned by:
Milestone: 2.7.1 Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:


WordPress 2.7 RC1 does not save the post_name (slug) until the post is published or if it is edited. So, if you have permalinks enabled, you get a 404 error and can't preview a new post.

Steps to reproduce:

  1. Create a new post.
  2. Save it.
  3. Check the database. You will see that the post_name field for the post you just created is empty.
  4. Try to preview. You will receive a 404 error.
  5. Edit the post slug.
  6. Save it and the post itself.
  7. Try to preview. The page is displayed correctly.

Attachments (1)

post.php.diff (554 bytes) - added by brianwhite 15 years ago.

Download all attachments as: .zip

Change History (9)

#1 @azaozz
15 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Post id (or page id) is used when previewing drafts and seems to work correctly.

#2 @azaozz
15 years ago

  • Milestone 2.7 deleted

#3 @brianwhite
15 years ago

After further analysis, I discovered root cause of the issue. Even though I had disabled all plugins, a copy of object-cache.php was still in the appropriate directory in the file system. And, since the cache was stale/inconsistent, the post wasn't found. Deleting object-cache.php solved the issue. I don't know why; but WordPress 2.7 and the object-cache.php (for APC) don't work well together. I will notify the author. Sorry for the false alarm.

I am adding this information here in the hope that it may help other users who might experience the same problem sometime in and are looking for answers.. I left the ticket closed. I hope that this is the proper way to do this.

15 years ago

#4 @brianwhite
15 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Summary changed from Wordpress 2.7 RC1 Does Not Save The Post_Name (Slug) to Bad Preview Link In WordPress 2.7 With object-cache.php present

It turns out this is a "bug" albeit it a subtle one in WordPress. Here's what I discovered after further investigation. get_sample_permalink() in /wordpress/wp-admin/includes/post.php temporarily overwrites post_status, post_date, and post_name for the current post object and uses the updated object to call get_permalink(). After the call the values are restored. Unfortunatly, get_permalink() calls get_posts() which, in turn, calls wp_cache_add() which refreshes the cache with the fake data used to avoid an ugly permalink. Later when, get_permalink() is called to retrieve the URL for the preview, the status and name in the post object in the cache are used which results in a "pretty" URL when drafts need "/?p=<Id>" format since the post_date and post_name have not yet been persisted to the database.

This error only manifests itself when an object-cache.php is present in the /wordpress/wp-content directory. Since the cached\ implemented by /wordpress/wp-includes/cache.php dies after every page load, there are no issues with a standard install. The problem only occurs if someone is using a semi-persistent cache like memcache or APC. The same behavior happened in Wordpres 2.6; however, the code to calculate the preview link occurred earlier in the page life cycle than the code to calculate the sample permalink so the "bad" data in the cached object had no visible effects.

A patch which fixes the issue by reached the "correct" data is attached.

#5 @ryan
15 years ago

I think passing $post->ID instead of $post to get_permalink() will avoid the cache tainting.

#6 @ryan
15 years ago

  • Milestone set to 2.7.1

#7 @ryan
15 years ago

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

(In [10213]) Don't cache filtered post objects. Set filter when getting sample permalink. Props brianwhite. fixes #8526 for trunk

#8 @ryan
15 years ago

(In [10214]) Don't cache filtered post objects. Set filter when getting sample permalink. Props brianwhite. fixes #8526 for 2.7

Note: See TracTickets for help on using tickets.