Add globals and simplify gettext filter

This commit is contained in:
Takumi
2013-07-25 16:42:03 +10:00
parent 3f82e5c72c
commit 16fc3a5bb9
8 changed files with 69 additions and 46 deletions

View File

@@ -1,14 +0,0 @@
<?php
$sp_options = array(
'settings' => array(
'sp_event_team_count' => 2,
),
);
foreach( $sp_options as $optiongroupkey => $optiongroup ) {
foreach( $optiongroup as $key => $value ) {
if ( get_option( $key ) === false )
update_option( $key, $value );
}
}
?>

View File

@@ -47,7 +47,7 @@ add_filter( 'gettext', 'sp_event_text_replace', 20, 3 );
function sp_event_meta_init() {
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
add_meta_box( 'submitdiv', __( 'Kick-off', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
}

View File

@@ -1,5 +1,5 @@
<?php
function sp_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
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', 'sp_venue' ) ) ) {
$parents = get_post_ancestors( $post_id );
foreach ( $parents as $parent ) {
@@ -11,6 +11,26 @@ function sp_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr )
}
return $html;
}
add_filter( 'post_thumbnail_html', 'sp_post_thumbnail_html', 10, 5 );
add_filter( 'post_thumbnail_html', 'sp_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 ];
else
return $translated_text;
}
add_filter( 'gettext', 'sp_gettext', 20, 3 );
function sp_admin_post_thumbnail_html( $translated_text, $post_id ) {
global $sportspress_texts;
$typenow = get_post_type( $post_id );
if ( is_admin() && array_key_exists( $typenow, $sportspress_texts ) ):
foreach ( $sportspress_texts[ $typenow ] as $key => $value ):
$translated_text = str_replace( __( $key ), $value, $translated_text );
endforeach;
endif;
return $translated_text;
}
add_filter( 'admin_post_thumbnail_html', 'sp_admin_post_thumbnail_html', 10, 2 );
?>

36
globals.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
$sportspress_options = array(
'settings' => array(
'sp_event_team_count' => 2,
)
);
$sportspress_texts = array(
'sp_team' => array(
'Enter title here' => __( 'Team', 'sportspress' ),
'Set featured image' => sprintf( __( 'Add %s', 'sportspress' ), __( 'Logo', 'sportspress' ) ),
'Set Featured Image' => sprintf( __( 'Add %s', 'sportspress' ), __( 'Logo', 'sportspress' ) ),
'Parent' => sprintf( __( 'Parent %s', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Logo', 'sportspress' ) )
),
'sp_player' => array(
'Enter title here' => __( 'Name', 'sportspress' ),
'Set featured image' => sprintf( __( 'Add %s', 'sportspress' ), __( 'Photo', 'sportspress' ) ),
'Set Featured Image' => sprintf( __( 'Add %s', 'sportspress' ), __( 'Photo', 'sportspress' ) ),
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Photo', 'sportspress' ) )
),
'sp_staff' => array(
'Enter title here' => __( 'Name', 'sportspress' ),
'Set featured image' => sprintf( __( 'Add %s', 'sportspress' ), __( 'Photo', 'sportspress' ) ),
'Set Featured Image' => sprintf( __( 'Add %s', 'sportspress' ), __( 'Photo', 'sportspress' ) ),
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Photo', 'sportspress' ) )
)
);
foreach( $sportspress_options as $optiongroupkey => $optiongroup ) {
foreach( $optiongroup as $key => $value ) {
if ( get_option( $key ) === false )
update_option( $key, $value );
}
}
?>

View File

@@ -12,7 +12,7 @@ if ( ! function_exists( 'sp_get_cpt_labels' ) ) {
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $name ),
'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $name ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'sportspress' ), $singular_name ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'sportspress' ), $singular_name )
);
return $labels;
}
@@ -32,7 +32,7 @@ if ( ! function_exists( 'sp_get_tax_labels' ) ) {
'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), __( $singular_name, 'sportspress' ) ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'sportspress' ), __( $singular_name, 'sportspress' ) ),
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), __( $name, 'sportspress' ) ),
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), __( $name, 'sportspress' ) ),
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), __( $name, 'sportspress' ) )
);
return $labels;
}
@@ -125,9 +125,6 @@ if ( ! function_exists( 'sp_team_select_html' ) ) {
if ( ! isset( $post_id ) )
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">

View File

@@ -17,7 +17,9 @@ function sp_player_cpt_init() {
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' );
remove_meta_box( 'postimagediv', 'sp_player', 'side' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_playerdiv', __( 'Teams', '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 ) {

View File

@@ -21,12 +21,12 @@ if ( !function_exists( 'add_action' ) ) {
define( 'SPORTSPRESS_VERSION', '0.1' );
define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
// Globals
include dirname( __FILE__ ) . '/globals.php' ;
// Helpers
require_once dirname( __FILE__ ) . '/helpers.php';
// Defaults
include dirname( __FILE__ ) . '/defaults.php' ;
// Settings
include dirname( __FILE__ ) . '/settings.php' ;

View File

@@ -16,27 +16,9 @@ function sp_team_cpt_init() {
}
add_action( 'init', 'sp_team_cpt_init' );
function sp_team_text_replace( $input, $text, $domain ) {
global $post;
if ( is_admin() && get_post_type( $post ) == 'sp_team' )
switch ( $text ):
case 'Set featured image':
return sprintf( __( 'Add %s', 'sportspress' ), __( 'Logo', 'sportspress' ) );
break;
case 'Set Featured Image':
return sprintf( __( 'Add %s', 'sportspress' ), __( 'Logo', 'sportspress' ) );
break;
case 'Remove featured image':
return sprintf( __( 'Remove %s', 'sportspress' ), __( 'Logo', 'sportspress' ) );
break;
default:
return $input;
endswitch;
return $input;
}
add_filter( 'gettext', 'sp_team_text_replace', 20, 3 );
function sp_team_meta_init() {
remove_meta_box( 'submitdiv', 'sp_team', 'side' );
add_meta_box( 'submitdiv', __( 'Publish', 'sportspress' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
}