[wp-trac] [WordPress Trac] #58345: Critical error if page_for_posts is set to non existing page ID

WordPress Trac noreply at wordpress.org
Wed May 17 15:27:20 UTC 2023


#58345: Critical error if page_for_posts is set to non existing page ID
---------------------------+-----------------------------
 Reporter:  wplindavantol  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Menus          |    Version:  trunk
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 **Description**
 If page_for_posts points to a non-existing page ID, get_posts() will fail
 and cause a critical error in line 406 (nav-menu.php). So probably a check
 is needed to prevent this. Tested with default theme and no active
 plugins.

 **Critical error location**
 Dashboard --> Appearance --> Menus

 **Error log**

 {{{
 PHP Fatal error:  Uncaught Error: Attempt to assign property "posts_page"
 on null in /.../wp-admin/includes/nav-menu.php:406
 Stack trace:
 #0 /.../wp-admin/includes/template.php(1577):
 wp_nav_menu_item_post_type_meta_box()
 #1 /.../wp-admin/nav-menus.php(984): do_accordion_sections()
 #2 {main}
    thrown in /.../wp-admin/includes/nav-menu.php on line 406, referer:
 https://.../wp-admin/nav-menus.php?
    action=locations
 }}}


 **nav-menu.php**

 {{{#!php
 <?php
   // Insert Posts Page.
      $posts_page = 'page' === get_option( 'show_on_front' ) ? (int)
 get_option('page_for_posts' ) : 0;

      if ( ! empty( $posts_page ) ) {
            $posts_page_obj             = get_post( $posts_page );
            $posts_page_obj->posts_page = true;

            $important_pages[]   = $posts_page_obj;
            $suppress_page_ids[] = $posts_page_obj->ID;
      }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58345>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list