Add actions, filters, hooks, and scripts

This commit is contained in:
Takumi
2013-07-24 19:09:02 +10:00
parent e3fb4c69dd
commit 3cade7da5d
17 changed files with 180 additions and 94 deletions

12
actions.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
function sp_load_textdomain() {
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' );
function sp_add_theme_support() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_theme_setup', 'sp_add_theme_support' );
?>

View File

@@ -35,10 +35,16 @@ function sp_calendar_custom_columns( $column ) {
echo 'TEAMS';
break;
case 'sp_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break;
case 'sp_season':
if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break;
endswitch;
endif;

View File

@@ -10,7 +10,7 @@ function sp_event_cpt_init() {
'hierarchical' => false,
'supports' => array( 'title', 'author', 'comments', 'page-attributes' ),
'register_meta_box_cb' => 'sp_event_meta_init',
'rewrite' => array( 'slug' => 'event' ),
'rewrite' => array( 'slug' => 'event' )
);
register_post_type( 'sp_event', $args );
}
@@ -30,13 +30,13 @@ function sp_event_text_replace( $input, $text, $domain ) {
if ( is_admin() && get_post_type( $post ) == 'sp_event' )
switch ( $text ):
case 'Scheduled for: <b>%1$s</b>':
return __( 'Kick-off: <b>%1$s</b>', 'sportspress' );
return __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>';
break;
case 'Published on: <b>%1$s</b>':
return __( 'Kick-off: <b>%1$s</b>', 'sportspress' );
return __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>';
break;
case 'Publish <b>immediately</b>':
return __( 'Kick-off: <b>%1$s</b>', 'sportspress' );
return __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>';
break;
default:
return $input;
@@ -46,22 +46,10 @@ function sp_event_text_replace( $input, $text, $domain ) {
add_filter( 'gettext', 'sp_event_text_replace', 20, 3 );
function sp_event_meta_init() {
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'
);
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( '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' );
}
function sp_event_team_meta( $post, $metabox ) {
@@ -73,8 +61,8 @@ function sp_event_team_meta( $post, $metabox ) {
'name' => 'sportspress[sp_team_' . $i . ']',
'selected' => get_post_meta( $post_id, 'sp_team_' . $i, true ),
);
echo '<label for="sp_team_' . $i . '">' . __( 'Team', 'sportspress' ) . ' ' . $i . ':</label>' . PHP_EOL;
wp_dropdown_pages( $args );
echo '<div class="clear"></div>' . PHP_EOL;
/*
$players = unserialize( get_post_meta( $post_id, 'sp_players', true ) );
?>
@@ -220,8 +208,7 @@ function sp_event_edit_columns( $columns ) {
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_kickoff' => __( 'Kick-off', 'sportspress' ),
'date' => __( 'Date' ),
'sp_kickoff' => __( 'Kick-off', 'sportspress' )
);
return $columns;
}
@@ -235,48 +222,45 @@ function sp_event_custom_columns( $column, $post_id ) {
$limit = get_option( 'sp_event_team_count' );
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 ) {
edit_post_link( get_the_title( $parent ), '', ' — ', $parent );
}
edit_post_link( get_the_title( $team ), '', '<br />', $team );
endfor;
break;
case 'sp_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break;
case 'sp_season':
if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break;
case 'sp_sponsor':
if ( get_the_terms ( $post_id, 'sp_sponsor' ) )
the_terms( $post_id, 'sp_sponsor' );
else
echo '—';
break;
case 'sp_kickoff':
echo get_the_time ( get_option ( 'time_format' ) );
break;
case 'date':
echo get_the_date ( get_option ( 'date_format' ) );
echo get_the_date ( get_option ( 'date_format' ) ) . '<br />' . get_the_time ( get_option ( 'time_format' ) );
break;
endswitch;
endif;
}
add_action( 'manage_posts_custom_column', 'sp_event_custom_columns', 10, 2 );
/*
function sp_event_edit_sortable_columns( $columns ) {
$columns['sp_team'] = 'sp_team';
$columns['sp_kickoff'] = 'sp_kickoff';
return $columns;
}
add_filter( 'manage_edit-sp_event_sortable_columns', 'sp_event_edit_sortable_columns' );
function sp_event_column_sorting( $vars ) {
if( isset( $vars['orderby'] ) && 'sp_team' == $vars['orderby'] ){
$vars = array_merge( $vars, array(
'meta_key' => 'sp_team_1',
'orderby' => 'meta_value'
) );
}
return $vars;
}
add_filter('requests', 'sp_event_column_sorting');
*/
function sp_event_request_filter_dropdowns() {
global $typenow, $wp_query;
if ( $typenow == 'sp_event' ) {

16
filters.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
function sp_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 ) {
if( has_post_thumbnail( $parent ) ) {
$html = get_the_post_thumbnail( $parent, $size, $attr );
break;
}
}
}
return $html;
}
add_filter( 'post_thumbnail_html', 'sp_thumbnail_html', 10, 5 );
?>

View File

@@ -64,7 +64,9 @@ if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) {
print( '</select>' );
}
}
if ( ! function_exists( 'sp_team_logo' ) ) {
}
if ( ! function_exists( 'sp_team_logo' ) ) {
function sp_team_logo( $post_id = null ) {
if ( ! isset( $post_id ) )
global $post_id;
@@ -80,6 +82,5 @@ if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) {
}
endif;
}
}
}
?>

8
hooks.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
// Flush rewrite rules on activation to make sure permalinks work properly
function sp_rewrite_flush() {
sp_team_cpt_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'sp_rewrite_flush' );
?>

View File

