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!

The future of WordPress: JSON API and Javascript

So taking a cue from Matt Mullenweg’s State of the Word address, I’ve decided to make it my New Year’s resolution to learn more about Javascript frameworks – specifically those methods and frameworks that help us connect to the new WordPress JSON API.

As manager of a large multisite installation that shares A LOT of content from one site to another, I’ve had to rely upon hacks and workarounds using switch_to_blog(), rss feeds, and other slow and resource intensive means.  But with the new API, WordPress is developing into a true application framework, which will enable developers to pull content and pipe it into whatever framework or application they want.  This will invariable rely heavily on Javascript.

So, my first task is a simple one. Build a plugin that pulls a list of posts from another site on the network via API calls and shortcodes.  Of course there are plugins that do this on a multisite installation using switch_to_blog, but none that I can find at the moment that utilize the API – which is way faster. Ideally this shortcode will accept arguments for post type, category, and a few different display options.

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.

Custom document titles in WordPress 4.4, Genesis, and WP SEO

Adding the global site title to wp_title

As part of a massive WordPress multisite installation, I wanted to force rewrite the document titles of all pages globally on a custom Genesis theme. Genesis includes its own document title filter, all managed through the dashboard of each site. On my installation child site document titles were missing the name of the global parent site.  However, manually entering custom titles via WordPress SEO or Genesis SEO settings would have taken forever on . So my solution was just to add a filter to wp_title() and add the global title where needed. Here’s what I came up with:

/**
* Remove site specific Genesis SEO title settings and creates template for titles globally
*/

 //Stop Genesis from using the SEO settings from dashboard
remove_filter( 'wp_title', 'genesis_default_title', 10, 3 ); 

//Filter default wordpress title to append SAU where needed
function sau_wp_title( $title, $sep ) {
global $blog_id;
$global_details = get_blog_details( 1 );
$global_title = $global_details-&gt;blogname;
$sep = ' | '; 
	
if ( ($blog_id != 1) &amp;&amp; ( !is_home()) &amp;&amp; (!is_front_page() ) ) {
$title = "$title $sep $global_title";
} // end if
return $title;
} 

add_filter( 'wp_title', 'sau_wp_title', 10, 2 );

It worked great… until a week later when I upgraded WordPress to 4.4. The new release replaced wp_title with an entirely new method for theme and plugin developers to customize document titles.

Plugin authors can now check for theme support and have a few new filters available that will allow them to change or replace the title in a reliable way:

  • 'pre_get_document_title' short-circuits wp_get_document_title() if it returns anything other than an empty value.
  • 'document_title_separator' filters the separator between title parts.
  • 'document_title_parts' filters the parts that make up the document title, passed in an associative array.

WordPress 4.4 adds document title filters

Googling around, I found a post that explain these new filters at length and rewrote my snippet to rewrite ALL titles globally just to my liking. Note: I did not change the snippet below to work for any site, as the $tagline variable will need to be rewritten to pull from get_bloginfo.

add_filter('pre_get_document_title', 'sau_pre_get_document_title', 10);
function sau_pre_get_document_title(){
 global $blog_id;
 global $post;
 $blog_title = get_bloginfo();
 $page_title = get_the_title($post-&gt;ID);
 $sep = ' | '; 
 $global_details = get_blog_details( 1 );
 $global_title = $global_details-&gt;blogname;
 $tagline = 'Modern, Affordable, Competitive';

 if ( ($blog_id == 1) ) {
    if (is_home()) {
    $title = "$global_title $sep $tagline";
    return $title;
    }
 
else {
    $title = "$page_title $sep $global_title";
    return $title;
    }
}

if ( ($blog_id != 1) &amp;&amp; ( is_home()) || (is_front_page() ) ) {
    $title = "$blog_title $sep $global_title";
    return $title;
}

if ( ($blog_id != 1) &amp;&amp; ( !is_home()) &amp;&amp; (!is_front_page() ) ) {
   $title = "$page_title $sep $blog_title $sep $global_title";
   return $title;
}
 
else {
   return $title;
}
}

Removing Yoast WP SEO titles

For those that are using Yoast’s WP SEO and want to stop it from forcing itself upon your custom title set up, all you have to do is add the following to your code (renaming the function added to the filter as needed):

add_filter('wpseo_title', 'sau_pre_get_document_title', 15);