jtsternberg / Taxonomy_MetaData

WordPress Helper Class for saving pseudo-metadata for taxonomy terms
54 stars 10 forks source link

Ability to set fields shown in 'add-new' section. Should take an array of field ids. #22

Open jtsternberg opened 9 years ago

jtsternberg commented 9 years ago

RE: https://github.com/jtsternberg/Taxonomy_MetaData/issues/19#issuecomment-69948692 I think the easiest way to handle this would be to use a new method on the returned Taxonomy_MetaData object.

$category_metadata = new Taxonomy_MetaData( 'category', array(
    // Term option key
    'sidebar' => array(
        // Option label
        'label'    => __( 'Enable sidebar for this issue', 'taxonomy-metadata' ),
        // Sanitization callback
        'sanitize' => 'parse_boolean',
        // Field type
        'type'     => 'checkbox',
    ),
), __( 'Category Settings', 'taxonomy-metadata' ) /* Settings heading */ );

$category_metadata->set_fields_for_add_new( array( 'sidebar' ) );
jtsternberg commented 9 years ago

get_fields_for_add_new method should probably still return a filtered value.

...
    public function set_fields_for_add_new( $fields ) {
        $this->add_new_fields = $fields;
    }

    public function get_fields_for_add_new() {
        return apply_filters( "taxonomy_metadata_{$this->taxonomy}_add_form_fields", $this->add_new_fields, $this );
    }
...