Browse files

Switch the delete endpoint to use the new method

  • Loading branch information...
1 parent 58ce648 commit e92599ed7be79f9a6d5bb103ce300808e519585b @nb nb committed Dec 26, 2012
Showing with 31 additions and 4 deletions.
  1. +3 −4 js/liveblog-publisher.js
  2. +28 −0 liveblog.php
View
7 js/liveblog-publisher.js
@@ -105,15 +105,14 @@
liveblog.publisher.delete_entry = function( id ) {
var data = {
- action: 'liveblog_insert_entry',
+ action: 'liveblog_delete_entry',
post_id: liveblog_settings.post_id,
- replaces: id,
- entry_content: ''
+ entry_id: id,
};
data[ liveblog_settings.nonce_key ] = liveblog.publisher.$nonce.val();
liveblog.publisher.disable_posting_interface();
liveblog.publisher.show_spinner();
- liveblog.ajax_request( liveblog_settings.endpoint_url + 'insert', data, liveblog.publisher.insert_entry_success, liveblog.publisher.insert_entry_error, 'POST' );
+ liveblog.ajax_request( liveblog_settings.endpoint_url + 'delete', data, liveblog.publisher.insert_entry_success, liveblog.publisher.insert_entry_error, 'POST' );
};
liveblog.publisher.disable_posting_interface = function() {
View
28 liveblog.php
@@ -193,6 +193,7 @@ private static function handle_ajax_request() {
$suffix_to_method = array(
'\d+/\d+' => 'ajax_entries_between',
'insert' => 'ajax_insert_entry',
+ 'delete' => 'ajax_delete_entry',
'preview' => 'ajax_preview_entry',
);
@@ -371,6 +372,33 @@ public static function ajax_insert_entry() {
) );
}
+ public static function ajax_delete_entry() {
+
+ self::ajax_current_user_can_edit_liveblog();
+ self::ajax_check_nonce();
+
+ $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
+ $entry_id = isset( $_POST['entry_id'] ) ? intval( $_POST['entry_id'] ) : 0;
+
+ $user = wp_get_current_user();
+ $ip = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );
+ $user_agent = substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 );
+
+ $entry = WPCOM_Liveblog_Entry::delete( $entry_id, array( 'post_id' => $post_id, 'user' => $user, 'ip' => $ip, 'user_agent' => $user_agent ) );
+
+ if ( is_wp_error( $entry ) ) {
+ self::send_server_error( $entry->get_error_message() );
+ }
+
+ // Do not send latest_timestamp. If we send it the client won't get
+ // older entries. Since we send only the new one, we don't know if there
+ // weren't any entries in between.
+ self::json_return( array(
+ 'entries' => array( $entry->for_json() ),
+ 'latest_timestamp' => null
+ ) );
+ }
+
function ajax_preview_entry() {
self::ajax_current_user_can_edit_liveblog();
self::ajax_check_nonce();

0 comments on commit e92599e

Please sign in to comment.