Put things in folders and stuff
This commit is contained in:
32
admin/actions/admin-menu.php
Normal file
32
admin/actions/admin-menu.php
Normal 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' );
|
||||
?>
|
||||
6
admin/actions/after-theme-setup.php
Normal file
6
admin/actions/after-theme-setup.php
Normal 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' );
|
||||
?>
|
||||
6
admin/actions/manage-posts-columns.php
Normal file
6
admin/actions/manage-posts-columns.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
function sp_manage_posts_columns() {
|
||||
sp_highlight_admin_menu();
|
||||
}
|
||||
add_action( 'manage_posts_columns', 'sp_manage_posts_columns' );
|
||||
?>
|
||||
86
admin/actions/manage-posts-custom-column.php
Normal file
86
admin/actions/manage-posts-custom-column.php
Normal 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 );
|
||||
?>
|
||||
7
admin/actions/plugins-loaded.php
Normal file
7
admin/actions/plugins-loaded.php
Normal 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' );
|
||||
?>
|
||||
15
admin/actions/post-thumbnail-html.php
Normal file
15
admin/actions/post-thumbnail-html.php
Normal 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 );
|
||||
?>
|
||||
37
admin/actions/restrict-manage-posts.php
Normal file
37
admin/actions/restrict-manage-posts.php
Normal 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
137
admin/actions/save-post.php
Normal 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' );
|
||||
?>
|
||||
27
admin/filters/admin-post-thumbnail-html.php
Normal file
27
admin/filters/admin-post-thumbnail-html.php
Normal 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
44
admin/filters/gettext.php
Normal 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 );
|
||||
?>
|
||||
16
admin/filters/pre-get-posts.php
Normal file
16
admin/filters/pre-get-posts.php
Normal 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');
|
||||
?>
|
||||
26
admin/filters/sanitize-title.php
Normal file
26
admin/filters/sanitize-title.php
Normal 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' );
|
||||
?>
|
||||
24
admin/filters/the-content.php
Normal file
24
admin/filters/the-content.php
Normal 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');
|
||||
?>
|
||||
20
admin/filters/wp-insert-post-data.php
Normal file
20
admin/filters/wp-insert-post-data.php
Normal 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 );
|
||||
?>
|
||||
@@ -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;
|
||||
?>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
?>
|
||||
|
||||
@@ -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;
|
||||
?>
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
<?php
|
||||
if ( !function_exists( 'sp_nonce' ) ) {
|
||||
function sp_nonce() {
|
||||
echo '<input type="hidden" name="sportspress_nonce" id="sportspress_nonce" value="' . wp_create_nonce( SPORTSPRESS_PLUGIN_BASENAME ) . '" />';
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_array_between' ) ) {
|
||||
function sp_array_between ( $array = array(), $delimiter = 0, $index = 0 ) {
|
||||
$keys = array_keys( $array, $delimiter );
|
||||
@@ -105,8 +111,8 @@ if ( !function_exists( 'sp_get_post_format' ) ) {
|
||||
function sp_get_post_format( $post_id ) {
|
||||
$format = get_post_meta ( $post_id, 'sp_format', true );
|
||||
if ( $format ):
|
||||
global $sportspress_config_formats;
|
||||
$format_str = __( sp_array_value( $sportspress_config_formats, $format, '—' ), 'sportspress' );
|
||||
$formats = sp_get_config_formats();
|
||||
$format_str = sp_array_value( $formats, $format, '—' );
|
||||
if ( in_array( $format, array( 'decimal', 'time' ) ) ):
|
||||
return $format_str . ' (' . sp_get_post_precision( $post_id ) . ')';
|
||||
else:
|
||||
@@ -159,6 +165,18 @@ if ( !function_exists( 'sp_get_post_order' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_get_config_formats' ) ) {
|
||||
function sp_get_config_formats() {
|
||||
$arr = array(
|
||||
'integer' => __( 'Integer', 'sportspress' ),
|
||||
'decimal' => __( 'Decimal', 'sportspress' ),
|
||||
'time' => __( 'Time', 'sportspress' ),
|
||||
'custom' => __( 'Custom Field', 'sportspress' ),
|
||||
);
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
||||
function sp_dropdown_taxonomies( $args = array() ) {
|
||||
$defaults = array(
|
||||
@@ -770,7 +788,8 @@ if ( !function_exists( 'sp_event_player_sub_selector' ) ) {
|
||||
// Add players as selectable options
|
||||
foreach( $data as $id => $statistics ):
|
||||
if ( ! $id || $id == $player_id ) continue;
|
||||
$output .= '<option value="' . $id . '"' . ( $id == $value ? ' selected' : '' ) . '>' . get_the_title( $id ) . '</option>';
|
||||
$number = get_post_meta( $id, 'sp_number', true );
|
||||
$output .= '<option value="' . $id . '"' . ( $id == $value ? ' selected' : '' ) . '>' . ( $number ? $number . '. ' : '' ) . get_the_title( $id ) . '</option>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</select>';
|
||||
@@ -799,10 +818,11 @@ if ( !function_exists( 'sp_event_players_table' ) ) {
|
||||
$i = 0;
|
||||
foreach ( $data as $player_id => $player_statistics ):
|
||||
if ( !$player_id ) continue;
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo get_the_title( $player_id ); ?>
|
||||
<?php echo ( $number ? $number . '. ' : '' ) . get_the_title( $player_id ); ?>
|
||||
</td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$value = sp_array_value( $player_statistics, $column, '' );
|
||||
41
i18n/strings.php
Normal file
41
i18n/strings.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// Localize sport names
|
||||
__( 'Association Football (Soccer)', 'sportspress' );
|
||||
__( 'American Football', 'sportspress' );
|
||||
__( 'Australian Rules Football', 'sportspress' );
|
||||
__( 'Baseball', 'sportspress' );
|
||||
__( 'Basketball', 'sportspress' );
|
||||
__( 'Competitive Gaming', 'sportspress' );
|
||||
__( 'Cricket', 'sportspress' );
|
||||
__( 'Golf', 'sportspress' );
|
||||
__( 'Handball', 'sportspress' );
|
||||
__( 'Hockey', 'sportspress' );
|
||||
__( 'Racing', 'sportspress' );
|
||||
__( 'Rugby', 'sportspress' );
|
||||
__( 'Swimming', 'sportspress' );
|
||||
__( 'Tennis', 'sportspress' );
|
||||
__( 'Volleyball', 'sportspress' );
|
||||
|
||||
// Localize post titles
|
||||
__( 'Appearances', 'sportspress' );
|
||||
__( 'Goals', 'sportspress' );
|
||||
__( 'Assists', 'sportspress' );
|
||||
__( 'Yellow Cards', 'sportspress' );
|
||||
__( 'Red Cards', 'sportspress' );
|
||||
__( 'Height', 'sportspress' );
|
||||
__( 'Weight', 'sportspress' );
|
||||
|
||||
// Localize post context texts
|
||||
__( 'Select Logo', 'sportspress' );
|
||||
__( 'Remove Logo', 'sportspress' );
|
||||
__( 'Kick-off: <b>%1$s</b>', 'sportspress' );
|
||||
__( 'Joined: <b>%1$s</b>', 'sportspress' );
|
||||
__( 'Select Photo', 'sportspress' );
|
||||
__( 'Remove Photo', 'sportspress' );
|
||||
|
||||
// Localize configuration formats
|
||||
__( 'Integer', 'sportspress' );
|
||||
__( 'Decimal', 'sportspress' );
|
||||
__( 'Time', 'sportspress' );
|
||||
__( 'Custom Field', 'sportspress' );
|
||||
?>
|
||||
@@ -1,293 +0,0 @@
|
||||
<?php
|
||||
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_plugins_loaded' );
|
||||
|
||||
function sp_after_theme_setup() {
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
}
|
||||
add_action( 'after_theme_setup', 'sp_after_theme_setup' );
|
||||
|
||||
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' );
|
||||
|
||||
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 );
|
||||
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;
|
||||
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 );
|
||||
|
||||
function sp_manage_posts_columns() {
|
||||
sp_highlight_admin_menu();
|
||||
}
|
||||
add_action( 'manage_posts_columns', 'sp_manage_posts_columns' );
|
||||
|
||||
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' );
|
||||
|
||||
function sp_nonce() {
|
||||
echo '<input type="hidden" name="sportspress_nonce" id="sportspress_nonce" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
|
||||
}
|
||||
|
||||
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'], plugin_basename( __FILE__ ) ) ) 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' );
|
||||
?>
|
||||
@@ -1,118 +0,0 @@
|
||||
<?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 );
|
||||
|
||||
function sp_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
global $typenow, $sportspress_texts;
|
||||
if ( is_admin() && array_key_exists( $typenow, $sportspress_texts ) && array_key_exists( $untranslated_text, $sportspress_texts[ $typenow ] ) )
|
||||
return __( $sportspress_texts[ $typenow ][ $untranslated_text ], 'sportspress' );
|
||||
else
|
||||
return $translated_text;
|
||||
}
|
||||
add_filter( 'gettext', 'sp_gettext', 20, 3 );
|
||||
|
||||
function sp_admin_post_thumbnail_html( $translated_text, $post_id ) {
|
||||
global $sportspress_thumbnail_texts;
|
||||
$typenow = get_post_type( $post_id );
|
||||
if ( is_admin() && array_key_exists( $typenow, $sportspress_thumbnail_texts ) ):
|
||||
foreach ( $sportspress_thumbnail_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 );
|
||||
|
||||
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');
|
||||
|
||||
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' );
|
||||
|
||||
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 );
|
||||
|
||||
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');
|
||||
?>
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
// Sports array to be populated with presets
|
||||
$sportspress_sports = array();
|
||||
|
||||
// Localize sport names
|
||||
__( 'Association Football (Soccer)', 'sportspress' );
|
||||
__( 'American Football', 'sportspress' );
|
||||
__( 'Australian Rules Football', 'sportspress' );
|
||||
__( 'Baseball', 'sportspress' );
|
||||
__( 'Basketball', 'sportspress' );
|
||||
__( 'Competitive Gaming', 'sportspress' );
|
||||
__( 'Cricket', 'sportspress' );
|
||||
__( 'Golf', 'sportspress' );
|
||||
__( 'Handball', 'sportspress' );
|
||||
__( 'Hockey', 'sportspress' );
|
||||
__( 'Racing', 'sportspress' );
|
||||
__( 'Rugby', 'sportspress' );
|
||||
__( 'Swimming', 'sportspress' );
|
||||
__( 'Tennis', 'sportspress' );
|
||||
__( 'Volleyball', 'sportspress' );
|
||||
|
||||
// Localize post titles
|
||||
__( 'Appearances', 'sportspress' );
|
||||
__( 'Goals', 'sportspress' );
|
||||
__( 'Assists', 'sportspress' );
|
||||
__( 'Yellow Cards', 'sportspress' );
|
||||
__( 'Red Cards', 'sportspress' );
|
||||
__( 'Height', 'sportspress' );
|
||||
__( 'Weight', 'sportspress' );
|
||||
|
||||
// Localize post context texts
|
||||
__( 'Select Logo', 'sportspress' );
|
||||
__( 'Remove Logo', 'sportspress' );
|
||||
__( 'Kick-off: <b>%1$s</b>', 'sportspress' );
|
||||
__( 'Joined: <b>%1$s</b>', 'sportspress' );
|
||||
__( 'Select Photo', 'sportspress' );
|
||||
__( 'Remove Photo', 'sportspress' );
|
||||
|
||||
// Localize configuration formats
|
||||
__( 'Integer', 'sportspress' );
|
||||
__( 'Decimal', 'sportspress' );
|
||||
__( 'Time', 'sportspress' );
|
||||
__( 'Custom Field', 'sportspress' );
|
||||
|
||||
$sportspress_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>',
|
||||
),
|
||||
);
|
||||
|
||||
$sportspress_thumbnail_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',
|
||||
),
|
||||
);
|
||||
|
||||
$sportspress_config_formats = array(
|
||||
'integer' => 'Integer',
|
||||
'decimal' => 'Decimal',
|
||||
'time' => 'Time',
|
||||
'custom' => 'Custom Field',
|
||||
);
|
||||
?>
|
||||
@@ -20,16 +20,16 @@ if ( !function_exists( 'add_action' ) ) {
|
||||
|
||||
define( 'SPORTSPRESS_VERSION', '0.1' );
|
||||
define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
define( 'SPORTSPRESS_PLUGIN_DIRNAME', dirname( __FILE__ ) );
|
||||
define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||
|
||||
// Libraries
|
||||
include dirname( __FILE__ ) . '/lib/eos/eos.class.php' ;
|
||||
|
||||
// Globals
|
||||
include dirname( __FILE__ ) . '/sportspress-globals.php' ;
|
||||
// Internationalization
|
||||
include dirname( __FILE__ ) . '/i18n/strings.php';
|
||||
|
||||
// Functions
|
||||
require_once dirname( __FILE__ ) . '/sportspress-functions.php';
|
||||
require_once dirname( __FILE__ ) . '/functions.php';
|
||||
|
||||
// Settings
|
||||
include dirname( __FILE__ ) . '/admin/settings/settings.php' ;
|
||||
@@ -72,10 +72,22 @@ include_once dirname( __FILE__ ) . '/admin/presets/volleyball.php';
|
||||
include dirname( __FILE__ ) . '/install.php';
|
||||
|
||||
// Actions
|
||||
require_once dirname( __FILE__ ) . '/sportspress-actions.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/plugins-loaded.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/post-thumbnail-html.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/after-theme-setup.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/admin-menu.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/manage-posts-custom-column.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/manage-posts-columns.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/restrict-manage-posts.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/actions/save-post.php';
|
||||
|
||||
// Filters
|
||||
require_once dirname( __FILE__ ) . '/sportspress-filters.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/filters/gettext.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/filters/admin-post-thumbnail-html.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/filters/the-content.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/filters/sanitize-title.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/filters/wp-insert-post-data.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/filters/pre-get-posts.php';
|
||||
|
||||
// Admin Styles
|
||||
function sp_admin_styles() {
|
||||
|
||||
Reference in New Issue
Block a user