Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#26901 closed defect (bug) (fixed)

Warning line 1059 in post-template.php

Reported by: tunjic's profile tunjic Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.1 Priority: normal
Severity: minor Version: 3.5
Component: Posts, Post Types Keywords: has-patch commit
Focuses: multisite Cc:

Description (last modified by ocean90)

Error produced in multisite (sub-directory) when combining switch_to_blog and wp_list_pages.

See this support thread: http://wordpress.org/support/topic/post-template-1059-warning-object?replies=15

Here is the page that produces the PHP warning in my server error logs: http://www.rockbrookcamp.com/sitemap/ It is an html sitemap with a custom page template. The code for that template is here: https://github.com/tunjic/rbc-sitemap-template

Ipstenu suggested this might be related to #23290

The following edit of wp-includes/post-template.php (suggested by Rasmataz in the support thread above) does remove the error:

"wp-includes/post-template.php was throwing a warning in the start_el function of class Walker at line 1059 because $_current_page results in NULL.

I worked around the issue by changing line 1059 as follows:"

FROM: if (in_array( $page->ID, $_current_page->ancestors ) )

TO: if (is_object($_current_page) && in_array( $page->ID, $_current_page->ancestors ) )

Attachments (1)

26901.diff (559 bytes) - added by jeremyfelt 10 years ago.

Download all attachments as: .zip

Change History (8)

#1 @ocean90
11 years ago

  • Description modified (diff)

#2 @tunjic
10 years ago

With 3.9, this has moved to line 1252. /wp-includes/post-template.php on line 1252,

#3 @DrewAPicture
10 years ago

  • Component changed from General to Posts, Post Types
  • Focuses multisite added

@jeremyfelt
10 years ago

#4 @jeremyfelt
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.1
  • Version changed from 3.8 to 3.5

Thanks for the bug report @tunjic.

It seems this can happen if the walker gets a list of pages and one does not exist. We actually used to check for $_current_page->ancestors here before some other cleanup in [21559] got rid of it. I'm not sure that this is specifically multisite related, but the use of switch_to_blog() could be resulting in the query of some post IDs that exist on one site and not the other.

26901.diff adds a check to make sure we didn't receive null back from get_post(). We do the same thing a bit farther down before looking for a post parent.

#5 @boonebgorges
10 years ago

  • Keywords commit added

I've seen this problem too. Fix looks good to me.

#6 @wonderboymusic
10 years ago

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

In 30157:

Check $_current_page before using it in Walker_Page->start_el().

Props jeremyfelt.
Fixes #26901.

#7 @5um17
10 years ago

#30136 was marked as a duplicate.

Note: See TracTickets for help on using tickets.