Created
April 11, 2012 21:38
-
-
Save justinwhall/2362880 to your computer and use it in GitHub Desktop.
PHP: WordPress | ex Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example_Widget extends WP_Widget { | |
/** | |
* Widget setup. | |
*/ | |
function Example_Widget() { | |
/* Widget settings. */ | |
$widget_ops = array( 'classname' => 'sidebar-menu', 'description' => __('Displays a menu in the side bar of "Review Us", "Welcome Packet" and "Patient Forms".', 'example') ); | |
/* Widget control settings. */ | |
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' ); | |
/* Create the widget. */ | |
$this->WP_Widget( 'example-widget', __('Dental Health Sidebar Menu', 'example'), $widget_ops, $control_ops ); | |
} | |
/** | |
* How to display the widget on the screen. | |
*/ | |
function widget( $args, $instance ) { | |
extract( $args ); | |
/* Our variables from the widget settings. */ | |
//$title = apply_filters('widget_title', $instance['title'] ); | |
// $review = $instance['review']; | |
// $reviewTitle = $instance['reviewTitle']; | |
$welcome = $instance['welcome']; | |
$welcomeTitle = $instance['welcomeTitle']; | |
$patient = $instance['patient']; | |
$patientTitle = $instance['patientTitle']; | |
$promo = $instance['promo']; | |
$promoTitle = $instance['promoTitle']; | |
$menu4 = $instance['menu4']; | |
$menu4Title = $instance['menu4Title']; | |
/* Before widget (defined by themes). */ | |
echo $before_widget . '<div id="jwh-menu">'; | |
/* Display name from widget settings if one was input. */ | |
if ( $patient ) | |
printf( '<a class="aside-buttons" id="promo" href="%1$s">%2$s</a>', $promo, $promoTitle); | |
// if ( $review ) | |
// printf( '<a class="aside-buttons" id="review" href="%1$s">%2$s</a>', $review, $reviewTitle ); | |
if ( $welcome ) | |
printf( '<a class="aside-buttons" id="welcome" href="%1$s">%2$s</a>', $welcome, $welcomeTitle ); | |
if ( $patient ) | |
printf( '<a class="aside-buttons" id="patient" href="%1$s">%2$s</a>', $patient, $patientTitle); | |
if ( $menu4 ) | |
printf( '<a class="aside-buttons" id="menu4" href="%1$s">%2$s</a>', $menu4, $menu4Title); | |
/* After widget (defined by themes). */ | |
echo $after_widget . '</div>'; | |
} | |
/** | |
* Update the widget settings. | |
*/ | |
function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
/* Strip tags for title and name to remove HTML (important for text inputs). */ | |
$instance['review'] = strip_tags( $new_instance['review'] ); | |
$instance['reviewTitle'] = strip_tags( $new_instance['reviewTitle'] ); | |
$instance['welcome'] = strip_tags( $new_instance['welcome'] ); | |
$instance['patient'] = strip_tags( $new_instance['patient'] ); | |
$instance['welcomeTitle'] = strip_tags( $new_instance['welcomeTitle'] ); | |
$instance['patientTitle'] = strip_tags( $new_instance['patientTitle'] ); | |
$instance['promoTitle'] = strip_tags( $new_instance['promoTitle'] ); | |
$instance['promo'] = strip_tags( $new_instance['promo'] ); | |
$instance['menu4Title'] = strip_tags( $new_instance['menu4Title'] ); | |
$instance['menu4'] = strip_tags( $new_instance['menu4'] ); | |
return $instance; | |
} | |
/** | |
* Displays the widget settings controls on the widget panel. | |
* Make use of the get_field_id() and get_field_name() function | |
* when creating your form elements. This handles the confusing stuff. | |
*/ | |
function form( $instance ) { | |
/* Set up some default widget settings. */ | |
$defaults = array('review' => 'http://www.example.com','welcome' => 'http://www.example.com','patient' => 'http://www.example.com'); | |
$instance = wp_parse_args( (array) $instance, $defaults ); ?> | |
<p> | |
Enter (Copy and Paste) the URLS to the pages you'd like the following menu items to link to. | |
</p> | |
<!-- welcome --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'welcomeTitle' ); ?>"><?php _e('Menu Title:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'welcomeTitle' ); ?>" name="<?php echo $this->get_field_name( 'welcomeTitle' ); ?>" value="<?php echo $instance['welcomeTitle']; ?>" style="width:100%;" /> | |
<label for="<?php echo $this->get_field_id( 'welcome' ); ?>"><?php _e('URL:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'welcome' ); ?>" name="<?php echo $this->get_field_name( 'welcome' ); ?>" value="<?php echo $instance['welcome']; ?>" style="width:100%;" /> | |
</p> | |
<!-- patient forms --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'patientTitle' ); ?>"><?php _e('Menu Title:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'patientTitle' ); ?>" name="<?php echo $this->get_field_name( 'patientTitle' ); ?>" value="<?php echo $instance['patientTitle']; ?>" style="width:100%;" /> | |
<label for="<?php echo $this->get_field_id( 'patient' ); ?>"><?php _e('URL:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'patient' ); ?>" name="<?php echo $this->get_field_name( 'patient' ); ?>" value="<?php echo $instance['patient']; ?>" style="width:100%;" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'promoTitle' ); ?>"><?php _e('Menu Title:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'promoTitle' ); ?>" name="<?php echo $this->get_field_name( 'promoTitle' ); ?>" value="<?php echo $instance['promoTitle']; ?>" style="width:100%;" /> | |
<label for="<?php echo $this->get_field_id( 'promo' ); ?>"><?php _e('URL:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'promo' ); ?>" name="<?php echo $this->get_field_name( 'promo' ); ?>" value="<?php echo $instance['promo']; ?>" style="width:100%;" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'menu4Title' ); ?>"><?php _e('Menu Title:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'menu4Title' ); ?>" name="<?php echo $this->get_field_name( 'menu4Title' ); ?>" value="<?php echo $instance['menu4Title']; ?>" style="width:100%;" /> | |
<label for="<?php echo $this->get_field_id( 'menu4' ); ?>"><?php _e('URL:', 'example'); ?></label> | |
<input id="<?php echo $this->get_field_id( 'menu4' ); ?>" name="<?php echo $this->get_field_name( 'menu4' ); ?>" value="<?php echo $instance['menu4']; ?>" style="width:100%;" /> | |
</p> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment