Inventory_Presser_Customize_Dashboard::save_vehicle_post_meta( int $post_id, WP_Post $post, bool $is_update )

save_vehicle_post_meta


Description Description

Saves vehicle attributes into their corresponding post meta fields when the Save or Update button is clicked in the editor.


Top ↑

Parameters Parameters

$post_id

(int) (Required)

$post

(WP_Post) (Required)

$is_update

(bool) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-customize-admin-dashboard.php

	function save_vehicle_post_meta( $post_id, $post, $is_update )
	{
		/**
		 * Do not continue if the post is being moved to the trash or if this is
		 * an auto-draft.
		 */
		if( in_array( $post->post_status, array( 'trash', 'auto-draft' ) ) )
		{
			return;
		}

		//Abort if autosave or AJAX/quick edit
		if( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
			|| ( defined('DOING_AJAX') && DOING_AJAX ) )
		{
			return;
		}

		//is this a vehicle?
		if( ! empty( $_POST['post_type'] ) && INVP::POST_TYPE != $_POST['post_type'] )
		{
			//no, don't create any meta data for vehicles
			return;
		}

		if( empty( $_POST ) )
		{
			return;
		}

		/**
		 * Tick the last modified date of this vehicle since we're saving changes.
		 * It looks like this: Tue, 06 Sep 2016 09:26:12 -0400
		 */
		$offset = sprintf( '%+03d00', intval( get_option('gmt_offset') ) );
		update_post_meta( $post_id, apply_filters( 'invp_prefix_meta_key', 'last_modified' ), current_time( 'D, d M Y h:i:s' ) . ' ' . $offset );

		//Clear this value that is defined by a checkbox
		update_post_meta( $post_id, apply_filters( 'invp_prefix_meta_key', 'featured' ), '0' );

		/**
		 * Loop over the post meta keys we manage and save their values
		 * if we find them coming over as part of the post to save.
		 */
		$keys = INVP::keys();
		$keys[] = 'options_array';

		foreach( $keys as $key )
		{
			$key = apply_filters( 'invp_prefix_meta_key', $key );
			if ( isset( $_POST[$key] ) )
			{
				if( is_array( $_POST[$key] ) )
				{
					//delete all meta, this is essentially for the options
					delete_post_meta( $post->ID, $key );
					$options = array(); //collect the options to maintain a CSV field for backwards compatibility

					foreach( $this->sanitize_array( $_POST[$key] ) as $value )
					{
						add_post_meta( $post->ID, $key, $value );
						if( 'inventory_presser_options_array' == $key )
						{
							$options[] = $value;
						}
					}
				}
				else
				{
					//string data
					update_post_meta( $post->ID, $key, sanitize_text_field( $_POST[$key] ) );
				}
				
			}
		}
	}