Add ability to select team players

This commit is contained in:
Takumi
2013-07-25 03:59:47 +10:00
parent 3cade7da5d
commit 39d0c1aac6
12 changed files with 133 additions and 62 deletions

View File

@@ -1,12 +1,29 @@
<?php
function sp_load_textdomain() {
function sp_plugins_loaded() {
load_plugin_textdomain ( 'sportspress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
add_image_size( 'sp_icon', 32, 32, false );
}
add_action( 'plugins_loaded', 'sp_load_textdomain' );
add_action( 'plugins_loaded', 'sp_plugins_loaded' );
function sp_add_theme_support() {
function sp_after_theme_setup() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_theme_setup', 'sp_add_theme_support' );
add_action( 'after_theme_setup', 'sp_after_theme_setup' );
function sp_save_post() {
global $post, $post_id, $typenow;
if ( isset( $_POST['sportspress'] ) ):
$sportspress = (array)$_POST['sportspress'];
if ( isset( $_POST ) && !empty( $sportspress ) ):
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
// if ( ! isset( $_POST['sp_event_team_nonce'] ) || ! wp_verify_nonce( $_POST['sp_event_team_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id;
foreach ( $sportspress as $key => $value ):
if ( is_array( $value ) )
$value = serialize( $value );
update_post_meta( $post_id, $key, $value );
endforeach;
endif;
endif;
}
add_action( 'save_post', 'sp_save_post' );
?>

View File

@@ -9,7 +9,7 @@ function sp_calendar_cpt_init() {
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'calendar' ),
'rewrite' => array( 'slug' => 'calendar' )
);
register_post_type( 'sp_calendar', $args );
}
@@ -20,8 +20,8 @@ function sp_calendar_edit_columns( $columns ) {
'cb' => '<input type="checkbox" />',
'title' => __( 'Title' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' )
);
return $columns;
}

View File

@@ -187,27 +187,14 @@ function sp_event_article_meta( $post, $metabox ) {
wp_editor( $post->post_content, 'content' );
}
function sp_event_save() {
global $post, $post_id, $typenow;
if ( $typenow == 'sp_event' && isset( $_POST ) ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if ( ! isset( $_POST['sp_event_team_nonce'] ) || ! wp_verify_nonce( $_POST['sp_event_team_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id;
$sportspress = (array)$_POST['sportspress'];
foreach ( $sportspress as $key => $value ):
update_post_meta( $post_id, $key, $value );
endforeach;
}
}
add_action( 'save_post', 'sp_event_save' );
function sp_event_edit_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Event', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_sponsor' => __( 'Sponsors', 'sportspress' ),
'sp_kickoff' => __( 'Kick-off', 'sportspress' )
);
return $columns;
@@ -223,9 +210,9 @@ function sp_event_custom_columns( $column, $post_id ) {
for ( $i = 1; $i <= $limit; $i++ ):
$team = get_post_meta( $post_id, 'sp_team_' . $i, true );
$parents = get_post_ancestors( $team );
foreach ( $parents as $parent ) {
foreach ( $parents as $parent ):
edit_post_link( get_the_title( $parent ), '', ' — ', $parent );
}
endforeach;
edit_post_link( get_the_title( $team ), '', '<br />', $team );
endfor;
break;

View File

@@ -83,4 +83,15 @@ if ( ! function_exists( 'sp_team_logo' ) ) {
endif;
}
}
if ( ! function_exists( 'sp_get_teams' ) ) {
function sp_get_teams( $post_id = null ) {
$teams = get_post_meta( $post_id, 'sp_teams', true );
if ( isset( $teams ) && $teams )
$teams = (array)unserialize( $teams );
else
$teams = array();
return $teams;
}
}
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -8,41 +8,102 @@ function sp_player_cpt_init() {
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'player' ),
'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes' ),
'register_meta_box_cb' => 'sp_player_meta_init',
'rewrite' => array( 'slug' => 'player' )
);
register_post_type( 'sp_player', $args );
}
add_action( 'init', 'sp_player_cpt_init' );
function sp_player_meta_init() {
add_meta_box( 'sp_playerdiv', __( 'Player', 'sportspress' ), 'sp_player_basic_meta', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_profilediv', __( 'Profile', 'sportspress' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
}
function sp_player_basic_meta( $post, $metabox ) {
global $post_id;
?>
<ul id="sp_team-tabs" class="wp-tab-bar">
<li class="tabs wp-tab-active"><?php _e( 'Teams', 'sportspress' ); ?></li>
</ul>
<div id="sp_team-all" class="wp-tab-panel">
<input type="hidden" value="0" name="sportspress[sp_teams]" />
<ul class="categorychecklist form-no-clear">
<?php
$player_teams = sp_get_teams( $post_id );
$teams = get_pages( array( 'post_type' => 'sp_team') );
foreach ( $teams as $team ):
?>
<li>
<label class="selectit">
<input type="checkbox" value="<?php echo $team->ID; ?>" name="sportspress[sp_teams][]"<?php if ( in_array( $team->ID, $player_teams ) ) echo ' checked="checked"'; ?>>
<?php
if ( $team->post_parent ):
$parents = get_post_ancestors( $team );
echo str_repeat( '— ', sizeof( $parents ) );
endif;
echo $team->post_title;
?>
</label>
</li>
<?php
endforeach;
?>
</ul>
</div>
<div id="sp_league-adder" class="wp-hidden-children">
<h4><?php add_thickbox(); ?>
<a title="<?php echo sprintf( esc_attr__( 'Add New %s', 'sportspress' ), esc_attr__( 'Team', 'sportspress' ) ); ?>" href="<?php echo admin_url( 'post-new.php?post_type=sp_team' ); ?>" target="_blank">
+ <?php echo sprintf( __( 'Add New %s', 'sportspress' ), __( 'Team', 'sportspress' ) ); ?>
</a>
</h4>
</div>
<?php
wp_reset_postdata();
echo '<input type="hidden" name="sp_event_team_nonce" id="sp_event_team_nonce" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
}
function sp_player_profile_meta( $post, $metabox ) {
wp_editor( $post->post_content, 'content' );
}
function sp_player_edit_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '&nbsp;',
'title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Position', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_sponsor' => __( 'Sponsors', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_player_columns', 'sp_player_edit_columns' );
function sp_player_custom_columns( $column ) {
global $post, $post_id, $typenow;
function sp_player_custom_columns( $column, $post_id ) {
global $post, $typenow;
if ( $typenow == 'sp_player' ):
switch ($column):
case 'sp_icon':
if ( has_post_thumbnail() ) the_post_thumbnail( 'sp_icon' );
break;
case 'sp_position':
if ( get_the_terms ( $post_id, 'sp_position' ) )
the_terms( $post_id, 'sp_position' );
else
echo '—';
break;
case 'sp_team':
$teams = sp_get_teams( $post_id );
foreach ( $teams as $team ):
$parents = get_post_ancestors( $team );
$parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) );
foreach ( $parents as $parent ):
if ( !in_array( $parent, $teams ) )
edit_post_link( get_the_title( $parent ), '', ' ', $parent );
echo '— ';
endforeach;
edit_post_link( get_the_title( $team ), '', '<br />', $team );
endforeach;
break;
case 'sp_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
@@ -64,7 +125,7 @@ function sp_player_custom_columns( $column ) {
endswitch;
endif;
}
add_action( 'manage_posts_custom_column', 'sp_player_custom_columns' );
add_action( 'manage_posts_custom_column', 'sp_player_custom_columns', 10, 2 );
function sp_player_request_filter_dropdowns() {
global $typenow, $wp_query;

View File

@@ -91,7 +91,8 @@
#sp_kickoffdiv #timestampdiv p {
display: none;
}
#sp_articlediv .wp-editor-container {
#sp_articlediv .wp-editor-container,
#sp_profilediv .wp-editor-container {
background-color:#fff;
}
.widefat th.column-sp_icon,

