Trail status widget
-
Having a hard time trying to find a widget or plugin that will allow my users to easily turn on and off a biking trail when needed. Ive looked at everything from office hours plugins, sport field statuses, and have come up with nothing. All i need is a widget to display a few trails with an open or closed status and an admin side with a toggle switch or radio button to open or close them. Without having to recreate the wheel has anyone seen anything like this or even similar that can be hacked together to work?
-
how many trails are you supporting? If it’s just one, an old plugin called Freelance Status would do the job. It isn’t updated anymore, but it is still compatible with current versions of WP. But it only supports one instance of the plug-in….if you find any other solutions, I would be interested as well. I use it for a travel soccer club, but we have three different fields and I have had to duplicate the plugin three different times with different variables and file names to handle this.
I have found a plugin for my needs to handle as many fields as I need. It does need to be coded specifically to the field names, but if you don’t have many trails and they don’t change, I could customize the code for you pretty quickly.
I hacked something together but I can I take a look at your plugin as well. We only have about 4 trails.
<?php /* Plugin Name: Trail Status Widget Description: Easy trail status update Author: itshanksleft Version: 1.0 */ // Addiing Action hook widgets_init add_action( 'widgets_init', 'trails_widget'); function trails_widget() { register_widget( 'trails_widget_info' ); } class trails_widget_info extends WP_Widget { //Name the widget, here Widget will be displayed as widget name, $widget_ops may be an array of value, which may holds the title, description like that. function trails_widget_info () { $this->WP_Widget('trails_widget_info', 'Trails Widget', $widget_ops ); } //Designing the form widget, which will be displayed in the admin dashboard widget location. public function form( $instance ) { if ( isset( $instance[ 'name' ]) && isset ($instance[ 'status' ]) && isset($instance[ 'comments' ]) ) { $name = $instance[ 'name' ]; $status = $instance[ 'status' ]; $comments = $instance[ 'comments' ]; $name2 = $instance[ 'name2' ]; $status2 = $instance[ 'status2' ]; $comments2 = $instance[ 'comments2' ]; } else { $name = __( '', 'widget_title' ); $status = __( '', 'widget_title' ); $comments = __( '', 'widget_title' ); $name2 = __( '', 'widget_title' ); $status2 = __( '', 'widget_title' ); $comments2 = __( '', 'widget_title' ); } ?> <p>Name: <input name="<?php echo $this->get_field_name( 'name' ); ?>" type="text" value="<?php echo esc_attr( $name );?>" /></p> <p>Status: <input name="<?php echo $this->get_field_name( 'status' ); ?>" type="text" value="<?php echo esc_attr( $status ); ?>" /></p> <p>Comments: <input name="<?php echo $this->get_field_name( 'comments' ); ?>" type="text" value="<?php echo esc_attr( $comments ); ?>" /></p> <p>Name: <input name="<?php echo $this->get_field_name( 'name2' ); ?>" type="text" value="<?php echo esc_attr( $name2 );?>" /></p> <p>Status: <input name="<?php echo $this->get_field_name( 'status2' ); ?>" type="text" value="<?php echo esc_attr( $status2 ); ?>" /></p> <p>Comments: <input name="<?php echo $this->get_field_name( 'comments2' ); ?>" type="text" value="<?php echo esc_attr( $comments2 ); ?>" /></p> <?php } // update the new values in database function update($new_instance, $old_instance) { $instance = $old_instance; $instance['name'] = ( ! empty( $new_instance['name'] ) ) ? strip_tags( $new_instance['name'] ) : ''; $instance['status'] = ( ! empty( $new_instance['status'] ) ) ? strip_tags( $new_instance['status'] ) : ''; $instance['comments'] = ( ! empty( $new_instance['comments'] ) ) ? strip_tags( $new_instance['comments'] ) : ''; $instance['name2'] = ( ! empty( $new_instance['name2'] ) ) ? strip_tags( $new_instance['name2'] ) : ''; $instance['status2'] = ( ! empty( $new_instance['status2'] ) ) ? strip_tags( $new_instance['status2'] ) : ''; $instance['comments2'] = ( ! empty( $new_instance['comments2'] ) ) ? strip_tags( $new_instance['comments2'] ) : ''; return $instance; } //Display the stored widget information in webpage. function widget($args, $instance) { extract($args); echo $before_widget; //Widget starts to print information $name = apply_filters( 'widget_title', $instance['name'] ); $status = empty( $instance['status'] ) ? ' ' : $instance['status']; $comments = empty( $instance['comments'] ) ? ' ' : $instance['comments']; $name2 = apply_filters( 'widget_title', $instance['name2'] ); $status2 = empty( $instance['status2'] ) ? ' ' : $instance['status2']; $comments2 = empty( $instance['comments2'] ) ? ' ' : $instance['comments2']; if ( !empty( $name ) ) { echo $before_title . $name . $after_title; }; echo '<p>Status: ' . $status . '</p>'; echo '<p>' . $comments . '</p>'; echo $before_title . $name2 . $after_title; echo '<p>Status: ' . $status2 . '</p>'; echo '<p>' . $comments2 . '</p>'; echo $after_widget; //Widget ends printing information } }Here is the code:
<?php /** * Plugin Name: FC Bolton Field Status * Original Plugin URI: http://github.com/crindt/wp-field-status * Description: Simple plugin to store FC Bolton Soccer Field Status in wp config variables, customized from Cardiff Soccer Field Status * Version: 0.1 * Author: Antonio Ayala * Original Author: Craig Rindt * Author URI: http://github.com/crindt * License: GPL2 */ add_action('admin_menu', 'field_status_admin_add_page'); function field_status_admin_add_page() { add_options_page('FC Bolton Soccer Field Status Page', 'FC Bolton Soccer Field Status Menu', 'manage_options', 'field_status', 'field_status_options_page'); } function otag($t, $attr = array()) { if ( $t == '' ) return ''; $attrs = ''; foreach( $attr as $attrn => $attrv ) { $attrs = $attrs . ' ' . $attrn . '= "' . $attrv . '"'; } return '<' . $t . $attrs.'>'; } function ctag($t) { if ( $t == '' ) return ''; return '</' . $t . '>'; } function echo_status( $fdata, $fmt ) { $ret = ''; $ret .= otag($fmt['ul']); foreach( $fdata as $skey => $data ) { $ret .= otag($fmt['li'],array("class" => strtolower($data['status']))).ucfirst($skey).': <span class="'.strtolower($data['status']).'">'.$data['status'].'</span><br>'.$data['comment'].''.ctag($fmt['li']); } $ret .= ctag($fmt['ul']); return $ret; } //[field_status] function field_status_shortcode( $atts ){ extract( shortcode_atts( array( 'field' => '', 'fmt' => 'ul' ), $atts ) ); # set up list formatting per user request. fmt=>brian uses <dt> tags. otherwise, we go with <ul> $fmt = array(); switch( $atts['fmt'] ) { case "brian": $fmt['dl'] = 'div'; $fmt['dt'] = 'dl'; $fmt['dd'] = ''; $fmt['ul'] = ''; $fmt['li'] = 'dt'; break; default: // default to a ul $fmt['dl'] = 'dl'; $fmt['dt'] = 'dt'; $fmt['dd'] = 'dd'; $fmt['ul'] = 'ul'; $fmt['li'] = 'li'; } $options = get_option('field_status_options'); $o2 = get_option('field_names'); if ( $atts['field'] == '' ) { # echo all fields $ret .= otag($fmt['dl'],array("class" => "f-wrap")); foreach( $options as $fkey => $val ) { $ret .= otag($fmt['dt']).$o2[$fkey].ctag($fmt['dt']); $ret .= otag($fmt['dd']); $ret .= echo_status($val, $fmt); $ret .= ctag($fmt['dd']); } $ret .= ctag($fmt['dl']); } else { # echo specified field $ret .= echo_status($options[$atts['field']], $fmt); } return $ret; } add_shortcode( 'field_status', 'field_status_shortcode' ); // display the admin options page function field_status_options_page() { echo "<div>"; echo "<h2>FC Bolton Soccer Field Status</h2>"; echo "<form action='options.php' method='post'>"; echo settings_fields('field_status_options'); echo do_settings_sections('field_status'); echo "<input name='Submit' type='submit' value='Save Changes' />"; echo "</form></div>"; } // add the admin settings and such add_action('admin_init', 'field_status_admin_init'); function field_status_admin_init(){ register_setting( 'field_status_options', 'field_status_options', 'field_status_options_validate' ); add_settings_section('field_status_main', 'Field Status', 'field_status_section_text', 'field_status'); add_field_settings('linden',array('Practice'),'Deer Run Soccer Park'); add_field_settings('grandblanc',array('Practice'),'Bicentennial Park'); add_field_settings('clio',array('Practice'),'Clio Area Sports Complex'); # add_settings_field('field_status_linden_practice', 'FC Bolton Premier', 'field_status_linden_practice_bool', 'field_status', 'field_status_main'); # add_settings_field('field_status_grandblanc_practice', 'FC Bolton Premier', 'field_status_grandblanc_practice_bool', 'field_status', 'field_status_main'); # add_settings_field('field_status_clio_practice', 'FC Bolton North', 'field_status_clio_practice_bool', 'field_status', 'field_status_main'); } function add_field_settings($tag, $subs, $name) { $options = get_option('field_status_options'); $o2 = get_option('field_names'); $o2[$tag] = $name; update_option('field_names', $o2); update_option('field_status_options',$options); foreach($subs as $sub) { add_settings_field('field_status_'.$tag.'_'.$sub, $name.' '.$sub,'field_status_'.$tag.'_'.$sub.'_bool','field_status','field_status_main'); } } function field_status_section_text() { echo '<p>Configure fields as open or closed.</p>'; } function field_status_bool($name,$sub,$options) { echo "<div>"; echo "<input type='radio' id='field_status_{$name}_bool' name='field_status_options[".$name."][".$sub."][status]' value='As Scheduled' ".($options[$name][$sub]['status']=='As Scheduled'?'CHECKED':'').">As Scheduled</input>"; echo " "; echo "<input type='radio' id='field_status_{$name}_bool' name='field_status_options[".$name."][".$sub."][status]' value='Cancelled' ".($options[$name][$sub]['status']=='Cancelled'?'CHECKED':'').">Cancelled</input>"; echo "<input id='field_status_{$name}_comment' name='field_status_options[".$name."][".$sub."][comment]' length=40 value='".$options[$name][$sub]["comment"]."'></input>"; echo "</div>"; } function field_status_linden_practice_bool() { $options = get_option('field_status_options'); field_status_bool('linden', 'practice', $options); } function field_status_grandblanc_practice_bool() { $options = get_option('field_status_options'); field_status_bool('grandblanc', 'practice', $options); } function field_status_clio_practice_bool() { $options = get_option('field_status_options'); field_status_bool('clio', 'practice', $options); } // validate our options function field_status_options_validate($input) { return $input; }and this is the needed css:
dl { padding: 10px 10px; background-color: #F1F1F1; margin: 0; font-weight: bold; text-align: center; border-top: 1px solid; border-left: 1px solid; border-right: 1px solid; } dt.as.scheduled { padding: 20px 10px 10px; background: #0d6e00 url(http://www.360bolton.com/wp-content/plugins/freelance-status3/top_arrow.png) no-repeat scroll center top; font-weight: bold; color: #fff; text-transform: uppercase; text-align: center; border-bottom: 1px solid #000; border-left: 1px solid #000; border-right: 1px solid #000; } dt.cancelled { padding: 20px 10px 10px; background: #ff0d00 url(http://www.360bolton.com/wp-content/plugins/freelance-status3/top_arrow.png) no-repeat scroll center top; font-weight: bold; color: #fff; text-transform: uppercase; text-align: center; border-bottom: 1px solid #000; border-left: 1px solid #000; border-right: 1px solid #000; }it can be placed in the page with shortcodes or in a text widget as long as you add the following line to your functions.php file:
add_filter('widget_text', 'do_shortcode');you can see how it looks in both versions by visiting our team page:
http://www.360bolton.com/field-status/Thanks, I was actually playing with the original version of this a few weeks ago. At least you got it to work! Thanks for the code! Did you get an “Warning: Illegal string offset ‘fmt'” error when you tried to add the shortcode to the widget?
no, but you have to go into your functions.php file in your active theme folder and add the
add_filter('widget_text', 'do_shortcode');
line in there to allow for shortcodes to be executed within the standard text widget.What I like is you can add a comment below the status, in case you have extra info you want to share.
The css I posted was to create the look I have, but you can edit those values to create what ever look you would like to have
The topic ‘Trail status widget’ is closed to new replies.