Skip to content

Commit e55102f

Browse files
committed
Use acf object, fix some version numbers
1 parent a139f6f commit e55102f

File tree

8 files changed

+55
-56
lines changed

8 files changed

+55
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jspm_packages/
4141
*.njsproj
4242
*.sln
4343
.cursorrules
44+
.cursorignore
4445

4546
# Assets build directory
4647
assets/build/**/*.css

assets/src/js/_acf-experiments.ts

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
11
/**
2-
* Experiments TypeScript
2+
* Admin experiments.
33
*
44
* @package Secure Custom Fields
5-
* @subpackage Admin
6-
* @since 6.4.2
5+
* @since 6.4.3
76
*/
87

98
// Define interfaces for our data structures
109
interface ExperimentsData {
1110
[key: string]: boolean; // Just store enabled status
1211
}
1312

14-
interface ScfExperiments {
15-
data: ExperimentsData;
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;
1623
}
1724

1825
// Declare global types
1926
declare global {
2027
interface Window {
21-
scfExperiments?: ScfExperiments;
22-
SCF?: {
23-
experiments?: {
24-
data: ExperimentsData;
25-
init: () => void;
26-
isEnabled: (name: string) => boolean;
27-
};
28-
};
28+
acf: ACF; // Ensure acf is available on window
29+
acfExperiments?: ExperimentsData; // Variable created by wp_localize_script
2930
}
31+
var acf: ACF;
32+
var acfExperiments: ExperimentsData | undefined; // Variable created by wp_localize_script
3033
}
3134

3235
// Create a module to avoid global scope augmentation issues
3336
export {};
3437

35-
// Initialize the SCF namespace if it doesn't exist
36-
if (typeof window.SCF === 'undefined') {
37-
window.SCF = {};
38-
}
39-
40-
// Initialize experiments module
41-
window.SCF.experiments = {
42-
data: {},
43-
init: function(): void {
44-
// Get experiments data from localized script
45-
this.data = window.scfExperiments ? window.scfExperiments.data : {};
46-
47-
// Log experiments data to console for debugging
48-
console.log('SCF Experiments initialized:', this.data);
49-
},
50-
isEnabled: function(name: string): boolean {
51-
return !!this.data[name];
38+
(function() {
39+
// End the function if acf doesn't exist
40+
if (typeof acf !== 'object' || acf === null) {
41+
return;
5242
}
53-
};
5443

55-
// Initialize when document is ready
56-
document.addEventListener('DOMContentLoaded', () => {
57-
if (window.SCF?.experiments) {
58-
window.SCF.experiments.init();
59-
}
60-
});
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+
});
6166

62-
// Log initial state
63-
console.log("SCF Experiments module loaded");
67+
})();

assets/src/js/acf-experiments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @package Secure Custom Fields
55
* @subpackage Admin
6-
* @since 6.4.2
6+
* @since 6.4.3
77
*/
88

99
// Import experiments module

includes/admin/admin-experiments.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* This file contains the admin experiments functionality for Secure Custom Fields.
66
*
77
* @package Secure Custom Fields
8-
* @subpackage Admin
9-
* @since 6.4.2
8+
* @since 6.4.3
109
*/
1110

1211
if ( ! defined( 'ABSPATH' ) ) {
@@ -126,10 +125,10 @@ public function load() {
126125
// load acf scripts
127126
acf_enqueue_scripts();
128127

129-
// Temporarily disabled. Uncomment to enable in production when ready.
128+
// Temporarily disabled - Uncomment to enable in production when ready.
130129
// acf_enqueue_script( 'acf-experiments' );
131130

132-
// Temporarily disabled. Localize experiments data. Uncomment to enable in production when ready.
131+
// Temporarily disabled - Localize experiments data. Uncomment to enable in production when ready.
133132
// $this->enqueue_experiments_script();
134133
}
135134

@@ -150,7 +149,7 @@ public function enqueue_experiments_script() {
150149
// Localize the script with experiments data
151150
wp_localize_script(
152151
'acf-experiments',
153-
'scfExperiments',
152+
'acfExperiments',
154153
array(
155154
'data' => $experiments_data,
156155
)

includes/admin/experiments/class-scf-admin-experiment-editor-sidebar.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* This experiment allows moving field group elements to the editor sidebar.
66
*
77
* @package Secure Custom Fields
8-
* @subpackage Admin
9-
* @since 6.4.2
8+
* @since 6.4.3
109
*/
1110

1211
if ( ! defined( 'ABSPATH' ) ) {
@@ -21,8 +20,7 @@
2120
* for a cleaner interface.
2221
*
2322
* @package Secure Custom Fields
24-
* @subpackage Admin
25-
* @since 6.4.2
23+
* @since 6.4.3
2624
*/
2725
class SCF_Admin_Experiment_Editor_Sidebar extends SCF_Admin_Experiment {
2826

includes/admin/experiments/class-scf-admin-experiment.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* This class serves as the base for all experiments in Secure Custom Fields.
66
*
77
* @package Secure Custom Fields
8-
* @subpackage Admin
9-
* @since 6.4.2
8+
* @since 6.4.3
109
*/
1110

1211
if ( ! defined( 'ABSPATH' ) ) {
@@ -21,8 +20,7 @@
2120
* for managing experiment settings and UI.
2221
*
2322
* @package Secure Custom Fields
24-
* @subpackage Admin
25-
* @since 6.4.2
23+
* @since 6.4.3
2624
*/
2725
class SCF_Admin_Experiment {
2826

includes/admin/views/experiments/experiments.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* Admin Experiments View
44
*
55
* @package Secure Custom Fields
6-
* @subpackage Admin
7-
* @since 6.4.2
6+
* @since 6.4.3
87
*/
98

109
if ( ! defined( 'ABSPATH' ) ) {

includes/assets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function register_scripts() {
193193
'handle' => 'acf-experiments',
194194
'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-experiments' ) ),
195195
'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-experiments' ) ),
196-
'deps' => array( 'jquery' ),
196+
'deps' => array( 'jquery', 'acf' ),
197197
'version' => $version,
198198
'in_footer' => true,
199199
),

0 commit comments

Comments
 (0)