-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Onload load Contact Form 7’s JavaScript if a form is present on the page.
- Loading branch information
1 parent
539ecea
commit 2b82b18
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
namespace WP_Rocket\ThirdParty\Plugins; | ||
|
||
use WP_Rocket\Event_Management\Subscriber_Interface; | ||
|
||
class ContactForm7 implements Subscriber_Interface { | ||
/** | ||
* Subscribed events. | ||
*/ | ||
public static function get_subscribed_events() { | ||
return [ | ||
'wp' => [ 'maybe_optimize_contact_form_7', 10 ], | ||
]; | ||
} | ||
|
||
/** | ||
* Optimize ContactForm7 scripts. | ||
* | ||
* @return array | ||
*/ | ||
public function maybe_optimize_contact_form_7() { | ||
if ( defined( 'WPCF7_LOAD_JS' ) && WPCF7_LOAD_JS && ! has_action( 'wpcf7_shortcode_callback' ) ) { | ||
// Only load the frontend scripts on the new 'wpcf7_shortcode_callback' hook. | ||
add_filter( 'wpcf7_load_js', '__return_false' ); | ||
add_action( 'wpcf7_shortcode_callback', 'wpcf7_enqueue_scripts' ); | ||
} | ||
} | ||
} |
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