@@ -38,16 +38,28 @@ function sp_player_custom_columns( $column ) {
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_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break;
case 'sp_season':
if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break;
case 'sp_sponsor':
if ( get_the_terms ( $post_id, 'sp_sponsor' ) )
the_terms( $post_id, 'sp_sponsor' );
else
echo '—';
break;
endswitch;
endif;

6
scripts.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
function sp_admin_enqueue_scripts() {
wp_enqueue_script( 'sportspress-admin', plugin_dir_url( __FILE__ ) .'/sportspress-admin.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker' ), time(), true );
}
add_action( 'admin_enqueue_scripts', 'sp_admin_enqueue_scripts' );
?>

View File

@@ -3,7 +3,7 @@ function sp_settings_menu() {
add_submenu_page(
'options-general.php',
__( 'SportsPress', 'sportspress' ),
__( 'Sportspress', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
'manage_options',
'sp_settings',
'sp_settings_page'
@@ -12,6 +12,8 @@ function sp_settings_menu() {
add_action('admin_menu', 'sp_settings_menu');
function sp_settings_page() {
echo '<input type="text" id="datepicker" name="example[datepicker]" value="" class="sp_datepicker" />';
/*
if ( true | ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
$hidden_field_name = 'tb_submit_hidden';
?>
@@ -110,4 +112,4 @@ function sp_settings_page() {
<?php submit_button( null, 'primary', 'save-sportspress-options' ); ?>
</form>
</div>
<?php } ?>
<?php */ } ?>

View File

@@ -84,7 +84,14 @@
background-position: -209px -1px;
}
#sp_articlediv .wp-editor-container{
#poststuff #sp_kickoffdiv .inside {
margin: 0;
padding: 0;
}
#sp_kickoffdiv #timestampdiv p {
display: none;
}
#sp_articlediv .wp-editor-container {
background-color:#fff;
}
.widefat th.column-sp_icon,

3
sportspress-admin.js Normal file
View File

@@ -0,0 +1,3 @@
jQuery(document).ready(function(){
jQuery('.sp_datepicker').datepicker();
});

View File

@@ -30,7 +30,7 @@ include dirname( __FILE__ ) . '/defaults.php' ;
// Settings
include dirname( __FILE__ ) . '/settings.php' ;
// Custom post types
// Custom Post Types
require_once dirname( __FILE__ ) . '/team.php';
require_once dirname( __FILE__ ) . '/event.php';
require_once dirname( __FILE__ ) . '/player.php';
@@ -46,20 +46,14 @@ require_once dirname( __FILE__ ) . '/venue.php';
require_once dirname( __FILE__ ) . '/position.php';
require_once dirname( __FILE__ ) . '/sponsor.php';
// Stylesheets
include dirname( __FILE__ ) . '/styles.php' ;
// Styles
include_once dirname( __FILE__ ) . '/styles.php' ;
// Flush rewrite rules on activation to make sure permalinks work properly
function sp_rewrite_flush() {
sp_team_cpt_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'sp_rewrite_flush' );
// Scripts
include_once dirname( __FILE__ ) . '/scripts.php' ;
function sp_init() {
add_theme_support( 'post-thumbnails' );
load_plugin_textdomain ( 'sportspress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
add_image_size( 'sp_icon', 32, 32, false );
}
add_action( 'plugins_loaded', 'sp_init' );
// Hooks, Actions, and Filters
require_once dirname( __FILE__ ) . '/hooks.php';
require_once dirname( __FILE__ ) . '/actions.php';
require_once dirname( __FILE__ ) . '/filters.php';
?>

View File

@@ -37,13 +37,22 @@ function sp_staff_custom_columns( $column ) {
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_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break;
case 'sp_season':
if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break;
endswitch;
endif;

View File

@@ -35,10 +35,16 @@ function sp_table_custom_columns( $column ) {
echo 'TEAMS';
break;
case 'sp_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break;
case 'sp_season':
if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break;
endswitch;
endif;

View File

@@ -9,6 +9,7 @@ function sp_team_cpt_init() {
'public' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'register_meta_box_cb' => 'sp_team_meta_init',
'rewrite' => array( 'slug' => 'team' ),
);
register_post_type( 'sp_team', $args );
@@ -19,8 +20,14 @@ function sp_team_text_replace( $input, $text, $domain ) {
global $post;
if ( is_admin() && get_post_type( $post ) == 'sp_team' )
switch ( $text ):
case 'Featured Image':
return __( 'Logo', 'themeboy' );
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;
@@ -29,6 +36,13 @@ function sp_team_text_replace( $input, $text, $domain ) {
}
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) {
$columns = array(
'cb' => '<input type="checkbox" />',
@@ -47,7 +61,7 @@ function sp_team_custom_columns( $column ) {
if ( $typenow == 'sp_team' ):
switch ( $column ):
case 'sp_icon':
sp_team_logo( $post_id );
the_post_thumbnail( 'sp_icon' );
break;
case 'sp_league':
if ( get_the_terms ( $post_id, 'sp_league' ) )

View File

@@ -35,10 +35,13 @@ function sp_tournament_custom_columns( $column ) {
echo 'TEAMS';
break;
case 'sp_event':
the_terms( $post_id, 'sp_event' );
echo 'EVENTS';
break;
case 'sp_sponsor':
if ( get_the_terms ( $post_id, 'sp_sponsor' ) )
the_terms( $post_id, 'sp_sponsor' );
else
echo '—';
break;
endswitch;
endif;

View File

@@ -31,7 +31,10 @@ function sp_venue_custom_columns( $column, $post_id ) {
if ( $typenow == 'sp_venue' ):
switch ( $column ):
case 'sp_sponsor':
if ( get_the_terms ( $post_id, 'sp_sponsor' ) )
the_terms( $post_id, 'sp_sponsor' );
else
echo '—';
break;
case 'sp_address':
echo get_post_meta( $post_id, 'sp_address', true );