Inventory_Presser_WP_All_Import::detect_delimited_options( mixed $post_id, mixed $meta_key, mixed $meta_value )

If the value being saved to the meta key inventory_presser_options_array contains pipe-delimited or comma-delimited values, split the string and add each option individually.


Parameters Parameters

$post_id

(mixed) (Required) ID of the post whose meta was updated.

$meta_key

(mixed) (Required) The meta key that has been updated.

$meta_value

(mixed) (Required) The new meta value.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/integrations/class-wp-all-import.php

	public function detect_delimited_options( $post_id, $meta_key, $meta_value ) {
		// Is it a vehicle?
		if ( ! class_exists( 'INVP' ) || INVP::POST_TYPE !== get_post_type( $post_id ) ) {
			// No.
			return;
		}

		if ( apply_filters( 'invp_prefix_meta_key', 'options_array' ) !== $meta_key ) {
			return;
		}

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

		// Are there lots of commas or pipes in the value?
		$delimiters = array(
			'|' => substr_count( $meta_value ?? '', '|' ),
			',' => substr_count( $meta_value ?? '', ',' ),
			';' => substr_count( $meta_value ?? '', ';' ),
		);
		$delimiters = array_filter(
			$delimiters,
			function ( $value ) {
				return $value > 1;
			}
		);

		if ( empty( $delimiters ) ) {
			// No.
			return;
		}

		$found_delimiter = array_search( max( $delimiters ), $delimiters, true );
		if ( false === $found_delimiter ) {
			// No.
			return;
		}

		// Repeating delimiter found. Erase the current value.
		delete_post_meta( $post_id, $meta_key );

		// Add each option individually, options_array is a multi-meta value.
		foreach ( array_filter( explode( $found_delimiter, $meta_value ) ) as $option ) {
			if ( '' === trim( $option ) ) {
				continue;
			}
			add_post_meta( $post_id, $meta_key, trim( $option ) );
		}
	}