#21106 closed defect (bug) (fixed)
Unable to add Taxonomies to custom post type taxonomies in 3.4.1
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.4.2 | Priority: | normal |
Severity: | major | Version: | 3.4 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | Cc: |
Description
This is reproducible in at least IE8 and FF 13.0.1, WordPress 3.4.1, and at least two separate domains.
Problem: We have a least two sites which have custom post types and taxonomies originally added by the Custom Post Type UI plugin, in which we are unable to add new taxonomies to. After disabling all plugins and putting the post type/taxonomy code directly into the functions.php file: we are still unable to add new taxonomies.
Reproduction: 1. Add a custom post type and a custom post type taxonomy. Add new custom post type "entry/post" from the admin menu or from the Dashboard sidebar. If is a hierarchical custom post type taxonomy, add a new custom post taxonomy. When the "Add New [Taxonomy]" button is pressed, the entered name in the taxonomy text field stays present, the add button seems to disappear from its location, and the add button is now displayed at the end of the custom post taxonomy list. The new taxonomy has not been added. (see image attached)
- Add a custom post type and a custom post type taxonomy. Add new custom post type "entry/post" from the admin menu or from the Dashboard sidebar. If is a hierarchical custom post type taxonomy, which already has taxonomy present, check several taxonomies. You will notice that there is "lag" in selecting these current taxonomies (IE8 at least).
- Although I have not been able to reproduce this, a client has mentioned that on an add custom post page where there is custom post taxonomy, the page is unusable and can eventually crash in IE8.
Example functions.php
register_post_type('events', array( 'label' => 'Events','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => ''),'query_var' => true,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),'labels' => array ( 'name' => 'Events', 'singular_name' => 'Event', 'menu_name' => 'Events', 'add_new' => 'Add Event', 'add_new_item' => 'Add New Event', 'edit' => 'Edit', 'edit_item' => 'Edit Event', 'new_item' => 'New Event', 'view' => 'View Event', 'view_item' => 'View Event', 'search_items' => 'Search Events', 'not_found' => 'No Events Found', 'not_found_in_trash' => 'No Events Found in Trash', 'parent' => 'Parent Event', ),) ); register_taxonomy('event-city',array ( 0 => 'events', ),array( 'hierarchical' => true, 'label' => 'Locations','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => ''),'singular_label' => 'Location') );
Attachments (7)
Change History (34)
#1
@
13 years ago
- Milestone changed from Awaiting Review to 3.4.2
I can reproduce issues 1 and 2 in Firefox 13 and IE 8.
Introduced in [20337] with jQuery 1.7.2.
#3
follow-up:
↓ 5
@
13 years ago
"event-city" starts with the word "even". WordPress uses some colon-separated class names. like: add:event-citychecklist
. See the :even
in there? The issue manifests if you replace "event-city" with "oddsfish".
On line 81 of wp-includes/js/wp-lists.dev.js has the following line:
if ( !e.is('[class^="add:' + list.id + ':"]') )
This test is failing when it shouldn't be.
Here's my theory: there was a bug introduced in jQuery 1.7.2 regarding attribute selector quoting. It's seeing :even
or :odd
in a quoted class selector and it's parsing that as the :even
/:odd
pseudo-classes that jQuery supports.
What's really frustrating is that I can't reproduce it more simply. I've been trying to make a simple proof of concept on jsfiddle.net
Maybe someone else will have better luck.
#4
@
13 years ago
21106.patch fixes issue 1 by checking id
attribute instead of class
.
#5
in reply to:
↑ 3
@
13 years ago
We have similar code in at least one more place:
http://core.trac.wordpress.org/browser/trunk/wp-includes/js/wp-lists.dev.js?rev=17981#L392
Not sure at a glance if it fails or not. Would be great to pinpoint the exact change in jQuery behaviour, but so far I could not reproduce it in a standalone example either.
#6
@
13 years ago
Koopersmith says it's probably a really low level thing that changed in their selector engine. The main takeaway is that our use of colons within class names is really ill-advised.
#8
@
13 years ago
- Owner set to markjaquith
- Resolution set to fixed
- Status changed from new to closed
In [21205]:
#9
@
13 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening so we can consider it for a potential 3.4.2. Not sure this merits it all by itself, but if we have to release one anyway, might consider working it in.
#10
@
13 years ago
Issue 2 (the lag in IE when selecting terms) still remains. Going to take a look by the weekend if no one beats me to it. Might be related to issue 3 as well.
#13
follow-up:
↓ 15
@
12 years ago
I patched the colon classes ticket: https://core.trac.wordpress.org/ticket/21152 - perhaps that can be used in some form?
#15
in reply to:
↑ 13
@
12 years ago
Replying to wonderboymusic:
I patched the colon classes ticket: #21152 - perhaps that can be used in some form?
Tested the patch in IE 7 and 8, doesn't fix the lagging when selecting a taxonomy term. Seems to be caused by something else.
#16
@
12 years ago
Closed #21747 as a duplicate.
In trunk (with jQuery 1.8.1), the symptoms are different:
- The lagging appears when checking any category on a regular Edit Post screen as well, in both IE and Firefox.
- If there's a taxonomy starting with "even", IE throws an error when checking its terms:
Stack overflow at line: 2
Upon debugging, I've found two particular places which seem to be slowing things down:
'[class^="add:' + list.id + ':"]:not(form)'
selector inwpList.process()
: http://core.trac.wordpress.org/browser/tags/3.4.1/wp-admin/js/post.dev.js#L345
As far as I can see, it only runs once, but commenting it out resulted in a significant speedup. With the patch from #21152 the results were the same, which made me think the culprit here is:not(form)
rather than the:even
part. Removing:not(form)
confirmed that.'#' + taxonomy + 'checklist li.popular-category :checkbox
selector inpost.js
: http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/js/wp-lists.dev.js#L400 jQuery.com suggests replacing it with[type="checkbox"]
:Because
:checkbox
is a jQuery extension and not part of the CSS specification, queries using:checkbox
cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method. For better performance in modern browsers, use[type="checkbox"]
instead.
21106.2.patch fixes the stack overflow in IE and the lagging in both Firefox and IE. It should cover all the existing core usage of those class names. Tested in 3.4.1 (with jQuery 1.7.2) as well.
21106.3.patch binds all three non-form functions to both a
and input
elements, in case plugins might rely on that. Seems is a little bit slower, but perhaps safer. Not sure if that's necessary though.
#17
@
12 years ago
We should be able to escape the :
when using the CSS classes in jQuery:
If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \\.
#19
follow-up:
↓ 21
@
12 years ago
After [21717], is there anything else necessary for the 3.4 branch?
SergeyBiryukov's comment suggests that this remaining issue has to do with jQuery 1.8.x, which is WP trunk only. The Sizzle selector engine was rebuilt in 1.8, so I would not be surprised if this did not affect 1.7. The original report does suggest this is a problem with 3.4.x. Does 21106.2.patch (or .3.patch) handle both?
#20
@
12 years ago
The selectors in 21106.2.patch are a bit nasty, but look good to me.
We can actually chain in 21106.3.patch, rather than relying on individual $el.find('a, input')
calls. That would probably be more performant than .2.patch and lessens the risk in the 3.4 branch.
#21
in reply to:
↑ 19
@
12 years ago
Replying to nacin:
After [21717], is there anything else necessary for the 3.4 branch?
I think so. In 3.4.1, the lagging (~3 seconds) only appears in IE when checking terms of a taxonomy starting with "even" (as described in the ticket). It would be good to fix that.
In trunk, the lagging appears in both IE and Firefox (~1 second in Firefox and IE 9, ~5 seconds in IE 8) when checking any category on a regular Edit Post screen as well. Additionally, a stack overflow error occurs in IE 8 when checking terms of a taxonomy starting with "even".
Upon more testing, it turned out that 21106.2.patch doesn't work as intended (the functions are not binded properly for some reason), so I've decided to simplify it.
21106.5.patch fixes the lagging in IE in 3.4.1. In trunk, it also fixes stack overflow in IE 8 and at least partially fixes the lagging (~0.2 seconds, almost unnoticeable, in FF, ~1 second in IE). We could look into further optimization in a new ticket.
#22
@
12 years ago
Actually, checking categories is not the only slow thing in trunk.
With jQuery 1.8.1, most of the actions on Add New Post screen are extremely slow in IE 8: editing post title, changing post format, etc. This can also be seen on
lessbloat's video (User 6) at 9:30.
Still, 21106.5.patch fixes that.
#23
follow-up:
↓ 16
@
12 years ago
Looked at this too. This part of wp-lists.js is pretty bad.
- The
process()
runs on load with no arg, then on adding elements with the element as arg. This isn't needed if the events are delegated (i.e. attached to $(document) so they will trigger when new elements are added with ajax). Also, on load$el = $(document)
so doing$el.find(...)
goes through the whole DOM.
For this to work it shouldn't use .find() and only attach the events to $(document) on load. There's no need to run it on each ajax response. All this can be seen in action on the Comments screen.
- We hit a bug in jQuery. When a class name contains
:event
it cannot be used as selector in jQuery even when the:
is escaped (it won't select any elements). This affectsprocess()
too.
Screenshot after adding new custom post taxonomy