Support

Home Forums Event Espresso Premium Exported CSV Fields – Fixing Lettering Format

Exported CSV Fields – Fixing Lettering Format

Posted: January 9, 2019 at 2:19 pm


gdtech

January 9, 2019 at 2:19 pm

I’d like to have the end-user type in all caps or at least upper case the first letter of their name fields, etc. I know I can accomplish this with some CSS magic but the problem is that I need the exported data dump csv file to reflect this and don’t want to have to fix this later in Excel. Is there any way to have the database accomplish this?


Tony

  • Support Staff

January 10, 2019 at 7:41 am

Hi there,

The quickest way to achieve this is to just change all of the strings to uppercase when exporting the CSV, that will leave all of the values however the user inputs them in EE but on export, you get the values in uppercase.

You can do that with a snippet like this:

https://gist.github.com/Pebblo/59af08753b201dbabd70a8b04217d783

You can add that to a custom functions plugin on your site, we have some documentation on creating one here:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/


gdtech

January 10, 2019 at 12:34 pm

That is great. I made some slight modifications and am very happy with this:

//Please do not include the opening PHP tag if you already have one.
function tw_ee_espresso_reg_report_filter_columns_ucwords( $csv_row){
	foreach($csv_row as $key => $value) {
		$csv_row[$key] = ucwords($value);
	}
	return $csv_row;
}
add_filter( 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ucwords', 999, 1);

However, can you specify the “Email Address” field to be lower case? If not, it’s ok. Thanks!


Tony

  • Support Staff

January 11, 2019 at 3:29 am

Just to note, in your opening post you have:

I’d like to have the end-user type in all caps or at least upper case the first letter of their name fields

All caps being preferred would use strtoupper(), first letter of each word can use ucwords().

Either is fine just noting for any other users.

However, can you specify the “Email Address” field to be lower case? If not, it’s ok. Thanks!

Sure, just check $key within the for each before running function:

if( $key !== 'Email Address' ) {
    $csv_row[$key] = ucwords($value);
}


gdtech

January 24, 2019 at 12:12 pm

Thanks, Tony!

With a little for manipulation, I got this to work just the way I needed. For anyone else looking, throw this into your theme’s function.php file:

//Manipulate CSV Export Dump
function tw_ee_espresso_reg_report_filter_columns_ucwords( $csv_row){
	foreach($csv_row as $key => $value) {
		$csv_row[$key] =
			$key == "Email Address"
			? strtolower($value)
			: ucwords($value);
	}
	
	return $csv_row;
}
add_filter( 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ucwords', 999, 1);


Tony

  • Support Staff

January 25, 2019 at 5:05 am

Great, I’m glad you got it working.

One change I would make is to NOT put this in my functions.php file but rather a custom functions plugin:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

There’s often debates on functions.php vs plugins (functions.php is essentially a plugin in the theme) but with functions like the above, which have absolutely nothing to do with the theme, your better to put that in a custom functions plugin along with any other functions like it.

The reason to do so is that if you ever change your theme, you now lose all of the functionality you placed in functions.php, which is fine for functions specific to the theme (which is what that file is for) but not when your changing functionality elsewhere as you then need to pick apart your functions to add to the new theme. Placing them in a functions plugin means even after switching themes everything you customized elsewhere continues to work as normal.

Most functions will work in functions.php just fine so if you want to leave it there that’s fine, but it’s not really what that file is intended for.

The support post ‘Exported CSV Fields – Fixing Lettering Format’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Tony 1 month, 3 weeks ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!