Skip to content

Instantly share code, notes, and snippets.

@89gsc
Created May 12, 2022 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 89gsc/faa7dde1c6ca55ab87791d44fd225824 to your computer and use it in GitHub Desktop.
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.
<?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