diff --git a/actions.php b/actions.php index 6054264f..538f510c 100644 --- a/actions.php +++ b/actions.php @@ -94,29 +94,50 @@ function sp_nonce() { 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 ( !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 ): - delete_post_meta( $post_id, $key ); - if ( is_array( $value ) ): - if ( sp_get_array_depth( $value ) >= 3 ): - add_post_meta( $post_id, $key, $value, false ); - else: - $values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) ); - foreach ( $values as $value ): - add_post_meta( $post_id, $key, $value, false ); - endforeach; - endif; + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 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; + switch ( $_POST['post_type'] ): + case ( 'sp_team' ): + update_post_meta( $post_id, 'sp_stats', $_POST['sp_stats'] ); + break; + case ( 'sp_event' ): + update_post_meta( $post_id, 'sp_stats', $_POST['sp_stats'] ); + sp_update_post_meta_recursive( $post_id, 'sp_team', $_POST['sp_team'] ); + sp_update_post_meta_recursive( $post_id, 'sp_player', $_POST['sp_player'] ); + break; + case ( 'sp_player' ): + update_post_meta( $post_id, 'sp_stats', $_POST['sp_stats'] ); + sp_update_post_meta_recursive( $post_id, 'sp_team', $_POST['sp_team'] ); + break; + case ( 'sp_staff' ): + sp_update_post_meta_recursive( $post_id, 'sp_team', $_POST['sp_team'] ); + break; + case ( 'sp_table' ): + update_post_meta( $post_id, 'sp_stats', $_POST['sp_stats'] ); + sp_update_post_meta_recursive( $post_id, 'sp_team', $_POST['sp_team'] ); + break; + endswitch; + + /* + + foreach ( $sportspress as $key => $value ): + delete_post_meta( $post_id, $key ); + if ( is_array( $value ) ): + if ( sp_get_array_depth( $value ) >= 3 ): + add_post_meta( $post_id, $key, $value, false ); else: - update_post_meta( $post_id, $key, $value ); + $values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) ); + foreach ( $values as $value ): + add_post_meta( $post_id, $key, $value, false ); + endforeach; endif; - endforeach; - endif; - endif; + else: + update_post_meta( $post_id, $key, $value ); + endif; + endforeach; + + */ } add_action( 'save_post', 'sp_save_post' ); ?> \ No newline at end of file diff --git a/event.php b/event.php index 57230cc0..6effb381 100644 --- a/event.php +++ b/event.php @@ -44,7 +44,7 @@ function sp_event_team_meta( $post ) { 'sp_team', - 'name' => 'sportspress[sp_team][]', + 'name' => 'sp_team[]', 'class' => 'sportspress-pages', 'show_option_none' => sprintf( __( 'Select %s' ), 'Team' ), 'option_none_value' => 0, diff --git a/helpers.php b/helpers.php index ff1b0fda..f9ab26c4 100644 --- a/helpers.php +++ b/helpers.php @@ -170,7 +170,7 @@ if ( !function_exists( 'sp_post_checklist' ) ) { global $post_id; ?>