'category', 'data_type' => 'serialize', 'class' => '', 'enqueue_webfont' => true, 'async_webfont' => false, 'output_css' => true, 'defaults' => array(), ); // run taxonomy construct public function __construct( $key, $params ) { $this->unique = $key; $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this ); $this->sections = apply_filters( "csf_{$this->unique}_sections", $params['sections'], $this ); $this->taxonomies = ( is_array( $this->args['taxonomy'] ) ) ? $this->args['taxonomy'] : array_filter( (array) $this->args['taxonomy'] ); $this->taxonomy = ( ! empty( $_REQUEST[ 'taxonomy' ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ 'taxonomy' ] ) ) : ''; $this->pre_fields = $this->pre_fields( $this->sections ); if ( ! empty( $this->taxonomies ) && in_array( $this->taxonomy, $this->taxonomies ) ) { add_action( 'admin_init', array( &$this, 'add_taxonomy_options' ) ); } // wp enqeueu for typography and output css parent::__construct(); } // instance public static function instance( $key, $params ) { return new self( $key, $params ); } public function pre_fields( $sections ) { $result = array(); foreach ( $sections as $key => $section ) { if ( ! empty( $section['fields'] ) ) { foreach ( $section['fields'] as $field ) { $result[] = $field; } } } return $result; } // add taxonomy add/edit fields public function add_taxonomy_options() { add_action( $this->taxonomy .'_add_form_fields', array( &$this, 'render_taxonomy_form_fields' ) ); add_action( $this->taxonomy .'_edit_form', array( &$this, 'render_taxonomy_form_fields' ) ); add_action( 'created_'. $this->taxonomy, array( &$this, 'save_taxonomy' ) ); add_action( 'edited_'. $this->taxonomy, array( &$this, 'save_taxonomy' ) ); } // get default value public function get_default( $field ) { $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default; return $default; } // get meta value public function get_meta_value( $field, $term_id = null ) { $value = null; $term_id = ( ! isset( $term_id ) ) ? get_queried_object_id() : $term_id; if ( ! empty( $term_id ) && ! empty( $field['id'] ) ) { if ( $this->args['data_type'] !== 'serialize' ) { $meta = get_term_meta( $term_id, $field['id'] ); $value = ( isset( $meta[0] ) ) ? $meta[0] : null; } else { $meta = get_term_meta( $term_id, $this->unique, true ); $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null; } } $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : ''; $value = ( isset( $value ) ) ? $value : $default; return $value; } // render taxonomy add/edit form fields public function render_taxonomy_form_fields( $term ) { $is_term = ( is_object( $term ) && isset( $term->taxonomy ) ) ? true : false; $term_id = ( $is_term ) ? $term->term_id : 0; $taxonomy = ( $is_term ) ? $term->taxonomy : $term; $classname = ( $is_term ) ? 'edit' : 'add'; $errors = ( ! empty( $term_id ) ) ? get_term_meta( $term_id, '_csf_errors_'. $this->unique, true ) : array(); $errors = ( ! empty( $errors ) ) ? $errors : array(); $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : ''; if ( ! empty( $errors ) ) { delete_term_meta( $term_id, '_csf_errors_'. $this->unique ); } wp_nonce_field( 'csf_taxonomy_nonce', 'csf_taxonomy_nonce'. $this->unique ); echo '