Guest

Untitled

By: a guest on Jun 16th, 2011  |  syntax: PHP  |  size: 3.01 KB  |  hits: 135  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. class wss_assignments_datepicker {
  2.         var $plugin_dir;
  3.         var $plugin_url;
  4.        
  5.         function __construct() {
  6.                 $this->plugin_dir = WP_PLUGIN_DIR . "/wss-assignments";
  7.                 $this->plugin_url = WP_PLUGIN_URL . "/wss-assignments";
  8.                
  9.                 add_action( 'admin_print_styles', array($this, 'wss_assignments_add_stylesheets') );
  10.                 add_action( 'admin_enqueue_scripts', array($this, 'wss_assignments_add_js') );
  11.                 add_action( 'add_meta_boxes', array( $this, 'wss_assignments_datepicker_metabox') );
  12.                 add_action( 'admin_head', array($this, 'wss_assignments_call_js') );
  13.                 add_action( 'save_post', array($this, 'wss_assignments_save_data') );
  14.         }
  15.        
  16.         function wss_assignments_add_stylesheets() {
  17.                 global $post;
  18.                 $styleFile = $this->plugin_dir . "/css/jquery-ui.custom.css";
  19.                 $styleFileURL = $this->plugin_url . "/css/jquery-ui.custom.css";
  20.                
  21.                 if( file_exists($styleFile) && $post->post_type == 'wss-assignments') {
  22.                         wp_register_style('wss_assignments_datepicker_css', $this->plugin_url . "/css/jquery-ui.custom.css");
  23.                         wp_enqueue_style( 'wss_assignments_datepicker_css' );
  24.                 }
  25.         }
  26.        
  27.         function wss_assignments_add_js() {
  28.                 global $post;
  29.                 $jsFile = $this->plugin_dir . "/js/jquery-ui.custom.min.js";
  30.                 $jsFileURL = $this->plugin_url . "/js/jquery-ui.custom.min.js";
  31.                
  32.                 if( file_exists($jsFile) && $post->post_type == 'wss-assignments') {
  33.                         wp_register_script('wss_datepicker-js', $this->plugin_url . "/js/jquery-ui.custom.min.js");
  34.                         wp_enqueue_script('wss_datepicker-js');
  35.                 }
  36.         }
  37.        
  38.         function wss_assignments_call_js() {
  39.                 global $post;
  40.                 if( $post->post_type == 'wss-assignments') {
  41.                         echo '<script>
  42.                         jQuery(document).ready(function() {
  43.                                 jQuery( "#wss-datepicker-field" ).datepicker();
  44.                         });
  45.                         </script>';
  46.                 }
  47.         }
  48.        
  49.         function wss_assignments_datepicker_metabox() {
  50.                 add_meta_box(
  51.                         'wss_assignments_dp_mb',
  52.                         'Assignment Due Date',
  53.                         array( &$this, 'wss_assignments_datepicker_metabox_content'),
  54.                         'wss_assignments', 'side', 'high'
  55.                 );
  56.         }
  57.        
  58.         function wss_assignments_datepicker_metabox_content() {
  59.                 global $post;
  60.                 // Use nonce for verification
  61.                 wp_nonce_field( plugin_basename(__FILE__), 'wss_assignments_dp_nonce');
  62.                
  63.                 // The actual fields for date entry
  64.                 echo '
  65.                 <input type="text" id="wss-datepicker-field" name="wss-datepicker-field"
  66.                 value="' . get_post_meta($post->ID, '_wss_assignments_duedate', true) . '" size="20">';
  67.         }
  68.        
  69.         function wss_assignments_save_data( $post_ID ) {
  70.                 if( defined( 'DOING_AUTOSAVE') && DOING_AUTOSAVE )
  71.                         return;
  72.                        
  73.                 if( !wp_verify_nonce( $_POST['wss_assignments_dp_nonce'], plugin_basename(__FILE__)))
  74.                         return;
  75.                        
  76.                 // Check for permission to post
  77.                 if( 'page' == $_POST['post_type']) {
  78.                         if( !current_user_can( 'edit_page', $post_ID) )
  79.                                 return;
  80.                 } else {
  81.                         if( !current_user_can( 'edit_post', $post_ID) )
  82.                                 return;
  83.                 }
  84.                
  85.                 $wss_assignemnts_data = $_POST['wss-datepicker-field'];
  86.                
  87.                 update_post_meta($post_ID, '_wss_assignments_duedate', $data);
  88.                
  89.                 return $data;
  90.         }
  91.        
  92. }
  93.  
  94. $wss_assignments_datepicker = new wss_assignments_datepicker;