写在前面
目前采用的一个插件 block-spam-by-math 用来放SPAM
改进了一下,但是验证的field是追加在comment form的最末处,经常被不小心忽略
昨天看到 jade 和 walker,把这个问题搞定了,详询之后,发现他们的方法只对他们的模板有效。
开始的时候以为是 add_action的 优先权对位置有影响,查阅响应文档才发现add_action的优先权是controller中运行的优先权,不影响view部分。
于是按照 block-spam-by-math 中原代码顺藤摸瓜,发现了不少东西。
add_action( ‘comment_form’, array( &$this, ‘add_hidden_fields’ ) );
原来主要是add_action使用的钩子’comment_form’对位置有影响
顺便也对wp的hook方式了解一下
1、comment_form()
函数位于 .\wp-includes\comment-template.php
主要是用于呈现comment的form
2、comment_form中可用的钩子接入点(按加载顺序)
comment_form_before comment_form_must_log_in_after comment_form_top comment_form_logged_in_after comment_form_before_fields comment_form_after_fields comment_form comment_form_after comment_form_comments_closed
3、comment_form_after_fields
最终我选用了位置比较合适的 comment_form_after_fields 作为hook点
4、admin/author不检查
需要在插件头部先: require( ABSPATH . WPINC . ‘/pluggable.php’ );
然后: if(!is_user_logged_in()) {add_filter( ‘preprocess_comment’, array( &$this, ‘preprocess_comment’ ) );}
暂无评论