public function __construct($regions, $options)
 {
     // we need at least one region, even if its empty
     if (empty($regions)) {
         $this->regions = array(array('country' => '', 'county' => '', 'state' => '', 'city' => ''));
     } else {
         $this->regions = $regions;
     }
     $this->options = wp_parse_args($options, array('maxRegions' => 1, 'showTextField' => false, 'showExistingRegionsOnly' => get_awpcp_option('buildsearchdropdownlists'), 'hierarchy' => array('country', 'county', 'state', 'city'), 'enabled_fields' => awpcp_get_enabled_region_fields()));
     $this->options['maxRegions'] = max($this->options['maxRegions'], count($regions));
 }
Пример #2
0
/**
 * @since 3.0.2
 */
function awpcp_default_region_fields($context = 'details', $enabled_fields = null)
{
    $enabled_fields = is_null($enabled_fields) ? awpcp_get_enabled_region_fields() : $enabled_fields;
    $show_city_field_before_county_field = get_awpcp_option('show-city-field-before-county-field');
    $always_shown = in_array($context, array('details', 'search'));
    $can_be_required = $context !== 'search';
    $_fields = array();
    if ($enabled_fields['country']) {
        $required = $can_be_required && (bool) get_awpcp_option('displaycountryfieldreqop');
        $_fields['country'] = array('type' => 'country', 'label' => __('Country', 'AWPCP') . ($required ? '*' : ''), 'help' => __('separate countries by commas', 'AWPCP'), 'required' => $required, 'alwaysShown' => $always_shown);
    }
    if ($enabled_fields['state']) {
        $required = $can_be_required && (bool) get_awpcp_option('displaystatefieldreqop');
        $_fields['state'] = array('type' => 'state', 'label' => __('State/Province', 'AWPCP') . ($required ? '*' : ''), 'help' => __('separate states by commas', 'AWPCP'), 'required' => $required, 'alwaysShown' => $always_shown);
    }
    if ($enabled_fields['city']) {
        $required = $can_be_required && (bool) get_awpcp_option('displaycityfieldreqop');
        $_fields['city'] = array('type' => 'city', 'label' => __('City', 'AWPCP') . ($required ? '*' : ''), 'help' => __('separate cities by commas', 'AWPCP'), 'required' => $required, 'alwaysShown' => $always_shown);
    }
    if ($enabled_fields['county']) {
        $required = $can_be_required && (bool) get_awpcp_option('displaycountyvillagefieldreqop');
        $_fields['county'] = array('type' => 'county', 'label' => __('County/Village/Other', 'AWPCP') . ($required ? '*' : ''), 'help' => __('separate counties by commas', 'AWPCP'), 'required' => $required, 'alwaysShown' => $always_shown);
    }
    if (!$show_city_field_before_county_field) {
        $fields = array();
        foreach (array('country', 'state', 'county', 'city') as $field) {
            if (isset($_fields[$field])) {
                $fields[$field] = $_fields[$field];
            }
        }
    } else {
        $fields = $_fields;
    }
    return $fields;
}