Add ability to choose multiple nationalities for players and staff
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Meta_Boxes
|
* @package SportsPress/Admin/Meta_Boxes
|
||||||
* @version 1.7
|
* @version 1.8.9
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -23,12 +23,15 @@ class SP_Meta_Box_Player_Details {
|
|||||||
$continents = SP()->countries->continents;
|
$continents = SP()->countries->continents;
|
||||||
|
|
||||||
$number = get_post_meta( $post->ID, 'sp_number', true );
|
$number = get_post_meta( $post->ID, 'sp_number', true );
|
||||||
$nationality = get_post_meta( $post->ID, 'sp_nationality', true );
|
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
|
||||||
if ( 2 == strlen( $nationality ) ):
|
foreach ( $nationalities as $index => $nationality ):
|
||||||
$legacy = SP()->countries->legacy;
|
if ( 2 == strlen( $nationality ) ):
|
||||||
$nationality = strtolower( $nationality );
|
$legacy = SP()->countries->legacy;
|
||||||
$nationality = sp_array_value( $legacy, $nationality, null );
|
$nationality = strtolower( $nationality );
|
||||||
endif;
|
$nationality = sp_array_value( $legacy, $nationality, null );
|
||||||
|
$nationalities[ $index ] = $nationality;
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||||
$league_ids = array();
|
$league_ids = array();
|
||||||
@@ -62,12 +65,12 @@ class SP_Meta_Box_Player_Details {
|
|||||||
<p><input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo $number; ?>"></p>
|
<p><input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo $number; ?>"></p>
|
||||||
|
|
||||||
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
|
||||||
<p><select id="sp_nationality" name="sp_nationality" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
|
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<?php foreach ( $continents as $continent => $countries ): ?>
|
<?php foreach ( $continents as $continent => $countries ): ?>
|
||||||
<optgroup label="<?php echo $continent; ?>">
|
<optgroup label="<?php echo $continent; ?>">
|
||||||
<?php foreach ( $countries as $code => $country ): ?>
|
<?php foreach ( $countries as $code => $country ): ?>
|
||||||
<option value="<?php echo $code; ?>" <?php selected ( $nationality, $code ); ?>><?php echo $country; ?></option>
|
<option value="<?php echo $code; ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo $country; ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -157,7 +160,7 @@ class SP_Meta_Box_Player_Details {
|
|||||||
*/
|
*/
|
||||||
public static function save( $post_id, $post ) {
|
public static function save( $post_id, $post ) {
|
||||||
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
|
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
|
||||||
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @category Admin
|
* @category Admin
|
||||||
* @package SportsPress/Admin/Meta_Boxes
|
* @package SportsPress/Admin/Meta_Boxes
|
||||||
* @version 1.8
|
* @version 1.8.9
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -22,12 +22,15 @@ class SP_Meta_Box_Staff_Details {
|
|||||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||||
$continents = SP()->countries->continents;
|
$continents = SP()->countries->continents;
|
||||||
|
|
||||||
$nationality = get_post_meta( $post->ID, 'sp_nationality', true );
|
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
|
||||||
if ( 2 == strlen( $nationality ) ):
|
foreach ( $nationalities as $index => $nationality ):
|
||||||
$legacy = SP()->countries->legacy;
|
if ( 2 == strlen( $nationality ) ):
|
||||||
$nationality = strtolower( $nationality );
|
$legacy = SP()->countries->legacy;
|
||||||
$nationality = sp_array_value( $legacy, $nationality, null );
|
$nationality = strtolower( $nationality );
|
||||||
endif;
|
$nationality = sp_array_value( $legacy, $nationality, null );
|
||||||
|
$nationalities[ $index ] = $nationality;
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||||
$league_ids = array();
|
$league_ids = array();
|
||||||
@@ -75,12 +78,12 @@ class SP_Meta_Box_Staff_Details {
|
|||||||
?></p>
|
?></p>
|
||||||
|
|
||||||
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
|
||||||
<p><select id="sp_nationality" name="sp_nationality" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
|
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<?php foreach ( $continents as $continent => $countries ): ?>
|
<?php foreach ( $continents as $continent => $countries ): ?>
|
||||||
<optgroup label="<?php echo $continent; ?>">
|
<optgroup label="<?php echo $continent; ?>">
|
||||||
<?php foreach ( $countries as $code => $country ): ?>
|
<?php foreach ( $countries as $code => $country ): ?>
|
||||||
<option value="<?php echo $code; ?>" <?php selected ( $nationality, $code ); ?>><?php echo $country; ?></option>
|
<option value="<?php echo $code; ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo $country; ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -155,8 +158,8 @@ class SP_Meta_Box_Staff_Details {
|
|||||||
*/
|
*/
|
||||||
public static function save( $post_id, $post ) {
|
public static function save( $post_id, $post ) {
|
||||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_role', null ), 'sp_role', false );
|
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_role', null ), 'sp_role', false );
|
||||||
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
|
|
||||||
|
|
||||||
|
sp_update_post_meta_recursive( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* The SportsPress player class handles individual player data.
|
* The SportsPress player class handles individual player data.
|
||||||
*
|
*
|
||||||
* @class SP_Player
|
* @class SP_Player
|
||||||
* @version 1.7.3
|
* @version 1.8.9
|
||||||
* @package SportsPress/Classes
|
* @package SportsPress/Classes
|
||||||
* @category Class
|
* @category Class
|
||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
@@ -42,6 +42,16 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
return get_post_meta( $this->ID, 'sp_past_team', false );
|
return get_post_meta( $this->ID, 'sp_past_team', false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns nationalities
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function nationalities() {
|
||||||
|
return get_post_meta( $this->ID, 'sp_nationality', false );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns formatted player metrics
|
* Returns formatted player metrics
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* The SportsPress staff class handles individual staff data.
|
* The SportsPress staff class handles individual staff data.
|
||||||
*
|
*
|
||||||
* @class SP_Staff
|
* @class SP_Staff
|
||||||
* @version 1.6
|
* @version 1.8.9
|
||||||
* @package SportsPress/Classes
|
* @package SportsPress/Classes
|
||||||
* @category Class
|
* @category Class
|
||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
@@ -32,6 +32,16 @@ class SP_Staff extends SP_Custom_Post {
|
|||||||
return get_post_meta( $this->ID, 'sp_past_team', false );
|
return get_post_meta( $this->ID, 'sp_past_team', false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns nationalities
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function nationalities() {
|
||||||
|
return get_post_meta( $this->ID, 'sp_nationality', false );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns role
|
* Returns role
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @package SportsPress/Templates
|
* @package SportsPress/Templates
|
||||||
* @version 1.8
|
* @version 1.8.9
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -28,7 +28,7 @@ $countries = SP()->countries->countries;
|
|||||||
|
|
||||||
$player = new SP_Player( $id );
|
$player = new SP_Player( $id );
|
||||||
|
|
||||||
$nationality = $player->nationality;
|
$nationalities = $player->nationalities();
|
||||||
$positions = $player->positions();
|
$positions = $player->positions();
|
||||||
$current_teams = $player->current_teams();
|
$current_teams = $player->current_teams();
|
||||||
$past_teams = $player->past_teams();
|
$past_teams = $player->past_teams();
|
||||||
@@ -36,14 +36,18 @@ $metrics_before = $player->metrics( true );
|
|||||||
$metrics_after = $player->metrics( false );
|
$metrics_after = $player->metrics( false );
|
||||||
|
|
||||||
$common = array();
|
$common = array();
|
||||||
if ( $show_nationality && $nationality ):
|
if ( $show_nationality && $nationalities && is_array( $nationalities ) ):
|
||||||
if ( 2 == strlen( $nationality ) ):
|
$values = array();
|
||||||
$legacy = SP()->countries->legacy;
|
foreach ( $nationalities as $nationality ):
|
||||||
$nationality = strtolower( $nationality );
|
if ( 2 == strlen( $nationality ) ):
|
||||||
$nationality = sp_array_value( $legacy, $nationality, null );
|
$legacy = SP()->countries->legacy;
|
||||||
endif;
|
$nationality = strtolower( $nationality );
|
||||||
$country_name = sp_array_value( $countries, $nationality, null );
|
$nationality = sp_array_value( $legacy, $nationality, null );
|
||||||
$common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
endif;
|
||||||
|
$country_name = sp_array_value( $countries, $nationality, null );
|
||||||
|
$values[] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
||||||
|
endforeach;
|
||||||
|
$common[ __( 'Nationality', 'sportspress' ) ] = implode( '<br>', $values );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( $show_positions && $positions ):
|
if ( $show_positions && $positions ):
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
* @package SportsPress/Templates
|
* @package SportsPress/Templates
|
||||||
* @version 1.6
|
* @version 1.8.9
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
@@ -27,19 +27,23 @@ $countries = SP()->countries->countries;
|
|||||||
|
|
||||||
$staff = new SP_Staff( $id );
|
$staff = new SP_Staff( $id );
|
||||||
|
|
||||||
$nationality = $staff->nationality;
|
$nationalities = $staff->nationalities();
|
||||||
$current_teams = $staff->current_teams();
|
$current_teams = $staff->current_teams();
|
||||||
$past_teams = $staff->past_teams();
|
$past_teams = $staff->past_teams();
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
if ( $show_nationality && $nationality ):
|
if ( $show_nationality && $nationalities && is_array( $nationalities ) ):
|
||||||
if ( 2 == strlen( $nationality ) ):
|
$values = array();
|
||||||
$legacy = SP()->countries->legacy;
|
foreach ( $nationalities as $nationality ):
|
||||||
$nationality = strtolower( $nationality );
|
if ( 2 == strlen( $nationality ) ):
|
||||||
$nationality = sp_array_value( $legacy, $nationality, null );
|
$legacy = SP()->countries->legacy;
|
||||||
endif;
|
$nationality = strtolower( $nationality );
|
||||||
$country_name = sp_array_value( $countries, $nationality, null );
|
$nationality = sp_array_value( $legacy, $nationality, null );
|
||||||
$data[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
endif;
|
||||||
|
$country_name = sp_array_value( $countries, $nationality, null );
|
||||||
|
$values[] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
||||||
|
endforeach;
|
||||||
|
$data[ __( 'Nationality', 'sportspress' ) ] = implode( '<br>', $values );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( $show_current_teams && $current_teams ):
|
if ( $show_current_teams && $current_teams ):
|
||||||
|
|||||||
Reference in New Issue
Block a user