@@ -42,10 +42,54 @@ class Stackable_Size_And_Spacing_Preset_Controls {
4242 * Initialize
4343 */
4444 function __construct () {
45+ add_action ( 'register_stackable_global_settings ' , array ( $ this , 'register_use_size_presets_by_default ' ) );
46+ add_action ( 'stackable_early_version_upgraded ' , array ( $ this , 'use_size_presets_by_default_set_default ' ), 10 , 2 );
47+ add_filter ( 'stackable_js_settings ' , array ( $ this , 'add_setting ' ) );
48+
4549 add_filter ( 'stackable_inline_styles_nodep ' , array ( $ this , 'add_preset_controls_styles ' ) );
4650 add_filter ( 'stackable_inline_editor_styles ' , array ( $ this , 'add_preset_controls_styles ' ) );
4751 }
4852
53+ // Register the setting for using presets by default
54+ function register_use_size_presets_by_default () {
55+ register_setting (
56+ 'stackable_global_settings ' ,
57+ 'stackable_use_size_presets_by_default ' ,
58+ array (
59+ 'type ' => 'boolean ' ,
60+ 'description ' => __ ( 'If enabled, range controls will be on preset mode by default ' , STACKABLE_I18N ),
61+ 'sanitize_callback ' => 'sanitize_text_field ' ,
62+ 'show_in_rest ' => true ,
63+ 'default ' => true ,
64+ )
65+ );
66+ }
67+
68+ /**
69+ * When upgrading to v3.16.0 and above, set option to false.
70+ * If new installation, set option to true.
71+ *
72+ * @since 3.16.0
73+ */
74+ public function use_size_presets_by_default_set_default ( $ old_version , $ new_version ) {
75+ if ( ! empty ( $ old_version ) && version_compare ( $ old_version , "3.16.0 " , "< " ) ) {
76+ if ( ! get_option ( 'stackable_use_size_presets_by_default ' ) ) {
77+ update_option ( 'stackable_use_size_presets_by_default ' , '' );
78+ }
79+ }
80+ }
81+
82+ // Make the setting available in the editor
83+ public function add_setting ( $ settings ) {
84+ $ settings ['stackable_use_size_presets_by_default ' ] = get_option ( 'stackable_use_size_presets_by_default ' );
85+ return $ settings ;
86+ }
87+
88+ /**
89+ * Loads the different preset values.
90+ *
91+ * @return void
92+ */
4993 public function load_presets () {
5094 $ this ->custom_presets = get_option ( 'stackable_global_custom_preset_controls ' );
5195 $ this ->theme_presets = WP_Theme_JSON_Resolver::get_theme_data ()->get_settings ();
@@ -57,6 +101,12 @@ public static function sanitize_array_setting( $input ) {
57101 return ! is_array ( $ input ) ? array ( array () ) : $ input ;
58102 }
59103
104+ /**
105+ * Loads and decodes a JSON file, returning the settings array if available.
106+ *
107+ * @param string $json_path Absolute path to the JSON file.
108+ * @return array The settings array from the decoded JSON file, or an empty array.
109+ */
60110 private function load_json_file ( $ json_path ) {
61111 if ( file_exists ( $ json_path ) ) {
62112 $ decoded_data = wp_json_file_decode ( $ json_path , [
0 commit comments