Fix bugs, use plural post slugs, move actions and filters into hooks folder

This commit is contained in:
Brian Miyaji
2014-01-09 02:37:13 +11:00
parent e76d392726
commit bfcf6e9b38
32 changed files with 390 additions and 312 deletions

View File

@@ -8,7 +8,12 @@ function sportspress_settings() {
<h2 class="nav-tab-wrapper">
<a href="?page=sportspress" class="nav-tab<?php echo $active_tab == 'general' ? ' nav-tab-active' : ''; ?>"><?php _e( 'SportsPress', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=events" class="nav-tab<?php echo $active_tab == 'events' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Events', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=teams" class="nav-tab<?php echo $active_tab == 'teams' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Teams', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=players" class="nav-tab<?php echo $active_tab == 'players' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Players', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=staff" class="nav-tab<?php echo $active_tab == 'staff' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Staff', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=config" class="nav-tab<?php echo $active_tab == 'config' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Configure', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=advanced" class="nav-tab<?php echo $active_tab == 'advanced' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Advanced', 'sportspress' ); ?></a>
</h2>
<form method="post" action="options.php">
@@ -27,83 +32,6 @@ function sportspress_settings() {
<?php
}
function sportspress_validate( $input ) {
$options = get_option( 'sportspress' );
// Do nothing if sport is the same as currently selected
if ( sportspress_array_value( $options, 'sport', null ) == sportspress_array_value( $input, 'sport', null ) )
return $input;
// Get sports presets
global $sportspress_sports;
// Get array of post types to insert
$post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() );
// Loop through each post type
foreach( $post_groups as $post_type => $posts ):
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'sp_preset',
'value' => 1
)
)
);
// Delete posts
$old_posts = get_posts( $args );
foreach( $old_posts as $post ):
wp_delete_post( $post->ID, true);
endforeach;
// Add posts
foreach( $posts as $index => $post ):
// Make sure post doesn't overlap
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
// Translate post title
$post['post_title'] = __( $post['post_title'], 'sportspress' );
// Set post type
$post['post_type'] = $post_type;
// Increment menu order by 2 and publish post
$post['menu_order'] = $index * 2 + 2;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
// Flag as preset
update_post_meta( $id, 'sp_preset', 1 );
// Update meta
if ( array_key_exists( 'meta', $post ) ):
foreach ( $post['meta'] as $key => $value ):
update_post_meta( $id, $key, $value );
endforeach;
endif;
endif;
endforeach;
endforeach;
return $input;
}
function sportspress_sport_callback() {
global $sportspress_sports;
$options = get_option( 'sportspress' );
@@ -113,7 +41,7 @@ function sportspress_sport_callback() {
<option value="<?php echo $slug; ?>" <?php selected( $options['sport'], $slug ); ?>><?php _e( $sport['name'], 'sportspress' ); ?></option>
<?php endforeach; ?>
</select>
<?
<?php
}
function sportspress_team_stats_callback() {