这里有一个简短的、未经测试的插件,因为有更简单的方法可以获取可用/注册的博客,通常您不需要它们的公共API函数。此外,我认为他们使用的一些东西已经被弃用了。
插件
。。。正如我所说,它还没有经过测试,应该只是提供一个起点。你必须跳过它,看看什么有效,什么无效。然后添加你需要的内容。
<?php
defined( \'ABSPATH\' ) OR exit;
/**
* Plugin Name: (#84066) Register user to all sites upon registration
*/
add_action( \'plugins_loaded\', array( \'WPSE84077_register_everywhere\' ) );
class WPSE84077_register_everywhere
{
protected static $instance;
public static function init()
{
null === self :: $instance AND self :: $instance = new self;
return self :: $instance;
}
public function __construct()
{
add_action( \'wpmu_activate_user\', array( $this, \'add_roles\' ) );
add_action( \'wpmu_new_user\', array( $this, \'add_roles\' ) );
add_action( \'user_register\', array( $this, \'add_roles\' ) );
}
public function add_roles( $user_id )
{
global $wpdb;
$blogs = $wpdb->get_results( "
SELECT *
FROM {$wpdb->prefix}blogs
ORDER BY blog_id
" );
if ( empty( $blogs ) )
return;
foreach( $blogs as $key => $blog )
{
if ( is_user_member_of_blog( $user_id, $blog[ \'blog_id\' ] ) )
continue;
switch_to_blog( $blog[ \'blog_id\' ] );
// \'none\' role means that user registration won\'t happen on this blog
$role = get_option( \'default_role\', \'none\' );
$role !== \'none\' AND add_user_to_blog( $blog[ \'blog_id\' ], $user_id, $role );
restore_current_blog();
}
}
}
如果你想在这里接受帮助并做出回报,你会回来用你的工作解决方案更新我的答案。