Astra_Target_Rules_Fields::get_format_rule_value( array $save_data, string $key )

Formated rule meta value to save.


Description


Parameters

$save_data

(array) (Required) PostData.

$key

(string) (Required) varaible key.


Return

(array) Rule data.


Source

File: classes/modules/target-rule/class-astra-target-rules-fields.php

		public static function get_format_rule_value( $save_data, $key ) {
			$meta_value = array();

			if ( isset( $save_data[ $key ]['rule'] ) ) {
				$save_data[ $key ]['rule'] = array_unique( $save_data[ $key ]['rule'] );
				if ( isset( $save_data[ $key ]['specific'] ) ) {
					$save_data[ $key ]['specific'] = array_unique( $save_data[ $key ]['specific'] );
				}

				// Unset the specifics from rule. This will be readded conditionally in next condition.
				$index = array_search( '', $save_data[ $key ]['rule'] );
				if ( false !== $index ) {
					unset( $save_data[ $key ]['rule'][ $index ] );
				}
				$index = array_search( 'specifics', $save_data[ $key ]['rule'] );
				if ( false !== $index ) {
					unset( $save_data[ $key ]['rule'][ $index ] );

					// Only re-add the specifics key if there are specific rules added.
					if ( isset( $save_data[ $key ]['specific'] ) && is_array( $save_data[ $key ]['specific'] ) ) {
						array_push( $save_data[ $key ]['rule'], 'specifics' );
					}
				}

				foreach ( $save_data[ $key ] as $meta_key => $value ) {
					if ( ! empty( $value ) ) {
						$meta_value[ $meta_key ] = array_map( 'esc_attr', $value );
					}
				}
				if ( ! isset( $meta_value['rule'] ) || ! in_array( 'specifics', $meta_value['rule'] ) ) {
					$meta_value['specific'] = array();
				}

				if ( empty( $meta_value['rule'] ) ) {
					$meta_value = array();
				}
			}

			return $meta_value;
		}

Changelog

Changelog
Version Description
1.0.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.