Created
May 12, 2022 12:35
-
-
Save 89gsc/faa7dde1c6ca55ab87791d44fd225824 to your computer and use it in GitHub Desktop.
Formidable - edit success message, added method to add post ID as using global post object / wp_query all appear to fail. Attempted to validate post id from hidden input field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('frm_success_filter', 'add_the_download_form_button', 1000, 2); | |
function add_the_download_form_button($type, $form) | |
{ | |
// If this is the download form we can now check for a file. | |
if ($form->id == 4 | |
&& isset($_POST)) { | |
$pid = null; | |
//this relies on a hidden input set to post id with format of `pid:<post_id>` I have tried over 1 hour to get global post ID from within this filter and it simply wont work so fuck it. | |
foreach ($_POST['item_meta'] as $meta) { | |
if (strpos($meta, ':') === 3) { | |
$parts = explode(':', $meta); | |
if (count($parts) == 2 && $parts[0] === 'pid') { | |
$pid_tmp = (int)end($parts); | |
if (is_int($pid_tmp) && get_post($pid_tmp)) { | |
$pid = $pid_tmp; | |
break; | |
} | |
} | |
} | |
} | |
if (isset($pid) && !is_null($pid)) { | |
$file = get_field('case_study_file', $pid); | |
if ($file) { | |
$type = 'message'; | |
$form->options['success_msg'] .= '<a href="' . $file . '" target="_blank" class="button button--chevron">Download Now</a>'; | |
} | |
} | |
} | |
return $type; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment