Created
August 11, 2016 18:21
-
-
Save anonymous/8825a298114eeb23c9f607337eb4ec12 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/* | |
Plugin Name: 1337 Date Picker | |
Plugin URI: http://1337datepicker.e1337geek.com | |
Description: A brief description of the Plugin. | |
Version: 1.0 | |
Author: e1337geek | |
Author URI: http://e1337geek.com | |
License: GPL2 | |
*/ | |
add_action( 'widgets_init', 'datepicker_load' ); /* Add our function to the widgets_init hook. */ | |
add_action( 'wp_enqueue_scripts', 'datepickerwidget_enqueue_scripts'); | |
add_action( 'admin_enqueue_scripts', 'datepickerwidget_enqueue_scripts'); | |
function datepicker_load() { register_widget( 'datepickerwidget' ); } /* Function that registers our widget. */ | |
function datepickerwidget_enqueue_scripts() { | |
wp_enqueue_script('jquery-ui-datepicker'); | |
wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); | |
} | |
class datepickerwidget extends WP_Widget { | |
function datepickerwidget() { | |
$widget_ops = array( 'classname' => 'datepickerwidget', 'description' => 'date picker widget' ); /* Widget settings. */ | |
$control_ops = array( 'id_base' => 'datepickerwidget' ); /* Widget control settings. */ | |
$this->WP_Widget( 'datepickerwidget', 'Date Picker Widget', $widget_ops, $control_ops ); /* Create the widget. */ | |
} | |
function widget( $args, $instance ) { | |
extract( $args ); | |
echo $before_widget; /* Before widget (defined by themes). */ | |
if ( $instance['title'] ) echo $before_title . $instance['title'] . $after_title; /* Title of widget (before and after defined by themes). */ | |
echo '<ul>'; | |
foreach($instance as $name=>$value) { | |
if ($name == 'title') continue; | |
echo '<li>' . $name . ': ' . $value . '</li>'; | |
} | |
echo '</ul>'; | |
echo $after_widget; /* After widget (defined by themes). */ | |
} | |
function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
foreach($new_instance as $k=>$v) { $instance[$k] = strip_tags($v); } /* Strip tags (if needed) and update the widget settings. */ | |
return $instance; | |
} | |
function form( $instance ) { | |
/* Set up some default widget settings. */ | |
$defaults = array('title' => 'Date Selector', 'datemask' => 'MM-DD-YYYY', 'defaultdate' => '01-01-2016'); | |
$instance = wp_parse_args( (array) $instance, $defaults ); | |
$datemask = ""; | |
foreach($instance as $name=>$value) { | |
if ($name == 'datemask') { | |
$datemask = $value; | |
} | |
} | |
echo '<p><label for="'.$this->get_field_id( 'title' ).'">'. 'Title'.'</label><br /> | |
<input type="text" id="'. $this->get_field_id( 'title' ).'" name="'.$this->get_field_name( 'title' ).'" value="'.$instance['title'].'" /></p>'; | |
echo '<p><label for="'.$this->get_field_id( 'datemask' ).'">'. 'Date Format'.'</label><br /> | |
<input type="text" id="'. $this->get_field_id( 'datemask' ).'" name="'.$this->get_field_name( 'datemask' ).'" value="'.$instance['datemask'].'" /></p>'; | |
echo '<p><label for="'.$this->get_field_id( 'defaultdate' ).'">'. 'Default Date'.'</label><br /> | |
<input type="text" class="datefield" id="'. $this->get_field_id( 'defaultdate' ).'" name="'.$this->get_field_name( 'defaultdate' ).'" value="'.$instance['defaultdate'].'" /> | |
<script type="text/javascript">jQuery(document).ready(function() {jQuery(\'.datefield\').datepicker({dateFormat : \''. $datemask .'\'});});</script><br /> | |
('.$datemask.')</p>'; | |
} //end function | |
} //end class | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment