Register_taxonomy was called incorrectly

In my latest app I wanted to force the naming of WooCommerce Product Attributes as my code would cycle through them to decide which custom properties apply to Variable Products.  A great way to introduce structure for custom values for variable Products.

My problem was that I grew the attribute names to include embedded information so that I could determine if the custom field was text or numeric, if it was to be displayed in the custom form or not, etc.  My attribute names grew long quite quick.  I should have kept an eye on that.

While experimenting with the code I accidentally got into a bit of a loop and ended up trying to register attribute slugs longer than 32 characters.  This threw an error but I’ve got myself stuck.

When I browse to any page of the site I get the error

Notice: register_taxonomy was called incorrectly. Taxonomy names must be between 1 and 32 characters in length. 
Please see Debugging in WordPress for more information. 
(This message was added in version 4.2.0.) in /Users/tony/Local Sites/nooksii/app/public/wp-includes/functions.php on line 5167

The site became unusable.

I commented out my code that tries to check and create missing attributes but the problem persisted.
I assumed that the setting was in the database and was trying to be re-set on INIT. So I cleared the table wp_woocommerce_attribute_taxonomies. I also cleared down the sessions table wp_woocommerce_sessions.
And rebooted the server.
But the problem persists. With debug running I can see the attribute causing the problem:

function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
.
.
// in here the passed variable $taxonomy has the value 'pa_pa_pick-txt-clear-item-part-ref'
.
}

34 characters – clearly too long. But where is it cropping up from? My code is NOT trying to do any new registrations.

Here is the call stack:-


Clearly MY code has not been touched. All WP init code.
So, where is WP getting the values to make a registration from?

A quick search of the WP tables shows similar values (but not exact ones like the one causing my problem) in wp_options in the column option_name under entry _transient_wc_attribute_taxonomies.

As I’m on a dev system and I’ve spent a lot of time already I’m going to delete all the values in _transient_wc_attribute_taxonomies and see if I can get sorted.

Guess what? That pushed a new error into wc-attribute-funciton.php. Line 73 (in my case) the WC code is trying to do an array_filter to return into $raw_attribute_taxonomies but the error says the passed in parameter is NOT an array.

This is backed up with the line in that function:

$raw_attribute_taxonomies = get_transient( 'wc_attribute_taxonomies' );

I also noticed the code:

if ( false === $raw_attribute_taxonomies ) {
  global $wpdb;
  $raw_attribute_taxonomies = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name != '' ORDER BY attribute_name ASC;" );
   .
   .

So I’ve basically screwed something up by emptying those tables and entries.

I’m guessing there is a link to the wp_term_taxonomy table (I recognised some of the transient values I deleted) so I need to delete my custom attribute names from there (yes – even the ones that did not cause a problem).

Now I’m in a bit of a mess I’m considering deleting everything (delete the site) and re-install a fresh WooCommerce base site.

A search for “woocommerce repair database” did not reveal any solutions. No specific hits at all.

In conclusion I’m putting this post out as a warning. Try not to get into this mess in the first place.
If you have code that registers Product Attributes make sure you do the following:-

  • Check the length of the attribute slug.
  • Check you are not using reserved slug values: wc_check_if_attribute_name_is_reserved

I would have loved to investigate this issue.  I suppose it could be reproduced by forcing a large attribute name and seeing if the system gets itself stuck again.  That an exercise for another day.

Leave a Reply

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close