在每个评论旁边添加一个按钮

时间:2019-06-14 11:44:32

标签: wordpress

我正在制作一个wordpress插件,该插件将添加“报告此评论”按钮。为了完成它,我需要在wordpress页面上的每个评论旁边添加一个“报告”按钮。尽管我找不到解决办法。

我已经尝试过了:

add_filter("comment_id_fields","my_submit_comment_message");

function my_submit_comment_message($result){
    return $result . " <span>(TEST)</span>";
}

但这只是添加了一个文本/按钮/等。到帖子末尾。

1 个答案:

答案 0 :(得分:0)

通过以下代码,我设法为每个评论添加了一个按钮:

add_filter('comment_text', 'AddButton');

function AddButton($content){
    $comment_id = get_comment_ID ();
    $comment_text = get_comment_text(); 

    $report_button = "<form action='CommentReport.php' method='get'>";
    $report_button .= "<input type='submit' name='Report_Button' value='Report Comment: 
    $comment_id' style='background-color: orange; color: black';/>";
    $report_button .= "</form>";
    $report_button .= "</br>";

    $new_content = $report_button;
    $content = $content . $new_content;
    return $content;
}
相关问题