Example #1
0
/**
 * Install the required data.
 *
 * @since 1.2.20
 * @return void
 */
function wpsl_install_data()
{
    global $wpsl;
    // Register the post type and flush the permalinks.
    $wpsl->post_types->register_post_types();
    flush_rewrite_rules();
    // Create the default settings.
    wpsl_set_default_settings();
    // Set the correct version.
    update_option('wpsl_version', WPSL_VERSION_NUM);
    // Add user roles.
    wpsl_add_roles();
    // Add user capabilities.
    wpsl_add_caps();
}
Example #2
0
/**
 * 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);
}