我们如何在名称为" wp_comments"的数据库表中保存对话框的文本。 WP-DISCUZ插件已用于显示已发布文章的评论。 我们定制的是,当用户发布文章时,它将发送给管理员进行审批。如果管理员拒绝评论(此评论框将 反映为对话框)然后评论的文本应保存在数据库表" wp_comments"中。我们如何实现这一点。
/* WordPress Function to Insert Comment */
function wp_insert_comment( $commentdata ) {
global $wpdb;
$data = wp_unslash( $commentdata );
$comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author'];
$comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
$comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
$comment_author_IP = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
$comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
$comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
$comment_post_ID = ! isset( $data['comment_post_ID'] ) ? '' : $data['comment_post_ID'];
$comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
$comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
$comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
$comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
$comment_type = ! isset( $data['comment_type'] ) ? '' : $data['comment_type'];
$comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
$user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
$compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
return false;
}
$id = (int) $wpdb->insert_id;
if ( $comment_approved == 1 ) {
wp_update_comment_count( $comment_post_ID );
}
$comment = get_comment( $id );
/**
* Fires immediately after a comment is inserted into the database.
*
* @since 2.8.0
*
* @param int $id The comment ID.
* @param obj $comment Comment object.
*/
do_action( 'wp_insert_comment', $id, $comment );
wp_cache_set( 'last_changed', microtime(), 'comment' );
return $id;
}
/* The function that will executed on Rejection by Admin */
$(".reject-post-status").on('click', function () {
// alert($(this).attr("id"))
var pid = $(this).attr("id");
$('#dialog').dialogBox({
hasClose: false,
// effect: 'fade',
width: 800,
height: 300,
hasBtn: true,
confirmValue: 'OK',
cancelValue: 'Cancel',
confirm: function () {
$.ajax({
type: "POST",
url: 'http://example.com/update-status.php?rejected-pid=' + pid,
data: { message: $('#comment').val() },
success: function (html) {
// alert(html);
window.location.href = 'http://example.com/Pending-Approval/';
}
});
},
content: '<textarea rows="6" cols="105" id="comment" required></textarea>',
title: "Add Comment"
});
return false;
});