评论处理在文件:wp Comments post中完成。php。你可以用钩子pre_comment_on_post
验证在注释表单字段中输入的值。
function custom_validate_comment_url() {
if( !empty( $_POST[\'url\'] ) && !preg_match( \'\\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]\', $_POST[\'url\'] ) // do you url validation here (I am not a regex expert)
wp_die( __(\'Error: please enter a valid url or leave the homepage field empty\') );
}
add_action(\'pre_comment_on_post\', \'custom_validate_comment_url\');
如果要更改提交的值,请使用筛选器
preprocess_comment
. 例如。:
function custom_change_comment_url( $commentdata ) {
if( $commentdata[\'comment_author_url\'] == \'Your homepage\' )
$commentdata[\'comment_author_url\'] = \'\';
return $commentdata;
}
add_filter(\'preprocess_comment\', \'custom_change_comment_url\');