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,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 );
?>