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'; echo 'TEAMS';
break; break;
case 'sp_league': case 'sp_league':
the_terms( $post_id, 'sp_league' ); if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break; break;
case 'sp_season': case 'sp_season':
the_terms( $post_id, 'sp_season' ); if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break; break;
endswitch; endswitch;
endif; endif;

View File

@@ -10,7 +10,7 @@ function sp_event_cpt_init() {
'hierarchical' => false, 'hierarchical' => false,
'supports' => array( 'title', 'author', 'comments', 'page-attributes' ), 'supports' => array( 'title', 'author', 'comments', 'page-attributes' ),
'register_meta_box_cb' => 'sp_event_meta_init', 'register_meta_box_cb' => 'sp_event_meta_init',
'rewrite' => array( 'slug' => 'event' ), 'rewrite' => array( 'slug' => 'event' )
); );
register_post_type( 'sp_event', $args ); 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' ) if ( is_admin() && get_post_type( $post ) == 'sp_event' )
switch ( $text ): switch ( $text ):
case 'Scheduled for: <b>%1$s</b>': case 'Scheduled for: <b>%1$s</b>':
return __( 'Kick-off: <b>%1$s</b>', 'sportspress' ); return __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>';
break; break;
case 'Published on: <b>%1$s</b>': case 'Published on: <b>%1$s</b>':
return __( 'Kick-off: <b>%1$s</b>', 'sportspress' ); return __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>';
break; break;
case 'Publish <b>immediately</b>': case 'Publish <b>immediately</b>':
return __( 'Kick-off: <b>%1$s</b>', 'sportspress' ); return __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>';
break; break;
default: default:
return $input; return $input;
@@ -46,22 +46,10 @@ function sp_event_text_replace( $input, $text, $domain ) {
add_filter( 'gettext', 'sp_event_text_replace', 20, 3 ); add_filter( 'gettext', 'sp_event_text_replace', 20, 3 );
function sp_event_meta_init() { function sp_event_meta_init() {
add_meta_box( remove_meta_box( 'submitdiv', 'sp_event', 'side' );
'sp_teamdiv', add_meta_box( 'submitdiv', __( 'Kick-off', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
__( 'Teams', 'sportspress' ), add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'normal', 'high' );
'sp_event_team_meta', add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
'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 ) { function sp_event_team_meta( $post, $metabox ) {
@@ -73,8 +61,8 @@ function sp_event_team_meta( $post, $metabox ) {
'name' => 'sportspress[sp_team_' . $i . ']', 'name' => 'sportspress[sp_team_' . $i . ']',
'selected' => get_post_meta( $post_id, 'sp_team_' . $i, true ), '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 ); wp_dropdown_pages( $args );
echo '<div class="clear"></div>' . PHP_EOL;
/* /*
$players = unserialize( get_post_meta( $post_id, 'sp_players', true ) ); $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_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ), 'sp_season' => __( 'Season', 'sportspress' ),
'sp_sponsor' => __( 'Sponsor', 'sportspress' ), 'sp_sponsor' => __( 'Sponsor', 'sportspress' ),
'sp_kickoff' => __( 'Kick-off', 'sportspress' ), 'sp_kickoff' => __( 'Kick-off', 'sportspress' )
'date' => __( 'Date' ),
); );
return $columns; return $columns;
} }
@@ -235,48 +222,45 @@ function sp_event_custom_columns( $column, $post_id ) {
$limit = get_option( 'sp_event_team_count' ); $limit = get_option( 'sp_event_team_count' );
for ( $i = 1; $i <= $limit; $i++ ): for ( $i = 1; $i <= $limit; $i++ ):
$team = get_post_meta( $post_id, 'sp_team_' . $i, true ); $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 ); edit_post_link( get_the_title( $team ), '', '<br />', $team );
endfor; endfor;
break; break;
case 'sp_league': case 'sp_league':
the_terms( $post_id, 'sp_league' ); if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break; break;
case 'sp_season': case 'sp_season':
the_terms( $post_id, 'sp_season' ); if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break; break;
case 'sp_sponsor': case 'sp_sponsor':
the_terms( $post_id, 'sp_sponsor' ); if ( get_the_terms ( $post_id, 'sp_sponsor' ) )
the_terms( $post_id, 'sp_sponsor' );
else
echo '—';
break; break;
case 'sp_kickoff': case 'sp_kickoff':
echo get_the_time ( get_option ( 'time_format' ) ); echo get_the_date ( get_option ( 'date_format' ) ) . '<br />' . get_the_time ( get_option ( 'time_format' ) );
break;
case 'date':
echo get_the_date ( get_option ( 'date_format' ) );
break; break;
endswitch; endswitch;
endif; endif;
} }
add_action( 'manage_posts_custom_column', 'sp_event_custom_columns', 10, 2 ); add_action( 'manage_posts_custom_column', 'sp_event_custom_columns', 10, 2 );
/*
function sp_event_edit_sortable_columns( $columns ) { function sp_event_edit_sortable_columns( $columns ) {
$columns['sp_team'] = 'sp_team'; $columns['sp_kickoff'] = 'sp_kickoff';
return $columns; return $columns;
} }
add_filter( 'manage_edit-sp_event_sortable_columns', 'sp_event_edit_sortable_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() { function sp_event_request_filter_dropdowns() {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow == 'sp_event' ) { 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,22 +64,23 @@ if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) {
print( '</select>' ); print( '</select>' );
} }
} }
if ( ! function_exists( 'sp_team_logo' ) ) { }
function sp_team_logo( $post_id = null ) {
if ( ! isset( $post_id ) ) if ( ! function_exists( 'sp_team_logo' ) ) {
global $post_id; function sp_team_logo( $post_id = null ) {
if ( has_post_thumbnail( $post_id ) ): if ( ! isset( $post_id ) )
the_post_thumbnail( 'sp_icon' ); global $post_id;
else: if ( has_post_thumbnail( $post_id ) ):
$parents = get_post_ancestors( $post_id ); the_post_thumbnail( 'sp_icon' );
foreach ( $parents as $parent ) { else:
if( has_post_thumbnail( $parent ) ) { $parents = get_post_ancestors( $post_id );
echo get_the_post_thumbnail( $parent, 'sp_icon'); foreach ( $parents as $parent ) {
break; if( has_post_thumbnail( $parent ) ) {
} echo get_the_post_thumbnail( $parent, 'sp_icon');
break;
} }
endif; }
} 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' ); if ( has_post_thumbnail() ) the_post_thumbnail( 'sp_icon' );
break; break;
case 'sp_position': case 'sp_position':
the_terms( $post_id, 'sp_position' ); if ( get_the_terms ( $post_id, 'sp_position' ) )
the_terms( $post_id, 'sp_position' );
else
echo '—';
break; break;
case 'sp_league': case 'sp_league':
the_terms( $post_id, 'sp_league' ); if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break; break;
case 'sp_season': case 'sp_season':
the_terms( $post_id, 'sp_season' ); if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break; break;
case 'sp_sponsor': case 'sp_sponsor':
the_terms( $post_id, 'sp_sponsor' ); if ( get_the_terms ( $post_id, 'sp_sponsor' ) )
the_terms( $post_id, 'sp_sponsor' );
else
echo '—';
break; break;
endswitch; endswitch;
endif; 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( add_submenu_page(
'options-general.php', 'options-general.php',
__( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ),
__( 'Sportspress', 'sportspress' ), __( 'SportsPress', 'sportspress' ),
'manage_options', 'manage_options',
'sp_settings', 'sp_settings',
'sp_settings_page' 'sp_settings_page'
@@ -12,6 +12,8 @@ function sp_settings_menu() {
add_action('admin_menu', 'sp_settings_menu'); add_action('admin_menu', 'sp_settings_menu');
function sp_settings_page() { 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.' ) ); 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'; $hidden_field_name = 'tb_submit_hidden';
?> ?>
@@ -110,4 +112,4 @@ function sp_settings_page() {
<?php submit_button( null, 'primary', 'save-sportspress-options' ); ?> <?php submit_button( null, 'primary', 'save-sportspress-options' ); ?>
</form> </form>
</div> </div>
<?php } ?> <?php */ } ?>

View File

@@ -84,7 +84,14 @@
background-position: -209px -1px; 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; background-color:#fff;
} }
.widefat th.column-sp_icon, .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 // Settings
include dirname( __FILE__ ) . '/settings.php' ; include dirname( __FILE__ ) . '/settings.php' ;
// Custom post types // Custom Post Types
require_once dirname( __FILE__ ) . '/team.php'; require_once dirname( __FILE__ ) . '/team.php';
require_once dirname( __FILE__ ) . '/event.php'; require_once dirname( __FILE__ ) . '/event.php';
require_once dirname( __FILE__ ) . '/player.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__ ) . '/position.php';
require_once dirname( __FILE__ ) . '/sponsor.php'; require_once dirname( __FILE__ ) . '/sponsor.php';
// Stylesheets // Styles
include dirname( __FILE__ ) . '/styles.php' ; include_once dirname( __FILE__ ) . '/styles.php' ;
// Flush rewrite rules on activation to make sure permalinks work properly // Scripts
function sp_rewrite_flush() { include_once dirname( __FILE__ ) . '/scripts.php' ;
sp_team_cpt_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'sp_rewrite_flush' );
function sp_init() { // Hooks, Actions, and Filters
add_theme_support( 'post-thumbnails' ); require_once dirname( __FILE__ ) . '/hooks.php';
load_plugin_textdomain ( 'sportspress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); require_once dirname( __FILE__ ) . '/actions.php';
add_image_size( 'sp_icon', 32, 32, false ); require_once dirname( __FILE__ ) . '/filters.php';
}
add_action( 'plugins_loaded', 'sp_init' );
?> ?>

View File

@@ -37,13 +37,22 @@ function sp_staff_custom_columns( $column ) {
if ( has_post_thumbnail() ) the_post_thumbnail( 'sp_icon' ); if ( has_post_thumbnail() ) the_post_thumbnail( 'sp_icon' );
break; break;
case 'sp_position': case 'sp_position':
the_terms( $post_id, 'sp_position' ); if ( get_the_terms ( $post_id, 'sp_position' ) )
the_terms( $post_id, 'sp_position' );
else
echo '—';
break; break;
case 'sp_league': case 'sp_league':
the_terms( $post_id, 'sp_league' ); if ( get_the_terms ( $post_id, 'sp_league' ) )
the_terms( $post_id, 'sp_league' );
else
echo '—';
break; break;
case 'sp_season': case 'sp_season':
the_terms( $post_id, 'sp_season' ); if ( get_the_terms ( $post_id, 'sp_season' ) )
the_terms( $post_id, 'sp_season' );
else
echo '—';
break; break;
endswitch; endswitch;
endif; endif;

View File

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

View File

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

View File

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

View File

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