Add time/status selector to events
This commit is contained in:
@@ -53,6 +53,27 @@
|
||||
content: "\f453";
|
||||
}
|
||||
|
||||
.post-type-sp_event .sp-event-status:before {
|
||||
color: #82878c;
|
||||
font: 400 20px/1 dashicons;
|
||||
speak: none;
|
||||
display: inline-block;
|
||||
padding: 0 2px 0 0;
|
||||
top: 0;
|
||||
left: -1px;
|
||||
position: relative;
|
||||
vertical-align: top;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-decoration: none!important;
|
||||
content: "\f469";
|
||||
}
|
||||
|
||||
.post-type-sp_event .sp-event-status-select {
|
||||
line-height: 1.5em;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.sp-link:before {
|
||||
font: normal 20px/1 dashicons;
|
||||
speak: none;
|
||||
|
||||
@@ -775,4 +775,33 @@ jQuery(document).ready(function($){
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Event status selector
|
||||
$('.sp-edit-event-status').click(function(e) {
|
||||
e.preventDefault();
|
||||
$select = $(this).siblings('.sp-event-status-select');
|
||||
if ( $select.is(':hidden') ) {
|
||||
$select.slideDown( 'fast', function() {
|
||||
$select.find( 'input[type="radio"]' ).first().focus();
|
||||
} );
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('.sp-save-event-status').click(function(e) {
|
||||
e.preventDefault();
|
||||
$select = $(this).closest('.sp-event-status-select');
|
||||
$input = $select.find('input[name=sp_status]:checked');
|
||||
val = $input.val();
|
||||
label = $input.data('sp-event-status');
|
||||
$select.slideUp('fast').siblings('.sp-edit-event-status').show().siblings('.sp-event-status').find('.sp-event-status-display').data('sp-event-status', val).html(label);
|
||||
});
|
||||
|
||||
$('.sp-cancel-event-status').click(function(e) {
|
||||
e.preventDefault();
|
||||
$select = $(this).closest('.sp-event-status-select');
|
||||
val = $select.siblings('.sp-event-status').find('.sp-event-status-display').data('sp-event-status');
|
||||
$select.find('input[value='+val+']').attr('checked', true);
|
||||
$select.slideUp('fast').siblings('.sp-edit-event-status').show();
|
||||
});
|
||||
});
|
||||
109
modules/sportspress-event-status.php
Normal file
109
modules/sportspress-event-status.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: SportsPress Event Status
|
||||
Plugin URI: http://themeboy.com/
|
||||
Description: Add a status option to SportsPress events.
|
||||
Author: ThemeBoy
|
||||
Author URI: http://themeboy.com/
|
||||
Version: 2.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'SportsPress_Event_Status' ) ) :
|
||||
|
||||
/**
|
||||
* Main SportsPress Event Status Class
|
||||
*
|
||||
* @class SportsPress_Event_Status
|
||||
* @version 2.1
|
||||
*/
|
||||
class SportsPress_Event_Status {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $statuses = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// Define constants
|
||||
$this->define_constants();
|
||||
|
||||
// Define statuses
|
||||
$this->get_statuses();
|
||||
|
||||
add_action( 'post_submitbox_misc_actions', array( $this, 'section' ) );
|
||||
add_action( 'sportspress_process_sp_event_meta', array( $this, 'save' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define constants.
|
||||
*/
|
||||
private function define_constants() {
|
||||
if ( !defined( 'SP_EVENT_STATUS_VERSION' ) )
|
||||
define( 'SP_EVENT_STATUS_VERSION', '2.1' );
|
||||
|
||||
if ( !defined( 'SP_EVENT_STATUS_URL' ) )
|
||||
define( 'SP_EVENT_STATUS_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
if ( !defined( 'SP_EVENT_STATUS_DIR' ) )
|
||||
define( 'SP_EVENT_STATUS_DIR', plugin_dir_path( __FILE__ ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define statuses.
|
||||
*/
|
||||
private function get_statuses() {
|
||||
$this->statuses = apply_filters( 'sportspress_event_statuses', array(
|
||||
'ok' => __( 'On time', 'sportspress' ),
|
||||
'tbd' => __( 'To be determined', 'sportspress' ) . ' (' . __( 'TBD', 'sportspress' ) . ')',
|
||||
'cancelled' => __( 'Cancelled', 'sportspress' ),
|
||||
'postponed' => __( 'Postponed', 'sportspress' ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add status section to submit box.
|
||||
*/
|
||||
public function section() {
|
||||
if ( 'sp_event' !== get_post_type() ) return;
|
||||
$status = get_post_meta( get_the_ID(), 'sp_status', true );
|
||||
if ( ! $status ) $status = 'ok';
|
||||
?>
|
||||
<div class="misc-pub-section sp-pub-event-status">
|
||||
<span class="sp-event-status"><?php _e( 'Time:', 'sportspress' ); ?> <strong class="sp-event-status-display" data-sp-event-status="<?php echo $status; ?>"><?php echo $this->statuses[ $status ]; ?></strong></span>
|
||||
<a href="#" class="sp-edit-event-status hide-if-no-js"><span aria-hidden="true"><?php _e( 'Edit', 'sportspress' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit status' ); ?></span></a>
|
||||
<div class="sp-event-status-select hide-if-js">
|
||||
<?php foreach ( $this->statuses as $value => $label ) { ?>
|
||||
<label><input type="radio" name="sp_status" value="<?php echo $value; ?>" data-sp-event-status="<?php echo $label; ?>" <?php checked( $status, $value ); ?>> <?php echo $label; ?></label><br>
|
||||
<?php } ?>
|
||||
<p>
|
||||
<a href="#" class="sp-save-event-status hide-if-no-js button">OK</a>
|
||||
<a href="#" class="sp-cancel-event-status hide-if-no-js button-cancel">Cancel</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php if ( false ) { ?>
|
||||
<label>
|
||||
<input type="checkbox" name="sp_tbd" value="1" <?php checked( $checked ); ?>></input>
|
||||
<?php _e( 'To be determined', 'sportspress' ); ?> (<?php _e( 'TBD', 'sportspress' ); ?>)
|
||||
</label>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save status option.
|
||||
*/
|
||||
public function save( $post_id ) {
|
||||
update_post_meta( $post_id, 'sp_status', sp_array_value( $_POST, 'sp_status', 'ok' ) );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
new SportsPress_Event_Status();
|
||||
Reference in New Issue
Block a user