function id_REST_set_comment_status() { $newStatus = id_param('status', ''); $comment_id = id_param('comment_id', 0); $rawComment = stripslashes(id_param('comment_data')); if (!$comment_id) { if (!$rawComment) { return false; } $comment = new id_comment(); $comment->loadFromRemoteJson($rawComment); $comment->duplicateCheck(); // Will locate a match and update with the WP id if ($comment->comment_ID) { // Found it, carry on $comment_id = $comment->comment_ID; } else { // No match if ('delete' == $newStatus) { return true; } else { return false; } } } id_debug_log("Receive Comment Status: {$newStatus} {$comment_id}"); // Check if the status is already set, if so, still return true if ($newStatus == wp_get_comment_status($comment_id)) { return true; } else { if ($newStatus == "delete" && in_array(wp_get_comment_status($comment_id), array("deleted", "trash"))) { // handle cases that don't quite line up (delete=deleted and hold=unapproved) return true; } else { if ($newStatus == "hold" && wp_get_comment_status($comment_id) == "unapproved") { return true; } } } // If not already set, then rename to local status, then attempt to set it and return the result remove_action('wp_set_comment_status', 'id_comment_status', 10, 2); if ('delete' == $newStatus) { $result = wp_delete_comment($comment_id); } else { $result = wp_set_comment_status($comment_id, $newStatus); } add_action('wp_set_comment_status', 'id_comment_status', 10, 2); return $result; }
function id_REST_save_comment() { $rawComment = stripslashes(id_param('id_comment_data')); id_debug_log("Receive Comment: {$rawComment}"); $comment = new id_comment(); $comment->loadFromRemoteJson($rawComment); return array('success' => $comment->save(), 'comment' => $comment->export()); }