每当新用户在站点上注册时,我都会向表中添加数据。
add_action( \'user_register\', \'auto_follow_admin\', 10, 1 );
function auto_follow_admin() {
global $wpdb;
$wpdb->insert( \'wp_um_followers\', array(
\'time\' => current_time( \'mysql\' ),
\'user_id1\' => 1,
\'user_id2\' => $user_id
)
);
}
除了没有传递给查询的新$user\\u id之外,其他一切都正常。
运行后存储的数据如下所示:
time : 2015-08-27 14:08:32
user_id1 : 1
user_id2 :
是的
global $wpdb; 是否重置user\\u id?
最合适的回答,由SO网友:TheDeadMedic 整理而成
因为您需要为函数指定一个参数:
function auto_follow_admin( $user_id ) {
// Now you can use $user_id, which is passed to the function from the hook caller
}