Put things in folders and stuff

This commit is contained in:
Brian Miyaji
2014-01-06 22:32:15 +11:00
parent 4e53aa5424
commit 3ab4ea33bd
26 changed files with 574 additions and 528 deletions

View File

@@ -0,0 +1,32 @@
<?php
function sp_admin_menu( $position ) {
if ( ! current_user_can( 'manage_options' ) )
return;
global $menu, $submenu;
// Find where our placeholder is in the menu
foreach( $menu as $key => $data ) {
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' )
$position = $key;
}
// Swap our placeholder post type with a menu separator
if ( $position ):
$menu[ $position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
endif;
// Remove "Add Configuration" link under SportsPress
unset( $submenu['edit.php?post_type=sp_config'][10] );
// Remove "Seasons" link under Events
unset( $submenu['edit.php?post_type=sp_event'][15] );
// Remove "Seasons" link under Players
unset( $submenu['edit.php?post_type=sp_player'][15] );
// Remove "Seasons" link under Staff
unset( $submenu['edit.php?post_type=sp_staff'][15] );
}
add_action( 'admin_menu', 'sp_admin_menu' );
?>

View File

@@ -0,0 +1,6 @@
<?php
function sp_after_theme_setup() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_theme_setup', 'sp_after_theme_setup' );
?>

View File

@@ -0,0 +1,6 @@
<?php
function sp_manage_posts_columns() {
sp_highlight_admin_menu();
}
add_action( 'manage_posts_columns', 'sp_manage_posts_columns' );
?>

View File

@@ -0,0 +1,86 @@
<?php
function sp_manage_posts_custom_column( $column, $post_id ) {
global $post;
switch ( $column ):
case 'sp_logo':
edit_post_link( get_the_post_thumbnail( $post_id, 'sp_icon' ), '', '', $post_id );
break;
case 'sp_position':
echo get_the_terms ( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '—';
break;
case 'sp_team':
$post_type = get_post_type( $post );
$teams = get_post_meta ( $post_id, 'sp_team', false );
unset( $teams[0] );
if ( $post_type == 'sp_event' ):
$results = get_post_meta( $post_id, 'sp_results', true );
foreach( $teams as $team_id ):
$team = get_post( $team_id );
$outcome_slug = sp_array_value( sp_array_value( $results, $team_id, null ), 'outcome', null );
$args=array(
'name' => $outcome_slug,
'post_type' => 'sp_outcome',
'post_status' => 'publish',
'posts_per_page' => 1
);
$outcomes = get_posts( $args );
echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '<br>';
endforeach;
elseif ( $post_type == 'sp_player' ):
$results = get_post_meta( $post_id, 'sp_results', true );
foreach( $teams as $team_id ):
$team = get_post( $team_id );
$outcome_slug = sp_array_value( sp_array_value( $results, $team_id, null ), 'outcome', null );
$args=array(
'name' => $outcome_slug,
'post_type' => 'sp_outcome',
'post_status' => 'publish',
'posts_per_page' => 1
);
$outcomes = get_posts( $args );
echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '<br>';
endforeach;
else:
foreach( $teams as $team_id ):
$team = get_post( $team_id );
echo $team->post_title . '<br>';
endforeach;
endif;
break;
case 'sp_equation':
echo sp_get_post_equation( $post_id );
break;
case 'sp_order':
echo sp_get_post_order( $post_id );
break;
case 'sp_key':
echo $post->post_name;
break;
case 'sp_format':
echo sp_get_post_format( $post_id );
break;
case 'sp_player':
echo sp_the_posts( $post_id, 'sp_player' );
break;
case 'sp_event':
echo get_post_meta ( $post_id, 'sp_event' ) ? sizeof( get_post_meta ( $post_id, 'sp_event' ) ) : '—';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '—';
break;
case 'sp_sponsor':
echo get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : '—';
break;
case 'sp_kickoff':
echo ( $post->post_status == 'future' ? __( 'Scheduled' ) : __( 'Played', 'sportspress' ) ) . '<br />' . date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) );
break;
case 'sp_address':
echo get_post_meta( $post_id, 'sp_address', true ) ? get_post_meta( $post_id, 'sp_address', true ) : '—';
break;
endswitch;
}
add_action( 'manage_posts_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
add_action( 'manage_pages_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
?>

View File

@@ -0,0 +1,7 @@
<?php
function sp_plugins_loaded() {
load_plugin_textdomain ( 'sportspress', false, dirname( SPORTSPRESS_PLUGIN_BASENAME ) . '/i18n/languages/' );
add_image_size( 'sp_icon', 32, 32, false );
}
add_action( 'plugins_loaded', 'sp_plugins_loaded' );
?>

View File

@@ -0,0 +1,15 @@
<?php
function sp_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if( empty ( $html ) && in_array( get_post_type( $post_id ), array( 'sp_team', 'sp_tournament' ) ) ) {
$parents = get_post_ancestors( $post_id );
foreach ( $parents as $parent ) {
if( has_post_thumbnail( $parent ) ) {
$html = get_the_post_thumbnail( $parent, $size, $attr );
break;
}
}
}
return $html;
}
add_filter( 'post_thumbnail_html', 'sp_post_thumbnail_html', 10, 5 );
?>

View File

@@ -0,0 +1,37 @@
<?php
function sp_restrict_manage_posts() {
sp_highlight_admin_menu();
global $typenow, $wp_query;
if ( in_array( $typenow, array( 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
$selected = isset( $_REQUEST['sp_team'] ) ? $_REQUEST['sp_team'] : null;
$args = array(
'show_option_none' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'post_type' => 'sp_team',
'name' => 'sp_team',
'selected' => $selected
);
// wp_dropdown_pages( $args );
endif;
if ( in_array( $typenow, array( 'sp_player' ) ) ):
$selected = isset( $_REQUEST['sp_position'] ) ? $_REQUEST['sp_position'] : null;
$args = array(
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ),
'taxonomy' => 'sp_position',
'name' => 'sp_position',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
if ( in_array( $typenow, array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
$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 );
endif;
}
add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' );
?>

137
admin/actions/save-post.php Normal file
View File

@@ -0,0 +1,137 @@
<?php
function sp_save_post( $post_id ) {
global $post, $typenow;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $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 columns
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
break;
case ( 'sp_event' ):
// Get results
$results = (array)sp_array_value( $_POST, 'sp_results', array() );
// Update results
update_post_meta( $post_id, 'sp_results', $results );
// Update player statistics
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
// Update player array
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
// Update staff array
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
break;
case ( 'sp_column' ):
// Update format as string
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'integer' ) );
// Update precision as integer
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0' ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
break;
case ( 'sp_statistic' ):
// Update format as string
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'integer' ) );
// Update precision as integer
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0' ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
break;
case ( 'sp_result' ):
// Update format as string
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'integer' ) );
break;
case ( 'sp_player' ):
// Update player statistics
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
// Update player number
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
// Update player details array
update_post_meta( $post_id, 'sp_details', sp_array_value( $_POST, 'sp_details', array() ) );
break;
case ( 'sp_staff' ):
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
break;
case ( 'sp_table' ):
// Update teams array
update_post_meta( $post_id, 'sp_teams', sp_array_value( $_POST, 'sp_teams', array() ) );
// Update season taxonomy
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
break;
case ( 'sp_list' ):
// Update players array
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
// Update team array
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
// Update season taxonomy
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
//Update player array
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
break;
endswitch;
}
add_action( 'save_post', 'sp_save_post' );
?>

