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)

$meta_key

(mixed) (Required)

$meta_value

(mixed) (Required)


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 ) {
		if ( ! class_exists( 'INVP' ) || INVP::POST_TYPE !== get_post_type( $post_id ) ) {
			return;
		}

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

		// Are there lots of commas or pipes in the value?
		$pipe_count  = substr_count( $meta_value ?? '', '|' );
		$comma_count = substr_count( $meta_value ?? '', ',' );
		if ( $pipe_count + $comma_count < 2 ) {
			// No.
			return;
		}
		$delimiter = $pipe_count > $comma_count ? '|' : ',';

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

		// Add each option individually, options_array is a multi-meta value.
		foreach ( explode( $delimiter, $meta_value ) as $option ) {
			add_post_meta( $post_id, $meta_key, $option );
		}
	}