admin管理员组文章数量:1391804
I am writing a media plugin that uses custom tables to store its contents. (eg not the post tables where wordpress stores it attachment data). Now i'm looking for a way to use the default wordpress comment system to add comments to it. (These comments will not be in the regular comment table but also a custom table.
I need two things:
- A hook that allows me to intercept the comment submit and process it with my own code if criteria are met. The criteria itself is arbitrary and not important, just need a way to get to the post data before Wordpress processes it.
- A filter that allows me to replace the wp_list_comments() data with my own tabledata.
It's a hacky idea, I know, but the post/attachment table is too limiting for what I need. Any ideas?
I am writing a media plugin that uses custom tables to store its contents. (eg not the post tables where wordpress stores it attachment data). Now i'm looking for a way to use the default wordpress comment system to add comments to it. (These comments will not be in the regular comment table but also a custom table.
I need two things:
- A hook that allows me to intercept the comment submit and process it with my own code if criteria are met. The criteria itself is arbitrary and not important, just need a way to get to the post data before Wordpress processes it.
- A filter that allows me to replace the wp_list_comments() data with my own tabledata.
It's a hacky idea, I know, but the post/attachment table is too limiting for what I need. Any ideas?
Share Improve this question edited May 6, 2011 at 13:23 Bainternet 67.7k8 gold badges132 silver badges188 bronze badges asked May 6, 2011 at 12:07 PatriekPatriek 4573 silver badges8 bronze badges2 Answers
Reset to default 3wp_list_comments()
has no filters or hooks so its going to be a bit hard, what you can do is use comments_array
filter hook
add_filter('comments_array','my_custom_comments_list');
function my_custom_comments_list($comments, $post_id){
//if criteria are met
//pull your comments from your own table
//in to an array and return it.
return $my_comments;
//else return $comments
}
and as for "intercept the comment submit and process" chips answer would be the best way using preprocess_comment
filter hook but you want be able to avoid WordPress form inserting the comment to the default table as well, so you can use wp_insert_comment
action hook to remove the comment from the default table right after its inserted:
add_action('wp_insert_comment','remove_comment_from_default_table');
function remove_comment_from_default_table( $id, $comment){
//if criteria are met
//and the comment was inserted in your own table
//remove it from the default table:
wp_delete_comment($id, $force_delete = true);
}
Try using the preprocess_comment
filter hook, e.g.
function my_handling_function( $comment_data ) {
// Here, do whatever you need to do with the comment
// modify it, pull data out of it to save somewhere
// or whatever you need to do
// just be sure to return $comment_data when you're done!
return $comment_data;
}
add_filter( 'preprocess_comment', 'my_handling_function' );
本文标签: pluginsIntercept comment form submitlist by hookfilter
版权声明:本文标题:plugins - Intercept comment form submitlist by hookfilter 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744762144a2623814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论