wordpress/wp-content/themes/basic/themify/themify-metabox/includes/themify-term-fields.php
/**
	 * Save custom fields when a term is edited
	 */
Save custom fields when a term is edited
Save custom fields when a term is edited
function save_fields( $term_id, $taxonomy_term_id, $taxonomy ) {
		$fields = $this->get_fields( $taxonomy );
		if ( empty( $fields ) ) {
			return false;
		}
		foreach ( $fields as $field ) {
			if ( isset( $_POST[ $field['name'] ] ) ) {
				$new_meta = isset( $field['name'] ) && isset( $_POST[ $field['name'] ] ) ? $_POST[ $field['name'] ] : '';
				$old_meta = get_term_meta( $term_id, $field['name'], true );
				if( isset( $field['default'] ) && $new_meta == $field['default'] ) {
					$new_meta = '';
				}
				if ( '' == $new_meta && metadata_exists( 'term', $term_id, $field['name'] ) ) {
					delete_term_meta( $term_id, $field['name'] );
				}
				if ( $new_meta !== '' && $new_meta != $old_meta ) {
					update_term_meta( $term_id, $field['name'], $new_meta );
				}
			}
		}
	}
function save_fields ( $ term_id , $ taxonomy_term_id , $ taxonomy ) { $ fields = $ this -> get_fields ( $ taxonomy ) ; if ( empty ( $ fields ) ) { return false ; } foreach ( $ fields as $ field ) { if ( isset ( $ _POST [ $ field [ 'name' ] ] ) ) { $ new_meta = isset ( $ field [ 'name' ] ) && isset ( $ _POST [ $ field [ 'name' ] ] ) ? $ _POST [ $ field [ 'name' ] ] : '' ; $ old_meta = get_term_meta ( $ term_id , $ field [ 'name' ] , true ) ; if ( isset ( $ field [ 'default' ] ) && $ new_meta == $ field [ 'default' ] ) { $ new_meta = '' ; } if ( '' == $ new_meta && metadata_exists ( 'term' , $ term_id , $ field [ 'name' ] ) ) { delete_term_meta ( $ term_id , $ field [ 'name' ] ) ; } if ( $ new_meta !== '' && $ new_meta != $ old_meta ) { update_term_meta ( $ term_id , $ field [ 'name' ] , $ new_meta ) ; } } } }
Save custom fields when a term is edited
Save custom fields when a term is edited
// when a default value is set for the field and it's the same as $new_meta, do not bother with saving the field // remove empty meta fields from database