-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting-41757.php
More file actions
46 lines (38 loc) · 1.47 KB
/
Copy pathtesting-41757.php
File metadata and controls
46 lines (38 loc) · 1.47 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
<?php
/**
* Plugin Name: Testing 41757 Plugin
* Description: Tests the added_new_user_to_blog custom hook
* Version: 1.0
* Author: SirLouen <[email protected]>
*/
if (!defined('ABSPATH')) {
exit;
}
function test_added_new_user_to_blog($user_id, $password, $meta, $blog_id) {
// Test 1: Simple file logging
$log_file = WP_CONTENT_DIR . '/user-blog-additions.log';
$log_message = sprintf(
"[%s] User ID: %d was added to Blog ID: %d with role: %s and password %s\n",
date('Y-m-d H:i:s'),
$user_id,
$blog_id,
$meta['new_role'],
$password
);
file_put_contents($log_file, $log_message, FILE_APPEND);
// Test 2: We can update for example, user meta based on $blog_id
update_user_meta($user_id, 'date_added_to_blog_' . $blog_id, current_time('mysql'));
}
add_action('added_new_user_to_blog', 'test_added_new_user_to_blog', 10, 4);
// Test 3: Adding a special capability caled "access_premium_content"
// based on the fact that the user has registered in this specific network site
function assign_special_capability($user_id, $password, $meta, $blog_id) {
// For the test we are sticking with the second network site created with ID = 2
if ($blog_id == 2) {
switch_to_blog($blog_id);
$user = new WP_User($user_id);
$user->add_cap('access_premium_content');
restore_current_blog();
}
}
add_action('added_new_user_to_blog', 'assign_special_capability', 20, 4);