maximus87

Untitled

Jul 10th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: PDF After Submission
  4. Description: Opens a PDF in a new tab after a Gravity Form is submitted for the resource custom post type.
  5. Version: 1.0
  6. Author: Your Name
  7. */
  8.  
  9. // Hook to Gravity Form submission for form ID 25
  10. add_action('gform_after_submission_25', 'redirect_after_submission', 10, 2);
  11.  
  12. function redirect_after_submission($entry, $form) {
  13. // Get the PDF URL from ACF field
  14. $pdf_url = get_field('resource_target', $entry['post_id']);
  15.  
  16. // If PDF URL is valid
  17. if (!empty($pdf_url) && filter_var($pdf_url, FILTER_VALIDATE_URL) !== false) {
  18. // Define the custom thank you page URL
  19. $thank_you_url = home_url('/thank-you/');
  20. $redirect_url = add_query_arg('pdf_url', urlencode($pdf_url), $thank_you_url);
  21. wp_redirect($redirect_url);
  22. exit;
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment