class wss_assignments_datepicker {
var $plugin_dir;
var $plugin_url;
function __construct() {
$this->plugin_dir = WP_PLUGIN_DIR . "/wss-assignments";
$this->plugin_url = WP_PLUGIN_URL . "/wss-assignments";
add_action( 'admin_print_styles', array($this, 'wss_assignments_add_stylesheets') );
add_action( 'admin_enqueue_scripts', array($this, 'wss_assignments_add_js') );
add_action( 'add_meta_boxes', array( $this, 'wss_assignments_datepicker_metabox') );
add_action( 'admin_head', array($this, 'wss_assignments_call_js') );
add_action( 'save_post', array($this, 'wss_assignments_save_data') );
}
function wss_assignments_add_stylesheets() {
global $post;
$styleFile = $this->plugin_dir . "/css/jquery-ui.custom.css";
$styleFileURL = $this->plugin_url . "/css/jquery-ui.custom.css";
if( file_exists($styleFile) && $post->post_type == 'wss-assignments') {
wp_register_style('wss_assignments_datepicker_css', $this->plugin_url . "/css/jquery-ui.custom.css");
wp_enqueue_style( 'wss_assignments_datepicker_css' );
}
}
function wss_assignments_add_js() {
global $post;
$jsFile = $this->plugin_dir . "/js/jquery-ui.custom.min.js";
$jsFileURL = $this->plugin_url . "/js/jquery-ui.custom.min.js";
if( file_exists($jsFile) && $post->post_type == 'wss-assignments') {
wp_register_script('wss_datepicker-js', $this->plugin_url . "/js/jquery-ui.custom.min.js");
wp_enqueue_script('wss_datepicker-js');
}
}
function wss_assignments_call_js() {
global $post;
if( $post->post_type == 'wss-assignments') {
echo '<script>
jQuery(document).ready(function() {
jQuery( "#wss-datepicker-field" ).datepicker();
});
</script>';
}
}
function wss_assignments_datepicker_metabox() {
add_meta_box(
'wss_assignments_dp_mb',
'Assignment Due Date',
array( &$this, 'wss_assignments_datepicker_metabox_content'),
'wss_assignments', 'side', 'high'
);
}
function wss_assignments_datepicker_metabox_content() {
global $post;
// Use nonce for verification
wp_nonce_field( plugin_basename(__FILE__), 'wss_assignments_dp_nonce');
// The actual fields for date entry
echo '
<input type="text" id="wss-datepicker-field" name="wss-datepicker-field"
value="' . get_post_meta($post->ID, '_wss_assignments_duedate', true) . '" size="20">';
}
function wss_assignments_save_data( $post_ID ) {
if( defined( 'DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if( !wp_verify_nonce( $_POST['wss_assignments_dp_nonce'], plugin_basename(__FILE__)))
return;
// Check for permission to post
if( 'page' == $_POST['post_type']) {
if( !current_user_can( 'edit_page', $post_ID) )
return;
} else {
if( !current_user_can( 'edit_post', $post_ID) )
return;
}
$wss_assignemnts_data = $_POST['wss-datepicker-field'];
update_post_meta($post_ID, '_wss_assignments_duedate', $data);
return $data;
}
}
$wss_assignments_datepicker = new wss_assignments_datepicker;