WordPress.org

Ready to get started?Download WordPress

Forums

post-template 1059 Warning object (15 posts)

  1. Rasmataz
    Member
    Posted 7 months ago #

    I'm running multi-site with several related sites involved. In creating a master menu into all the sites using wp_list_pages I ran into a problem with one because the $current_page number didn't exist in the specific site.

    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 ) )

    It may be an unusual situation but I have posted it just in case someone else encounters it. It might also be beneficial for future use.

  2. tunjic
    Member
    Posted 6 months ago #

    I think it's more common than you think. A quick search for "post-template.php on line 1059" returns about 34,000 results of pages displaying the error on the frontend.

    Might be worth submitting to trac.

    Thanks for tracking this down.

  3. It's rare, but editing core WOULD NOT be the right thing here.

    In creating a master menu into all the sites using wp_list_pages I ran into a problem with one because the $current_page number didn't exist in the specific site.

    Okay, how'd you make the menu? :) You're listing the pages, so what's the code. If you're calling each page in the menu by the ID number then YOU should be having the code check "Does the page ID exist? If no, do not display."

  4. tunjic
    Member
    Posted 6 months ago #

    Well, for me, my site's menus were not created by ID number or in any peculiar way, and on the front end everything works fine. However, in my server error logs, I see this error repeated:

    [Mon Jan 06 20:42:03 2014] [error] [client 199.58.86.206] PHP Warning: in_array() expects parameter 2 to be array, null given in /var/www/vhosts/mysite.com/httpdocs/wp-includes/post-template.php on line 1059

    Or some other IP address. And this error is not thrown by every visitor to the site.

    Given that this is appearing on so many sites (several thousand) around the web, and that the php warnings in my logs (for my sub-directory, multi-site install) ended when I made the @Rasmataz edit to post-template.php, I think there might be something to this.

  5. Well, for me, my site's menus were not created by ID number or in any peculiar way, and on the front end everything works fine.

    Again: HOW did you make your menu? :)

  6. tunjic
    Member
    Posted 5 months ago #

    Yes, odds are good that something about our custom menus (especially, as @Rasmataz suggests, when creating a 'master menu' that brings together parent/child pages from different multi-site network sites) is causing the trouble (again, a minor trouble that only occasionally appears in my error logs).

    It's just very odd to me that so many people seem to have the issue.

  7. Well ... until someone wants to actually pony up the code and show us how they're creating the problem, no one will be able to actually fix it. I mean, it MIGHT be WP is doing it wrong, but it might be your code, and before anyone files a legit bug report, I would like to figure out which it is :)

    Besides, you're going to have to provide steps to reproduce in that bug report, why not do it now? I promise it won't hurt!

  8. tunjic
    Member
    Posted 5 months ago #

    Thank you for the encouragement. But that is exactly my problem; I have yet to find a reliable way to reproduce this error. There's no particular page or post that seems to be the culprit, and no pattern to the error logs.

    I could start posting menu code (from the header, footer, or sidebar, etc.), but I'm not sure it would help.

  9. I am 100% confident that not posting the code won't help :)

    You can't reproduce it reliably, which really does suggest it's the code. I can't reproduce it at all without the code. You see the theme here? We can't help you debug in the dark.

    Post the code up on Github :)

  10. tunjic
    Member
    Posted 5 months ago #

    Now we're getting somewhere! After spending some time digging through server logs comparing error time codes and access time codes, I've found the culprit. It's a custom page template we wrote to create an html sitemap of the 3 main sites in our multisite network.

    It's a pretty simple template and is part of our Genesis child theme, but it does use wp_list_pages(); I am suddenly confident this issue (at least for me) is a matter of debugging this code.

    I also took your advice about Github and posted the template code: https://github.com/tunjic/rbc-sitemap-template

    Please feel free to have a look, comment, etc... and thanks very much!

  11. You have list pages up there multiple times... So I would strip it down to one and test that, repeat etc till you find WHICH call :)

    My guess is these two:

    https://github.com/tunjic/rbc-sitemap-template/blob/master/sitemap.php#L50
    https://github.com/tunjic/rbc-sitemap-template/blob/master/sitemap.php#L64

    Because you switched to the new blog so 'current_page' is messed up, as the page you're on NOW doesn't exist in the other blog.

  12. tunjic
    Member
    Posted 5 months ago #

    It looks like I'm having trouble combining switch_to_blog and wp_list_pages. Like this person as well:

    http://wordpress.org/support/topic/trouble-with-switch_to_blog-and-wp_list_pages-1?replies=4

    But no solution is provided except for hacking /wp-includes/post-template.php (as was suggested at the beginning of this thread).

    Can we get these two functions to play nicely together?

  13. I'm not sure which one's at fault honestly ...

    I suspect it's related to https://core.trac.wordpress.org/ticket/23290

    You're setting this as code in a page template, right? I wonder if it would work better as a shortcode instead...

  14. tunjic
    Member
    Posted 5 months ago #

    That might be a workaround, but I doubt it since both switch_to_blog and wp_list_pages are called together in my function.

    Do you think we might have an issue worth a ticket, since we have explicit code that causes the error?

  15. I think so at this point. Go ahead and make it :) The trac site uses the same login/password as the forums. I'd mention that it MIGHT be related to #23290 just to be sure.

Reply

You must log in to post.

About this Topic