Last active
October 27, 2021 14:59
-
-
Save spivurno/ac64e07e9ce83229d47843f1aaf6da2c to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Check If Form Will Be Loaded on Page
This file contains hidden or 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 | |
/** | |
* Gravity Wiz // Gravity Forms // Check If Form Will Be Loaded on Page | |
* http://gravitywiz.com/ | |
* | |
* This snippet will allow you to check if a form will be loaded on the current page and do something if it will be. | |
* Note: this is a simple version that will only work on singular views where the [gravityforms] shortcode is used in | |
* the post content. | |
* | |
* @todo: | |
* + Update to parse all posts on a given page. See: GFFormDisplay::enqueue_scripts(). | |
*/ | |
add_filter( 'wp', function() { | |
if ( ! class_exists( 'GFCommon' ) || ! is_singular() ) { | |
return; | |
} | |
require_once( GFCommon::get_base_path() . '/form_display.php' ); | |
GFFormDisplay::parse_forms( get_queried_object()->post_content, $forms, $blocks ); | |
foreach( $forms as $form ) { | |
// Update "123" to your target form ID. | |
if ( $form['id'] == 123 ) { | |
// Form 123 will be loaded. Do what you need to do here. | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-check-if-form-will-be-loaded.php