Add match days to event lists and move columns into dedicated meta box
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Calendar Columns
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 2.1.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Calendar_Columns
|
||||
*/
|
||||
class SP_Meta_Box_Calendar_Columns {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
|
||||
$title_format = get_option( 'sportspress_event_list_title_format', 'title' );
|
||||
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
|
||||
|
||||
if ( is_array( $selected ) ) {
|
||||
$selected = array_filter( $selected );
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
|
||||
if ( 'teams' === $title_format ) {
|
||||
$columns[ 'event' ] = __( 'Home', 'sportspress' ) . ' | ' . __( 'Away', 'sportspress' );
|
||||
} elseif ( 'homeaway' === $title_format ) {
|
||||
$columns[ 'event' ] = __( 'Teams', 'sportspress' );
|
||||
} else {
|
||||
$columns[ 'event' ] = __( 'Title', 'sportspress' );
|
||||
}
|
||||
|
||||
if ( 'time' === $time_format || 'separate' === $time_format ) {
|
||||
$columns['time'] = __( 'Time', 'sportspress' );
|
||||
} elseif ( 'combined' === $time_format ) {
|
||||
$columns['time'] = __( 'Time/Results', 'sportspress' );
|
||||
}
|
||||
|
||||
if ( 'results' === $time_format || 'separate' === $time_format ) {
|
||||
$columns['results'] = __( 'Results', 'sportspress' );
|
||||
}
|
||||
|
||||
$columns['league'] = __( 'Competition', 'sportspress' );
|
||||
$columns['season'] = __( 'Season', 'sportspress' );
|
||||
$columns['venue'] = __( 'Venue', 'sportspress' );
|
||||
$columns['article'] = __( 'Article', 'sportspress' );
|
||||
$columns['day'] = __( 'Match Day', 'sportspress' );
|
||||
|
||||
$columns = apply_filters( 'sportspress_calendar_columns', $columns );
|
||||
?>
|
||||
<div class="sp-instance">
|
||||
<ul class="categorychecklist form-no-clear">
|
||||
<?php
|
||||
foreach ( $columns as $key => $label ) {
|
||||
?>
|
||||
<li>
|
||||
<label>
|
||||
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $selected ) || in_array( $key, $selected ) ); ?>>
|
||||
<?php echo $label; ?>
|
||||
</label>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,9 @@ class SP_Meta_Box_Calendar_Data {
|
||||
<th class="column-date">
|
||||
<?php _e( 'Date', 'sportspress' ); ?>
|
||||
</th>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ) { ?>
|
||||
<th class="column-event">
|
||||
<label for="sp_columns_event">
|
||||
<input type="checkbox" name="sp_columns[]" value="event" id="sp_columns_event" <?php checked( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ); ?>>
|
||||
<?php
|
||||
if ( 'teams' == $title_format ) {
|
||||
_e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' );
|
||||
@@ -63,10 +63,10 @@ class SP_Meta_Box_Calendar_Data {
|
||||
?>
|
||||
</label>
|
||||
</th>
|
||||
<?php if ( in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
|
||||
<th class="column-time">
|
||||
<label for="sp_columns_time">
|
||||
<input type="checkbox" name="sp_columns[]" value="time" id="sp_columns_time" <?php checked( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ); ?>>
|
||||
<?php
|
||||
if ( 'time' == $time_format || 'separate' == $time_format ) {
|
||||
_e( 'Time', 'sportspress' );
|
||||
@@ -77,38 +77,48 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
|
||||
<th class="column-results">
|
||||
<label for="sp_columns_results">
|
||||
<input type="checkbox" name="sp_columns[]" value="results" id="sp_columns_results" <?php checked( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Results', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<th class="column-league">
|
||||
<label for="sp_columns_league">
|
||||
<input type="checkbox" name="sp_columns[]" value="league" id="sp_columns_league" <?php checked( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Competition', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<th class="column-season">
|
||||
<label for="sp_columns_season">
|
||||
<input type="checkbox" name="sp_columns[]" value="season" id="sp_columns_season" <?php checked( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Season', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<th class="column-venue">
|
||||
<label for="sp_columns_venue">
|
||||
<input type="checkbox" name="sp_columns[]" value="venue" id="sp_columns_venue" <?php checked( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Venue', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<th class="column-article">
|
||||
<label for="sp_columns_article">
|
||||
<input type="checkbox" name="sp_columns[]" value="article" id="sp_columns_article" <?php checked( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Article', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ) { ?>
|
||||
<th class="column-league">
|
||||
<label for="sp_columns_league">
|
||||
<?php _e( 'Competition', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ) { ?>
|
||||
<th class="column-season">
|
||||
<label for="sp_columns_season">
|
||||
<?php _e( 'Season', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ) { ?>
|
||||
<th class="column-venue">
|
||||
<label for="sp_columns_venue">
|
||||
<?php _e( 'Venue', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ) { ?>
|
||||
<th class="column-article">
|
||||
<label for="sp_columns_article">
|
||||
<?php _e( 'Article', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'day', $usecolumns ) ) { ?>
|
||||
<th class="column-day">
|
||||
<label for="sp_columns_day">
|
||||
<?php _e( 'Match Day', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -125,46 +135,62 @@ class SP_Meta_Box_Calendar_Data {
|
||||
?>
|
||||
<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, true ); ?></td>
|
||||
<td>
|
||||
<div class="sp-title-format sp-title-format-title<?php if ( $title_format && $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo $event->post_title; ?></div>
|
||||
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>">
|
||||
<?php
|
||||
if ( $teams ): foreach ( $teams as $team ):
|
||||
$name = get_the_title( $team );
|
||||
if ( $name ):
|
||||
$team_results = sp_array_value( $results, $team, null );
|
||||
|
||||
if ( $main_result ):
|
||||
$team_result = sp_array_value( $team_results, $main_result, null );
|
||||
else:
|
||||
if ( is_array( $team_results ) ):
|
||||
end( $team_results );
|
||||
$team_result = prev( $team_results );
|
||||
else:
|
||||
$team_result = null;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
$team_result = apply_filters( 'sportspress_calendar_team_result_admin', $team_result, $event->ID, $team );
|
||||
$main_results[] = $team_result;
|
||||
unset( $team_results['outcome'] );
|
||||
$team_results = implode( ' | ', $team_results );
|
||||
echo '<a class="result sp-tip" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
|
||||
endif;
|
||||
|
||||
echo $name . '<br>';
|
||||
endif;
|
||||
endforeach; else:
|
||||
echo '—';
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<?php if ( 'separate' == $time_format ) { ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ) { ?>
|
||||
<td>
|
||||
<?php echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); ?>
|
||||
<div class="sp-title-format sp-title-format-title<?php if ( $title_format && $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo $event->post_title; ?></div>
|
||||
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>">
|
||||
<?php
|
||||
if ( $teams ): foreach ( $teams as $team ):
|
||||
$name = get_the_title( $team );
|
||||
if ( $name ):
|
||||
$team_results = sp_array_value( $results, $team, null );
|
||||
|
||||
if ( $main_result ):
|
||||
$team_result = sp_array_value( $team_results, $main_result, null );
|
||||
else:
|
||||
if ( is_array( $team_results ) ):
|
||||
end( $team_results );
|
||||
$team_result = prev( $team_results );
|
||||
else:
|
||||
$team_result = null;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
$team_result = apply_filters( 'sportspress_calendar_team_result_admin', $team_result, $event->ID, $team );
|
||||
$main_results[] = $team_result;
|
||||
unset( $team_results['outcome'] );
|
||||
$team_results = implode( ' | ', $team_results );
|
||||
echo '<a class="result sp-tip" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
|
||||
endif;
|
||||
|
||||
echo $name . '<br>';
|
||||
endif;
|
||||
endforeach; else:
|
||||
echo '—';
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
|
||||
<?php if ( 'time' == $time_format || 'separate' == $time_format ) { ?>
|
||||
<td>
|
||||
<?php echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); ?>
|
||||
</td>
|
||||
<?php } else { ?>
|
||||
<td>
|
||||
<?php
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
else:
|
||||
echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID );
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
if ( ! empty( $main_results ) ):
|
||||
@@ -174,38 +200,48 @@ class SP_Meta_Box_Calendar_Data {
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<?php } else { ?>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ) { ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_league' ); ?></td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ) { ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_season' ); ?></td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ) { ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ) { ?>
|
||||
<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>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'day', $usecolumns ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
else:
|
||||
echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID );
|
||||
endif;
|
||||
$day = get_post_meta( $event->ID, 'sp_day', true );
|
||||
if ( '' == $day ) {
|
||||
echo '—';
|
||||
} else {
|
||||
echo $day;
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_league' ); ?></td>
|
||||
<td><?php the_terms( $event->ID, 'sp_season' ); ?></td>
|
||||
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></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++;
|
||||
|
||||
@@ -194,6 +194,13 @@ class SportsPress_Calendars {
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
'columns' => array(
|
||||
'title' => __( 'Columns', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Calendar_Columns::save',
|
||||
'output' => 'SP_Meta_Box_Calendar_Columns::output',
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
'details' => array(
|
||||
'title' => __( 'Details', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Calendar_Details::save',
|
||||
|
||||
@@ -154,6 +154,9 @@ endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'article' ) )
|
||||
echo '<th class="data-article">' . __( 'Article', 'sportspress' ) . '</th>';
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'day' ) )
|
||||
echo '<th class="data-day">' . __( 'Match Day', 'sportspress' ) . '</th>';
|
||||
?>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -390,6 +393,17 @@ endif;
|
||||
echo '</td>';
|
||||
endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'day' ) ):
|
||||
echo '<td class="data-day">';
|
||||
$day = get_post_meta( $event->ID, 'sp_day', true );
|
||||
if ( '' == $day ) {
|
||||
echo '-';
|
||||
} else {
|
||||
echo $day;
|
||||
}
|
||||
echo '</td>';
|
||||
endif;
|
||||
|
||||
echo '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
Reference in New Issue
Block a user