diff --git a/admin-functions.php b/admin-functions.php index 25617a78..441d2971 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -509,7 +509,7 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) { ?> - + $label ): $value = sportspress_array_value( $team_stats, $column, '' ); @@ -948,8 +948,8 @@ if ( !function_exists( 'sportspress_solve' ) ) { } -if ( !function_exists( 'sportspress_get_table' ) ) { - function sportspress_get_table( $post_id, $breakdown = false ) { +if ( !function_exists( 'sportspress_get_league_table_data' ) ) { + function sportspress_get_league_table_data( $post_id, $breakdown = false ) { $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 ); $team_ids = (array)get_post_meta( $post_id, 'sp_team', false ); $table_stats = (array)get_post_meta( $post_id, 'sp_teams', true ); @@ -1017,10 +1017,13 @@ if ( !function_exists( 'sportspress_get_table' ) ) { foreach ( $results as $team_id => $team_result ): + if ( ! in_array( $team_id, $team_ids ) ) + continue; + foreach ( $team_result as $key => $value ): if ( $key == 'outcome' ): - if ( array_key_exists( $value, $totals[ $team_id ] ) ): + if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $value, $totals[ $team_id ] ) ): $totals[ $team_id ]['eventsplayed']++; $totals[ $team_id ][ $value ]++; endif; @@ -1033,7 +1036,7 @@ if ( !function_exists( 'sportspress_get_table' ) ) { endif; endif; else: - if ( array_key_exists( $key . 'for', $totals[ $team_id ] ) ): + if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ): $totals[ $team_id ][ $key . 'for' ] += $value; endif; endif; @@ -1119,7 +1122,9 @@ if ( !function_exists( 'sportspress_get_table' ) ) { foreach( $placeholders as $team_id => $team_data ): // Add team name to row - $merged[ $team_id ] = array( 'name' => get_the_title( $team_id ) ); + $merged[ $team_id ] = array(); + + $team_data['name'] = get_the_title( $team_id ); foreach( $team_data as $key => $value ): @@ -1173,8 +1178,8 @@ if ( !function_exists( 'sportspress_get_table' ) ) { } } -if ( !function_exists( 'sportspress_get_list' ) ) { - function sportspress_get_list( $post_id, $breakdown = false ) { +if ( !function_exists( 'sportspress_get_player_list_data' ) ) { + function sportspress_get_player_list_data( $post_id, $breakdown = false ) { $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 ); $team_id = get_post_meta( $post_id, 'sp_team', true ); $player_ids = (array)get_post_meta( $post_id, 'sp_player', false ); @@ -1250,6 +1255,9 @@ if ( !function_exists( 'sportspress_get_list' ) ) { foreach ( $players as $player_id => $player_statistics ): + if ( ! $player_id || ! in_array( $player_id, $player_ids ) ) + continue; + // Increment events played $totals[ $player_id ]['eventsplayed']++; @@ -1311,20 +1319,9 @@ if ( !function_exists( 'sportspress_get_list' ) ) { foreach ( $statistics as $statistic ): if ( sportspress_array_value( $placeholders[ $player_id ], $statistic->post_name, '' ) == '' ): - if ( empty( $statistic->equation ) ): + // Reflect totals + $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_array_value( sportspress_array_value( $totals, $player_id, array() ), $statistic->post_name, 0 ); - // Reflect totals - $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_array_value( sportspress_array_value( $totals, $player_id, array() ), $key, 0 ); - - else: - - // Calculate value - if ( sizeof( $events ) > 0 ): - $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_solve( $statistic->equation, sportspress_array_value( $totals, $player_id, array() ) ); - else: - $placeholders[ $player_id ][ $statistic->post_name ] = 0; - endif; - endif; endif; endforeach; endforeach; @@ -1334,7 +1331,7 @@ if ( !function_exists( 'sportspress_get_list' ) ) { foreach( $placeholders as $player_id => $player_data ): - // Add team name to row + // Add player name to row $merged[ $player_id ] = array( 'name' => get_the_title( $player_id ) ); foreach( $player_data as $key => $value ): diff --git a/admin/actions/admin-init.php b/admin/actions/admin-init.php deleted file mode 100644 index f195c5d0..00000000 --- a/admin/actions/admin-init.php +++ /dev/null @@ -1,158 +0,0 @@ -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 ); diff --git a/admin/actions/admin-enqueue-scripts.php b/admin/hooks/admin-enqueue-scripts.php similarity index 100% rename from admin/actions/admin-enqueue-scripts.php rename to admin/hooks/admin-enqueue-scripts.php diff --git a/admin/actions/admin-head.php b/admin/hooks/admin-head.php similarity index 100% rename from admin/actions/admin-head.php rename to admin/hooks/admin-head.php diff --git a/admin/hooks/admin-init.php b/admin/hooks/admin-init.php new file mode 100644 index 00000000..d7090412 --- /dev/null +++ b/admin/hooks/admin-init.php @@ -0,0 +1,130 @@ + $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; +} \ No newline at end of file diff --git a/admin/actions/admin-menu.php b/admin/hooks/admin-menu.php similarity index 100% rename from admin/actions/admin-menu.php rename to admin/hooks/admin-menu.php diff --git a/admin/filters/admin-post-thumbnail-html.php b/admin/hooks/admin-post-thumbnail-html.php similarity index 100% rename from admin/filters/admin-post-thumbnail-html.php rename to admin/hooks/admin-post-thumbnail-html.php diff --git a/admin/actions/after-setup-theme.php b/admin/hooks/after-setup-theme.php similarity index 100% rename from admin/actions/after-setup-theme.php rename to admin/hooks/after-setup-theme.php diff --git a/admin/filters/gettext.php b/admin/hooks/gettext.php similarity index 100% rename from admin/filters/gettext.php rename to admin/hooks/gettext.php diff --git a/admin/actions/manage-posts-custom-column.php b/admin/hooks/manage-posts-custom-column.php similarity index 88% rename from admin/actions/manage-posts-custom-column.php rename to admin/hooks/manage-posts-custom-column.php index 5750fb04..9b620ed9 100644 --- a/admin/actions/manage-posts-custom-column.php +++ b/admin/hooks/manage-posts-custom-column.php @@ -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' ) ) . '
' . 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 '
' . 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 ) : '—'; diff --git a/admin/hooks/plugin-action-links.php b/admin/hooks/plugin-action-links.php new file mode 100644 index 00000000..7eb177a8 --- /dev/null +++ b/admin/hooks/plugin-action-links.php @@ -0,0 +1,9 @@ +' . __( 'Settings', 'sportspress' ) . ''; + array_unshift( $links, $settings_link ); + return $links; +} + +$plugin = SPORTSPRESS_PLUGIN_BASENAME; +add_filter( "plugin_action_links_$plugin", 'sportspress_plugin_action_links' ); diff --git a/admin/actions/plugins-loaded.php b/admin/hooks/plugins-loaded.php similarity index 100% rename from admin/actions/plugins-loaded.php rename to admin/hooks/plugins-loaded.php diff --git a/admin/actions/post-thumbnail-html.php b/admin/hooks/post-thumbnail-html.php similarity index 100% rename from admin/actions/post-thumbnail-html.php rename to admin/hooks/post-thumbnail-html.php diff --git a/admin/filters/pre-get-posts.php b/admin/hooks/pre-get-posts.php similarity index 100% rename from admin/filters/pre-get-posts.php rename to admin/hooks/pre-get-posts.php diff --git a/admin/hooks/register-activation-hook.php b/admin/hooks/register-activation-hook.php new file mode 100644 index 00000000..04d3d9dd --- /dev/null +++ b/admin/hooks/register-activation-hook.php @@ -0,0 +1,141 @@ +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' ); diff --git a/admin/actions/restrict-manage-posts.php b/admin/hooks/restrict-manage-posts.php similarity index 100% rename from admin/actions/restrict-manage-posts.php rename to admin/hooks/restrict-manage-posts.php diff --git a/admin/filters/sanitize-title.php b/admin/hooks/sanitize-title.php similarity index 100% rename from admin/filters/sanitize-title.php rename to admin/hooks/sanitize-title.php diff --git a/admin/actions/save-post.php b/admin/hooks/save-post.php similarity index 100% rename from admin/actions/save-post.php rename to admin/hooks/save-post.php diff --git a/admin/filters/the-content.php b/admin/hooks/the-content.php similarity index 81% rename from admin/filters/the-content.php rename to admin/hooks/the-content.php index ab08982d..d99927bd 100644 --- a/admin/filters/the-content.php +++ b/admin/hooks/the-content.php @@ -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' ); \ No newline at end of file diff --git a/admin/actions/wp-enqueue-scripts.php b/admin/hooks/wp-enqueue-scripts.php similarity index 100% rename from admin/actions/wp-enqueue-scripts.php rename to admin/hooks/wp-enqueue-scripts.php diff --git a/admin/filters/wp-insert-post-data.php b/admin/hooks/wp-insert-post-data.php similarity index 100% rename from admin/filters/wp-insert-post-data.php rename to admin/hooks/wp-insert-post-data.php diff --git a/admin/post-types/event.php b/admin/post-types/event.php index 7a0d5e2a..aed43c58 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -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' ); diff --git a/admin/post-types/list.php b/admin/post-types/list.php index 2758c5d6..458249b9 100644 --- a/admin/post-types/list.php +++ b/admin/post-types/list.php @@ -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(); diff --git a/admin/post-types/player.php b/admin/post-types/player.php index 6a6ec942..15b37281 100644 --- a/admin/post-types/player.php +++ b/admin/post-types/player.php @@ -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', ); diff --git a/admin/post-types/table.php b/admin/post-types/table.php index c26d9a5c..4d37c54c 100644 --- a/admin/post-types/table.php +++ b/admin/post-types/table.php @@ -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 ); diff --git a/admin/post-types/team.php b/admin/post-types/team.php index 0b0c69e7..5c8e47af 100644 --- a/admin/post-types/team.php +++ b/admin/post-types/team.php @@ -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' ); diff --git a/admin/settings/settings.php b/admin/settings/settings.php index a03ee9c1..4417ab17 100644 --- a/admin/settings/settings.php +++ b/admin/settings/settings.php @@ -8,7 +8,12 @@ function sportspress_settings() {
@@ -27,83 +32,6 @@ function sportspress_settings() { $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() { - ' . '' . ''; @@ -12,6 +12,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) { // Remove the first row to leave us with the actual data unset( $data[0] ); + $output .= '' . __( '#', 'sportspress' ) . ''; foreach( $labels as $key => $label ): $output .= '' . $label . ''; endforeach; @@ -24,11 +25,14 @@ if ( !function_exists( 'sportspress_league_table' ) ) { $output .= ''; + // Position as number + $output .= '' . $i . ''; + // Thumbnail and name as link $permalink = get_post_permalink( $team_id ); - $thumbnail = get_the_post_thumbnail( $team_id, 'sp_icon' ); - $name = sportspress_array_value( $row, 'name', ' ' ); - $output .= '' . $i . '. ' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '' . $name . ''; + $thumbnail = get_the_post_thumbnail( $team_id, 'thumbnail', array( 'class' => 'logo' ) ); + $name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) ); + $output .= '' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '' . $name . ''; foreach( $labels as $key => $value ): if ( $key == 'name' ) @@ -52,7 +56,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) { if ( !function_exists( 'sportspress_player_list' ) ) { function sportspress_player_list( $id ) { - $data = sportspress_get_list( $id ); + $data = sportspress_get_player_list_data( $id ); $output = '' . '' . ''; @@ -62,25 +66,32 @@ if ( !function_exists( 'sportspress_player_list' ) ) { // Remove the first row to leave us with the actual data unset( $data[0] ); - foreach( $labels as $label ): - $output .= ''; + $output .= ''; + foreach( $labels as $key => $label ): + $output .= ''; endforeach; $output .= '' . '' . '' . ''; + $i = 1; + foreach( $data as $player_id => $row ): $output .= ''; + // Player number + $number = get_post_meta( $player_id, 'sp_number', true ); + $output .= ''; + // Name as link $permalink = get_post_permalink( $player_id ); - $number = get_post_meta( $player_id, 'sp_number', true ); - $output .= ''; + $name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) ); + $output .= ''; foreach( $labels as $key => $value ): if ( $key == 'name' ) continue; - $output .= ''; + $output .= ''; endforeach; $output .= ''; diff --git a/sportspress.php b/sportspress.php index f70f3fb9..e06632e6 100644 --- a/sportspress.php +++ b/sportspress.php @@ -21,6 +21,7 @@ if ( !function_exists( 'add_action' ) ) { define( 'SPORTSPRESS_VERSION', '0.1.3' ); define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); +define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ ); // Libraries include dirname( __FILE__ ) . '/lib/eos/eos.class.php' ; @@ -71,44 +72,31 @@ include_once dirname( __FILE__ ) . '/admin/presets/tennis.php'; include_once dirname( __FILE__ ) . '/admin/presets/volleyball.php'; // Typical request actions -require_once dirname( __FILE__ ) . '/admin/actions/plugins-loaded.php'; -require_once dirname( __FILE__ ) . '/admin/actions/after-setup-theme.php'; -require_once dirname( __FILE__ ) . '/admin/actions/wp-enqueue-scripts.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/plugins-loaded.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/after-setup-theme.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/wp-enqueue-scripts.php'; // Admin request actions -require_once dirname( __FILE__ ) . '/admin/actions/admin-menu.php'; -require_once dirname( __FILE__ ) . '/admin/actions/admin-init.php'; -require_once dirname( __FILE__ ) . '/admin/actions/admin-enqueue-scripts.php'; -require_once dirname( __FILE__ ) . '/admin/actions/admin-head.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/admin-menu.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/admin-init.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/admin-enqueue-scripts.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/admin-head.php'; // Administrative actions -require_once dirname( __FILE__ ) . '/admin/actions/manage-posts-custom-column.php'; -require_once dirname( __FILE__ ) . '/admin/actions/post-thumbnail-html.php'; -require_once dirname( __FILE__ ) . '/admin/actions/restrict-manage-posts.php'; -require_once dirname( __FILE__ ) . '/admin/actions/save-post.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/manage-posts-custom-column.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/post-thumbnail-html.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/restrict-manage-posts.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/save-post.php'; // Filters -require_once dirname( __FILE__ ) . '/admin/filters/admin-post-thumbnail-html.php'; -require_once dirname( __FILE__ ) . '/admin/filters/gettext.php'; -require_once dirname( __FILE__ ) . '/admin/filters/pre-get-posts.php'; -require_once dirname( __FILE__ ) . '/admin/filters/sanitize-title.php'; -require_once dirname( __FILE__ ) . '/admin/filters/the-content.php'; -require_once dirname( __FILE__ ) . '/admin/filters/wp-insert-post-data.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/admin-post-thumbnail-html.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/gettext.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/pre-get-posts.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/sanitize-title.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/the-content.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/wp-insert-post-data.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/plugin-action-links.php'; + +// Register activation hook +require_once dirname( __FILE__ ) . '/admin/hooks/register-activation-hook.php'; -// Flush rewrite rules on activation -function sportspress_rewrite_flush() { - 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( __FILE__, 'sportspress_rewrite_flush' ); \ No newline at end of file
' . $label . '' . __( '#', 'sportspress' ) . '' . $label . '
' . ( $number ? $number : ' ' ) . '' . ( $number ? $number . '. ' : '' ) . '' . sportspress_array_value( $row, 'name', ' ' ) . '' . '' . $name . '' . sportspress_array_value( $row, $key, '—' ) . '' . sportspress_array_value( $row, $key, '—' ) . '