function mcs_generate_fields() { $standard_fields = array('event_title', 'event_date', 'event_time', 'end_date', 'end_time', 'mcs_name', 'mcs_email', 'event_host', 'event_recurring', 'description', 'short_description', 'access', 'event_link', 'event_image', 'registration'); $output = "<table class='widefat wp-list-table'><caption>" . __('Event Field Settings', 'my-calendar-submissions') . "</caption><thead><tr><th>" . __('Enable Field', 'my-calendar-submissions') . "</th><th>" . __('Label', 'my-calendar-submissions') . "</th></tr></thead><tbody>"; foreach ($standard_fields as $field) { $field_title = ucfirst(str_replace('_', ' ', str_replace(array('event_', 'mcs_'), '', $field))); if ($field == 'event_recurring' || $field == 'registration') { $disabled = 'disabled="disabled" placeholder="Custom Label Not available"'; } else { $disabled = ''; } if ($field == 'event_title' || $field == 'event_date' || $field == 'event_time' || $field == 'mcs_name' || $field == 'mcs_email') { $required = "<input type='hidden' value='on' name='fields[{$field}][active]' id='{$field}' />(" . __('Required', 'my-calendar-submissions') . ")"; } else { $required = "<input type='checkbox' value='on' name='fields[{$field}][active]' id='{$field}' />"; } $output .= "<tr><td>{$required} <label for='{$field}'>{$field_title}</label></td><td><label class='screen-reader-text' for='label_{$field}'>" . sprintf(__('%s label', 'my-calendar-submissions'), $field_title) . "</label> <input {$disabled} type='text' name='fields[{$field}][label]' id='label_{$field}' /></td></tr>"; } $output .= "</tbody></table>"; $output .= "<p><input type='checkbox' name='categories' id='categories' value='on' /> <label for='categories'>" . __('Enable Category Dropdown', 'my-calendar-submissions') . "</label></p>"; $output .= "<p><label for='category'>" . __('Select default category', 'my-calendar-submissions') . "</label> <select name='category' id='category'>" . mc_category_select() . "</select></p>"; $output .= "<p><label for='locations'>" . __('Enable Location Options', 'my-calendar-submissions') . "</label> \n\t\t<select name='locations' id='locations'>\n\t\t\t<option value='none'>" . __('User cannot enter locations', 'my-calendar-submissions') . "</option>\n\t\t\t<option value='choose'>" . __('User can choose locations from a dropdown', 'my-calendar-submissions') . "</option>\n\t\t\t<option value='enter'>" . __('User can enter new locations', 'my-calendar-submissions') . "</option>\n\t\t\t<option value='either'>" . __('User can either enter new locations or select an existing location', 'my-calendar-submissions') . "</option>\n\t\t</select>\n\t\t</p>"; $output .= "<p><label for='location'>" . __('Select default location', 'my-calendar-submissions') . "</label> <select name='location' id='location'>" . mc_location_select() . "</select></p>"; $location_fields = array('event_label', 'street', 'street2', 'phone', 'city', 'state', 'zip', 'region', 'country', 'url', 'gps'); $output .= "<table class='widefat wp-list-table'><caption>" . __('Location Field Settings', 'my-calendar-submissions') . "</caption><thead><tr><th>" . __('Enable Location Field', 'my-calendar-submissions') . "</th><th>" . __('Label', 'my-calendar-submissions') . "</th></tr></thead><tbody>"; foreach ($location_fields as $field) { $field_title = ucfirst(str_replace('_', ' ', str_replace(array('event_', 'mcs_'), '', $field))); if ($field == 'event_gps') { $disabled = 'disabled="disabled" placeholder="Custom Label Not available"'; } else { $disabled = ''; } $output .= "<tr><td><input type='checkbox' value='on' name='location_fields[{$field}][active]' id='{$field}' /> <label for='{$field}'>{$field_title}</label></td><td><label class='screen-reader-text' for='label_{$field}'>" . sprintf(__('%s label', 'my-calendar-submissions'), $field_title) . "</label> <input {$disabled} type='text' name='location_fields[{$field}][label]' id='label_{$field}' /></td></tr>"; } $output .= "</tbody></table>"; return $output; }
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 }