• 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jaroat

    (@jaroat)

    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

    Thread Starter jaroat

    (@jaroat)

    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 4 years, 2 months ago by jaroat.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Notice when wp_debug activated’ is closed to new replies.