-
Notifications
You must be signed in to change notification settings - Fork 4
Description
In version 0.7.0, a new optimization was introduced to prevent unnecessary enqueuing of the JavaScript script and related assets, implemented in the following code block:
cf7-antispam/core/CF7_AntiSpam_Frontend.php
Lines 64 to 76 in 39e6f0c
| private function cf7_shortcode_exists() { | |
| global $post; | |
| return is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact-form-7' ); | |
| } | |
| public function load_scripts() { | |
| if ( ! $this->cf7_shortcode_exists() ) { | |
| return; | |
| } | |
| /* adds the javascript script to frontend */ | |
| add_action( 'wp_footer', array( $this, 'enqueue_scripts' ) ); | |
| } |
However, this optimization appears to fail in certain scenarios, specifically when the contact form is added programmatically (i.e., not directly through the editor/shortcode).
To address this compatibility issue, the script loading optimization should be made optional. This would allow users to manually enable or disable the feature, ensuring stability for non-standard implementations while maintaining the performance benefit for others.
Otherwise I need to check in other way whether the form is present on the page. (I used the code from the first example on this page https://developer.wordpress.org/reference/functions/has_shortcode/)