Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#26901 closed defect (bug) (fixed)

Warning line 1059 in post-template.php

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

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 12 years ago.

Download all attachments as: .zip

Change History (8)

#1 @ocean90
12 years ago

  • Description modified (diff)

#2 @tunjic
12 years ago

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

#3 @DrewAPicture
12 years ago

  • Component GeneralPosts, Post Types
  • Focuses multisite added

@jeremyfelt
12 years ago

#4 @jeremyfelt
12 years ago

  • Keywords has-patch added
  • Milestone Awaiting Review4.1
  • Version 3.83.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
12 years ago

  • Keywords commit added

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

#6 @wonderboymusic
12 years ago

  • Owner set to wonderboymusic
  • Resolutionfixed
  • Status newclosed

In 30157:

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

Props jeremyfelt.
Fixes #26901.

#7 @5um17
12 years ago

#30136 was marked as a duplicate.

Note: See TracTickets for help on using tickets.