Inventory_Presser_Admin_Location_Meta::save_location_meta( int $term_id, int $tt_id )
save_location_meta
Contents
Description Description
When a location term is saved, put all of the values in the right term meta fields.
Parameters Parameters
- $term_id
-
(int) (Required)
- $tt_id
-
(int) (Required)
Return Return
(void)
Source Source
File: includes/admin/class-admin-location-meta.php
public function save_location_meta( $term_id, $tt_id ) { // Street address pieces $keys = array( 'address_street', 'address_street_line_two', 'address_city', 'address_state', 'address_zip', ); foreach ( $keys as $key ) { if ( ! empty( $_POST[ $key ] ) ) { update_term_meta( $term_id, $key, sanitize_text_field( $_POST[ $key ] ) ); } } /** * Now that the street address has been updated, repopulate the term * description based on these pieces in term meta so the full street * address in the term description always matches the pieces of the * address. */ $this->update_location_term_description( $term_id ); // HOURS if ( ! empty( $_POST['hours_title'] ) ) { $hours_count = sizeof( $_POST['hours_title'] ) - 1; for ( $i = 0; $i <= $hours_count; $i++ ) { // if this is an update, carry the id through $uid = ''; if ( isset( $_POST['hours_uid'][ $i ] ) ) { $uid = sanitize_text_field( $_POST['hours_uid'][ $i ] ); } else { // generate a unique id for these hours $uid = $this->generate_location_uid( $term_id . '_hours_' . $i ); } update_term_meta( $term_id, 'hours_' . strval( $i + 1 ) . '_uid', $uid ); // title of hours set update_term_meta( $term_id, 'hours_' . strval( $i + 1 ) . '_title', sanitize_text_field( $_POST['hours_title'][ $i ] ) ); foreach ( array_keys( INVP::weekdays() ) as $d => $day ) { update_term_meta( $term_id, 'hours_' . strval( $i + 1 ) . '_' . $day . '_appt', sanitize_text_field( $_POST['hours'][ $d ]['appt'][ $i ] ) ); update_term_meta( $term_id, 'hours_' . strval( $i + 1 ) . '_' . $day . '_open', sanitize_text_field( $_POST['hours'][ $d ]['open'][ $i ] ) ); update_term_meta( $term_id, 'hours_' . strval( $i + 1 ) . '_' . $day . '_close', sanitize_text_field( $_POST['hours'][ $d ]['close'][ $i ] ) ); } } // delete hours in slots higher than we just filled or deletes are not possible for ( $h = $hours_count + 1; $h < INVP::LOCATION_MAX_HOURS; $h++ ) { delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_uid' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_title' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_sunday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_sunday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_sunday_close' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_saturday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_saturday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_saturday_close' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_friday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_friday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_friday_close' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_thursday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_thursday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_thursday_close' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_wednesday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_wednesday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_wednesday_close' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_tuesday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_tuesday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_tuesday_close' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_monday_appt' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_monday_open' ); delete_term_meta( $term_id, 'hours_' . strval( $h ) . '_monday_close' ); } } // PHONE NUMBERS if ( ! empty( $_POST['phone_number'] ) ) { $phones_count = 0; foreach ( $_POST['phone_number'] as $i => $phone_number ) { $phone_number = sanitize_text_field( $phone_number ); if ( empty( $phone_number ) ) { continue; } update_term_meta( $term_id, 'phone_' . strval( $i + 1 ) . '_number', $phone_number ); update_term_meta( $term_id, 'phone_' . strval( $i + 1 ) . '_description', sanitize_text_field( $_POST['phone_description'][ $i ] ) ); // if this is an update, carry the id through $uid = ''; if ( isset( $_POST['phone_uid'][ $i ] ) ) { $uid = sanitize_text_field( $_POST['phone_uid'][ $i ] ); } else { // generate a unique id for this phone number $uid = $this->generate_location_uid( $term_id . '_phone_' . $i ); } update_term_meta( $term_id, 'phone_' . strval( $i + 1 ) . '_uid', $uid ); $phones_count++; } // delete phones in slots higher than we just filled or deletes are not possible for ( $p = $phones_count + 1; $p < INVP::LOCATION_MAX_PHONES; $p++ ) { delete_term_meta( $term_id, 'phone_' . strval( $p ) . '_uid' ); delete_term_meta( $term_id, 'phone_' . strval( $p ) . '_description' ); delete_term_meta( $term_id, 'phone_' . strval( $p ) . '_number' ); } } }
Expand full source code Collapse full source code View on Github