Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions classes/simplemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function location_search_form( $atts ) {
$city_value = isset( $_REQUEST['location_search_city'] ) ? $_REQUEST['location_search_city'] : '';
$state_value = isset( $_REQUEST['location_search_state'] ) ? $_REQUEST['location_search_state'] : '';
$zip_value = get_query_var( 'location_search_zip' );
$country_value = get_query_var( 'location_search_country' );
$country_value = isset( $_REQUEST['location_search_country'] ) ? $_REQUEST['location_search_country'] : $options['default_country'];
$radius_value = isset( $_REQUEST['location_search_distance'] ) ? $_REQUEST['location_search_distance'] : $radius;
$limit_value = isset( $_REQUEST['location_search_limit'] ) ? $_REQUEST['location_search_limit'] : $limit;
$is_sm_search = isset( $_REQUEST['location_is_search_results'] ) ? 1 : 0;
Expand All @@ -246,10 +246,7 @@ function location_search_form( $atts ) {
'label' => apply_filters( 'sm-search-label-zip', __( 'Zip: ', 'simplemap' ), $post ),
'input' => '<input type="text" id="location_search_zip_field" name="location_search_zip" value="' . esc_attr( $zip_value ) . '" />',
);
$ffi['country'] = array(
'label' => apply_filters( 'sm-search-label-country', __( 'Country: ', 'simplemap' ), $post ),
'input' => '<input type="text" id="location_search_country_field" name="location_search_country" value="' . esc_attr( $country_value ) . '" />',
);
$ffi['country'] = $this->add_country_field( $country_value );
$ffi['empty'] = array( 'label' => '', 'input' => '', );
$ffi['submit'] = array(
'label' => '',
Expand Down Expand Up @@ -520,6 +517,28 @@ function add_distance_field( $radius_value, $units ) {

}

/**
* Adds Country field to form.
*
* @param $country_value
*
* @return array
*/
function add_country_field( $country_value ) {
global $post;

$country_input = '<select id="location_search_country_field" name="location_search_country">';
foreach ( $this->get_search_countries() as $key => $value ) {
$country_input .= '<option value="' . $key . '"' . selected( $country_value, $key, false ) . '>' . $value . "</option>\n";
}
$country_input .= '</select>';

return array(
'label' => apply_filters( 'sm-search-label-country', __( 'Country: ', 'simplemap' ), $post ),
'input' => $country_input,
);
}

/**
* Adds taxonomy fields to search form.
*
Expand Down Expand Up @@ -1124,7 +1143,7 @@ function searchLocationsNear(searchData) {
}
?>

var searchUrl = siteurl + '/?sm-xml-search=1&<?php echo $wpmlquery; ?>lat=' + searchData.center.lat() + '&lng=' + searchData.center.lng() + '&radius=' + searchData.radius + '&namequery=' + searchData.homeAddress + '&query_type=' + searchData.query_type + '&limit=' + searchData.limit + <?php echo $js_tax_string; ?>'&address=' + searchData.address + '&city=' + searchData.city + '&state=' + searchData.state + '&zip=' + searchData.zip + '&pid=<?php echo esc_js( absint( $_GET['smpid'] ) ); ?>';
var searchUrl = siteurl + '/?sm-xml-search=1&<?php echo $wpmlquery; ?>lat=' + searchData.center.lat() + '&lng=' + searchData.center.lng() + '&radius=' + searchData.radius + '&namequery=' + searchData.homeAddress + '&query_type=' + searchData.query_type + '&limit=' + searchData.limit + <?php echo $js_tax_string; ?>'&address=' + searchData.address + '&city=' + searchData.city + '&state=' + searchData.state + '&zip=' + searchData.zip + '&country=' + searchData.country + '&pid=<?php echo esc_js( absint( $_GET['smpid'] ) ); ?>';

<?php if ( apply_filters( 'sm-use-updating-image', true ) ) : ?>
// Display Updating Message and hide search results
Expand Down Expand Up @@ -2237,6 +2256,34 @@ function get_language_options() {
return apply_filters( 'sm-language-list', $language_list );
}

/**
* Get the search countries.
*
* Returns the countries that have been populated.
* @return array
*/
function get_search_countries() {
$countries = array();
$all_countries = $this->get_country_options();
$args = array(
'post_type' => 'sm-location',
'post_status' => 'publish',
'posts_per_page' => '-1',
);
$locations = get_posts( $args );

foreach ( $locations as $key => $location ) {
$country_code = get_post_meta( $location->ID, 'location_country', true );
if ( ! isset( $countries[ $country_code ] ) ) {
$countries[ $country_code ] = $all_countries[ $country_code ];
}
}

asort($countries);

return $countries;
}

/**
* Get auto locate options.
*
Expand Down Expand Up @@ -2364,6 +2411,7 @@ function register_query_vars( $vars ) {
$vars[] = 'location_search_city';
$vars[] = 'location_search_state';
$vars[] = 'location_search_zip';
$vars[] = 'location_search_country';
$vars[] = 'location_search_distance';
$vars[] = 'location_search_limit';
$vars[] = 'location_is_search_results';
Expand Down Expand Up @@ -2529,7 +2577,7 @@ function get_default_shortcode_atts() {
'search_title' => __( 'Find Locations Near:', 'simplemap' ),
'search_form_type' => 'table',
'search_form_cols' => 3,
'search_fields' => 'labelbr_street||labelbr_city||labelbr_state||labelbr_zip||empty||empty||labeltd_distance||empty' . implode( '', $tax_search_fields ) . '||submit||empty||empty',
'search_fields' => 'labelbr_street||labelbr_city||labelbr_state||labelbr_zip||labelbr_country||empty||empty||labeltd_distance||empty' . implode( '', $tax_search_fields ) . '||submit||empty||empty',
'taxonomy_field_type' => 'checkboxes',
'hide_search' => '',
'hide_map' => 0,
Expand Down
18 changes: 18 additions & 0 deletions classes/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function widget( $args, $instance ) {
$show_city = $instance['show_city'];
$show_state = $instance['show_state'];
$show_zip = $instance['show_zip'];
$show_country = $instance['show_country'];
$show_distance = $instance['show_distance'];

$default_lat = $instance['default_lat'];
Expand Down Expand Up @@ -85,6 +86,7 @@ public function widget( $args, $instance ) {
$city_value = isset( $_REQUEST['location_search_city'] ) ? $_REQUEST['location_search_city'] : '';
$state_value = isset( $_REQUEST['location_search_state'] ) ? $_REQUEST['location_search_state'] : '';
$zip_value = isset( $_REQUEST['location_search_zip'] ) ? $_REQUEST['location_search_zip'] : '';
$country_value = isset( $_REQUEST['location_search_country'] ) ? $_REQUEST['location_search_country'] : $options['default_country'];
$radius_value = isset( $_REQUEST['location_search_distance'] ) ? $_REQUEST['location_search_distance'] : $options['default_radius'];
$limit_value = isset( $_REQUEST['location_search_limit'] ) ? $_REQUEST['location_search_limit'] : $options['results_limit'];

Expand Down Expand Up @@ -115,6 +117,15 @@ public function widget( $args, $instance ) {
if ( $show_zip ) {
$location_search .= '<tr><td class="location_search_widget_zip_cell location_search_widget_cell">' . apply_filters( 'sm-search-label-zip', __( 'Zip', 'simplemap' ) ) . ':<br /><input type="text" id="location_search_widget_zip_field" name="location_search_zip" /></td></tr>';
}
if ( $show_country ) {
$location_search .= '<tr><td class="location_search_widget_country_cell location_search_widget_cell">' . apply_filters( 'sm-search-label-country', __( 'Country', 'simplemap' ) ) . ':<br /><select id="location_search_widget_country_field" name="location_search_country">';

foreach ( $simple_map->get_search_countries() as $key => $value ) {
$location_search .= '<option value="' . $key . '"' . selected( $country_value, $key, false ) . '>' . $value . "</option>\n";
}

$location_search .= '</select></td></tr>';
}
if ( $show_distance ) {
$location_search .= '<tr><td class="location_search_widget_distance_cell location_search_widget_cell">' . apply_filters( 'sm-search-label-distance', __( 'Select a distance', 'simplemap' ) ) . ':<br /><select id="location_search_widget_distance_field" name="location_search_distance" >';

Expand Down Expand Up @@ -228,6 +239,7 @@ public function form( $instance ) {
$show_city = $instance['show_city'];
$show_state = $instance['show_state'];
$show_zip = $instance['show_zip'];
$show_country = $instance['show_country'];
$show_distance = $instance['show_distance'];
$default_lat = ! empty( $instance['default_lat'] ) ? esc_attr( $instance['default_lat'] ) : 0;
$default_lng = ! empty( $instance['default_lng'] ) ? esc_attr( $instance['default_lng'] ) : 0;
Expand Down Expand Up @@ -259,6 +271,11 @@ public function form( $instance ) {
<label
for="<?php echo $this->get_field_id( 'show_zip' ); ?>"><?php _e( 'Show Zip', 'simplemap' ); ?></label><br/>

<input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_country' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'show_country' ) ); ?>"<?php checked( $show_country ); ?> />
<label
for="<?php echo $this->get_field_id( 'show_country' ); ?>"><?php _e( 'Show Country', 'simplemap' ); ?></label><br/>

<input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_distance' ) ); ?>"
name="<?php echo $this->get_field_name( 'show_distance' ); ?>"<?php checked( $show_distance ); ?> />
<label
Expand Down Expand Up @@ -328,6 +345,7 @@ private function set_instance( $instance, $old_instance = array() ) {
'show_city' => false,
'show_state' => false,
'show_zip' => false,
'show_country' => false,
'show_distance' => false,
'default_lat' => 0,
'default_lng' => 0,
Expand Down