Fix bugs, use plural post slugs, move actions and filters into hooks folder
This commit is contained in:
@@ -1,158 +0,0 @@
|
||||
<?php
|
||||
function sportspress_admin_init() {
|
||||
|
||||
$installed = get_option( 'sportspress_installed', false );
|
||||
|
||||
// Define roles and capabilities
|
||||
if ( ! $installed ):
|
||||
|
||||
$role = get_role( 'administrator' );
|
||||
|
||||
// Events
|
||||
$role->add_cap( 'edit_sp_event' );
|
||||
$role->add_cap( 'edit_sp_events' );
|
||||
$role->add_cap( 'edit_others_sp_events' );
|
||||
$role->add_cap( 'delete_sp_event' );
|
||||
$role->add_cap( 'publish_sp_events' );
|
||||
$role->add_cap( 'read_sp_events' );
|
||||
$role->add_cap( 'read_private_sp_events' );
|
||||
|
||||
// Teams
|
||||
$role->add_cap( 'edit_sp_team' );
|
||||
$role->add_cap( 'edit_sp_teams' );
|
||||
$role->add_cap( 'edit_others_sp_teams' );
|
||||
$role->add_cap( 'delete_sp_team' );
|
||||
$role->add_cap( 'publish_sp_teams' );
|
||||
$role->add_cap( 'read_sp_teams' );
|
||||
$role->add_cap( 'read_private_sp_teams' );
|
||||
|
||||
// League Tables
|
||||
$role->add_cap( 'edit_sp_table' );
|
||||
$role->add_cap( 'edit_sp_tables' );
|
||||
$role->add_cap( 'edit_others_sp_tables' );
|
||||
$role->add_cap( 'delete_sp_table' );
|
||||
$role->add_cap( 'publish_sp_tables' );
|
||||
$role->add_cap( 'read_sp_tables' );
|
||||
$role->add_cap( 'read_private_sp_tables' );
|
||||
|
||||
// Players
|
||||
$role->add_cap( 'edit_sp_player' );
|
||||
$role->add_cap( 'edit_sp_players' );
|
||||
$role->add_cap( 'edit_others_sp_players' );
|
||||
$role->add_cap( 'delete_sp_player' );
|
||||
$role->add_cap( 'publish_sp_players' );
|
||||
$role->add_cap( 'read_sp_players' );
|
||||
$role->add_cap( 'read_private_sp_players' );
|
||||
|
||||
// Player Lists
|
||||
$role->add_cap( 'edit_sp_list' );
|
||||
$role->add_cap( 'edit_sp_lists' );
|
||||
$role->add_cap( 'edit_others_sp_lists' );
|
||||
$role->add_cap( 'delete_sp_list' );
|
||||
$role->add_cap( 'publish_sp_lists' );
|
||||
$role->add_cap( 'read_sp_lists' );
|
||||
$role->add_cap( 'read_private_sp_lists' );
|
||||
|
||||
// Staff
|
||||
$role->add_cap( 'edit_sp_staff' );
|
||||
$role->add_cap( 'edit_sp_staffs' );
|
||||
$role->add_cap( 'edit_others_sp_staffs' );
|
||||
$role->add_cap( 'delete_sp_staff' );
|
||||
$role->add_cap( 'publish_sp_staffs' );
|
||||
$role->add_cap( 'read_sp_staffs' );
|
||||
$role->add_cap( 'read_private_sp_staffs' );
|
||||
|
||||
// Settings
|
||||
$role->add_cap( 'read_sp_configs' );
|
||||
$role->add_cap( 'read_private_sp_configs' );
|
||||
$role->add_cap( 'edit_sp_config' );
|
||||
$role->add_cap( 'edit_sp_configs' );
|
||||
$role->add_cap( 'edit_published_sp_configs' );
|
||||
$role->add_cap( 'edit_private_sp_configs' );
|
||||
$role->add_cap( 'edit_others_sp_configs' );
|
||||
$role->add_cap( 'delete_sp_config' );
|
||||
$role->add_cap( 'delete_published_sp_configs' );
|
||||
$role->add_cap( 'delete_private_sp_configs' );
|
||||
$role->add_cap( 'delete_others_sp_configs' );
|
||||
$role->add_cap( 'publish_sp_configs' );
|
||||
|
||||
// Team Manager
|
||||
remove_role( 'sp_team_manager' );
|
||||
add_role(
|
||||
'sp_team_manager',
|
||||
__( 'Team Manager', 'sportspress' ),
|
||||
array(
|
||||
'read' => true,
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => true,
|
||||
'read_sp_players' => true,
|
||||
'edit_sp_players' => true,
|
||||
'edit_others_sp_players' => true,
|
||||
'delete_sp_player' => true,
|
||||
'publish_sp_players' => true,
|
||||
'read_sp_staffs' => true,
|
||||
'edit_sp_staffs' => true,
|
||||
'edit_others_sp_staffs' => true,
|
||||
'delete_sp_staff' => true,
|
||||
'publish_sp_staffs' => true
|
||||
)
|
||||
);
|
||||
|
||||
// Staff
|
||||
remove_role( 'sp_staff' );
|
||||
add_role(
|
||||
'sp_staff',
|
||||
__( 'Staff', 'sportspress' ),
|
||||
array(
|
||||
'read' => true,
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => true,
|
||||
'read_sp_staffs' => true,
|
||||
'edit_sp_staffs' => true,
|
||||
'delete_sp_staff' => true
|
||||
)
|
||||
);
|
||||
|
||||
// Player
|
||||
remove_role( 'sp_player' );
|
||||
add_role(
|
||||
'sp_player',
|
||||
__( 'Player', 'sportspress' ),
|
||||
array(
|
||||
'read' => true,
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => true,
|
||||
'read_sp_players' => true,
|
||||
'edit_sp_players' => true,
|
||||
'delete_sp_player' => true
|
||||
)
|
||||
);
|
||||
|
||||
update_option( 'sportspress_installed', 1 );
|
||||
|
||||
endif;
|
||||
|
||||
// Add settings sections
|
||||
register_setting(
|
||||
'sportspress_general',
|
||||
'sportspress',
|
||||
'sportspress_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'general',
|
||||
'',
|
||||
'',
|
||||
'sportspress_general'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'sport',
|
||||
__( 'Sport', 'sportspress' ),
|
||||
'sportspress_sport_callback',
|
||||
'sportspress_general',
|
||||
'general'
|
||||
);
|
||||
|
||||
}
|
||||
add_action( 'admin_init', 'sportspress_admin_init', 1 );
|
||||
130
admin/hooks/admin-init.php
Normal file
130
admin/hooks/admin-init.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
function sportspress_admin_init() {
|
||||
|
||||
$installed = get_option( 'sportspress_installed', false );
|
||||
|
||||
// General settings
|
||||
register_setting(
|
||||
'sportspress_general',
|
||||
'sportspress',
|
||||
'sportspress_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'general',
|
||||
'',
|
||||
'',
|
||||
'sportspress_general'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'sport',
|
||||
__( 'Sport', 'sportspress' ),
|
||||
'sportspress_sport_callback',
|
||||
'sportspress_general',
|
||||
'general'
|
||||
);
|
||||
|
||||
// Event Settings
|
||||
register_setting(
|
||||
'sportspress_events',
|
||||
'sportspress',
|
||||
'sportspress_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'events',
|
||||
'',
|
||||
'',
|
||||
'sportspress_events'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'sport',
|
||||
__( 'Sport', 'sportspress' ),
|
||||
'sportspress_sport_callback',
|
||||
'sportspress_events',
|
||||
'events'
|
||||
);
|
||||
|
||||
}
|
||||
add_action( 'admin_init', 'sportspress_admin_init', 1 );
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -72,7 +72,16 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||
echo get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : '—';
|
||||
break;
|
||||
case 'sp_kickoff':
|
||||
echo ( $post->post_status == 'future' ? __( 'Scheduled' ) : __( 'Played', 'sportspress' ) ) . '<br />' . date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) );
|
||||
if ( $post->post_status == 'future' ):
|
||||
_e( 'Scheduled', 'sportspress' );
|
||||
elseif( $post->post_status == 'publish' ):
|
||||
_e( 'Played', 'sportspress' );
|
||||
elseif( $post->post_status == 'draft' ):
|
||||
_e( 'Draft', 'sportspress' );
|
||||
else:
|
||||
_e( 'Pending Review', 'sportspress' );
|
||||
endif;
|
||||
echo '<br />' . date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) );
|
||||
break;
|
||||
case 'sp_address':
|
||||
echo get_post_meta( $post_id, 'sp_address', true ) ? get_post_meta( $post_id, 'sp_address', true ) : '—';
|
||||
9
admin/hooks/plugin-action-links.php
Normal file
9
admin/hooks/plugin-action-links.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
function sportspress_plugin_action_links( $links ) {
|
||||
$settings_link = '<a href="options-general.php?page=sportspress">' . __( 'Settings', 'sportspress' ) . '</a>';
|
||||
array_unshift( $links, $settings_link );
|
||||
return $links;
|
||||
}
|
||||
|
||||
$plugin = SPORTSPRESS_PLUGIN_BASENAME;
|
||||
add_filter( "plugin_action_links_$plugin", 'sportspress_plugin_action_links' );
|
||||
141
admin/hooks/register-activation-hook.php
Normal file
141
admin/hooks/register-activation-hook.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
function sportspress_activation_hook() {
|
||||
|
||||
$role = get_role( 'administrator' );
|
||||
|
||||
// Events
|
||||
$role->add_cap( 'edit_sp_event' );
|
||||
$role->add_cap( 'edit_sp_events' );
|
||||
$role->add_cap( 'edit_others_sp_events' );
|
||||
$role->add_cap( 'delete_sp_event' );
|
||||
$role->add_cap( 'publish_sp_events' );
|
||||
$role->add_cap( 'read_sp_events' );
|
||||
$role->add_cap( 'read_private_sp_events' );
|
||||
|
||||
// Teams
|
||||
$role->add_cap( 'edit_sp_team' );
|
||||
$role->add_cap( 'edit_sp_teams' );
|
||||
$role->add_cap( 'edit_others_sp_teams' );
|
||||
$role->add_cap( 'delete_sp_team' );
|
||||
$role->add_cap( 'publish_sp_teams' );
|
||||
$role->add_cap( 'read_sp_teams' );
|
||||
$role->add_cap( 'read_private_sp_teams' );
|
||||
|
||||
// League Tables
|
||||
$role->add_cap( 'edit_sp_table' );
|
||||
$role->add_cap( 'edit_sp_tables' );
|
||||
$role->add_cap( 'edit_others_sp_tables' );
|
||||
$role->add_cap( 'delete_sp_table' );
|
||||
$role->add_cap( 'publish_sp_tables' );
|
||||
$role->add_cap( 'read_sp_tables' );
|
||||
$role->add_cap( 'read_private_sp_tables' );
|
||||
|
||||
// Players
|
||||
$role->add_cap( 'edit_sp_player' );
|
||||
$role->add_cap( 'edit_sp_players' );
|
||||
$role->add_cap( 'edit_others_sp_players' );
|
||||
$role->add_cap( 'delete_sp_player' );
|
||||
$role->add_cap( 'publish_sp_players' );
|
||||
$role->add_cap( 'read_sp_players' );
|
||||
$role->add_cap( 'read_private_sp_players' );
|
||||
|
||||
// Player Lists
|
||||
$role->add_cap( 'edit_sp_list' );
|
||||
$role->add_cap( 'edit_sp_lists' );
|
||||
$role->add_cap( 'edit_others_sp_lists' );
|
||||
$role->add_cap( 'delete_sp_list' );
|
||||
$role->add_cap( 'publish_sp_lists' );
|
||||
$role->add_cap( 'read_sp_lists' );
|
||||
$role->add_cap( 'read_private_sp_lists' );
|
||||
|
||||
// Staff
|
||||
$role->add_cap( 'edit_sp_staff' );
|
||||
$role->add_cap( 'edit_sp_staffs' );
|
||||
$role->add_cap( 'edit_others_sp_staffs' );
|
||||
$role->add_cap( 'delete_sp_staff' );
|
||||
$role->add_cap( 'publish_sp_staffs' );
|
||||
$role->add_cap( 'read_sp_staffs' );
|
||||
$role->add_cap( 'read_private_sp_staffs' );
|
||||
|
||||
// Settings
|
||||
$role->add_cap( 'read_sp_configs' );
|
||||
$role->add_cap( 'read_private_sp_configs' );
|
||||
$role->add_cap( 'edit_sp_config' );
|
||||
$role->add_cap( 'edit_sp_configs' );
|
||||
$role->add_cap( 'edit_published_sp_configs' );
|
||||
$role->add_cap( 'edit_private_sp_configs' );
|
||||
$role->add_cap( 'edit_others_sp_configs' );
|
||||
$role->add_cap( 'delete_sp_config' );
|
||||
$role->add_cap( 'delete_published_sp_configs' );
|
||||
$role->add_cap( 'delete_private_sp_configs' );
|
||||
$role->add_cap( 'delete_others_sp_configs' );
|
||||
$role->add_cap( 'publish_sp_configs' );
|
||||
|
||||
// Team Manager
|
||||
remove_role( 'sp_team_manager' );
|
||||
add_role(
|
||||
'sp_team_manager',
|
||||
__( 'Team Manager', 'sportspress' ),
|
||||
array(
|
||||
'read' => true,
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => true,
|
||||
'read_sp_players' => true,
|
||||
'edit_sp_players' => true,
|
||||
'edit_others_sp_players' => true,
|
||||
'delete_sp_player' => true,
|
||||
'publish_sp_players' => true,
|
||||
'read_sp_staffs' => true,
|
||||
'edit_sp_staffs' => true,
|
||||
'edit_others_sp_staffs' => true,
|
||||
'delete_sp_staff' => true,
|
||||
'publish_sp_staffs' => true
|
||||
)
|
||||
);
|
||||
|
||||
// Staff
|
||||
remove_role( 'sp_staff' );
|
||||
add_role(
|
||||
'sp_staff',
|
||||
__( 'Staff', 'sportspress' ),
|
||||
array(
|
||||
'read' => true,
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => true,
|
||||
'read_sp_staffs' => true,
|
||||
'edit_sp_staffs' => true,
|
||||
'delete_sp_staff' => true
|
||||
)
|
||||
);
|
||||
|
||||
// Player
|
||||
remove_role( 'sp_player' );
|
||||
add_role(
|
||||
'sp_player',
|
||||
__( 'Player', 'sportspress' ),
|
||||
array(
|
||||
'read' => true,
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => true,
|
||||
'read_sp_players' => true,
|
||||
'edit_sp_players' => true,
|
||||
'delete_sp_player' => true
|
||||
)
|
||||
);
|
||||
|
||||
// Flush rewrite rules
|
||||
sportspress_event_post_init();
|
||||
sportspress_result_post_init();
|
||||
sportspress_outcome_post_init();
|
||||
sportspress_column_post_init();
|
||||
sportspress_statistic_post_init();
|
||||
sportspress_team_post_init();
|
||||
sportspress_table_post_init();
|
||||
sportspress_player_post_init();
|
||||
sportspress_list_post_init();
|
||||
sportspress_staff_post_init();
|
||||
sportspress_position_term_init();
|
||||
sportspress_season_term_init();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
register_activation_hook( SPORTSPRESS_PLUGIN_FILE, 'sportspress_activation_hook' );
|
||||
@@ -20,4 +20,5 @@ function sportspress_the_content( $content ) {
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'sportspress_the_content');
|
||||
add_filter( 'the_content', 'sportspress_the_content' );
|
||||
add_filter( 'get_the_content', 'sportspress_the_content' );
|
||||
@@ -11,7 +11,7 @@ function sportspress_event_post_init() {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'author', 'comments' ),
|
||||
'register_meta_box_cb' => 'sportspress_event_meta_init',
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_event_slug', 'event' ) ),
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_event_slug', 'events' ) ),
|
||||
'menu_icon' => 'dashicons-calendar',
|
||||
'capability_type' => 'sp_event'
|
||||
);
|
||||
|
||||
@@ -11,8 +11,9 @@ function sportspress_list_post_init() {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'author' ),
|
||||
'register_meta_box_cb' => 'sportspress_list_meta_init',
|
||||
'rewrite' => array( 'slug' => 'list' ),
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_list_slug', 'lists' ) ),
|
||||
'show_in_menu' => 'edit.php?post_type=sp_player',
|
||||
'show_in_admin_bar' => true,
|
||||
'capability_type' => 'sp_list'
|
||||
);
|
||||
register_post_type( 'sp_list', $args );
|
||||
@@ -78,7 +79,7 @@ function sportspress_list_player_meta( $post ) {
|
||||
|
||||
function sportspress_list_stats_meta( $post ) {
|
||||
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_list( $post->ID, true );
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_player_list_data( $post->ID, true );
|
||||
|
||||
sportspress_edit_player_table( $columns, $data, $placeholders );
|
||||
sportspress_nonce();
|
||||
|
||||
@@ -11,7 +11,7 @@ function sportspress_player_post_init() {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||
'register_meta_box_cb' => 'sportspress_player_meta_init',
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_player_slug', 'player' ) ),
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_player_slug', 'players' ) ),
|
||||
'menu_icon' => 'dashicons-groups',
|
||||
'capability_type' => 'sp_player',
|
||||
);
|
||||
|
||||
@@ -11,8 +11,9 @@ function sportspress_table_post_init() {
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'author', 'excerpt' ),
|
||||
'register_meta_box_cb' => 'sportspress_table_meta_init',
|
||||
'rewrite' => array( 'slug' => 'table' ),
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_table_slug', 'tables' ) ),
|
||||
'show_in_menu' => 'edit.php?post_type=sp_team',
|
||||
'show_in_admin_bar' => true,
|
||||
// 'capability_type' => 'sp_table'
|
||||
);
|
||||
register_post_type( 'sp_table', $args );
|
||||
@@ -66,7 +67,7 @@ function sportspress_table_team_meta( $post, $test ) {
|
||||
|
||||
function sportspress_table_columns_meta( $post ) {
|
||||
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_table( $post->ID, true );
|
||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_league_table_data( $post->ID, true );
|
||||
|
||||
sportspress_edit_league_table( $columns, $data, $placeholders );
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ function sportspress_team_post_init() {
|
||||
'hierarchical' => true,
|
||||
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
|
||||
'register_meta_box_cb' => 'sportspress_team_meta_init',
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_team_slug', 'team' ) ),
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_team_slug', 'teams' ) ),
|
||||
'menu_icon' => 'dashicons-shield-alt',
|
||||
'capability_type' => 'sp_team'
|
||||
);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user