Add calendar post type
This commit is contained in:
@@ -7,6 +7,9 @@ function sportspress_define_formats_global() {
|
||||
$sportspress_formats['event']['league'] = __( 'League', 'sportspress' );
|
||||
$sportspress_formats['event']['friendly'] = __( 'Friendly', 'sportspress' );
|
||||
|
||||
$sportspress_formats['calendar']['calendar'] = __( 'Calendar', 'sportspress' );
|
||||
$sportspress_formats['calendar']['list'] = __( 'List', 'sportspress' );
|
||||
|
||||
$sportspress_formats['list']['list'] = __( 'List', 'sportspress' );
|
||||
$sportspress_formats['list']['gallery'] = __( 'Gallery', 'sportspress' );
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ function sportspress_save_post( $post_id ) {
|
||||
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
|
||||
if ( !isset( $_POST['sportspress_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_nonce'], SPORTSPRESS_PLUGIN_BASENAME ) ) return $post_id;
|
||||
switch ( $_POST['post_type'] ):
|
||||
|
||||
case ( 'sp_team' ):
|
||||
|
||||
// Update leagues seasons to show
|
||||
@@ -50,6 +51,25 @@ function sportspress_save_post( $post_id ) {
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_calendar' ):
|
||||
|
||||
// Update format
|
||||
update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'calendar' ) );
|
||||
|
||||
// Update league taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
|
||||
|
||||
// Update season taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||
|
||||
// Update venue taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' );
|
||||
|
||||
// Update team
|
||||
update_post_meta( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', 0 ) );
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_result' ):
|
||||
|
||||
// Delete posts with duplicate key
|
||||
|
||||
156
admin/post-types/calendar.php
Normal file
156
admin/post-types/calendar.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
function sportspress_calendar_post_init() {
|
||||
$labels = array(
|
||||
'name' => __( 'Calendars', 'sportspress' ),
|
||||
'singular_name' => __( 'Calendar', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New Calendar', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Calendar', 'sportspress' ),
|
||||
'new_item' => __( 'New', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'search_items' => __( 'Search', 'sportspress' ),
|
||||
'not_found' => __( 'No results found.', 'sportspress' ),
|
||||
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
|
||||
);
|
||||
$args = array(
|
||||
'label' => __( 'Calendars', 'sportspress' ),
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'has_archive' => false,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||
'register_meta_box_cb' => 'sportspress_calendar_meta_init',
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_calendar_slug', 'calendar' ) ),
|
||||
'show_in_menu' => 'edit.php?post_type=sp_event',
|
||||
'show_in_admin_bar' => true,
|
||||
'capability_type' => 'sp_calendar'
|
||||
);
|
||||
register_post_type( 'sp_calendar', $args );
|
||||
}
|
||||
add_action( 'init', 'sportspress_calendar_post_init' );
|
||||
|
||||
function sportspress_calendar_edit_columns() {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Title', 'sportspress' ),
|
||||
'sp_league' => __( 'League', 'sportspress' ),
|
||||
'sp_season' => __( 'Season', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_events' => __( 'Events', 'sportspress' ),
|
||||
'sp_views' => __( 'Views', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
add_filter( 'manage_edit-sp_calendar_columns', 'sportspress_calendar_edit_columns' );
|
||||
|
||||
function sportspress_calendar_meta_init( $post ) {
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
|
||||
remove_meta_box( 'sp_seasondiv', 'sp_calendar', 'side' );
|
||||
remove_meta_box( 'sp_leaguediv', 'sp_calendar', 'side' );
|
||||
remove_meta_box( 'sp_venuediv', 'sp_calendar', 'side' );
|
||||
add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'sportspress_calendar_format_meta', 'sp_calendar', 'side', 'high' );
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_calendar_details_meta', 'sp_calendar', 'side', 'default' );
|
||||
add_meta_box( 'sp_columnsdiv', __( 'Events', 'sportspress' ), 'sportspress_calendar_events_meta', 'sp_calendar', 'normal', 'high' );
|
||||
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'sportspress_calendar_description_meta', 'sp_calendar', 'normal', 'high' );
|
||||
}
|
||||
|
||||
function sportspress_calendar_format_meta( $post ) {
|
||||
global $sportspress_formats;
|
||||
$the_format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<?php foreach ( $sportspress_formats['calendar'] as $key => $format ): ?>
|
||||
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( true, ( $key == 'calendar' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $format; ?></label><br>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function sportspress_calendar_details_meta( $post, $test ) {
|
||||
global $sportspress_formats;
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$venue_id = sportspress_get_the_term_id( $post->ID, 'sp_venue', 0 );
|
||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||
$formats = get_post_meta( $post->ID, 'sp_format' );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_all' => __( 'All', 'sportspress' ),
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'selected' => $league_id,
|
||||
'values' => 'term_id'
|
||||
);
|
||||
if ( ! sportspress_dropdown_taxonomies( $args ) ):
|
||||
sportspress_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Season', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-tab-select">
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_all' => __( 'All', 'sportspress' ),
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'selected' => $season_id,
|
||||
'values' => 'term_id'
|
||||
);
|
||||
if ( ! sportspress_dropdown_taxonomies( $args ) ):
|
||||
sportspress_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Venue', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_all' => __( 'All', 'sportspress' ),
|
||||
'taxonomy' => 'sp_venue',
|
||||
'name' => 'sp_venue',
|
||||
'selected' => $venue_id,
|
||||
'values' => 'term_id'
|
||||
);
|
||||
if ( ! sportspress_dropdown_taxonomies( $args ) ):
|
||||
sportspress_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_all' => __( 'All', 'sportspress' ),
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'selected' => $team_id,
|
||||
'values' => 'ID'
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
sportspress_nonce();
|
||||
}
|
||||
|
||||
function sportspress_calendar_events_meta( $post ) {
|
||||
|
||||
$data = sportspress_get_calendar_data( $post->ID );
|
||||
|
||||
sportspress_edit_calendar_table( $data );
|
||||
|
||||
sportspress_nonce();
|
||||
|
||||
}
|
||||
|
||||
function sportspress_calendar_description_meta( $post ) {
|
||||
wp_editor( $post->post_content, 'content' );
|
||||
}
|
||||
@@ -23,7 +23,7 @@ function sportspress_league_term_init() {
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => 'league' ),
|
||||
);
|
||||
$object_types = array( 'sp_event', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' );
|
||||
$object_types = array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' );
|
||||
register_taxonomy( 'sp_league', $object_types, $args );
|
||||
foreach ( $object_types as $object_type ):
|
||||
register_taxonomy_for_object_type( 'sp_league', $object_type );
|
||||
|
||||
@@ -23,7 +23,7 @@ function sportspress_season_term_init() {
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => 'season' ),
|
||||
);
|
||||
$object_types = array( 'sp_event', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' );
|
||||
$object_types = array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' );
|
||||
register_taxonomy( 'sp_season', $object_types, $args );
|
||||
foreach ( $object_types as $object_type ):
|
||||
register_taxonomy_for_object_type( 'sp_league', $object_type );
|
||||
|
||||
@@ -23,7 +23,7 @@ function sportspress_venue_term_init() {
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => 'venue' ),
|
||||
);
|
||||
$object_types = array( 'sp_event', 'attachment' );
|
||||
$object_types = array( 'sp_event', 'sp_calendar', 'attachment' );
|
||||
register_taxonomy( 'sp_venue', $object_types, $args );
|
||||
foreach ( $object_types as $object_type ):
|
||||
register_taxonomy_for_object_type( 'sp_league', $object_type );
|
||||
|
||||
@@ -757,6 +757,69 @@ if ( !function_exists( 'sportspress_get_var_calculates' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sportspress_edit_calendar_table' ) ) {
|
||||
function sportspress_edit_calendar_table( $data = array() ) {
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<table class="widefat sp-data-table sp-calendar-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="column-date"><?php _e( 'Date', 'sportspress' ); ?></th>
|
||||
<th class="column-event"><?php _e( 'Event', 'sportspress' ); ?></th>
|
||||
<th class="column-time"><?php _e( 'Time', 'sportspress' ); ?></th>
|
||||
<th class="column-article"><?php _e( 'Article', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( is_array( $data ) && sizeof( $data ) > 0 ):
|
||||
$i = 0;
|
||||
foreach ( $data as $event ):
|
||||
$video = get_post_meta( $event->ID, 'sp_video', true );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event ); ?></td>
|
||||
<td><?php echo $event->post_title; ?></td>
|
||||
<td><?php echo get_post_time( get_option( 'time_format' ), false, $event ); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
|
||||
<?php if ( $video ): ?>
|
||||
<div class="dashicons dashicons-video-alt"></div>
|
||||
<?php elseif ( has_post_thumbnail( $event->ID ) ): ?>
|
||||
<div class="dashicons dashicons-camera"></div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if ( $event->post_content == null ):
|
||||
_e( 'None', 'sportspress' );
|
||||
elseif ( $event->post_status == 'publish' ):
|
||||
_e( 'Recap', 'sportspress' );
|
||||
else:
|
||||
_e( 'Preview', 'sportspress' );
|
||||
endif;
|
||||
?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="4">
|
||||
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sportspress_edit_league_table' ) ) {
|
||||
function sportspress_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) {
|
||||
if ( is_array( $usecolumns ) )
|
||||
@@ -833,7 +896,7 @@ if ( !function_exists( 'sportspress_edit_player_list_table' ) ) {
|
||||
$usecolumns = array_filter( $usecolumns );
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<table class="widefat sp-data-table">
|
||||
<table class="widefat sp-data-table sp-player-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
@@ -1013,11 +1076,11 @@ if ( !function_exists( 'sportspress_edit_event_results_table' ) ) {
|
||||
<table class="widefat sp-data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $label ): ?>
|
||||
<th><?php echo $label; ?></th>
|
||||
<th class="column-team"><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $key => $label ): ?>
|
||||
<th class="outcome-<?php echo $key; ?>"><?php echo $label; ?></th>
|
||||
<?php endforeach; ?>
|
||||
<th><?php _e( 'Outcome', 'sportspress' ); ?></th>
|
||||
<th class="column-outcome"><?php _e( 'Outcome', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -1379,6 +1442,7 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
|
||||
$leagues = get_the_terms( $post_id, 'sp_league' );
|
||||
$seasons = get_the_terms( $post_id, 'sp_season' );
|
||||
$venues = get_the_terms( $post_id, 'sp_venue' );
|
||||
$team = get_post_meta( $post_id, 'sp_team', true );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
@@ -1428,6 +1492,15 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
|
||||
);
|
||||
endif;
|
||||
|
||||
if ( $team ):
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => $team,
|
||||
),
|
||||
);
|
||||
endif;
|
||||
|
||||
$events = get_posts( $args );
|
||||
|
||||
return $events;
|
||||
|
||||
@@ -68,6 +68,7 @@ require_once dirname( __FILE__ ) . '/admin/post-types/metric.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/result.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/outcome.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/event.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/calendar.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/team.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/table.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/player.php';
|
||||
|
||||
Reference in New Issue
Block a user