Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions gp-inventory/gpi-disable-object-cache.php
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 );
Comment on lines +15 to +22
Copy link

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:

  1. Removing one of the filters based on your actual needs
  2. Uncommenting only the filter you want to use
  3. Adding a configuration option to choose between form-specific or global disabling
// 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' );
+// Uncomment the line below to disable caching for ALL forms instead of a specific form
+// add_filter( 'gpi_should_cache_object', '__return_false' );

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:

  • Removing or commenting out the global filter if you want to disable caching only for a specific form.
  • Removing or modifying the form-specific filter if you prefer to disable caching globally.
  • Introducing a configuration option to toggle between these two behaviors.
// 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' );
+ // Uncomment the line below to disable caching for ALL forms instead of a specific form
+ // add_filter( 'gpi_should_cache_object', '__return_false' );

🏁 Script executed:

#!/bin/bash
# Display the first 40 lines of the file to verify the presence of both filter hooks.
sed -n '1,40p' gp-inventory/gpi-disable-object-cache.php

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:

  • Remove or properly comment out the global filter if you only need form-specific caching control.
  • Remove or adjust the form-specific filter if you intend to disable caching globally.
  • Introduce a configuration option to toggle between the two behaviors.
// 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' );
+ // Uncomment the line below to disable caching for ALL forms instead of a specific form
+ // add_filter( 'gpi_should_cache_object', '__return_false' );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 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 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.
// Uncomment the line below to disable caching for ALL forms instead of a specific form
// add_filter( 'gpi_should_cache_object', '__return_false' );


// This snippet disables object caching for all forms.
add_filter( 'gpi_should_cache_object', '__return_false' );
Comment on lines +24 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// This snippet disables object caching for all forms.
add_filter( 'gpi_should_cache_object', '__return_false' );
// This snippet disables object caching for all forms.
// Uncomment the line below to disable caching for ALL forms
// add_filter( 'gpi_should_cache_object', '__return_false' );

Loading