WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 4 weeks ago

#25416 closed defect (bug) (fixed)

"Preview Changes" throws a PHP Notice and Warning every second use

Reported by: crysman Owned by: wonderboymusic
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.6
Component: Autosave Keywords: has-patch commit
Focuses: Cc:

Description

This is so weird... Every second time I press "Preview Changes" in the page edit admin interface I get these errors instead of the page preview:

Notice: Undefined index: post_excerpt in /var/www/cmstest3/wp-admin/includes/post.php on line 1333

Warning: Cannot modify header information - headers already sent by (output started at /var/www/cmstest3/wp-admin/includes/post.php:1333) in /var/www/cmstest3/wp-includes/pluggable.php on line 875

Using latest WP (3.6.1), standard template (20-13), no plugins activated.
We are running Apache 2 webserver with this PHP on GNU/Linux:

$ php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613/snmp.so' - /usr/lib/php5/20060613/snmp.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.2.4-2ubuntu5.27 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2013 14:13:32) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

Attachments (1)

25416.diff (713 bytes) - added by kovshenin 3 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 SergeyBiryukov7 months ago

  • Component changed from General to Autosave
  • Keywords reporter-feedback added

Could not reproduce on a clean install.

The error is coming from wp_create_post_autosave() (tags/3.6.1/wp-admin/includes/post.php#L1333), however $new_autosave does contain the post_excerpt field:

Array
(
    [post_title] => test
    [post_content] => 1 2
    [post_excerpt] => 
    [post_parent] => 6654
    [post_status] => inherit
    [post_type] => revision
    [post_name] => 6654-autosave-v1
    [post_date] => 
    [post_date_gmt] => 
    [ID] => 6656
    [post_author] => 1
)

As far as I can see, this can only happen if a plugin hooked to _wp_post_revision_fields filter (tags/3.6.1/wp-includes/revision.php#L9) removes post_excerpt from the default fields.

comment:2 crysman7 months ago

Hmm, I'll try on clean install, too, then (same server configuration as now)

But if it works, that would mean that:
1) disabling all plugins and activating the default template is not enough to report a bug :(
2) the only solution to fix it is making the clean install, which would mean a lot of work and backuping on functional online web :(

Both is very unpleasant.

Last edited 7 months ago by crysman (previous) (diff)

kovshenin3 months ago

comment:3 kovshenin3 months ago

  • Keywords has-patch added; reporter-feedback removed

I was able to reproduce this in trunk.

however $new_autosave does contain the post_excerpt field

This is true, except when the current post type does not support excerpts, such as the page post type. I guess with CPT this will also affect the content and title fields, since the first time _wp_post_revision_fields() returns off of the posted data, but the loop runs on a clean call to _wp_post_revision_fields, referencing fields that might not exist in $new_autosave.

It's fairly tricky to reproduce, but give it a shot like this:

  1. Turn on WP_DEBUG_LOG and watch wp-content/debug.log
  2. Create a new page, name it "foo", type in "bar" as the content and hit Publish
  3. Set the content to "bar baz" and hit Preview Changes (don't Publish)
  4. Set the content back to "bar" and hit Preview Changes again
  5. See debug.log

Introduced in [24879], suggested fix in 25416.diff. Thoughts on moving this to 3.8.2 or 3.9?

comment:4 ircbot3 months ago

This ticket was mentioned in IRC in #wordpress-dev by kovshenin. View the logs.

comment:5 kovshenin3 months ago

  • Milestone changed from Awaiting Review to 3.8.2

comment:6 SergeyBiryukov8 weeks ago

  • Keywords commit added
  • Milestone changed from 3.8.2 to 3.9
  • Version changed from 3.6.1 to 3.6

25416.diff looks good to me. Not a new regression, let's move to 3.9.

comment:7 wonderboymusic4 weeks ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 27690:

In wp_create_post_autosave(), intersect the $new_autosave's keys with the keys from _wp_post_revision_fields() to ensure that all expected fields are present.

Props kovshenin.
Fixes #25416.

Note: See TracTickets for help on using tickets.