WPIntell

Source evidence

Notice when wp_debug activated

WP API Menus · support · 2020-09-17T13:31:00+00:00

complaintsentiment
mediumseverity
0.86relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

2 / 21 rows with source links

9.5% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

19 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
jaroat unresolved
Hi – Did take a look at your plugin and noticed that it throws a PHP notice while WP_DEBUG is enabled: <b>Notice</b>: Trying to get property ‘post_name’ of non-object in <b>/var/www/73/skimo/htdocs/wp-content/plugins/wp-api-menus/includes/wp-api-menus-v2.php</b> on line <b>390</b><br /> Best from Salzburg, – Johannes Hi – Seems to be a problem if a nav menu item doesn’t refer to a wp_posts entry. In my case, the menu item was linked to a category (resulting in a link to the category overview page) so the object_id doesn’t refer to a wp_posts row but on a wp_term instead. get_post fails in that case and returns null. A possible solution would be to extend the format_menu_item function a little bit so it differentiates between the possible menu-item-types (taxonomy, custom, post_type, etc.). Best from Salzburg! – Johannes Something like this should do it: switch ( $item[ 'type' ] ) { case 'post_type': $post = get_post( $item['object_id'] ); $menu_item = array( 'id' => abs( $item['ID'] ), 'order' => (int) $item['menu_order'], 'parent' => abs( $item['menu_item_parent'] ), 'title' => $item['title'], 'url' => $item['url'], 'attr' => $item['attr_title'], 'target' => $item['target'], 'classes' => implode( ' ', $item['classes'] ), 'xfn' => $item['xfn'], 'description' => $item['description'], 'object_id' => abs( $item['object_id'] ), 'object' => $item['object'], 'object_slug' => $post !== null ? $post->post_name : '', 'type' => $item['type'], 'type_label' => $item['type_label'], ); break; default: $menu_item = array( 'id' => abs( $item['ID'] ), 'order' => (int) $item['menu_order'], 'parent' => abs( $item['menu_item_parent'] ), 'title' => $item['title'], 'url' => $item['url'], 'attr' => $item['attr_title'], 'target' => $item['target'], 'classes' => implode( ' ', $item['classes'] ), 'xfn' => $item['xfn'], 'description' => $item['description'], 'object_id' => abs( $item['object_id'] ), 'object' => $item['object'], 'object_slug' => null, 'type' => $item['type'], 'type_label' => $item['type_label'], ); break; } This reply was modified 5 years, 8 months ago by jaroat .

Comments

2 shown
jaroat 2020-09-17T14:24:00+00:00

Hi – Seems to be a problem if a nav menu item doesn’t refer to a wp_posts entry. In my case, the menu item was linked to a category (resulting in a link to the category overview page) so the object_id doesn’t refer to a wp_posts row but on a wp_term instead. get_post fails in that case and returns null. A possible solution would be to extend the format_menu_item function a little bit so it differentiates between the possible menu-item-types (taxonomy, custom, post_type, etc.). Best from Salzburg! – Johannes

jaroat 2020-09-17T15:09:00+00:00

Something like this should do it: switch ( $item[ 'type' ] ) { case 'post_type': $post = get_post( $item['object_id'] ); $menu_item = array( 'id' => abs( $item['ID'] ), 'order' => (int) $item['menu_order'], 'parent' => abs( $item['menu_item_parent'] ), 'title' => $item['title'], 'url' => $item['url'], 'attr' => $item['attr_title'], 'target' => $item['target'], 'classes' => implode( ' ', $item['classes'] ), 'xfn' => $item['xfn'], 'description' => $item['description'], 'object_id' => abs( $item['object_id'] ), 'object' => $item['object'], 'object_slug' => $post !== null ? $post->post_name : '', 'type' => $item['type'], 'type_label' => $item['type_label'], ); break; default: $menu_item = array( 'id' => abs( $item['ID'] ), 'order' => (int) $item['menu_order'], 'parent' => abs( $item['menu_item_parent'] ), 'title' => $item['title'], 'url' => $item['url'], 'attr' => $item['attr_title'], 'target' => $item['target'], 'classes' => implode( ' ', $item['classes'] ), 'xfn' => $item['xfn'], 'description' => $item['description'], 'object_id' => abs( $item['object_id'] ), 'object' => $item['object'], 'object_slug' => null, 'type' => $item['type'], 'type_label' => $item['type_label'], ); break; } This reply was modified 5 years, 8 months ago by jaroat .