-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add optimization for Contact Form 7 #6215
Add optimization for Contact Form 7 #6215
Conversation
Release v3.14.4
Release v3.14.4.1
Release v3.14.4.2
Release 3.15
Release v3.15.0.1
Onload load Contact Form 7’s JavaScript if a form is present on the page.
Release v3.15.2
…lugin * Use template_redirect action rather than wp to prevent accidental admin usage. * Add version check for CF7. * Add conditional enqueueing for styles in addition to scripts. * Override filters for wpcf7_load_js and wpcf7_load_css to return false. * Prevent re-enqueueing scripts after they have been enqueued.
6284813
to
6ece016
Compare
Note this PR incorporates optimizations from a standalone mini plugin. This was developed to fix rocklobster-in/contact-form-7#1278 in which scripts and styles for CF7 are enqueued on every page even when there is no contact form present. |
# Conflicts: # inc/ThirdParty/ServiceProvider.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working as expected and js/css isn't loaded now unless it's used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adamsilverstein , this is a great honor working with u on the same PR.
We will merge this PR but we need to revisit it to add tests and also change it a bit to have the callbacks registering inside the method get_subscribed_events
after adding the bailout conditions there and small code formatting concepts that we use here like bailout early.
But the PR itself is good and working perfectly.
Thanks everyone for the attention on this, great to see this merged! |
Only load Contact Form 7’s JavaScript if a form is present on the page.
Description
The Contact Form 7 ("CF7") specific optimization ensures that CF7 front end scripts are only enqueued when the page contains a contact form.
fixes #6241
Type of change
Is the solution different from the one proposed during the grooming?
Please describe in this section if there is any change to the groomed solution, and why.
Checklists
Generic development checklist
Test summary
If not, detail what you could not test.
Please describe any additional tests you performed.