Inventory_Presser_Admin_Location_Meta::update_location_term_description( int $term_id )

Updates the term description with an address built from the term meta values so the meta pieces and the description string match.


Parameters Parameters

$term_id

(int) (Required) Term ID.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/admin/class-admin-location-meta.php

	protected function update_location_term_description( $term_id ) {
		$line_one   = '';
		$line_two   = '';
		$line_three = '';
		$meta       = get_term_meta( $term_id );
		if ( ! empty( $meta['address_street'][0] ) ) {
			$line_one .= $meta['address_street'][0];
		}
		if ( ! empty( $meta['address_street_line_two'][0] ) ) {
			$line_two .= $meta['address_street_line_two'][0];
		}
		if ( ! empty( $meta['address_city'][0] ) ) {
			$line_three .= $meta['address_city'][0];
		}
		if ( ! empty( $meta['address_state'][0] ) ) {
			$line_three .= ', ' . $meta['address_state'][0];
		}
		if ( ! empty( $meta['address_zip'][0] ) ) {
			$line_three .= ' ' . $meta['address_zip'][0];
		}
		$term = get_term( $term_id );
		if ( empty( $term ) || is_wp_error( $term ) ) {
			return;
		}

		/**
		 * This method is called from save_location_meta, which is hooked to
		 * location_edited. Remove that hook or else an infinite loop happens.
		 */
		remove_action( 'edited_location', array( $this, 'save_location_meta' ), 10, 1 );
		wp_update_term(
			$term->term_id,
			$term->taxonomy,
			array(
				'description' => trim( $line_one . "\n" . trim( $line_two . "\n" . $line_three ) ),
			)
		);
		add_action( 'edited_location', array( $this, 'save_location_meta' ), 10, 1 );
	}