- <?php
- /*
- Plugin Name: Riser RSVP
- Plugin URI: http://risermedia.com
- Description: A simple user interface for RSVP and a custom events post type.
- Version: 1
- Author: Merrick Christensen
- Author URI: http://risermedia.com
- */
- defined('ABSPATH') or die('No direct script access.');
- class Riser_RSVP
- {
- public function __construct()
- {
- add_action('admin_init', array($this, 'action_admin_init'));
- add_action('delete_post', array($this, 'action_delete_post'));
- add_action('init', array($this, 'action_create_post_type'));
- add_action('admin_menu', array($this, 'action_add_rsvp_box'));
- add_action('save_post', array($this, 'action_save_post'));
- }
- public function action_admin_init()
- {
- if(current_user_can('add_posts') AND current_user_can('edit_posts'))
- {
- }
- }
- public function action_create_post_type()
- {
- register_post_type( 'events',
- array(
- 'labels' => array(
- 'name' => __( 'Events' ),
- 'singular_name' => __( 'Event' )
- ),
- 'public' => true,
- 'supports' => array('title', 'editor')
- )
- );
- }
- public function action_delete_post($post_id)
- {
- // Remove RSVPs for this post.
- }
- public function action_add_rsvp_box()
- {
- add_meta_box('RSVP', __( 'RSVP', 'rsvp' ), array($this, 'rsvp_box'), 'events', 'side', 'low');
- }
- public function rsvp_box()
- {
- global $post;
- $checked = array_pop(get_post_custom_values('rsvp', $post->ID)) == 'true' ? ' checked' : '';
- echo '<input type="checkbox" name="rsvp" value="true"'.$checked.'/> RSVP Enabled';
- }
- public function action_save_post($post_id)
- {
- if(get_post_type($post_id) == 'events')
- {
- if($_POST['rsvp'] == 'true')
- {
- if( ! update_post_meta($post_id, 'rsvp', 'true'))
- {
- add_post_meta($post_id, 'rsvp', 'true', true);
- }
- }
- else
- {
- if( ! update_post_meta($post_id, 'rsvp', 'false'))
- {
- add_post_meta($post_id, 'rsvp', 'false', true);
- }
- }
- }
- }
- public static function form()
- {
- ?>
- hi
- <?php
- }
- }
- new Riser_RSVP();
- ?>