HS Min/Max Quantities · Development version 0.12.0
Developer reference: rule-change hook
React to a saved rule collection without depending on internal storage. This is a development contract introduced in 0.12.0.
The public Min/Max event
do_action( 'hs_minmax_rules_changed', $current, $previous, $site_id );| Argument | Type | Meaning |
|---|---|---|
$current | array | Persisted normalized rules, keyed by local rule ID. |
$previous | array | The previous readable rule collection. |
$site_id | int | Current WordPress site ID. |
This is an action, not a filter. Callback return values are ignored. Changing the argument arrays does not edit stored rules.
Example: invalidate your own cache
Create wp-content/plugins/myshop-minmax-cache/myshop-minmax-cache.php on a test site, paste the following complete file and activate it from Plugins. Keep custom integrations in their own plugin so updates do not overwrite them. This example only clears a cache that your own code would populate; it creates no visible storefront feature.
<?php
/**
* Plugin Name: My Store Min/Max Cache Integration
* Description: Invalidates a local derived cache after Min/Max rule changes.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action(
'hs_minmax_rules_changed',
static function ( array $current, array $previous, int $site_id ): void {
delete_transient( 'myshop_minmax_summary' );
},
10,
3
);
The final 3 tells WordPress to pass all three action arguments. The callback is registered even if Min/Max is inactive, but cannot run until the plugin emits the event. Deactivate the integration to stop invalidation.
When the event fires
- After a changed collection is persisted: save, enable/disable, duplicate, delete, committed bulk operations or append.
- Not for unchanged or rejected writes.
- Not for direct option writes, backup restoration or changes to global messages alone.
Execution rules
Callbacks run synchronously while the configuration lock is held. Keep them short. Do not change rules recursively, throw exceptions or make slow remote requests. This event is not confirmation that an entire HTTP request or import workflow completed. Prefer invalidating derived state and rebuilding it on the next read.
Detect multiple changes
Do not assume the event concerns one rule. Compare keys for additions/removals and compare each shared key’s values for edits. Treat rule names and messages as untrusted text and escape them when rendering. Avoid relying on undocumented array fields as a stable CRUD interface.
Legacy hook and Core boundary
plab_minmax_rules_changed fires after the new action with the same payload. Subscribe to one name only, otherwise your integration runs twice. New code should use hs_minmax_rules_changed.
hs_core_ai_providers belongs to the internal Core V1 provider contract; it is not a public shop-rule customization API. This version does not provide a documented general REST CRUD API or a public filter for replacing effective limits. Registered WordPress/WooCommerce callbacks inside the plugin are not extra Min/Max extension points.
Verify the integration
- On a test store, populate
myshop_minmax_summarywith your own cache value. - Save a changed inactive test rule; the transient should be absent afterwards.
- Repopulate it and save unchanged values; the event should not invalidate it.
- Test a bulk change too. Restore your test rules and remove test data.
Reference checked against RuleStore::write(). The source observer tests cover persistence timing and successful, unchanged and rejected mutations. This does not certify third-party callbacks.