The Zenbership environment is always available within a hook, so you have access to all Zenbership methods and classes. That allows you to easily load data from the Zenbership database as follows:

  • Learn more about the variables used in these examples

    • Note that since editing a member or contact runs the lifecycle of the program, doing this may trigger additional "Member Edited" or "Contact Edited" hooks, should they exist.

    Editing a Member Record

    In this example, we assume that you have created a custom field named has_triggered_event and want to update that field on the member/contact's record when this hook is run.

    <?php
    
    $member = new user();
    
    $changes_to_make = array(
        'has_triggered_event' => '1',
    );
    
    $member->edit_member($member_id, $changes_to_make);
    

    Editing a Contact Record

    <?php
    
    $contact = new contact();
    
    $changes_to_make = array(
        'has_triggered_event' => '1',
    );
    
    $contact->edit($member_id, $changes_to_make);
    

    Determining Whether a Member or Contact Triggered the Task

    <?php
    
    // A contact triggered the task.
    if ($member_type == "contact") {
    	$contact = new contact();
    	// $userData = $contact->get_contact($member_id);
    	// ...your code here.
    }
    
    // A member triggered the task.
    else if ($member_type == "member") {
    	$member = new user();
    	// $userData = $member->get_user($member_id);
    	// ...your code here.
    }
    
    // var_dump($userData);
    

  • Last modified 3 months ago.