From 99785a7a82d8bc3b5ad2385091faba4df48fcffd Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 3 May 2018 16:18:01 +1000 Subject: [PATCH] Revert "Always load player assignments and rename post meta" This reverts commit 427b18052d4eb8ae9bc436577f8c9ed79423f416. --- includes/class-sp-player-list.php | 2 +- modules/sportspress-player-assignments.php | 46 +++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/includes/class-sp-player-list.php b/includes/class-sp-player-list.php index 5d364d77..56e31a3d 100644 --- a/includes/class-sp-player-list.php +++ b/includes/class-sp-player-list.php @@ -115,7 +115,7 @@ class SP_Player_List extends SP_Secondary_Post { if ( !empty( $assignments ) ) { $args['meta_query'] = array( array( - 'key' => 'sp_assignments', + 'key' => 'sp_player_assignments', 'value' => $assignments, 'compare' => 'IN' ), diff --git a/modules/sportspress-player-assignments.php b/modules/sportspress-player-assignments.php index 8f543864..da0b061d 100644 --- a/modules/sportspress-player-assignments.php +++ b/modules/sportspress-player-assignments.php @@ -5,7 +5,7 @@ Plugin URI: http://themeboy.com/ Description: Add player assignments support to SportsPress. Author: Savvas Author URI: http://themeboy.com/ -Version: 2.6 +Version: 2.6.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; @@ -14,7 +14,7 @@ if ( ! class_exists( 'SportsPress_Player_Assignments' ) ) : * Main SportsPress Player Assignments Class * * @class SportsPress_Player_Assignments - * @version 2.6 + * @version 2.6.0 */ class SportsPress_Player_Assignments { /** @@ -26,13 +26,16 @@ class SportsPress_Player_Assignments { // Actions add_action( 'sportspress_save_meta_player_statistics', array( $this, 'save_additional_statistics' ), 10, 2 ); + + // Filters + add_filter( 'sportspress_player_list_options', array( $this, 'add_settings' ) ); } /** * Define constants. */ private function define_constants() { if ( !defined( 'SP_PLAYER_ASSIGNMENTS_VERSION' ) ) - define( 'SP_PLAYER_ASSIGNMENTS_VERSION', '2.6' ); + define( 'SP_PLAYER_ASSIGNMENTS_VERSION', '2.6.0' ); if ( !defined( 'SP_PLAYER_ASSIGNMENTS_URL' ) ) define( 'SP_PLAYER_ASSIGNMENTS_URL', plugin_dir_url( __FILE__ ) ); if ( !defined( 'SP_PLAYER_ASSIGNMENTS_DIR' ) ) @@ -43,17 +46,17 @@ class SportsPress_Player_Assignments { * Save Additional Statistics */ public function save_additional_statistics( $post_id, $post_data ) { - $old = (array) get_post_custom_values( 'sp_assignments', $post_id ); + $old = (array) get_post_custom_values( 'sp_player_assignments', $post_id ); $leagues = $post_data['sp_leagues']; - $transfers = get_post_meta($post_id, 'sp_assignments', true); + $transfers = get_post_meta($post_id, 'sp_player_assignments', true); foreach ( $leagues as $l_id => $season ) { foreach ( $season as $s_id => $team_id ) { if ( $team_id != '-1' ) { $serialized = $l_id.'_'.$s_id.'_'.$team_id; if( !in_array( $serialized, $old ) ){ - add_post_meta( $post_id, 'sp_assignments', $serialized, false ); + add_post_meta( $post_id, 'sp_player_assignments', $serialized, false ); } } //Check if there are any Mid-Season transfers @@ -61,14 +64,39 @@ class SportsPress_Player_Assignments { foreach ( $transfers[$l_id][$s_id] as $t_id => $performance ) { $serialized = $l_id.'_'.$s_id.'_'.$t_id; if( !in_array( $serialized, $old ) ){ - add_post_meta( $post_id, 'sp_assignments', $serialized, false ); + add_post_meta( $post_id, 'sp_player_assignments', $serialized, false ); } } } } } } + + /** + * Add settings. + * + * @return array + */ + public function add_settings( $settings ) { + + $settings = array_merge( $settings, + array( + array( + 'title' => __( 'Filter by player assignment', 'sportspress' ), + 'desc' => __( 'Use a stronger connection between leagues, seasons and teams', 'sportspress' ), + 'id' => 'sportspress_list_player_assignments', + 'default' => 'yes', + 'type' => 'checkbox', + ), + array( + array( 'type' => 'sectionend', 'id' => 'timelines_options' ), + ) + ) + ); + return $settings; + } } endif; - -new SportsPress_Player_Assignments(); \ No newline at end of file +if ( get_option( 'sportspress_load_player_assignments_module', 'yes' ) == 'yes' ) { //Is it needed? + new SportsPress_Player_Assignments(); +} \ No newline at end of file