View File

@@ -9,7 +9,7 @@ function sp_staff_cpt_init() {
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'staff' ),
'rewrite' => array( 'slug' => 'staff' )
);
register_post_type( 'sp_staff', $args );
}
@@ -18,12 +18,11 @@ add_action( 'init', 'sp_staff_cpt_init' );
function sp_staff_edit_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '&nbsp;',
'title' => __( 'Name', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_position' => __( 'Position', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' )
);
return $columns;
}
@@ -33,9 +32,6 @@ function sp_staff_custom_columns( $column ) {
global $post, $post_id, $typenow;
if ( $typenow == 'sp_staff' ):
switch ($column):
case 'sp_icon':
if ( has_post_thumbnail() ) the_post_thumbnail( 'sp_icon' );
break;
case 'sp_position':
if ( get_the_terms ( $post_id, 'sp_position' ) )
the_terms( $post_id, 'sp_position' );

View File

@@ -9,7 +9,7 @@ function sp_table_cpt_init() {
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'table' ),
'rewrite' => array( 'slug' => 'table' )
);
register_post_type( 'sp_table', $args );
}
@@ -20,8 +20,8 @@ function sp_table_edit_columns( $columns ) {
'cb' => '<input type="checkbox" />',
'title' => __( 'Title' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' )
);
return $columns;
}

View File

@@ -10,7 +10,7 @@ function sp_team_cpt_init() {
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'register_meta_box_cb' => 'sp_team_meta_init',
'rewrite' => array( 'slug' => 'team' ),
'rewrite' => array( 'slug' => 'team' )
);
register_post_type( 'sp_team', $args );
}
@@ -39,8 +39,6 @@ add_filter( 'gettext', 'sp_team_text_replace', 20, 3 );
function sp_team_meta_init() {
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
remove_meta_box( 'pageparentdiv', 'sp_team', 'side' );
add_meta_box( 'pageparentdiv', __( 'Team', 'sportspress' ), 'page_attributes_meta_box', 'sp_team', 'side', 'high' );
}
function sp_team_edit_columns($columns) {
@@ -48,9 +46,9 @@ function sp_team_edit_columns($columns) {
'cb' => '<input type="checkbox" />',
'sp_icon' => '&nbsp;',
'title' => __( 'Team', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_sponsor' => __( 'Sponsors', 'sportspress' )
);
return $columns;
}

View File

@@ -9,7 +9,7 @@ function sp_tournament_cpt_init() {
'public' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'page-attributes' ),
'rewrite' => array( 'slug' => 'tournament' ),
'rewrite' => array( 'slug' => 'tournament' )
);
register_post_type( 'sp_tournament', $args );
}
@@ -21,7 +21,7 @@ function sp_tournament_edit_columns( $columns ) {
'title' => __( 'Title' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_event' => __( 'Events', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' )
);
return $columns;
}

View File

@@ -9,7 +9,7 @@ function sp_venue_cpt_init() {
'public' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'rewrite' => array( 'slug' => 'venue' ),
'rewrite' => array( 'slug' => 'venue' )
);
register_post_type( 'sp_venue', $args );
}
@@ -20,7 +20,7 @@ function sp_venue_edit_columns( $columns ) {
'cb' => '<input type="checkbox" />',
'title' => __( 'Venue', 'sportspress' ),
'sp_address' => __( 'Address', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_sponsor' => __( 'Sponsors', 'sportspress' )
);
return $columns;
}