0

I'm trying to add custom taxonomy to a custom post type in WordPress. When wp_debig is enabled the wp-admin page throws a notice:

Notice: Undefined property: stdClass::$taxonomy in /opt/lampp/htdocs/wordpress/wp-includes/admin-bar.php on line 503

in the line 503 there is only this:

 && ( $tax = get_taxonomy( $tag->taxonomy ) )

My custom taxonomy is like this:

    function create_project_types(){
        $labels = array(
            'name' => __('Project Type', 'abc'),
            'singular_name' => __('Project Type', 'abc'),
            'search_items' => __('Search Project Types', 'abc'),
            'all_items' => __('All Project Types', 'abc'),
            'edit_item' => __('Edit Project Type', 'abc'),
            'update_item' => __('Update Project Type', 'abc'),
            'add_new_item' => __('Add New Project Type', 'abc'),
            'new_item_name' => __('New Project Type', 'abc'),
            'separate_items_with_commas' => __('Separate Types with commas', 'abc'),
            'add_or_remove_items' => __('Add or Remove Project Type', 'abc'),
            'choose_from_most_used' => __('Choose from Most Used Project Types', 'abc')
        );
        $args = array(
            'label' => __('Project Type', 'abc'),
            'labels' => $labels,
            'public' => true,
            "hierarchical" => true,
            'show_ui' => true,
            'show_in_nav_menus' => true,
            'args' => array('orderby' => 'term_order'),
            'rewrite' => array('slug' => 'project-type','with_front' => true),
            'query_var' => true
        );
        register_taxonomy("project-type", 'project', $args);
    }
add_action('init', 'create_project_types', 0);

Everything is working properly I'm just trying to dismiss that notice. Can You help me?

Arpad Hollo
  • 201
  • 1
  • 9

2 Answers2

0

Notices are not errors. Depending on context they could mean something its wrong, though.

If you are leaving the house and you->keys is undefined, you have a problem, but if you->pocketlint were undefined instead, maybe its no big deal. Maybe its pretty expected, because its your new coat. :)

Your code is saying something like:

"If wallet exists and wallet have money then buy icecream"

Note that if the code absolutely-have-to-get-icecream-or-die, then it should not let things carry on without it. It should die appropriately.

Of course, poorly written code that lets the program jump_from_plane() with !$parachute. Its just doesn't seems to me to be the case.

If all things are working fine and code isn't making a fuss about it, neither should you.

SO DISMISS THE NOTICE. You have my permission. If anything goes wrong you may say I told you so.

Some things related you should read if you didn't get some or any thing of the above:

$tag is a stdClass object. See what stdClass is.

You turned on debug mode, so you said. Check PHP error reporting

Debug mode set error reporting up high, so you'll get ERRORs, WARNINGs and NOTICEs.

BUT:

Anyways, if you are so annoyed by it, replace $tax = get_taxonomy( $tag->taxonomy ) with $tax = property_exists($tag, 'taxonomy') ? get_taxonomy( $tag->taxonomy ) : false

Community
  • 1
  • 1
nocarrier
  • 119
  • 5
  • the full part of the admin-bar.php file which belongs here: `global $tag, $wp_the_query; if ( is_admin() ) { $current_screen = get_current_screen(); $post = get_post(); . . . } elseif ( 'edit-tags' == $current_screen->base && isset( $tag ) && is_object( $tag ) && ( $tax = get_taxonomy( $tag->taxonomy ) ) && $tax->public ) { $wp_admin_bar->add_menu( array( 'id' => 'view', 'title' => $tax->labels->view_item, 'href' => get_term_link( $tag ) ) ); }` – Arpad Hollo Aug 26 '14 at 19:05
  • Have anything missing in the admin bar? If not you are good to go. Check [link](http://codex.wordpress.org/Class_Reference/WP_Admin_Bar/add_menu) – nocarrier Aug 26 '14 at 19:20
  • nothing. everything is on the right position. even the custom post types under the "new" menu item. – Arpad Hollo Aug 26 '14 at 23:38
  • it only appears when i add term to a taxonomy. if there's no term, there's no notice... – Arpad Hollo Sep 02 '14 at 10:37
0

I found my own answer. I overwited the global $tag variable, and this couse the notice.

Arpad Hollo
  • 201
  • 1
  • 9