Skip to content

Commit 1070f1c

Browse files
committed
Added "sv_wc_plugin_framework_use_dynamic_props_class" filter to make use of Dynamic_Props class opt-in only.
1 parent 14eb0db commit 1070f1c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

woocommerce/payment-gateway/Dynamic_Props.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ public static function unset( \WC_Order &$order, string $key ): void {
134134
}
135135
}
136136

137+
/**
138+
* Checks if Dynamic_Props class should be used based on the filter.
139+
*
140+
* @return bool True if Dynamic_Props class should be used, false otherwise.
141+
*/
142+
private static function use_dynamic_props_class(): bool {
143+
static $use_dynamic_props_class = null;
144+
if ( null === $use_dynamic_props_class ) {
145+
/**
146+
* Filters whether to use Dynamic_Props class for storing order data.
147+
*
148+
* @since x.x.x
149+
*
150+
* @var bool Whether to Dynamic_Props class for storing order data.
151+
*/
152+
$use_dynamic_props_class = apply_filters( 'sv_wc_plugin_framework_use_dynamic_props_class', false );
153+
}
154+
return $use_dynamic_props_class;
155+
}
156+
137157
/**
138158
* Checks if WeakMap should be used based on PHP version.
139159
*
@@ -147,7 +167,7 @@ private static function use_weak_map(): bool {
147167
static $use_weak_map = null;
148168

149169
if ( null === $use_weak_map ) {
150-
$use_weak_map = version_compare( PHP_VERSION, '8.0', '>=' ) && class_exists( '\WeakMap' );
170+
$use_weak_map = version_compare( PHP_VERSION, '8.0', '>=' ) && self::use_dynamic_props_class();
151171
}
152172

153173
return $use_weak_map;

0 commit comments

Comments
 (0)