View File

@@ -0,0 +1,27 @@
<?php
function sp_admin_post_thumbnail_html( $translated_text, $post_id ) {
$texts = array(
'sp_team' => array(
'Set featured image' => 'Select Logo',
'Remove featured image' => 'Remove Logo',
),
'sp_player' => array(
'Set featured image' => 'Select Photo',
'Remove featured image' => 'Remove Photo',
),
'sp_staff' => array(
'Set featured image' => 'Select Photo',
'Remove featured image' => 'Remove Photo',
),
);
$typenow = get_post_type( $post_id );
if ( is_admin() && array_key_exists( $typenow, $texts ) ):
foreach ( $texts[ $typenow ] as $key => $value ):
$translated_text = str_replace( __( $key ), __( $value, 'sportspress' ), $translated_text );
endforeach;
endif;
return $translated_text;
}
add_filter( 'admin_post_thumbnail_html', 'sp_admin_post_thumbnail_html', 10, 2 );
?>

44
admin/filters/gettext.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
function sp_gettext( $translated_text, $untranslated_text, $domain ) {
global $typenow;
$texts = array(
'sp_team' => array(
'Enter title here' => 'Team',
'Set featured image' => 'Select Logo',
'Set Featured Image' => 'Select Logo',
'Remove featured image' => 'Remove Logo',
),
'sp_event' => array(
'Enter title here' => '(no title)',
'Scheduled for: <b>%1$s</b>' => 'Kick-off: <b>%1$s</b>',
'Published on: <b>%1$s</b>' => 'Kick-off: <b>%1$s</b>',
'Publish <b>immediately</b>' => 'Kick-off: <b>%1$s</b>',
),
'sp_player' => array(
'Enter title here' => 'Name',
'Set featured image' => 'Select Photo',
'Set Featured Image' => 'Select Photo',
'Remove featured image' => 'Remove Photo',
'Scheduled for: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
'Published on: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
'Publish <b>immediately</b>' => 'Joined: <b>%1$s</b>',
),
'sp_staff' => array(
'Enter title here' => 'Name',
'Set featured image' => 'Select Photo',
'Set Featured Image' => 'Select Photo',
'Remove featured image' => 'Remove Photo',
'Scheduled for: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
'Published on: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
'Publish <b>immediately</b>' => 'Joined: <b>%1$s</b>',
),
);
if ( is_admin() && array_key_exists( $typenow, $texts ) && array_key_exists( $untranslated_text, $texts[ $typenow ] ) )
return __( $texts[ $typenow ][ $untranslated_text ], 'sportspress' );
else
return $translated_text;
}
add_filter( 'gettext', 'sp_gettext', 20, 3 );
?>

