Highlight admin menu when editing configs and add abbreviation to outcome
This commit is contained in:
@@ -12,6 +12,7 @@ function sp_outcome_cpt_init() {
|
||||
'show_in_menu' => false,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'page-attributes' ),
|
||||
'register_meta_box_cb' => 'sp_outcome_meta_init',
|
||||
'capability_type' => 'sp_config'
|
||||
);
|
||||
register_post_type( 'sp_outcome', $args );
|
||||
@@ -21,9 +22,25 @@ add_action( 'init', 'sp_outcome_cpt_init' );
|
||||
function sp_outcome_edit_columns() {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Label', 'sportspress' )
|
||||
'title' => __( 'Label', 'sportspress' ),
|
||||
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' )
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
add_filter( 'manage_edit-sp_outcome_columns', 'sp_outcome_edit_columns' );
|
||||
|
||||
function sp_outcome_meta_init() {
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_outcome_details_meta', 'sp_outcome', 'normal', 'high' );
|
||||
}
|
||||
|
||||
function sp_outcome_details_meta( $post ) {
|
||||
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
|
||||
?>
|
||||
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_abbreviation" type="text" size="4" id="sp_abbreviation" value="<?php echo $abbreviation; ?>" placeholder="<?php echo get_the_title( $post->ID ); ?>">
|
||||
</p>
|
||||
<?php
|
||||
sp_nonce();
|
||||
}
|
||||
?>
|
||||
26
install.php
26
install.php
@@ -176,4 +176,30 @@ if ( !function_exists( 'sportspress_install' ) ) {
|
||||
}
|
||||
}
|
||||
add_action( 'admin_init', 'sportspress_install', 1 );
|
||||
|
||||
// Flush rewrite rules on activation
|
||||
function sp_rewrite_flush() {
|
||||
sp_event_cpt_init();
|
||||
sp_result_cpt_init();
|
||||
sp_outcome_cpt_init();
|
||||
sp_column_cpt_init();
|
||||
sp_statistic_cpt_init();
|
||||
sp_team_cpt_init();
|
||||
sp_table_cpt_init();
|
||||
sp_player_cpt_init();
|
||||
sp_list_cpt_init();
|
||||
sp_staff_cpt_init();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
register_activation_hook( __FILE__, 'sp_rewrite_flush' );
|
||||
|
||||
function sp_admin_head_edit() {
|
||||
global $typenow;
|
||||
|
||||
if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
|
||||
sp_highlight_admin_menu();
|
||||
endif;
|
||||
}
|
||||
add_action( 'admin_head-edit.php', 'sp_admin_head_edit', 10, 2 );
|
||||
add_action( 'admin_head-post.php', 'sp_admin_head_edit', 10, 2 );
|
||||
?>
|
||||
@@ -78,6 +78,14 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
|
||||
echo '—';
|
||||
endif;
|
||||
break;
|
||||
case 'sp_abbreviation':
|
||||
$abbreviation = get_post_meta ( $post_id, 'sp_abbreviation', true );
|
||||
if ( $abbreviation ):
|
||||
echo $abbreviation;
|
||||
else:
|
||||
echo get_the_title( $post_id );
|
||||
endif;
|
||||
break;
|
||||
case 'sp_player':
|
||||
echo sp_the_posts( $post_id, 'sp_player' );
|
||||
break;
|
||||
@@ -101,7 +109,13 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
|
||||
add_action( 'manage_posts_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
|
||||
add_action( 'manage_pages_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
|
||||
|
||||
function sp_manage_posts_columns() {
|
||||
sp_highlight_admin_menu();
|
||||
}
|
||||
add_action( 'manage_posts_columns', 'sp_manage_posts_columns' );
|
||||
|
||||
function sp_restrict_manage_posts() {
|
||||
sp_highlight_admin_menu();
|
||||
global $typenow, $wp_query;
|
||||
if ( in_array( $typenow, array( 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list', 'sp_tournament' ) ) ):
|
||||
$selected = isset( $_REQUEST['sp_team'] ) ? $_REQUEST['sp_team'] : null;
|
||||
@@ -184,8 +198,8 @@ function sp_save_post( $post_id ) {
|
||||
|
||||
case ( 'sp_outcome' ):
|
||||
|
||||
// Update equation as string
|
||||
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
|
||||
// Update abbreviation as string
|
||||
update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) );
|
||||
|
||||
break;
|
||||
|
||||
|
||||
@@ -463,7 +463,7 @@ if ( !function_exists( 'sp_league_table' ) ) {
|
||||
if ( !$team_id ) continue;
|
||||
$div = get_term( $team_id, 'sp_league' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo get_the_title( $team_id ); ?>
|
||||
</td>
|
||||
@@ -503,7 +503,7 @@ if ( !function_exists( 'sp_player_table' ) ) {
|
||||
if ( !$player_id ) continue;
|
||||
$div = get_term( $player_id, 'sp_league' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo get_the_title( $player_id ); ?>
|
||||
</td>
|
||||
@@ -541,7 +541,7 @@ if ( !function_exists( 'sp_team_columns_table' ) ) {
|
||||
$i = 0;
|
||||
if ( empty( $data ) ):
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><strong><?php printf( __( 'Select %s', 'sportspress' ), __( 'League', 'sportspress' ) ); ?></strong></td>
|
||||
</tr>
|
||||
<?php
|
||||
@@ -550,7 +550,7 @@ if ( !function_exists( 'sp_team_columns_table' ) ) {
|
||||
if ( !$div_id ) continue;
|
||||
$div = get_term( $div_id, 'sp_league' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo $div->name; ?>
|
||||
</td>
|
||||
@@ -598,7 +598,7 @@ if ( !function_exists( 'sp_player_statistics_table' ) ) {
|
||||
if ( !$div_id ) continue;
|
||||
$div = get_term( $div_id, 'sp_league' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo $div->name; ?>
|
||||
</td>
|
||||
@@ -639,7 +639,7 @@ if ( !function_exists( 'sp_event_results_table' ) ) {
|
||||
foreach ( $data as $team_id => $team_results ):
|
||||
if ( !$team_id ) continue;
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo get_the_title( $team_id ); ?>
|
||||
</td>
|
||||
@@ -692,7 +692,7 @@ if ( !function_exists( 'sp_event_players_table' ) ) {
|
||||
foreach ( $data as $player_id => $player_statistics ):
|
||||
if ( !$player_id ) continue;
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php echo get_the_title( $player_id ); ?>
|
||||
</td>
|
||||
@@ -706,7 +706,7 @@ if ( !function_exists( 'sp_event_players_table' ) ) {
|
||||
$i++;
|
||||
endforeach;
|
||||
?>
|
||||
<tr class="sp-row sp-total<?php if ( $i % 2 ) echo ' alternate'; ?>">
|
||||
<tr class="sp-row sp-total<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$player_id = 0;
|
||||
@@ -1328,4 +1328,13 @@ if ( !function_exists( 'sp_get_list_html' ) ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !function_exists( 'sp_highlight_admin_menu' ) ) {
|
||||
function sp_highlight_admin_menu() {
|
||||
global $parent_file, $submenu_file;
|
||||
$parent_file = 'options-general.php';
|
||||
$submenu_file = 'sportspress';
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
// Flush rewrite rules on activation to make sure permalinks work properly
|
||||
function sp_rewrite_flush() {
|
||||
sp_config_cpt_init();
|
||||
sp_event_cpt_init();
|
||||
sp_team_cpt_init();
|
||||
sp_table_cpt_init();
|
||||
sp_player_cpt_init();
|
||||
sp_list_cpt_init();
|
||||
sp_staff_cpt_init();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
register_activation_hook( __FILE__, 'sp_rewrite_flush' );
|
||||
?>
|
||||
@@ -53,9 +53,10 @@ require_once dirname( __FILE__ ) . '/admin/terms/position.php';
|
||||
// Install
|
||||
include dirname( __FILE__ ) . '/install.php';
|
||||
|
||||
// Hooks, Actions, and Filters
|
||||
require_once dirname( __FILE__ ) . '/sportspress-hooks.php';
|
||||
// Actions
|
||||
require_once dirname( __FILE__ ) . '/sportspress-actions.php';
|
||||
|
||||
// Filters
|
||||
require_once dirname( __FILE__ ) . '/sportspress-filters.php';
|
||||
|
||||
// Admin Styles
|
||||
|
||||
Reference in New Issue
Block a user