Inventory_Presser_Plugin::register_meta_fields()

Registers all meta fields our custom post type uses to define a vehicle and its attachments.


Return Return

(void)


Top ↑

Source Source

File: inventory-presser.php

	public function register_meta_fields() {
		// Add meta fields to our post type.
		foreach ( INVP::keys_and_types( true ) as $key_arr ) {
			$key = apply_filters( 'invp_prefix_meta_key', $key_arr['name'] );
			register_post_meta(
				INVP::POST_TYPE,
				$key,
				array(
					'show_in_rest' => true,
					'single'       => true,
					'type'         => $key_arr['type'],
				)
			);
		}

		// Register a meta field for a multi-value options array.
		register_post_meta(
			INVP::POST_TYPE,
			apply_filters( 'invp_prefix_meta_key', 'options_array' ),
			array(
				'show_in_rest' => true,
				'single'       => false,
				'type'         => 'string',
			)
		);

		// Add a couple fields that are used on media attachments.
		$attachment_keys   = array();
		$attachment_keys[] = array(
			'name' => 'hash',
			'type' => 'string',
		);
		$attachment_keys[] = array(
			'name' => 'photo_number',
			'type' => 'integer',
		);
		$attachment_keys[] = array(
			'name' => 'vin',
			'type' => 'string',
		);

		// Add meta fields to attachments.
		foreach ( $attachment_keys as $key_arr ) {
			$key = apply_filters( 'invp_prefix_meta_key', $key_arr['name'] );
			register_post_meta(
				'attachment',
				$key,
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'show_in_rest'      => true,
					'single'            => true,
					'type'              => $key_arr['type'],
				)
			);
		}
	}