/** * Get the default plugin settings. * * @since 1.0.0 * @return void */ function wpsl_get_default_settings() { $default_settings = array('api_key' => '', 'api_language' => 'en', 'api_region' => '', 'api_geocode_component' => 0, 'distance_unit' => 'km', 'max_results' => '[25],50,75,100', 'search_radius' => '10,25,[50],100,200,500', 'marker_effect' => 'bounce', 'address_format' => 'city_state_zip', 'hide_distance' => 0, 'auto_locate' => 1, 'autoload' => 1, 'autoload_limit' => 50, 'zoom_level' => 3, 'auto_zoom_level' => 15, 'zoom_name' => '', 'zoom_latlng' => '', 'height' => 350, 'map_type' => 'roadmap', 'map_style' => '', 'type_control' => 0, 'streetview' => 0, 'results_dropdown' => 1, 'radius_dropdown' => 1, 'category_dropdown' => 0, 'infowindow_width' => 225, 'search_width' => 179, 'label_width' => 95, 'control_position' => 'left', 'scrollwheel' => 1, 'marker_clusters' => 0, 'cluster_zoom' => 0, 'cluster_size' => 0, 'new_window' => 0, 'reset_map' => 0, 'template_id' => 'default', 'listing_below_no_scroll' => 0, 'direction_redirect' => 0, 'more_info' => 0, 'store_url' => 0, 'phone_url' => 0, 'marker_streetview' => 0, 'marker_zoom_to' => 0, 'more_info_location' => 'info window', 'mouse_focus' => 1, 'start_marker' => 'red.png', 'store_marker' => 'blue.png', 'editor_country' => '', 'editor_hours' => wpsl_default_opening_hours(), 'editor_hour_input' => 'dropdown', 'editor_hour_format' => 12, 'editor_map_type' => 'roadmap', 'hide_hours' => 0, 'permalinks' => 0, 'permalink_slug' => __('stores', 'wpsl'), 'category_slug' => __('store-category', 'wpsl'), 'infowindow_style' => 'default', 'show_credits' => 0, 'debug' => 0, 'start_label' => __('Start location', 'wpsl'), 'search_label' => __('Your location', 'wpsl'), 'search_btn_label' => __('Search', 'wpsl'), 'preloader_label' => __('Searching...', 'wpsl'), 'radius_label' => __('Search radius', 'wpsl'), 'no_results_label' => __('No results found', 'wpsl'), 'results_label' => __('Results', 'wpsl'), 'more_label' => __('More info', 'wpsl'), 'directions_label' => __('Directions', 'wpsl'), 'no_directions_label' => __('No route could be found between the origin and destination', 'wpsl'), 'back_label' => __('Back', 'wpsl'), 'street_view_label' => __('Street view', 'wpsl'), 'zoom_here_label' => __('Zoom here', 'wpsl'), 'error_label' => __('Something went wrong, please try again!', 'wpsl'), 'limit_label' => __('API usage limit reached', 'wpsl'), 'phone_label' => __('Phone', 'wpsl'), 'fax_label' => __('Fax', 'wpsl'), 'email_label' => __('Email', 'wpsl'), 'url_label' => __('Url', 'wpsl'), 'hours_label' => __('Hours', 'wpsl'), 'category_label' => __('Category filter', 'wpsl')); return $default_settings; }
/** * If the db doesn't hold the current version, run the upgrade procedure * * @since 1.2 * @return void */ function wpsl_check_upgrade() { global $wpsl_settings; $current_version = get_option('wpsl_version'); if (version_compare($current_version, WPSL_VERSION_NUM, '===')) { return; } if (version_compare($current_version, '1.1', '<')) { if (is_array($wpsl_settings)) { /* Add the default value for the reset map option */ if (empty($wpsl_settings['reset_map'])) { $wpsl_settings['reset_map'] = 0; } /* Add the default value for the way the store listings are shown, either below or next to the map */ if (empty($wpsl_settings['auto_load'])) { $wpsl_settings['auto_load'] = 1; } /* Add the default value for the route redirect */ if (empty($wpsl_settings['new_window'])) { $wpsl_settings['new_window'] = 0; } update_option('wpsl_settings', $wpsl_settings); } } if (version_compare($current_version, '1.2', '<')) { if (is_array($wpsl_settings)) { /* Add the default value for the way the store listings are shown, either below or next to the map */ if (empty($wpsl_settings['store_below'])) { $wpsl_settings['store_below'] = 0; } /* Add the default value for the route redirect */ if (empty($wpsl_settings['direction_redirect'])) { $wpsl_settings['direction_redirect'] = 0; } update_option('wpsl_settings', $wpsl_settings); } } if (version_compare($current_version, '1.2.11', '<')) { if (is_array($wpsl_settings)) { /* Add the default value for the 'more info' link option */ if (empty($wpsl_settings['more_info'])) { $wpsl_settings['more_info'] = 0; } /* Add the default value for the 'more info' label */ if (empty($wpsl_settings['more_label'])) { $wpsl_settings['more_label'] = __('More info', 'wpsl'); } /* Add the default value mouse focus option */ if (empty($wpsl_settings['mouse_focus'])) { $wpsl_settings['mouse_focus'] = 1; } update_option('wpsl_settings', $wpsl_settings); } } if (version_compare($current_version, '1.2.12', '<')) { if (is_array($wpsl_settings)) { /* Add the default value for the 'more info link' link option */ if (empty($wpsl_settings['more_info_location'])) { $wpsl_settings['more_info_location'] = __('info window', 'wpsl'); } /* Add the default value for the back label */ if (empty($wpsl_settings['back_label'])) { $wpsl_settings['back_label'] = __('Back', 'wpsl'); } /* Add the default value for the reset label */ if (empty($wpsl_settings['reset_label'])) { $wpsl_settings['reset_label'] = __('Reset', 'wpsl'); } /* Add the default value for removing the scroll bar when the store listing is shown below the map */ if (empty($wpsl_settings['store_below_scroll'])) { $wpsl_settings['store_below_scroll'] = 0; } update_option('wpsl_settings', $wpsl_settings); } } if (version_compare($current_version, '1.2.20', '<')) { global $wpdb; $wpsl_table = $wpdb->prefix . 'wpsl_stores'; /* Rename the street field to address */ $wpdb->query("ALTER TABLE {$wpsl_table} CHANGE street address VARCHAR(255)"); /* Add the second address field */ $wpdb->query("ALTER TABLE {$wpsl_table} ADD address2 VARCHAR(255) NULL AFTER address"); if (is_array($wpsl_settings)) { if (empty($wpsl_settings['store_url'])) { $wpsl_settings['store_url'] = 0; } if (empty($wpsl_settings['phone_url'])) { $wpsl_settings['phone_url'] = 0; } if (empty($wpsl_settings['marker_clusters'])) { $wpsl_settings['marker_clusters'] = 0; } if (empty($wpsl_settings['cluster_zoom'])) { $wpsl_settings['cluster_zoom'] = 0; } if (empty($wpsl_settings['cluster_size'])) { $wpsl_settings['cluster_size'] = 0; } if (empty($wpsl_settings['template_id'])) { $wpsl_settings['template_id'] = $wpsl_settings['store_below'] ? 1 : 0; unset($wpsl_settings['store_below']); } if (empty($wpsl_settings['marker_streetview'])) { $wpsl_settings['marker_streetview'] = 0; } if (empty($wpsl_settings['marker_zoom_to'])) { $wpsl_settings['marker_zoom_to'] = 0; } if (!isset($wpsl_settings['editor_country'])) { $wpsl_settings['editor_country'] = ''; } if (empty($wpsl_settings['street_view_label'])) { $wpsl_settings['street_view_label'] = __('Street view', 'wpsl'); } if (empty($wpsl_settings['zoom_here_label'])) { $wpsl_settings['zoom_here_label'] = __('Zoom here', 'wpsl'); } if (empty($wpsl_settings['no_directions_label'])) { $wpsl_settings['no_directions_label'] = __('No route could be found between the origin and destination', 'wpsl'); } update_option('wpsl_settings', $wpsl_settings); } } if (version_compare($current_version, '2.0', '<')) { global $wpdb; $wpsl_table = $wpdb->prefix . 'wpsl_stores'; if (is_array($wpsl_settings)) { if (empty($wpsl_settings['radius_dropdown'])) { $wpsl_settings['radius_dropdown'] = 1; } if (empty($wpsl_settings['permalinks'])) { $wpsl_settings['permalinks'] = 0; } if (empty($wpsl_settings['permalink_slug'])) { $wpsl_settings['permalink_slug'] = __('stores', 'wpsl'); } if (empty($wpsl_settings['category_slug'])) { $wpsl_settings['category_slug'] = __('store-category', 'wpsl'); } if (empty($wpsl_settings['editor_hours'])) { $wpsl_settings['editor_hours'] = wpsl_default_opening_hours(); } if (empty($wpsl_settings['editor_hour_format'])) { $wpsl_settings['editor_hour_format'] = 12; } if (empty($wpsl_settings['editor_map_type'])) { $wpsl_settings['editor_map_type'] = 'roadmap'; } if (empty($wpsl_settings['infowindow_style'])) { $wpsl_settings['infowindow_style'] = 'default'; } if (empty($wpsl_settings['email_label'])) { $wpsl_settings['email_label'] = __('Email', 'wpsl'); } if (empty($wpsl_settings['url_label'])) { $wpsl_settings['url_label'] = __('Url', 'wpsl'); } if (empty($wpsl_settings['category_label'])) { $wpsl_settings['category_label'] = __('Category filter', 'wpsl'); } if (empty($wpsl_settings['show_credits'])) { $wpsl_settings['show_credits'] = 0; } if (empty($wpsl_settings['autoload_limit'])) { $wpsl_settings['autoload_limit'] = 50; } if (empty($wpsl_settings['scrollwheel'])) { $wpsl_settings['scrollwheel'] = 1; } if (empty($wpsl_settings['type_control'])) { $wpsl_settings['type_control'] = 0; } if (empty($wpsl_settings['hide_hours'])) { $wpsl_settings['hide_hours'] = 0; } /* Either correct the existing map style format from the 2.0 beta or set it to empty */ if (isset($wpsl_settings['map_style']) && is_array($wpsl_settings['map_style']) && isset($wpsl_settings['map_style']['id'])) { switch ($wpsl_settings['map_style']['id']) { case 'custom': $map_style = $wpsl_settings['map_style']['custom_json']; break; case 'default': $map_style = ''; break; default: $map_style = $wpsl_settings['map_style']['theme_json']; break; } $wpsl_settings['map_style'] = $map_style; } else { $wpsl_settings['map_style'] = ''; } if (empty($wpsl_settings['autoload'])) { $wpsl_settings['autoload'] = $wpsl_settings['auto_load']; unset($wpsl_settings['auto_load']); } if (empty($wpsl_settings['address_format'])) { $wpsl_settings['address_format'] = 'city_state_zip'; } if (empty($wpsl_settings['auto_zoom_level'])) { $wpsl_settings['auto_zoom_level'] = 15; } if (empty($wpsl_settings['hide_distance'])) { $wpsl_settings['hide_distance'] = 0; } if (empty($wpsl_settings['debug'])) { $wpsl_settings['debug'] = 0; } if (empty($wpsl_settings['category_dropdown'])) { $wpsl_settings['category_dropdown'] = 0; } /* Replace marker_bounce with marker_effect to better reflect what the option contains. * * If a user hovers over the result list then either the corresponding marker will bounce, * the info window will open, or nothing will happen. * * The default behaviour is that the marker will bounce. */ if (empty($wpsl_settings['marker_effect'])) { $wpsl_settings['marker_effect'] = $wpsl_settings['marker_bounce'] ? 'bounce' : 'ignore'; unset($wpsl_settings['marker_bounce']); } /* The default input for the opening hours is set to textarea for current users, * for new users it will be set to dropdown ( easier to format in a table output and to use with schema.org in the future ). */ if (empty($wpsl_settings['editor_hour_input'])) { $wpsl_settings['editor_hour_input'] = 'textarea'; } /* Rename store_below_scroll to listing_below_no_scroll, it better reflects what it does */ if (empty($wpsl_settings['listing_below_no_scroll']) && isset($wpsl_settings['store_below_scroll'])) { $wpsl_settings['listing_below_no_scroll'] = $wpsl_settings['store_below_scroll']; unset($wpsl_settings['store_below_scroll']); } /* Change the template ids from number based to name based */ if (is_numeric($wpsl_settings['template_id'])) { $wpsl_settings['template_id'] = !$wpsl_settings['template_id'] ? 'default' : 'below_map'; } $replace_data = array('max_results' => $wpsl_settings['max_results'], 'search_radius' => $wpsl_settings['search_radius']); /* Replace the () with [], this fixes an issue with the mod_security module that is installed on some servers. * It triggerd a 'Possible SQL injection attack' warning probably because of the int,(int) format of the data. */ foreach ($replace_data as $index => $option_value) { $wpsl_settings[$index] = str_replace(array('(', ')'), array('[', ']'), $option_value); } /* The reset button now uses an icon instead of text, so no need for the label anymore */ unset($wpsl_settings['reset_label']); update_option('wpsl_settings', $wpsl_settings); /* Users upgrading from 1.x will be given the choice between the textarea or * dropdowns for the opening hours. * * New users don't get that choice, they will only get the dropdowns. * * The wpsl_legacy_support option is used to determine if we need to show both options. */ update_option('wpsl_legacy_support', 1); /* Add the WPSL roles and caps */ wpsl_add_roles(); wpsl_add_caps(); /* If there is a wpsl_stores table, then we need to convert all the locations to the 'wpsl_stores' custom post type */ if ($wpdb->get_var("SHOW TABLES LIKE '{$wpsl_table}'") && version_compare($current_version, '1.9', '<')) { if (wpsl_remaining_cpt_count()) { update_option('wpsl_convert_cpt', 'in_progress'); } } } } /* * Both map options are no longer supported in 3.22 of the Google Maps API. * See: https://developers.google.com/maps/articles/v322-controls-diff */ if (version_compare($current_version, '2.0.3', '<')) { unset($wpsl_settings['control_style']); unset($wpsl_settings['pan_controls']); update_option('wpsl_settings', $wpsl_settings); } if (version_compare($current_version, '2.1.0', '<')) { if (empty($wpsl_settings['api_geocode_component'])) { $wpsl_settings['api_geocode_component'] = 0; } update_option('wpsl_settings', $wpsl_settings); } update_option('wpsl_version', WPSL_VERSION_NUM); }