Detach duties from officials to simplify admin
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Official Details
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 2.5
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Official_Details
|
||||
*/
|
||||
class SP_Meta_Box_Official_Details {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||
$continents = SP()->countries->continents;
|
||||
|
||||
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
|
||||
foreach ( $nationalities as $index => $nationality ):
|
||||
if ( 2 == strlen( $nationality ) ):
|
||||
$legacy = SP()->countries->legacy;
|
||||
$nationality = strtolower( $nationality );
|
||||
$nationality = sp_array_value( $legacy, $nationality, null );
|
||||
$nationalities[ $index ] = $nationality;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
if ( taxonomy_exists( 'sp_duty' ) ):
|
||||
$positions = get_the_terms( $post->ID, 'sp_duty' );
|
||||
$position_ids = array();
|
||||
if ( $positions ):
|
||||
foreach ( $positions as $position ):
|
||||
$position_ids[] = $position->term_id;
|
||||
endforeach;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
|
||||
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
|
||||
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
|
||||
?>
|
||||
|
||||
<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; ?>" multiple="multiple">
|
||||
<option value=""></option>
|
||||
<?php foreach ( $continents as $continent => $countries ): ?>
|
||||
<optgroup label="<?php echo $continent; ?>">
|
||||
<?php foreach ( $countries as $code => $country ): ?>
|
||||
<option value="<?php echo $code; ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo $country; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</optgroup>
|
||||
<?php endforeach; ?>
|
||||
</select></p>
|
||||
|
||||
<?php if ( taxonomy_exists( 'sp_duty' ) ) { ?>
|
||||
<p><strong><?php _e( 'Duties', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_duty',
|
||||
'name' => 'tax_input[sp_duty][]',
|
||||
'selected' => $position_ids,
|
||||
'values' => 'term_id',
|
||||
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Duties', 'sportspress' ) ),
|
||||
'class' => 'widefat',
|
||||
'property' => 'multiple',
|
||||
'chosen' => true,
|
||||
);
|
||||
sp_dropdown_taxonomies( $args );
|
||||
?></p>
|
||||
<?php } ?>
|
||||
|
||||
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_current_team[]',
|
||||
'selected' => $current_teams,
|
||||
'values' => 'ID',
|
||||
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
|
||||
'class' => 'sp-current-teams widefat',
|
||||
'property' => 'multiple',
|
||||
'chosen' => true,
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?></p>
|
||||
|
||||
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_past_team[]',
|
||||
'selected' => $past_teams,
|
||||
'values' => 'ID',
|
||||
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
|
||||
'class' => 'sp-past-teams widefat',
|
||||
'property' => 'multiple',
|
||||
'chosen' => true,
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
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_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() ) ) );
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ class SportsPress_Officials {
|
||||
// Actions
|
||||
add_action( 'sportspress_after_register_taxonomy', array( $this, 'register_taxonomy' ) );
|
||||
add_action( 'sportspress_after_register_post_type', array( $this, 'register_post_type' ) );
|
||||
add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
|
||||
add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) );
|
||||
add_action( 'sportspress_create_rest_routes', array( $this, 'create_rest_routes' ) );
|
||||
add_action( 'sportspress_register_rest_fields', array( $this, 'register_rest_fields' ) );
|
||||
@@ -41,6 +40,8 @@ class SportsPress_Officials {
|
||||
add_action( 'sportspress_calendar_data_meta_box_table_row', array( $this, 'calendar_meta_row' ), 10, 2 );
|
||||
add_action( 'sp_duty_edit_form_fields', array( $this, 'edit_taxonomy_fields' ), 10, 1 );
|
||||
add_action( 'edited_sp_duty', array( $this, 'save_taxonomy_fields' ), 10, 1 );
|
||||
add_action( 'admin_menu', array( $this, 'duties_menu' ) );
|
||||
add_action( 'parent_file', array( $this, 'parent_file' ) );
|
||||
|
||||
// Filters
|
||||
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||
@@ -102,7 +103,7 @@ class SportsPress_Officials {
|
||||
'rest_controller_class' => 'SP_REST_Terms_Controller',
|
||||
'rest_base' => 'duties',
|
||||
) );
|
||||
$object_types = apply_filters( 'sportspress_duty_object_types', array( 'sp_official' ) );
|
||||
$object_types = apply_filters( 'sportspress_duty_object_types', array() );
|
||||
register_taxonomy( 'sp_duty', $object_types, $args );
|
||||
foreach ( $object_types as $object_type ):
|
||||
register_taxonomy_for_object_type( 'sp_duty', $object_type );
|
||||
@@ -151,13 +152,6 @@ class SportsPress_Officials {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove meta boxes.
|
||||
*/
|
||||
public function remove_meta_boxes() {
|
||||
remove_meta_box( 'sp_dutydiv', 'sp_official', 'side' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditonally load the class and functions only needed when viewing this post type.
|
||||
*/
|
||||
@@ -315,15 +309,6 @@ class SportsPress_Officials {
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
);
|
||||
$meta_boxes['sp_official'] = array(
|
||||
'details' => array(
|
||||
'title' => __( 'Details', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Official_Details::save',
|
||||
'output' => 'SP_Meta_Box_Official_Details::output',
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
);
|
||||
return $meta_boxes;
|
||||
}
|
||||
|
||||
@@ -589,6 +574,26 @@ class SportsPress_Officials {
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
*/
|
||||
public function duties_menu() {
|
||||
add_submenu_page( 'edit.php?post_type=sp_official', __( 'Duties', 'sportspress' ), __( 'Duties', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_duty');
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight parent menu item
|
||||
*/
|
||||
public function parent_file( $parent_file ) {
|
||||
global $current_screen;
|
||||
$taxonomy = $current_screen->taxonomy;
|
||||
|
||||
if ( 'sp_duty' == $taxonomy )
|
||||
$parent_file = 'edit.php?post_type=sp_official';
|
||||
|
||||
return $parent_file;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user