Can I turn off write-in tags/taxonomies?

Here is what I came up with, seems to work:

add_filter( 'pre_post_tags_input', 'no_tags_input_create' );
add_filter( 'pre_post_tax_input', 'no_tax_input_create' );

function no_tags_input_create($tags_input) {

    $output = array();

    foreach( $tags_input as $tag )
        if( term_exists( $tag, 'post_tag') )
            $output[] = $tag;

    return $output;
}

function no_tax_input_create($tax_input) {

    if( !isset($tax_input['post_tag']) )
        return $tax_input;

    $output = array();
    $tags = explode(',', $tax_input['post_tag']);

    foreach( $tags as $tag )
        if( term_exists( $tag, 'post_tag') )
            $output[] = $tag;

    $tax_input['post_tag'] = implode(',',$output);

    return $tax_input;
}

This is for tags, you can easily extend second function to handle custom taxonomies.

Leave a Comment