Support

Home Forums Event Espresso Premium Include event author in the registrations csv download

Include event author in the registrations csv download

Posted: June 28, 2016 at 4:19 am

Viewing 16 reply threads


Oguzhan Altun

June 28, 2016 at 4:19 am

Hello,

Is there any possibility to include the event authors in the registrations csv download? I use that field to indicate the instructors for each training, and I use the csv for all the course reporting.. Therefore this feature would be very useful to me.


Josh

  • Support Staff

June 28, 2016 at 7:06 am

Yes, you can use the
FHEE__EE_Export__report_registrations__reg_csv_array
filter hook to add/remove columns to/from the CSV report.


Oguzhan Altun

June 28, 2016 at 7:07 am

thanks Josh. As you know, I’m not a developer, so what do I have to do exactly to enable this?


Josh

  • Support Staff

June 28, 2016 at 7:23 am

Usually the best thing to do is hire a developer if you need customizations done.


Oguzhan Altun

June 28, 2016 at 7:34 am

Is this a difficult customization? I don’t want to hire a developer who will take 4 hours to learn how EE4 works for a 5 minute customization πŸ™‚ Thanks for your perspective.


Josh

  • Support Staff

June 28, 2016 at 7:44 am

Using the filter isn’t terribly difficult because it was designed to allow for altering the array of data that gets passed to the CSV report generator.


Oguzhan Altun

June 29, 2016 at 2:31 am

is it possible to do it without touching the core EE4 files, so that I can continue to get the new versions?


Oguzhan Altun

June 29, 2016 at 2:32 am

if it is just a few lines of code, I would really appreciate your help here πŸ™‚


Josh

  • Support Staff

June 29, 2016 at 2:38 pm

Yes it’s possible (and recommended) to make this customization without touching the core files. There’s some example code that shows how to add a column that adds the venue to the CSV report in this gist. Maybe you can adapt the code to get the author of the event.


Oguzhan Altun

June 29, 2016 at 3:41 pm

thanks, that would help if I knew php, but unfortunately I have no idea how to modify this code to replace venue with author πŸ™


Josh

  • Support Staff

June 29, 2016 at 5:51 pm

Here are a few resources that will help you get the author name:

http://wordpress.stackexchange.com/a/191288

https://codex.wordpress.org/Function_Reference/get_userdata#Examples


Oguzhan Altun

July 1, 2016 at 6:08 am

I gave it a shot with my non existent PHP knowledge, could you check and correct if needed?


add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_author_to_report', 10, 2);
function espresso_add_author_to_report( $reg_csv_array, $reg_row ) {
	$event_id = $reg_row['Registration.EVT_ID'];
	$event = EEM_Event::instance()->get_one_by_ID( $event_id );
	if ( $event instanceof EE_Event ) {
		$post_author = get_post_field( 'post_author', $post_id );
		if ( $post_author instanceof EE_Post_Author ) {
			$post_author_name = !empty( $post_author ) ? $post_author->name() : '';
			$reg_csv_array['post_author'] = $post_author_name;
		}
	}
	return $reg_csv_array;
}


Josh

  • Support Staff

July 1, 2016 at 8:07 am

This needs to be corrected because the $post_id variable isn’t set:

$post_author = get_post_field( 'post_author', $post_id );

You do have the $event_id variable, which is equivalent. So instead:

$post_author = get_post_field( 'post_author', $event_id );

This conditional will likely do nothing since there’s no EE_Post_Author:

if ( $post_author instanceof EE_Post_Author ) {
			$post_author_name = !empty( $post_author ) ? $post_author->name() : '';
			$reg_csv_array['post_author'] = $post_author_name;
		}

So you remove that and replace with some code to get the author name. This is the part where you can use the examples from the above linked codex article. If you want the name to be displayed as Last Name, First Name; the code will look something like this:

$author_info = get_userdata( $post_author );
$reg_csv_array['Author'] = $author_info->last_name .  ", " . $author_info->first_name;


Oguzhan Altun

July 8, 2016 at 8:30 am

Ok thank you for your inputs. I have changed to code to the below, would that work?

add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_author_to_report', 10, 2);
function espresso_add_author_to_report( $reg_csv_array, $reg_row ) {
	$event_id = $reg_row['Registration.EVT_ID'];
	$event = EEM_Event::instance()->get_one_by_ID( $event_id );
	if ( $event instanceof EE_Event ) {
		$post_author = get_post_field( 'post_author', $event_id );
		$author_info = get_userdata( $post_author );
		$reg_csv_array['Author'] = $author_info->last_name .  ", " . $author_info->first_name;
	}
	return $reg_csv_array;
}


Josh

  • Support Staff

July 8, 2016 at 10:10 am

Of course!


Oguzhan Altun

July 10, 2016 at 7:44 am

That worked! Thanks:)

I’m also wondering if it’s possible to add the Event Tags to the download with a similar code?


Josh

  • Support Staff

July 11, 2016 at 10:33 am

It’d be different code, but you’d use the same
FHEE__EE_Export__report_registrations__reg_csv_array filter hook.

I can recommend looking through the code examples in the WordPress codex for the get_the_tags() function. That’s the function that gets the event’s tags.

https://codex.wordpress.org/Function_Reference/get_the_tags

Viewing 16 reply threads

The support post ‘Include event author in the registrations csv download’ 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