View File

@@ -0,0 +1,16 @@
<?php
function sp_pre_get_posts( $wp_query ) {
if ( is_admin() ):
$post_type = $wp_query->query['post_type'];
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
$wp_query->set( 'orderby', 'menu_order' );
$wp_query->set( 'order', 'ASC' );
elseif ( $post_type == 'sp_event' ):
$wp_query->set( 'orderby', 'post_date' );
$wp_query->set( 'order', 'ASC' );
endif;
endif;
}
add_filter('pre_get_posts', 'sp_pre_get_posts');
?>

View File

@@ -0,0 +1,26 @@
<?php
function sp_sanitize_title( $title ) {
if ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
$key = $_POST['sp_key'];
if ( ! $key ) $key = $_POST['post_title'];
$title = sp_get_eos_safe_slug( $key, sp_array_value( $_POST, 'ID', 'var' ) );
elseif ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && $_POST['post_type'] == 'sp_event' ):
// Auto slug generation
if ( $_POST['post_title'] == '' && ( $_POST['post_name'] == '' || is_int( $_POST['post_name'] ) ) ):
$title = '';
endif;
endif;
return $title;
}
add_filter( 'sanitize_title', 'sp_sanitize_title' );
?>

View File

@@ -0,0 +1,24 @@
<?php
function sportspress_the_content( $content ) {
if ( is_singular( 'sp_team' ) && in_the_loop() ):
elseif ( is_singular( 'sp_table' ) && in_the_loop() ):
global $post;
// Display league table
$content .= '<p>' . sp_get_table_html( $post->ID ) . '</p>';
elseif ( is_singular( 'sp_list' ) && in_the_loop() ):
global $post;
// Display player list
$content .= '<p>' . sp_get_list_html( $post->ID ) . '</p>';
endif;
return $content;
}
add_filter('the_content', 'sportspress_the_content');
?>

View File

@@ -0,0 +1,20 @@
<?php
function sp_insert_post_data( $data, $postarr ) {
if( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
$teams = (array)$postarr['sp_team'];
$team_names = array();
foreach( $teams as $team ):
$team_names[] = get_the_title( $team );
endforeach;
$data['post_title'] = implode( ' ' . __( 'vs', 'sportspress' ) . ' ', $team_names );
endif;
return $data;
}
add_filter( 'wp_insert_post_data' , 'sp_insert_post_data' , '99', 2 );
?>

View File

@@ -37,7 +37,7 @@ function sp_column_meta_init() {
}
function sp_column_details_meta( $post ) {
global $sportspress_config_formats;
$formats = sp_get_config_formats();
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
@@ -55,7 +55,7 @@ function sp_column_details_meta( $post ) {
<p class="sp-format-selector">
<select name="sp_format">
<?php
foreach ( $sportspress_config_formats as $key => $value ):
foreach ( $formats as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
endforeach;
?>

View File

@@ -13,7 +13,7 @@ function sp_player_cpt_init() {
'register_meta_box_cb' => 'sp_player_meta_init',
'rewrite' => array( 'slug' => get_option( 'sp_player_slug', 'player' ) ),
'menu_icon' => 'dashicons-groups',
'capability_type' => 'sp_player'
'capability_type' => 'sp_player',
);
register_post_type( 'sp_player', $args );
}
@@ -25,7 +25,7 @@ function sp_player_edit_columns() {
'title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' )
'sp_season' => __( 'Seasons', 'sportspress' ),
);
return $columns;
}

View File

@@ -35,7 +35,7 @@ function sp_result_meta_init() {
}
function sp_result_details_meta( $post ) {
global $sportspress_config_formats;
$formats = sp_get_config_formats();
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p>
@@ -45,7 +45,7 @@ function sp_result_details_meta( $post ) {
<p class="sp-format-selector">
<select name="sp_format">
<?php
foreach ( $sportspress_config_formats as $key => $value ):
foreach ( $formats as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
endforeach;
?>

View File

@@ -37,7 +37,7 @@ function sp_statistic_meta_init() {
}
function sp_statistic_equation_meta( $post ) {
global $sportspress_config_formats;
$formats = sp_get_config_formats();
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
@@ -55,7 +55,7 @@ function sp_statistic_equation_meta( $post ) {
<p class="sp-format-selector">
<select name="sp_format">
<?php
foreach ( $sportspress_config_formats as $key => $value ):
foreach ( $formats as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
endforeach;
?>