• Resolved HelgaTheViking

    (@helgatheviking)


    We have a “types” taxonomy. It looks like in v1.9 “types” was added to the reserved list and now we can’t add/edit that taxonomy.

    I’ve tried adding the following snippet as a site-specific plugin does not seem to have the desired effect:

    
    function kia_allow_type_tax( $reserved_tax ) {
    	$key = array_search( 'types', $reserved_tax );
    
    	if ( false !== $key ) {
    		unset( $reserved_tax[$key] );
    	}
    
    	return $reserved_tax;
    }
    add_filter( 'cptui_reserved_taxonomies', 'kia_allow_type_tax' );

    `

    In theory, this seems like it should permit me to save a taxonomy with the “types” slug. However, when attempting to save a new tax, it still shows the error “Please choose a different taxonomy name. type is already registered.” notice.

    Is there an alternative way for overriding a reserved taxonomy slug?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hey Kathy, is it not allowing you to save even if you’re not touching the slug field?

    Also it looks like possibly a mix of type vs types being tried here, in terms of attempt to save?

    We don’t run any of our reserved taxonomy checks against the “import/export” process either, which is under the Tools menu, and I actually just this week was working with a different support thread about this same taxonomy slug. I bypassed myself by saving a taxonomy with everything except the slug set, grabbed the JSON blob, edited the slug, and then imported that new version back into the plugin and got “types” saved and in our options.

    Thread Starter HelgaTheViking

    (@helgatheviking)

    Hi Michael… I am not sure I follow you? You have to fill in the taxonomy slug field… it’s required and you can’t submit the form without it.

    Also it looks like possibly a mix of type vs types being tried here, in terms of attempt to save?

    I tried both, but I don’t *think* I mixed them up. If I var_dump() the result of the cptui_reserved_taxonomies() function I see that type or types is unset (depending on which I am targeting with the above filter). However, it still is blocking me when trying to save a new one

    @tenthmuse maybe you can clarify what happened on your site, but for my own testing.. I was having issues adding a custom taxonomy called type or types… even when removing it from the reserved taxonomies array.

    Thread Starter HelgaTheViking

    (@helgatheviking)

    Ooops… I’ve been reading this wrong… the cptui_reserved_taxonomies filter is for adding additional reserved taxonomy slugs and not for unsetting any in your reserved array.

    So in that case, I think the problem is that types was used in the past and now it cannot be edited (but posts exist with terms assigned in this taxonomy). What’s the best path forward there with respect to renaming this taxonomy slug while not losing the existing connections?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Had to take a trip down memory lane with this one to figure out what was going on with editing the taxonomies and how that all worked.

    Found that this function was also playing its part:

    function cptui_updated_taxonomy_slug_exists( $slug_exists, $taxonomy_slug = '', $taxonomies = [] ) {
    	if (
    		( ! empty( $_POST['cpt_tax_status'] ) && 'edit' === $_POST['cpt_tax_status'] ) &&
    		! in_array( $taxonomy_slug, cptui_reserved_taxonomies(), true ) &&
    		( ! empty( $_POST['tax_original'] ) && $taxonomy_slug === $_POST['tax_original'] )
    	) {
    		$slug_exists = false;
    	}
    	return $slug_exists;
    }
    add_filter( 'cptui_taxonomy_slug_exists', 'cptui_updated_taxonomy_slug_exists', 11, 3 );
    

    Note the fairly complex if statement there.

    That said though, this is all juggling a boolean value on a filter. So, I added this quick snippet and it’s looking like it bypasses most everything for the intended protection including allowing to register by default, as well as update the taxonomy settigs afterwards.

    add_filter( 'cptui_taxonomy_slug_exists', function( $slug_exists, $tax_slug, $taxonomies ) {
    	if ( 'types' === $tax_slug || 'type' === $tax_slug ) {
    		return false;
    	}
    	return $slug_exists;
    }, 11, 3 );
    

    I still stand by the decisions to protect them from the start, but I am understanding that sites are already using some of these should-be-reserved slugs, and may be wanting to move in to CPTUI as well for their management. Give this second snippet above a try and see if it works out for you.

    Thread Starter HelgaTheViking

    (@helgatheviking)

    Hi Michael, this snippet worked! Thanks so much. We will probably move towards renaming that slug going forward.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Glad I could help Kathy. See ya around on the Twitters ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Unsetting reserved taxonomy’ is closed to new replies.