Add inline result editing

This commit is contained in:
Brian Miyaji
2014-11-23 13:32:19 +11:00
parent fcf398420e
commit 7319549abc
4 changed files with 118 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ class SP_Admin_AJAX {
*/
public function __construct() {
add_action( 'wp_ajax_sp-save-primary-result', array( $this, 'save_primary_result' ), 1 );
add_action( 'wp_ajax_sp-save-inline-results', array( $this, 'save_inline_results' ) );
}
/**
@@ -34,6 +35,40 @@ class SP_Admin_AJAX {
update_option( 'sportspress_primary_result', $primary_result );
wp_send_json_success();
}
/**
* Save event results inline.
*
* @since 1.5
*/
function save_inline_results() {
check_ajax_referer( 'sp-save-inline-results', 'nonce' );
$post_id = sp_array_value( $_POST, 'post_id' );
$results = sp_array_value( $_POST, 'results' );
if ( ! $post_id || ! is_array( $results ) ) {
// Return error
wp_send_json_error();
}
// Get current results meta
$meta = get_post_meta( $post_id, 'sp_results', true );
foreach ( $results as $result ) {
$id = sp_array_value( $result, 'id' );
$key = sp_array_value( $result, 'key' );
if ( ! $id || ! $key ) continue;
$meta[ $id ][ $key ] = sp_array_value( $result, 'result' );
}
// Update results
update_post_meta( $post_id, 'sp_results', $meta );
// Return success
wp_send_json_success();
}
}
return new SP_Admin_AJAX();