使用插件:
-
在插件激活时修改所有用户元
-
检查每个发布的评论,必要时进行更新
您必须使用每个函数中提供的用户ID来填补空白:
<?php
register_activation_hook( __FILE__, function()
{
if ( ! current_user_can( 'activate_plugins' ) )
return;
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
check_admin_referer( "activate-plugin_{$plugin}" );
foreach( get_users() as $user )
{
$user_comment_count = grab_custom_user_comments_count( $user->data->ID );
}
});
add_action( 'wp_insert_comment', function( $id, $comment_obj )
{
if( is_admin() || !is_user_logged_in() )
return;
global $user_ID;
get_currentuserinfo();
$user_comment_count = grab_custom_user_comments_count( $comment_obj->user_id );
}, 10, 2 );
这个
$comment_obj
已通过
wp_insert_comment
hook包含如下数组,您可以使用
get_post( $comment_obj->comment_post_ID )
获取有关当前帖子的信息。
stdClass Object
(
[comment_ID] => 36
[comment_post_ID] => 885
[comment_author] => nicename
[comment_author_email] => email@mail.com
[comment_author_url] =>
[comment_author_IP] => 127.0.0.1
[comment_date] => 2014-08-23 19:16:49
[comment_date_gmt] => 2014-08-23 17:16:49
[comment_content] => Lorem ipsum lorem
[comment_karma] => 0
[comment_approved] => 1
[comment_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 FirePHP/4Chrome
[comment_type] =>
[comment_parent] => 0
[user_id] => 1
)