55 * @since 6.4.3
66 */
77
8- // Define interfaces for our data structures
98interface 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-
9+ [ key : string ] : boolean ;
10+ }
11+
12+ interface ExperimentsObject {
13+ [ key : string ] : boolean | ( ( name : string ) => boolean ) ;
14+ isEnabled : ( name : string ) => boolean ;
15+ }
16+
17+ interface ACF {
18+ experiments ?: ExperimentsObject ;
19+ [ key : string ] : any ;
20+ }
21+
22+ declare global {
23+ interface Window {
24+ acf : ACF ;
25+ acfExperiments ?: ExperimentsData ; // Variable created by wp_localize_script in admin-experiments.php L150.
26+ }
27+ var acf : ACF ;
28+ var acfExperiments : ExperimentsData | undefined ;
29+ }
30+
31+ // Create a module to avoid global scope augmentation issues.
32+ export { } ;
33+
34+ ( function ( ) {
35+ if ( typeof acf !== 'object' || acf === null ) {
36+ return ;
37+ }
38+
39+ acf . experiments = {
40+ isEnabled : function ( name : string ) : boolean {
41+ return this . hasOwnProperty ( name ) && this [ name ] === true ;
42+ } ,
43+ } ;
44+
45+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
46+ if ( ! acf . experiments || typeof acfExperiments === 'undefined' ) {
47+ return ;
48+ }
49+
50+ if ( acfExperiments && acfExperiments . data ) {
51+ Object . assign ( acf . experiments , acfExperiments . data ) ;
52+ }
53+ } ) ;
54+ } ) ( ) ;
0 commit comments