当有人从when中删除评论时,我正在尝试添加一个trash_reason。我设法添加了一个带有下拉列表删除原因的加厚框,并在垃圾链接的query_string中传递/更新了所选选项的值,但在我的add_action中无法得到它。
这是我的代码:
add_filter('comment_row_actions', 'filter_comments_actions', 1, 2);
function filter_comments_actions($actions, $comment)
{
global $wpdb;
$del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_$comment->comment_ID"));
$trash_url = $trash_url = esc_url("comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce&reason=1");
add_thickbox();
$reasons = $wpdb->get_results('SELECT * FROM wp_jb_rejected_review_reasons');
$actions['trash'] = "
Trash
Reason for deletion
";
foreach ($reasons as $reason) {
$actions['trash'] .= "$reason->reason";
}
$actions['trash'] .= "
";
$actions['trash'] .= "" . _x('Trash', 'verb') . '';
$actions['trash'] .=
"
";
unset($actions['edit']);
return $actions;
}
add_action('trash_comment', 'log_trash_comment', 1);
function log_trash_comment($comment_id)
{
$reason = $_REQUEST['reason'];
global $wpdb;
$wpdb->query("INSERT INTO wp_rejected_reviews (moderator_id,
comment_id, reason_id) VALUES (".get_current_user_id().", $comment_id,
$reason)");
}
我的javascript:
function update_moderate_reason_id(comment_id) {
var reason_id = jQuery("select[name='rejected_reason']#rejected_reason_"+comment_id).val();
console.log(reason_id);
var confirm_link = jQuery("a.confirm-deletion-comment-"+comment_id);
var _href = confirm_link.attr('href');
if(_href.indexOf('&reason=') != -1){
_href = _href.substr(0, _href.length-9);
}
_href += "&reason="+reason_id;
confirm_link.attr('href', _href); }
function log_moderation_href(link){
console.log(link);
}
但是当我在我的var_dump() $_REQUEST函数中使用log_trash_comment函数时,原因并没有出现
提前感谢你的宝贵帮助,
发布于 2019-06-18 14:51:42
您向url添加参数的方式不起作用。ajax请求旨在防止这样的参数插入。
我建议您启动另一个ajax请求来处理这个过程,而不是试图以这种方式连接到现有进程。
例如,您可以在注释被破坏后启动您的模式窗口,并分别控制提交和日志记录过程。
https://wordpress.stackexchange.com/questions/340720
复制相似问题