更新日期:2018-09-07
在發表迴響中,wordpress 允許網友使用一些不危及系統的 HTML 標籤與屬性,這在 /wp-includes/kses.php 程式中有命名為 $allowedtags 變數。
如果不允許網友使用 HTML 標籤,網路上有些教學是以下面程式教你這樣子移除:
function sig_remove_comment_form_allowed_tags( $defaults ) { $defaults['comment_notes_after'] = ''; return $defaults; } add_filter( 'comment_form_defaults', 'sig_remove_comment_form_allowed_tags' );
↑↑↑注意,這是錯誤的方式,這只能移除下方的說明文字,並沒有更改到這個功能。
請再增加下方的程式一起用:
function sig_allowed_html_tags_in_comments() { define('CUSTOM_TAGS', true); global $allowedtags; $allowedtags = array(); } add_action('init', 'sig_allowed_html_tags_in_comments', 10);
若是我們只想要開放一些 HTML 標籤與屬性,可以依照下面程式方式撰寫,在 $allowedtags 陣列變數內自行增加 HTML 標籤,若要增加屬性就是在 HTML 標籤下增加陣列。
function sig_allowed_html_tags_in_comments() { define('CUSTOM_TAGS', true); global $allowedtags; $allowedtags = array( 'a' => array( 'href' => array (), 'title' => array () ), 'blockquote' => array( 'cite' => array () ), 'cite' => array (), 'code' => array(), 'em' => array(), 'strong' => array() ); } add_action('init', 'sig_allowed_html_tags_in_comments', 10);
請再注意:勿開放一些不該開放的 HTML 標籤,後果自行負責呀。