• Resolved JiveDig

    (@jivedig)


    This is an internal taxonomy that should not be publicly accessible. We’re seeing /yes/ in our breadcrumbs and URLS are publicly viewable like /?taxonomy=wc_square_synced&term=yes

    I’m currently using this to force it to false:

    /**
     * WooCommerce Square taxonomy is public by default,
     * this filter forces public to false.
     *
     * @return array
     */
    add_filter( 'register_taxonomy_args', function( $args, $taxonomy, $object_type ) {
        if ( 'wc_square_synced' === $taxonomy ) {
            $args['public'] = false;
        }
    
        return $args;
    
    }, 10, 3 );
Viewing 1 replies (of 1 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Howdy,

    The code you’ve provided seems to be a good approach to modifying the arguments of a custom taxonomy to make it non-public. To ensure that the taxonomy is not queryable and its terms don’t appear in the URL, you can also set the query_var argument to false. Here is a suggestion:

    
    
    /**
     * Adjust WooCommerce Square taxonomy to be non-public and non-queryable.
     *
     * @param array  $args       Array of arguments for registering a taxonomy.
     * @param string $taxonomy   Taxonomy key.
     * @param array|string $object_type Object type or array of object types.
     * @return array
     */
    add_filter( 'register_taxonomy_args', function( $args, $taxonomy, $object_type ) {
        if ( 'wc_square_synced' === $taxonomy ) {
            $args['public'] = false;
            $args['query_var'] = false; // Ensure the taxonomy is not queryable.
            $args['rewrite'] = false; // Disable the rewrite rules for this taxonomy.
        }
    
        return $args;
    }, 10, 3 );
    
    

    I haven’t tested the above code. Since the taxonomy has already been registered with different arguments, you may need to unregister it first and then re-register it with the updated arguments.

    Don’t forget to backup as always.

    Kind regards,

Viewing 1 replies (of 1 total)
  • The topic ‘Why is the wc_square_synced public?’ is closed to new replies.