multisite.php
3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if( !is_multisite() )
return;
class ACUI_Multisite{
var $sites;
function __construct(){
$this->sites = get_sites();
add_filter( 'acui_restricted_fields', array( $this, 'restricted_fields' ), 10, 1 );
add_action( 'acui_documentation_after_plugins_activated', array( $this, 'documentation' ) );
add_action( 'post_acui_import_single_user', array( $this, 'assign' ), 10, 4 );
add_filter( 'acui_email_apply_wildcards', array( $this, 'email_apply_wildcards' ), 10, 2 );
add_action( 'acui_email_wildcards_list_elements', array( $this, 'email_wildcards_list_elements' ) );
}
function restricted_fields( $acui_restricted_fields ){
return array_merge( $acui_restricted_fields, array( 'blogs' ) );
}
function documentation(){
?>
<tr valign="top">
<th scope="row"><?php _e( "Multisite is activated", 'import-users-from-csv-with-meta' ); ?></th>
<td><?php _e( "Plugin can assing users to blogs after importing them roles. This is how it works:", 'import-users-from-csv-with-meta' ); ?>
<ul style="list-style:disc outside none; margin-left:2em;">
<li><?php _e( "You have to <strong>create a column called 'blogs'</strong>: if cell is empty, it won't assign users to any blog; if cell has a value, it will be used. You have to fill it with blog_id", 'import-users-from-csv-with-meta' ); ?></li>
<li><?php _e( "Multiple blogs can be assigned creating <strong>a list of blog ids</strong> using commas to separate values.", 'import-users-from-csv-with-meta' ); ?></li>
</ul>
</td>
</tr>
<?php
}
function assign( $headers, $row, $user_id, $role ){
$pos = array_search( 'blogs', $headers );
if( $pos === FALSE )
return;
if( empty( $role ) )
$role = 'subscriber';
if( is_array( $role ) )
$role = reset( $role );
$user_blogs_csv = explode( ',', $row[ $pos ] );
$user_blogs_csv = array_filter( $user_blogs_csv, function( $value ){ return $value !== ''; } );
foreach ( $user_blogs_csv as $blog_id ) {
add_user_to_blog( $blog_id, $user_id, $role );
}
}
function email_apply_wildcards( $string, $args ){
foreach( $this->sites as $subsite ) {
$subsite_id = get_object_vars( $subsite )["blog_id"];
$passwordreseturl_subsite = get_site_url( $subsite_id, 'wp-login.php?action=rp&key=' . $args['key'] . '&login=' . rawurlencode( $args['user_login'] ), 'login' );
$string = str_replace( "**passwordreseturl_" . $subsite_id . "**", $passwordreseturl_subsite, $string );
}
return $string;
}
function email_wildcards_list_elements(){
?>
<?php _e( 'Multisite activated', 'import-users-from-csv-with-meta' ); ?>
<ul style="list-style-type:disc; margin-left:2em;">
<li>**passwordreseturl** = <?php _e( "It will work as follows: if there is only one site in the network, the URL will be that site's URL; if there is more than one site, it will lead to the login of the main site in the network of sites.", 'import-users-from-csv-with-meta' ); ?></li>
<li>**passwordreseturllink** = <?php _e( "same behaviour as above", 'import-users-from-csv-with-meta' ); ?></li>
<?php foreach( $this->sites as $subsite ): ?>
<li>**passwordreseturl_<?php echo get_object_vars( $subsite )["blog_id"]; ?>**: <?php _e( 'password reset url for the sub-site', 'import-users-from-csv-with-meta' ); ?> <?php echo get_object_vars( $subsite )["path"]; ?></li>
<?php endforeach; ?>
</ul>
<?php
}
}
new ACUI_Multisite();