ControlledChaos of Controlled Chaos Design
7/20/2017 - 4:32 PM

Return an array of rules for use with register_field_group() 'location' key

Return an array of rules for use with register_field_group() 'location' key

<?php
/**
* @func acfw_location_rules
* Return an array of rules for use with register_field_group() 'location' key
* @param array $a
* @param str $param
* @param str $operator
* @param bool $extended
*/
function acfw_location_rules( array $a, $param, $op, $extended = false ){
	$return = array();
	foreach ($a as $b){
		$push = array(
			'param' => $param,
			'operator' => $op,
			'value' => $b
		);
		if ($extended){
			// wrap it to denote an "OR"
			$push = array($push);
		}
		$return[] = $push;
	}
	if (! $extended){
		// wrap it so we don't have to
		$return = array($return);	
	}
	return $return;
}