WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#21117 closed defect (bug)

CPT called "content" triggers a PHP notice — at Version 2

Reported by: bpierre Owned by:
Milestone: 3.5 Priority: normal
Severity: minor Version: 3.4
Component: Administration Keywords: has-patch
Focuses: Cc:

Description (last modified by scribu)

If a custom post type is called "content", the following error appears on all the admin pages:

Notice: Undefined index: meta in /path/to/wp-includes/class-wp-admin-bar.php on line 108

"content" is not in the taxonomy reserved terms list: http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms

PS: according to the ticket:19868, the taxonomy reserved terms are used for everything?

Change History (4)

@jeremyfelt3 years ago

Replaces wp_parse_args() with a direct assignment to avoid PHP notice

comment:1 @jeremyfelt3 years ago

  • Keywords has-patch added

Confirmed on latest trunk. Looks like two separate, but related, issues here.

First, when the admin menu is built, an ID is auto generated of the structure new-{$post_type}. The default id for the Add New item in the WP Admin bar is new-content. When a post type is registered as content, a conflict appears because that ID already exists. The bigger problem is that the Add New menu does not appear at all at this point.

I would personally assume 'content' is too generic a name to use when registering a post type, but perhaps the ID used for the Add New item is too generic as well. Prefixing the post type is probably the best answer to avoid any other unforseen conflicts.

Separately from this - The code in add_node() detects that a node already exists with this ID and grabs the default data associated with it. The next line of code attempts to then use wp_parse_args() with data it has just confirmed was empty, which generates the PHP notice.

The patch attached (attachment:21117.diff) addresses only the removal of wp_parse_args() in this scenario.

comment:2 @scribu3 years ago

  • Description modified (diff)
  • Summary changed from Custom post called "content" triggers a PHP notice to CPT called "content" triggers a PHP notice

@jeremyfelt3 years ago

Replaces wp_parse_args() with a direct assignment to avoid PHP notice and changes the Add New menu ID to add-new

Note: See TracTickets for help on using tickets.