public function display_fields($field)
        {
            extract($field);
            // Prepare country dropdowns
            if ($key == 'focus_country') {
                $country_html = '';
                $country_codes = LocationsSearchGeneric::get_country_codes();
                foreach ($country_codes as $country_code => $country_name) {
                    $country_html .= sprintf('<option value="%s"%s>%s</option>', $country_code, selected($value, $country_code, false), $country_name);
                }
            }
            // Output fields
            switch ($field['key']) {
                case 'google_api_key':
                    printf('
						<input id="%s" type="text" name="%s" class="large-text" value="%s">
						<p class="description"><a href="https://developers.google.com/maps/documentation/javascript/get-api-key#get-an-api-key" target="_blank">Generate a Google Maps Javascript API key</a> and enter it here.</p>
						', esc_attr($id), esc_attr($name), esc_attr($value));
                    break;
                case 'permalinks_base':
                    printf('
						<input id="%s" type="text" name="%s" class="regular-text" value="%s">
						<p class="description">Text to be used as a base for creating the urls for each location, e.g: ' . home_url('/') . '<strong>locations</strong>/location-name/</p>
						', esc_attr($id), esc_attr($name), esc_attr($value));
                    break;
                case 'permalinks_category':
                    printf('
						<input id="%s" type="text" name="%s" class="regular-text" value="%s">
						<p class="description">Text to be used to create the urls for each category, e.g: ' . home_url('/') . '<strong>locations-category</strong>/category-name/</p>
						', esc_attr($id), esc_attr($name), esc_attr($value));
                    break;
                case 'focus_country':
                    printf('
						<select id="%s" name="%s">
							<option value="">- Select a country -</option>
							%s
						</select>
						<p class="description">If you want to focus the map on a single country, select it here.</p>
						', esc_attr($id), esc_attr($name), $country_html);
                    break;
                case 'focus_country_strict':
                    printf('
						<label>
							<input type="radio" name="%1$s" value=""%2$s>
							Bias
						</label>
						&nbsp;
						<label>
							<input type="radio" name="%1$s" value="1"%3$s>
							Restrict
						</label>
						<p class="description">Select <strong>bias</strong> to give preference to the Focus Country on the map but still allow other countries to be displayed, or select <strong>restrict</strong> to strictly restrict the map only on the Focus Country.</p>
						', esc_attr($name), checked(false, $value, false), checked(true, $value, false));
                    break;
                case 'map_styles':
                    printf('
						<textarea id="%s" name="%s" class="large-text" rows="10">%s</textarea>
						<p class="description">Use this <a href="https://mapstyle.withgoogle.com/" target="_blank">tool to generate custom map styles</a> and paste the JSON code here.</p>
						', esc_attr($id), esc_attr($name), esc_textarea($value));
                    break;
                case 'map_marker':
                    $description = 'Select an image to be used to create the markers on the map.';
                case 'map_marker_active':
                    if (!isset($description)) {
                        $description = 'You can use a different image to represent active markers (when a user clicks on a specific location).';
                    }
                case 'map_cluster':
                    if (!isset($description)) {
                        $description = 'Image to be used when creating clusters (if they are enabled).';
                    }
                    printf('
						<div class="lsmediaupload" data-frame-title="%s" data-frame-button-text="%s">
							<div class="lsmediaupload__preview">
								%s
							</div>
							<input type="hidden" class="lsmediaupload__field" id="%s" name="%s" value="%s">
							<input type="button" class="lsmediaupload__upload button" value="%s" data-label-replace="%s">
							<input type="button" class="lsmediaupload__reset button hidden" value="%s">
						</div>
						<p class="description">%s</p>
						', 'Select an image', 'Use this image', wp_get_attachment_image(absint($value), 'medium'), esc_attr($id), esc_attr($name), esc_attr($value), 'Select File', 'Replace File', 'Remove File', $description);
                    break;
            }
        }
예제 #2
0
        public function display_text($post, $meta_key)
        {
            // Init vars
            $label = isset($this->meta_fields[$meta_key]['label']) ? $this->meta_fields[$meta_key]['label'] : $meta_key;
            $meta_value = get_post_meta($post->ID, $meta_key, true);
            // Default country
            if ($meta_key == 'country' && empty($meta_value)) {
                $meta_value = LocationsSearchGeneric::get_country_name(LocationsSearchSettings::get('focus_country'));
            }
            // Output
            printf('
				<div class="lsedit__column">
					<div class="field-box %1$s_%2$s-box">
						<label for="%1$s_%2$s">%3$s</label>
						<input type="text" id="%1$s_%2$s" name="%2$s" value="%4$s" size="25">
					</div>
				</div>', $this->box_id, $meta_key, $label, esc_attr($meta_value));
        }
 public static function get_formatted_address($post)
 {
     $meta_keys = array('address', 'address2', 'suburb', 'state', 'postcode', 'country');
     foreach ($meta_keys as $meta_key) {
         ${$meta_key} = trim(esc_html(get_post_meta($post->ID, $meta_key, true)));
     }
     $focus_country = LocationsSearchGeneric::get_country_name(LocationsSearchSettings::get('focus_country'));
     if ($country == $focus_country) {
         $country = '';
     }
     $address_line_1 = $address;
     $address_line_2 = $address2;
     $address_line_3 = implode(', ', array_filter(array($suburb, $state, $postcode, $country)));
     $formatted_address = implode('<br>', array_filter(array($address_line_1, $address_line_2, $address_line_3)));
     return $formatted_address;
 }