Support

Home Forums Event Espresso Premium What Am I doing Wrong !!!

What Am I doing Wrong !!!

Posted: August 21, 2015 at 3:44 pm

Viewing 1 reply thread


David Anderson

August 21, 2015 at 3:44 pm

I followed
https://eventespresso.com/wiki/add-course-curriculum-events-using-advanced-custom-fields/
To come up with a function that adds a user to a UAM group However $registration->event()->ID(); does not work to return the id of the event I need the custom field of.

What am I missing to get the event registration information…..


  function addUAMrole($registration) {

		global $oUserAccessManager;
		$wp_uid = get_current_user_id();
		$userGroupId = get_field('groupid', $registration->event()->ID());
		if (isset($oUserAccessManager)) {
			$oUamAccessHandler = $oUserAccessManager->getAccessHandler();
		$uamUserGroup = $oUamAccessHandler->getUserGroups($userGroupId);
		if ($record_status == "Archived" OR $record_status == "Pending" OR $record_status == "Rejected") {
			$uamUserGroup->removeObject('user', $wp_uid);
		} else {
			$uamUserGroup->addObject('user', $wp_uid);
		}
		$uamUserGroup->save();
		}

}

add_action( 'AHEE__thank_you_page_registration_details_template__after_registration_details', 'addUAMrole', 10, 3 );


Tony

  • Support Staff

August 24, 2015 at 6:08 am

Hi David,

The hook you are currently using does not pass any variables to it, so $registration is actually nothing.

Your using:

add_action( 'AHEE__thank_you_page_registration_details_template__after_registration_details', 'addUAMrole', 10, 3 );

Which hooks into ‘AHEE__thank_you_page_registration_details_template__after_registration_details’ at prioirty 10 and specifies 3 arguments are accepted.

However that action is fired using:

do_action( 'AHEE__thank_you_page_registration_details_template__after_registration_details' );

Notice nothing is passed to the hook? That’s why $registration isn’t working within your function.

The code within the article you linked to uses ‘AHEE__thank_you_page_registration_details_template__after_registration_table_row’ hook which does pass the registration along, so change:

add_action( 'AHEE__thank_you_page_registration_details_template__after_registration_details', 'addUAMrole', 10, 3 );

To this:

add_action( 'AHEE__thank_you_page_registration_details_template__after_registration_table_row', 'addUAMrole', 10 );

That hook does pass the registration and then your code should work as expected 🙂

  • This reply was modified 9 years, 3 months ago by Tony. Reason: Fix formatting
Viewing 1 reply thread

The support post ‘What Am I doing Wrong !!!’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso