Skip to content

Instantly share code, notes, and snippets.

@EvanHerman
Last active October 8, 2015 17:49
Show Gist options
  • Save EvanHerman/6ce76b12fef3a89f5e45 to your computer and use it in GitHub Desktop.
Save EvanHerman/6ce76b12fef3a89f5e45 to your computer and use it in GitHub Desktop.
After a form is successfully submitted, redirect the user to a download attached to the current page and assigned to an ACF (http://www.advancedcustomfields.com/) 'file' field.
<?php
/*
* Grab the contents of an ACF 'file' field, called attached_file, on the page the form was submitted on (ie: page with ID 15)
* and re-direct the user to that URL (to download the file) after a successful submission.
* @since 0.1
*/
function yikes_mailchimp_alter_redirect_url( $url, $form_id, $page_data ) {
// grab the ACF field -- returns an array
// (Example: Array ( [id] => 43 [alt] => [title] => 2002 [caption] => [description] => [mime_type] => file/zip [url] => http://www.example.com/file.zip ) )
$acf_field = get_field( 'attached_file', $page_data->ID );
// confirm that the acf field array is not empty, and the URL is set
if( isset( $acf_field) && ! empty( $acf_field ) ) {
// return the URL to the file
$url = esc_url( $acf_field['url'] );
}
return $url;
}
add_filter( 'yikes-mailchimp-redirect-url', 'yikes_mailchimp_alter_redirect_url', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment