Saving Authorize.net data to Gravity Forms entry object

I won’t get into all of the details of why I needed this functionality, but I was working on developing an online payment process using Gravity Forms and Authorize.net and the accounting office requested a very, very specific reporting format.

After developing a convoluted system using Google App Scripts to combine, archive, package, and delivery this data on a daily basis from multiple forms on multiple sites – the accounting office requested the CSV data also be merged with transaction data from Authorize.net. It would save them significant amounts of time. (Also, Google App Scripts are REALLY amazing for managing and automating documents and spreadsheets.)

Unfortunately Gravity Forms payment add-ons store payment data in a separate table and then simply call it when you view and entry in the dashboard, but it’s not accessible from the regular GFAPI entry object. Sigh.

So here’s what I came up with. Hopefully another poor soul may find it useful…

Upgrading WordPress installation to PHP7 (WHM, Easy Apache, CentOS)

After a couple of years of hearing how HHVM was dominating other installations in speed tests, I was please when earlier this year, PHP7 was finally release. Zend claimed similar (or even greater) speed gains. But the proof is in the pudding, yes?

So I set off to install and test PHP 7 on my own hosted VPS – which I recently upgraded to CentOS7 and Easy Apache 4. After months of waiting, the folks at cPanel finally released support…

PHP7 support

Unfortunately yum install ea-php70 only installs the most basic modules to the server. You’ll need to go through an find all of the modules built for PHP7 and Easy Apache. At the moment, the only method I know of identifying which modules are available is to view them through WMH (Home >> Software >> EasyApache 4). Then you can install them via command line like so… yum install ea-php70-php-gd.

Speed Increase

So here’s the before on a site running on PHP 5.6 no caching or CDN applied.

php56-saualumni

And here’s the after with the same site running PHP 7.0 with no additional configuration of any kind.

php70-saualumni

NOTE: I had to install ea-php70-php-pdo and ea-php70-php-mysqlnd to get MySQL to work with PHP7. mysql() is deprecated in PHP7 and any plugins that rely on it will throw errors as well.

That’s a full second off and and a 43% speed increase. Sweet!

Adding custom fields with multiple values to a WordPress post

The problem

I was working to create a system that allowed users to submit a Gravity Form entry with multiple file attachments that would create a post on the front end, printing those attachments. GF and the wonderful Gravity Forms + Custom Post Types plugin makes it easy to map a form field to a custom meta field (new or existing) – however I ran into a snag when trying to display multiple file uploads.  Simply echoing get_post_meta was just returning one of the meta field values, not each value.

Multiple custom field values with same key

The answer

Create a simple loop that stores each of the meta values to a variable, then loop through each echoing out the file links. This loop will need to be added to the post content either via theme template, filtering the_content(), and adding it onto a hook.  With this particular project using Genesis, I added it to the genesis_entry_content hook.

<?php $bulletin_files = get_post_meta( get_the_ID(), 'bulletin_file_upload' );
 if ( $bulletin_files ) : ?>
 <div><ul>
 <?php foreach( $bulletin_files as $url ) { ?>
 <li><a href="<?php echo $url; ?>">
 <?php echo basename($url ); ?>
 </a></li>
 <?php } ?>
 </ul></div>
 <?php endif; ?>

Custom fields looped

A really cool function used in the snippet above is basename(). It’s a simple php function that takes a string for a file path (in this case a url) and just grabs that filename at the end of the string.  Pretty cool and way simpler than some regex solution.