Add nonce and team select functions

This commit is contained in:
Takumi
2013-07-25 14:52:58 +10:00
parent 39d0c1aac6
commit 3f82e5c72c
6 changed files with 71 additions and 51 deletions

View File

@@ -10,13 +10,18 @@ function sp_after_theme_setup() {
}
add_action( 'after_theme_setup', 'sp_after_theme_setup' );
function sp_save_post() {
global $post, $post_id, $typenow;
function sp_nonce() {
echo '<input type="hidden" name="sportspress_nonce" id="sportspress_nonce" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
}
function sp_save_post( $post_id ) {
global $post, $typenow;
if ( isset( $_POST['sportspress'] ) ):
$sportspress = (array)$_POST['sportspress'];
if ( isset( $_POST ) && !empty( $sportspress ) ):
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
// if ( ! isset( $_POST['sp_event_team_nonce'] ) || ! wp_verify_nonce( $_POST['sp_event_team_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
if ( !isset( $_POST['sportspress_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id;
foreach ( $sportspress as $key => $value ):
if ( is_array( $value ) )
$value = serialize( $value );

View File

@@ -180,7 +180,7 @@ function sp_event_team_meta( $post, $metabox ) {
<?php
*/
endfor;
echo '<input type="hidden" name="sp_event_team_nonce" id="sp_event_team_nonce" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
sp_nonce();
}
function sp_event_article_meta( $post, $metabox ) {

View File

@@ -94,4 +94,54 @@ if ( ! function_exists( 'sp_get_teams' ) ) {
return $teams;
}
}
if ( ! function_exists( 'sp_team_checklist' ) ) {
function sp_team_checklist( $post_id = null ) {
if ( ! isset( $post_id ) )
global $post_id;
$selected = sp_get_teams( $post_id );
$teams = get_pages( array( 'post_type' => 'sp_team') );
foreach ( $teams as $team ):
?>
<li>
<label class="selectit">
<input type="checkbox" value="<?php echo $team->ID; ?>" name="sportspress[sp_teams][]"<?php if ( in_array( $team->ID, $selected ) ) echo ' checked="checked"'; ?>>
<?php
if ( $team->post_parent ):
$parents = get_post_ancestors( $team );
echo str_repeat( '— ', sizeof( $parents ) );
endif;
echo $team->post_title;
?>
</label>
</li>
<?php
endforeach;
}
}
if ( ! function_exists( 'sp_team_select_html' ) ) {
function sp_team_select_html( $post_id = null ) {
if ( ! isset( $post_id ) )
global $post_id;
?>
<ul id="sp_team-tabs" class="wp-tab-bar">
<li class="tabs wp-tab-active"><?php _e( 'Teams', 'sportspress' ); ?></li>
</ul>
<div id="sp_team-all" class="wp-tab-panel">
<input type="hidden" value="0" name="sportspress[sp_teams]" />
<ul class="categorychecklist form-no-clear">
<?php sp_team_checklist( $post_id ); ?>
</ul>
</div>
<div id="sp_team-adder">
<h4>
<a title="<?php echo sprintf( esc_attr__( 'Add New %s', 'sportspress' ), esc_attr__( 'Team', 'sportspress' ) ); ?>" href="<?php echo admin_url( 'post-new.php?post_type=sp_team' ); ?>" target="_blank">
+ <?php echo sprintf( __( 'Add New %s', 'sportspress' ), __( 'Team', 'sportspress' ) ); ?>
</a>
</h4>
</div>
<?php
}
}
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -22,45 +22,8 @@ function sp_player_meta_init() {
}
function sp_player_basic_meta( $post, $metabox ) {
global $post_id;
?>
<ul id="sp_team-tabs" class="wp-tab-bar">
<li class="tabs wp-tab-active"><?php _e( 'Teams', 'sportspress' ); ?></li>
</ul>
<div id="sp_team-all" class="wp-tab-panel">
<input type="hidden" value="0" name="sportspress[sp_teams]" />
<ul class="categorychecklist form-no-clear">
<?php
$player_teams = sp_get_teams( $post_id );
$teams = get_pages( array( 'post_type' => 'sp_team') );
foreach ( $teams as $team ):
?>
<li>
<label class="selectit">
<input type="checkbox" value="<?php echo $team->ID; ?>" name="sportspress[sp_teams][]"<?php if ( in_array( $team->ID, $player_teams ) ) echo ' checked="checked"'; ?>>
<?php
if ( $team->post_parent ):
$parents = get_post_ancestors( $team );
echo str_repeat( '— ', sizeof( $parents ) );
endif;
echo $team->post_title;
?>
</label>
</li>
<?php
endforeach;
?>
</ul>
</div>
<div id="sp_league-adder" class="wp-hidden-children">
<h4><?php add_thickbox(); ?>
<a title="<?php echo sprintf( esc_attr__( 'Add New %s', 'sportspress' ), esc_attr__( 'Team', 'sportspress' ) ); ?>" href="<?php echo admin_url( 'post-new.php?post_type=sp_team' ); ?>" target="_blank">
+ <?php echo sprintf( __( 'Add New %s', 'sportspress' ), __( 'Team', 'sportspress' ) ); ?>
</a>
</h4>
</div>
<?php
wp_reset_postdata();
echo '<input type="hidden" name="sp_event_team_nonce" id="sp_event_team_nonce" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
sp_team_select_html( $post_id );
sp_nonce();
}
function sp_player_profile_meta( $post, $metabox ) {

View File

@@ -1,4 +1,3 @@
#adminmenu #toplevel_page_sp_settings div.wp-menu-image,
#adminmenu #menu-posts-sp_team div.wp-menu-image,
#adminmenu #menu-posts-sp_event div.wp-menu-image,
#adminmenu #menu-posts-sp_player div.wp-menu-image,
@@ -10,15 +9,9 @@
#adminmenu #menu-posts-sp_venue div.wp-menu-image {
background-image: url(images/menu.png);
background-repeat: no-repeat;
}
#adminmenu #toplevel_page_sp_settings div.wp-menu-image {
background-position: 1px -33px;
}
#adminmenu #toplevel_page_sp_settings:hover div.wp-menu-image,
#adminmenu #toplevel_page_sp_settings.wp-has-current-submenu div.wp-menu-image,
#adminmenu #toplevel_page_sp_settings.current div.wp-menu-image {
background-position: 1px -1px;
}
/*
#adminmenu #menu-posts-sp_team div.wp-menu-image {
background-position: 1px -97px;
}
@@ -27,6 +20,15 @@
#adminmenu #menu-posts-sp_team.current div.wp-menu-image {
background-position: 1px -65px;
}
*/
#adminmenu #menu-posts-sp_team div.wp-menu-image {
background-position: 1px -33px;
}
#adminmenu #menu-posts-sp_team:hover div.wp-menu-image,
#adminmenu #menu-posts-sp_team.wp-has-current-submenu div.wp-menu-image,
#adminmenu #menu-posts-sp_team.current div.wp-menu-image {
background-position: 1px -1px;
}
#adminmenu #menu-posts-sp_event div.wp-menu-image {
background-position: -29px -33px;
}