itshanksleft
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: Trail status widgetThanks, 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?
Forum: Plugins
In reply to: Trail status widgetI 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 } }
Viewing 2 replies - 1 through 2 (of 2 total)