Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 4 years ago

#22867 closed defect (bug) (worksforme)

Function wp_get_nav_menu_items - Fatal error - Wordpress 3.5 and earlier

Reported by: sporky's profile sporky Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Menus Keywords: reporter-feedback
Focuses: Cc:

Description (last modified by SergeyBiryukov)

The function wp_get_nav_menu_items fails when a "Page" type post has been added to a menu.

This is a fresh install of Wordpress 3.5, using the "Sample Page" page added to a menu called "main_menu". This menu has no other menu options added to it. This bug also occurs in earlier versions of Wordpress.

Sample PHP Code:


$menu_name = 'main_menu';

$nav_menu_object = wp_get_nav_menu_object($menu_name);

$menu_id = $nav_menu_object->term_id;

$menu_items = wp_get_nav_menu_items($menu_id); <<--- Error occurs here


The following error occurs:

Fatal error: Call to a member function get_page_permastruct() on a non-object in C:\xampp\htdocs\lchs4\wp-includes\link-template.php on line 271

This occurs in the following area of code:

function _get_page_link( $post = false, $leavename = false, $sample = false ) {
	global $wp_rewrite;

	$post = get_post( $post );

	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );

	$link = $wp_rewrite->get_page_permastruct(); <--- happens here

Essentially, the variable $wp_rewrite shows as <Uninitialized> when viewed in xdebug using Eclipse.

Change History (6)

#1 @SergeyBiryukov
12 years ago

  • Component changed from General to Menus
  • Description modified (diff)

#2 @SergeyBiryukov
12 years ago

$wp_rewrite is set after plugins are loaded.

You're probably calling wp_get_nav_menu_items() too early. That code needs to wait at least until the init action runs.

#3 @scribu
12 years ago

  • Severity changed from critical to normal
  • Version changed from 3.5 to 3.3

#4 @dd32
12 years ago

  • Keywords reporter-feedback added

#5 @SergeyBiryukov
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

No feedback in 2 months.

Feel free to reopen with more information if there's still a problem.

This ticket was mentioned in Slack in #design by richtabor. View the logs.

4 years ago

Note: See TracTickets for help on using tickets.