-
Notifications
You must be signed in to change notification settings - Fork 3
/
manual_sync.php
executable file
·68 lines (58 loc) · 2.14 KB
/
manual_sync.php
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
<div id="icon-edit-pages" class="icon32"></div>
<div class="wrap">
<h2 id="add-new-user">Manual Synchronize</h2>
<?php if ( ! $_GET['action']) { ?>
<table class="form-table">
<td>
<span>Manual Synchronization:</span> <br/>
<?php $sync_confirm_url = get_bloginfo( 'url' ) . "/wp-admin/admin.php?&action=confirm&page=" . CIV_MEMB_SYNC_BASE . "manual_sync.php"; ?>
<input class="button-primary" type="submit"
value="Synchronize CiviMember Membership Types to WordPress Roles now"
onclick="window.location.href='<?php echo $sync_confirm_url; ?>'"/>
</td>
</tr>
</table>
</div>
<?php } ?>
<?php
if ( $_GET['action'] == 'confirm' ) {
$users = get_users();
require_once( 'civi.php' );
require_once 'CRM/Core/BAO/UFMatch.php';
foreach ( $users as $user ) {
$uid = $user->ID;
if ( empty( $uid ) ) {
continue;
}
$sql = "SELECT * FROM civicrm_uf_match WHERE uf_id =$uid";
$contact = CRM_Core_DAO::executeQuery( $sql );
if ( $contact->fetch() ) {
$cid = $contact->contact_id;
$memDetails = civicrm_api( "Membership", "get", array( 'version' => '3',
'page' => 'CiviCRM',
'q' => 'civicrm/ajax/rest',
'sequential' => '1',
'contact_id' => $cid
) );
if ( ! empty( $memDetails['values'] ) ) {
foreach ( $memDetails['values'] as $key => $value ) {
$memStatusID = $value['status_id'];
$membershipTypeID = $value['membership_type_id'];
}
}
$userData = get_userdata( $uid );
if ( ! empty( $userData ) ) {
$currentRole = $userData->roles[0];
}
//checking membership status and assign role
$check = member_check( $cid, $uid, $currentRole );
}
}
?>
<div id="message" class="updated below-h2">
<span><p> CiviMember Memberships and WordPress Roles have been
synchronized using available rules. Note: if no association
rules exist then synchronization has not been
completed.</p></span>
</div>
<?php } ?>