在WordPress多站点中创建博客后,更新当前用户的主要博客


Update current user's primary blog after creating a blog in wordpress multisite

我想将当前用户的主要博客更新为在wp-signup.php表单上注册博客后创建的博客。以便将当前用户的主博客设置为他创建的博客。

我试过这个,但它不起作用,

add_action('wpmu_new_blog','update_primary_blog',10);
function update_primary_blog() {
global $wpdb;
update_user_meta( get_current_user_id(), 'primary_blog', $wpdb->insert_id );
}

有没有其他方法可以做到这一点?

试试这个:

<?php
add_action('wpmu_new_blog','update_primary_blog',10, 1);
function update_primary_blog($blog_id) {
    update_user_meta( get_current_user_id(), 'primary_blog', $blog_id);
}

更多信息(和参数)在钩子上:
http://adambrown.info/p/wp_hooks/hook/wpmu_new_blog?version=3.3&file=wp-includes/ms-functions.php