Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: None  |  size: 2.04 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. <?php
  3. /*
  4. Plugin Name: Riser RSVP
  5. Plugin URI: http://risermedia.com
  6. Description: A simple user interface for RSVP and a custom events post type.
  7. Version: 1
  8. Author: Merrick Christensen
  9. Author URI: http://risermedia.com
  10. */
  11.  
  12. defined('ABSPATH') or die('No direct script access.');
  13.  
  14. class Riser_RSVP
  15. {
  16.         public function __construct()
  17.         {
  18.                 add_action('admin_init', array($this, 'action_admin_init'));
  19.                 add_action('delete_post', array($this, 'action_delete_post'));
  20.                 add_action('init', array($this, 'action_create_post_type'));
  21.                 add_action('admin_menu', array($this, 'action_add_rsvp_box'));
  22.                 add_action('save_post', array($this, 'action_save_post'));
  23.         }
  24.        
  25.         public function action_admin_init()
  26.         {
  27.                 if(current_user_can('add_posts') AND current_user_can('edit_posts'))
  28.                 {
  29.                        
  30.                 }
  31.         }
  32.        
  33.         public function action_create_post_type()
  34.         {
  35.                 register_post_type( 'events',
  36.                         array(
  37.                                 'labels' => array(
  38.                                         'name' => __( 'Events' ),
  39.                                         'singular_name' => __( 'Event' )
  40.                                 ),
  41.                                 'public' => true,
  42.                                 'supports' => array('title', 'editor')
  43.                         )
  44.                 );
  45.         }
  46.        
  47.         public function action_delete_post($post_id)
  48.         {
  49.                 // Remove RSVPs for this post.
  50.         }
  51.        
  52.         public function action_add_rsvp_box()
  53.         {
  54.                 add_meta_box('RSVP', __( 'RSVP', 'rsvp' ), array($this, 'rsvp_box'), 'events', 'side', 'low');
  55.         }
  56.        
  57.         public function rsvp_box()
  58.         {
  59.                 global $post;
  60.                
  61.                 $checked = array_pop(get_post_custom_values('rsvp', $post->ID)) == 'true' ? ' checked' : '';
  62.                
  63.                 echo '<input type="checkbox" name="rsvp" value="true"'.$checked.'/> RSVP Enabled';
  64.         }
  65.        
  66.         public function action_save_post($post_id)
  67.         {
  68.                 if(get_post_type($post_id) == 'events')
  69.                 {
  70.                         if($_POST['rsvp'] == 'true')
  71.                         {
  72.                                 if( ! update_post_meta($post_id, 'rsvp', 'true'))
  73.                                 {
  74.                                         add_post_meta($post_id, 'rsvp', 'true', true);
  75.                                 }
  76.                         }
  77.                         else
  78.                         {
  79.                                 if( ! update_post_meta($post_id, 'rsvp', 'false'))
  80.                                 {
  81.                                         add_post_meta($post_id, 'rsvp', 'false', true);
  82.                                 }
  83.                         }
  84.                 }
  85.         }
  86.        
  87.         public static function form()
  88.         {
  89. ?>
  90.                 hi
  91. <?php
  92.                
  93.         }
  94. }
  95.  
  96. new Riser_RSVP();
  97. ?>