/** function to check user's membership record while login and logout **/
function civi_member_sync_check()
{
    civicrm_wp_initialize();
    global $wpdb;
    global $current_user, $currentUserID, $currentUserEmail;
    //get username in post while login
    if (!empty($_POST['log'])) {
        $username = $_POST['log'];
        /*$userDetails   = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE user_login =%s", $username ) );
        		$currentUserID = $userDetails[0]->ID;*/
        $current_user = get_user_by('login', $username);
        $currentUserID = $current_user->ID;
        $currentUserEmail = $current_user->user_email;
        //getting current logged in user's role
        //$current_user_role = new WP_User( $currentUserID );
        $current_user_role = $current_user->roles[0];
        //getting user's civi contact id and checkmembership details
        if ($current_user_role != 'administrator') {
            require_once 'CRM/Core/Config.php';
            $config = CRM_Core_Config::singleton();
            require_once 'api/api.php';
            $params = array('version' => '3', 'page' => 'CiviCRM', 'q' => 'civicrm/ajax/rest', 'sequential' => '1', 'uf_name' => $currentUserEmail);
            $contactDetails = civicrm_api("UFMatch", "get", $params);
            $contactID = $contactDetails['values'][0]['contact_id'];
            if (!empty($contactID)) {
                $member = CrmSync::member_check($contactID, $currentUserID, $current_user_role);
            }
        }
    }
    return true;
}
</div>
<?php 
require_once 'civi.php';
require_once ABSPATH . 'wp-content/plugins/civicrm/civicrm/CRM/Core/BAO/UFMatch.php';
if (isset($_GET['action'])) {
    $status_message = '';
    if ($_GET['action'] == 'confirm') {
        $status_message = CrmSync::civi_member_sync();
    }
    ?>

	<?php 
    /* NEW FUNCTION: sync civicrm members into wordpress user list */
    //function import_civicrm_members_to_wordpress() {
    if ($_GET['action'] == 'import') {
        $status_message = CrmSync::import_civi_members_to_wordpress();
    }
    ?>

	<div class="updated below-h2">
		<span><p> <?php 
    echo $status_message;
    ?>
 </p></span>
	</div>
<?php 
}
?>


Esempio n. 3
0
        ?>
">Edit</a> | </span>
						<span class="delete"><a href="<?php 
        echo $delete_url;
        ?>
" class="submitdelete">Delete</a></span>
					</div>
				</td>
				<td><?php 
        echo $value->wp_role;
        ?>
</td>
				<td><?php 
        echo CrmSync::get_names_serialized($value->current_rule, CrmSync::getMembershipStatus());
        ?>
</td>
				<td><?php 
        echo CrmSync::get_names_serialized($value->expiry_rule, CrmSync::getMembershipStatus());
        ?>
</td>
				<td><?php 
        echo $value->expire_wp_role;
        ?>
</td>
			</tr>
		<?php 
    }
}
?>
	</tbody>
</table>  
</option>
							<?php 
}
?>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row">
						<label for="user_login">
							Current Status *
						</label>
					</th>
					<td id="current-status-td">
						<?php 
foreach (CrmSync::getMembershipStatus() as $key => $value) {
    ?>
							<input type="checkbox"
							       name=<?php 
    echo "current[{$key}]";
    ?>
 id =<?php 
    echo "current[{$key}]";
    ?>
  value=<?php 
    echo $key;
    if (!empty($current_rule)) {
        if (array_search($key, $current_rule)) {
            ?>
 checked="checked"  <?php 
        }