1+ /**
2+ * Admin experiments.
3+ *
4+ * @package Secure Custom Fields
5+ * @since 6.4.3
6+ */
7+
8+ // Define interfaces for our data structures
9+ interface ExperimentsData {
10+ [ key : string ] : boolean ; // Just store enabled status
11+ }
12+
13+ // Define the experiments object structure
14+ interface ExperimentsObject {
15+ [ key : string ] : boolean | ( ( name : string ) => boolean ) ;
16+ isEnabled : ( name : string ) => boolean ;
17+ }
18+
19+ // Define a more complete ACF interface
20+ interface ACF {
21+ experiments ?: ExperimentsObject ;
22+ [ key : string ] : any ;
23+ }
24+
25+ // Declare global types
26+ declare global {
27+ interface Window {
28+ acf : ACF ; // Ensure acf is available on window
29+ acfExperiments ?: ExperimentsData ; // Variable created by wp_localize_script
30+ }
31+ var acf : ACF ;
32+ var acfExperiments : ExperimentsData | undefined ; // Variable created by wp_localize_script
33+ }
34+
35+ // Create a module to avoid global scope augmentation issues
36+ export { } ;
37+
38+ ( function ( ) {
39+ // End the function if acf doesn't exist
40+ if ( typeof acf !== 'object' || acf === null ) {
41+ return ;
42+ }
43+
44+ // Add experiments to acf object
45+ acf . experiments = {
46+ isEnabled : function ( name : string ) : boolean {
47+ return this . hasOwnProperty ( name ) && this [ name ] === true ;
48+ }
49+ } ;
50+
51+ // Initialize when document is ready
52+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
53+ if ( ! acf . experiments ) return ;
54+
55+ // Check if acfExperiments exists (created by wp_localize_script)
56+ if ( typeof acfExperiments === 'undefined' ) {
57+ return ;
58+ }
59+
60+ // Use the experiments data from wp_localize_script
61+ if ( acfExperiments && acfExperiments . data ) {
62+ // Copy all experiment flags directly to the experiments object
63+ Object . assign ( acf . experiments , acfExperiments . data ) ;
64+ }
65+ } ) ;
66+
67+ } ) ( ) ;
68+
0 commit comments