function mcs_check() { global $wpdb, $mcs_version; $mcdb = $wpdb; $current_version = get_option('mcs_version'); // If current version matches, don't bother running this. if ($current_version == $mcs_version) { return true; } // Lets see if this is first run and create a table if it is! // Assume this is not a new install until we prove otherwise $new_install = false; $my_calendar_exists = false; $upgrade_path = array(); $tables = $mcdb->get_results("show tables;"); foreach ($tables as $table) { foreach ($table as $value) { if ($value == MY_CALENDAR_PAYMENTS_TABLE) { $my_calendar_exists = true; // check whether installed version matches most recent version, establish upgrade process. } } } if ($my_calendar_exists == false) { $new_install = true; } else { // for each release requiring an upgrade path, add a version compare. // at this time, there are no upgrades available. } // having determined upgrade path, assign new version number update_option('mcs_version', $mcs_version); // Now we've determined what the current install is or isn't if ($new_install == true) { mcs_default_settings(); } else { if (version_compare($current_version, "1.1.1", "<")) { $upgrade_path[] = "1.1.1"; } if (version_compare($current_version, "1.5.8", "<")) { $upgrade_path[] = "1.5.8"; } } // switch for different upgrade paths foreach ($upgrade_path as $upgrade) { switch ($upgrade) { case '1.1.1': mcs_update_database(); break; case '1.5.8': delete_option('mcs-parsed-files'); delete_option('mcs-number-of-files'); delete_option('mcs-delimiter'); delete_option("mcs_parsing_now_0"); delete_option("mcs_parsing_now_1"); delete_option("mcs_parsing_now_2"); delete_option("mcs_parsing_now_3"); delete_option("mcs_parsing_now_4"); delete_option("mcs_parsing_now_5"); delete_option("mcs_parsing_now_6"); break; } } }
function form($instance) { mcs_check(); $options = get_option('mcs_options'); $fields = $options['fields']; $location_fields = $options['location_fields']; if (empty($fields)) { $options = mcs_default_settings(false); $fields = $options['fields']; $location_fields = $options['location_fields']; } $defaults = $options['widget_defaults']; $widget_title = !empty($instance['title']) ? esc_attr($instance['title']) : $defaults['title']; if (!empty($instance)) { $widget_fields = empty($instance['fields']) ? $fields : $instance['fields']; } else { $widget_fields = $fields; } if (!empty($instance)) { $widget_location_fields = empty($instance['location_fields']) ? $location_fields : $instance['location_fields']; } else { $widget_location_fields = $location_fields; } $widget_categories = !empty($instance['categories']) ? esc_attr($instance['categories']) : ''; $widget_category = !empty($instance['category']) ? esc_attr($instance['category']) : ''; $widget_locations = !empty($instance['locations']) ? esc_attr($instance['locations']) : ''; $widget_location = !empty($instance['location']) ? esc_attr($instance['location']) : ''; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Widget Title', 'my-calendar-submissions'); ?> :</label><br /> <input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " value="<?php esc_attr_e($widget_title); ?> "/> </p> <fieldset> <legend><strong><?php _e('Included Fields', 'my-calendar-submissions'); ?> </strong></legend> <ul> <li><?php _e('Event Title (required)', 'my-calendar-submissions'); ?> </li> <li><?php _e('Date/Time (required)', 'my-calendar-submissions'); ?> </li> <li><?php _e('Name', 'my-calendar-submissions'); ?> </li> <li><?php _e('Email (required)', 'my-calendar-submissions'); ?> </li> <?php $checked = " checked='checked'"; // can select: each field to require (title and date must be included) if (is_array($fields)) { foreach ($fields as $key => $value) { $check = in_array($value, $widget_fields) ? $checked : ''; $title = mcs_get_field_name($key, $value); echo "<li><input type='checkbox' name='" . $this->get_field_name('fields') . "[{$key}]' id='" . $this->get_field_id('title') . "mc_{$key}' value='{$value}'{$check} /> <label for='" . $this->get_field_id('title') . "mc_{$key}'>" . esc_html($title) . "</label></li>\n"; } } ?> </ul> </fieldset> <fieldset> <legend><strong><?php _e('Categories', 'my-calendar-submissions'); ?> </strong></legend> <p> <input type="checkbox" name="<?php echo $this->get_field_name('categories'); ?> " id="<?php echo $this->get_field_name('categories'); ?> " value="true"<?php echo $widget_categories == 'true' ? $checked : ''; ?> > <label for="<?php echo $this->get_field_name('categories'); ?> "><?php _e('Include list of categories', 'my-calendar-submissions'); ?> </label> </p> <p> <select name="<?php echo $this->get_field_name('category'); ?> " id="<?php echo $this->get_field_name('category'); ?> "> <?php echo mc_category_select($widget_category); ?> </select> <label for="<?php echo $this->get_field_name('category'); ?> "><?php _e('Default category', 'my-calendar-submissions'); ?> </label> </p> </fieldset> <fieldset> <legend><strong><?php _e('Locations', 'my-calendar-submissions'); ?> </strong></legend> <ul> <li><input type="radio" name="<?php echo $this->get_field_name('locations'); ?> " id="<?php echo $this->get_field_id('locations'); ?> choose" value="choose"<?php echo $widget_locations == 'choose' ? $checked : ''; ?> > <label for="<?php echo $this->get_field_id('locations'); ?> choose"><?php _e('Can choose a location', 'my-calendar-submissions'); ?> </label></li> <li><input type="radio" name="<?php echo $this->get_field_name('locations'); ?> " id="<?php echo $this->get_field_id('locations'); ?> either" value="either"<?php echo $widget_locations == 'either' ? $checked : ''; ?> > <label for="<?php echo $this->get_field_id('locations'); ?> either"><?php _e('Can enter or choose a location', 'my-calendar-submissions'); ?> </label></li> <li><input type="radio" name="<?php echo $this->get_field_name('locations'); ?> " id="<?php echo $this->get_field_id('locations'); ?> enter" value="enter"<?php echo $widget_locations == 'enter' ? $checked : ''; ?> > <label for="<?php echo $this->get_field_id('locations'); ?> enter"><?php _e('Can enter a location', 'my-calendar-submissions'); ?> </label></li> <li><input type="radio" name="<?php echo $this->get_field_name('locations'); ?> " id="<?php echo $this->get_field_id('locations'); ?> neither" value="neither"<?php echo $widget_locations == 'neither' ? $checked : ''; ?> > <label for="<?php echo $this->get_field_id('locations'); ?> neither"><?php _e('None of the above', 'my-calendar-submissions'); ?> </label></li> </ul> <p> <label for="<?php echo $this->get_field_name('location'); ?> "><?php _e('Default location', 'my-calendar-submissions'); ?> </label> <select name="<?php echo $this->get_field_name('location'); ?> " id="<?php echo $this->get_field_name('location'); ?> "> <option value=''><?php _e('None', 'my-calendar-submissions'); ?> </option> <?php echo mc_location_select($widget_location); ?> </select> </p> </fieldset> <fieldset> <legend><strong><?php _e('Included Location Fields', 'my-calendar-submissions'); ?> </strong></legend> <ul> <li><?php _e('Location Label (required)', 'my-calendar-submissions'); ?> </li> <?php // can select: each field to require (label must be included) if (is_array($location_fields)) { foreach ($location_fields as $key => $value) { $check = in_array($value, $widget_location_fields) ? $checked : ''; $title = mcs_get_field_name($key, $value); echo "<li><input type='checkbox' name='" . $this->get_field_name('location_fields') . "[{$key}]' id='" . $this->get_field_id('location_fields') . "mc_{$key}' value='{$value}'{$check} /> <label for='" . $this->get_field_id('location_fields') . "mc_{$key}'>" . esc_html($title) . "</label></li>\n"; } } ?> </ul> </fieldset> <?php }