-
Notifications
You must be signed in to change notification settings - Fork 91
gpi-disable-object-cache.php
: Added new snippet to disable object cache in GP Inventory.
#1070
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||||||||
<?php | ||||||||||||
/** | ||||||||||||
* Gravity Perks // Inventory // Disable Object Cache | ||||||||||||
* https://gravitywiz.com/documentation/gravity-forms-inventory/ | ||||||||||||
* | ||||||||||||
* GP Inventory caches objects to improve performance. This snippet disables object caching for a specific form. | ||||||||||||
* | ||||||||||||
* Instructions: | ||||||||||||
* | ||||||||||||
* 1. Install the snippet. | ||||||||||||
* https://gravitywiz.com/documentation/managing-snippets/#where-do-i-put-snippets | ||||||||||||
*/ | ||||||||||||
|
||||||||||||
|
||||||||||||
// This snippet disables object caching for a specific form. | ||||||||||||
add_filter( 'gpi_should_cache_object', function ( $cache, $form_id ) { | ||||||||||||
if ( $form_id === 123 ) { // Update "123" to your form ID | ||||||||||||
return false; | ||||||||||||
} | ||||||||||||
|
||||||||||||
return $cache; | ||||||||||||
}, 10, 2 ); | ||||||||||||
|
||||||||||||
// This snippet disables object caching for all forms. | ||||||||||||
add_filter( 'gpi_should_cache_object', '__return_false' ); | ||||||||||||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global cache disabling will override the form-specific filter. This filter will disable object caching for all forms, making the previous form-specific filter (lines 15-22) redundant. Since this filter runs after the form-specific one (with the same priority), it will override any decisions made by the previous filter. If your intention is to provide both options, consider updating the documentation to make it clear that users should choose one approach or the other, not both simultaneously. // This snippet disables object caching for all forms.
-add_filter( 'gpi_should_cache_object', '__return_false' );
+// Uncomment the line below to disable caching for ALL forms
+// add_filter( 'gpi_should_cache_object', '__return_false' ); 📝 Committable suggestion
Suggested change
|
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.
💡 Verification agent
🧩 Analysis chain
Form-specific filter implementation looks good, but will be overridden.
The implementation to disable caching for a specific form is well-structured with appropriate comments. The code checks if the form ID matches a specific value and returns false to disable caching only for that form.
However, this filter will be completely overridden by the second filter that disables caching for all forms (line 25). Since both filters have the same priority and the second one will run last, this code will never actually execute as intended.
Consider either:
Action Required: Resolve Filter Conflict in Object Caching
The file currently defines a form-specific filter (for form ID 123) to disable object caching, but a second, global filter (which disables caching for all forms) follows shortly after. Since these filters share the same priority, the global filter will override the form-specific one when both are active.
Please confirm your intended behavior and update the code accordingly by either:
🏁 Script executed:
Length of output: 921
Action: Resolve Conflict in Object Cache Filter Hooks
We've confirmed that both filters are active in the file and, due to having equal priority, the global filter (disabling caching for all forms) overrides the form-specific filter. This means the form-specific disabling logic (for form ID 123) will never execute.
Please decide your intended behavior and update the code accordingly. Consider one of the following:
📝 Committable suggestion