Files
sportspress/table.php
2013-07-24 19:09:02 +10:00

83 lines
2.3 KiB
PHP

<?php
function sp_table_cpt_init() {
$name = __( 'Tables', 'sportspress' );
$singular_name = __( 'Table', 'sportspress' );
$labels = sp_get_cpt_labels( $name, $singular_name );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'table' ),
);
register_post_type( 'sp_table', $args );
}
add_action( 'init', 'sp_table_cpt_init' );
function sp_table_edit_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
);
return $columns;
}
add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' );
function sp_table_custom_columns( $column ) {
global $post, $post_id, $typenow;
if ( $typenow == 'sp_table' ):
switch ($column):
case 'sp_team':
echo 'TEAMS';
break;
case 'sp_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break;
case 'sp_season':
if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break;
endswitch;
endif;
}
add_action( 'manage_posts_custom_column', 'sp_table_custom_columns' );
function sp_table_request_filter_dropdowns() {
global $typenow, $wp_query;
if ( $typenow == 'sp_table' ) {
// Leagues
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
$args = array(
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
echo PHP_EOL;
// Seasons
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
$args = array(
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
echo PHP_EOL;
}
}
add_action( 'restrict_manage_posts', 'sp_table_request_filter_dropdowns' );
?>