@@ -112,6 +112,9 @@ public function remove_scripts_and_styles(): void {
112112 }
113113
114114
115+ /**
116+ * @return void
117+ */
115118 private function check_troubleshooting_form_submission () {
116119 // Check if our form has been submitted
117120 if ( isset ( $ _POST ['troubleshooting_form_nonce ' ] ) ) {
@@ -132,6 +135,8 @@ private function check_troubleshooting_form_submission() {
132135 // Sanitize styles array
133136 if ( isset ( $ _POST ['styles ' ] ) && is_array ( $ _POST ['styles ' ] ) ) {
134137 $ sanitized_data ['styles ' ] = array_map ( 'sanitize_text_field ' , $ _POST ['styles ' ] );
138+ } else {
139+ $ sanitized_data ['styles ' ] = array (); // consider all styles unchecked if 'styles' is not submitted
135140 }
136141
137142 // Sanitize all_scripts array
@@ -142,24 +147,32 @@ private function check_troubleshooting_form_submission() {
142147 // Sanitize scripts array
143148 if ( isset ( $ _POST ['scripts ' ] ) && is_array ( $ _POST ['scripts ' ] ) ) {
144149 $ sanitized_data ['scripts ' ] = array_map ( 'sanitize_text_field ' , $ _POST ['scripts ' ] );
150+ } else {
151+ $ sanitized_data ['scripts ' ] = array (); // consider all scripts unchecked if 'scripts' is not submitted
145152 }
146153
147154 // Calculate unchecked styles and scripts
148- $ unchecked_styles = isset ( $ sanitized_data ['all_styles ' ], $ sanitized_data [ ' styles ' ] ) ? array_diff ( $ sanitized_data ['all_styles ' ], $ sanitized_data ['styles ' ] ) : array ();
149- $ unchecked_scripts = isset ( $ sanitized_data ['all_scripts ' ], $ sanitized_data [ ' scripts ' ] ) ? array_diff ( $ sanitized_data ['all_scripts ' ], $ sanitized_data ['scripts ' ] ) : array ();
155+ $ unchecked_styles = isset ( $ sanitized_data ['all_styles ' ] ) ? array_diff ( $ sanitized_data ['all_styles ' ], $ sanitized_data ['styles ' ] ) : array ();
156+ $ unchecked_scripts = isset ( $ sanitized_data ['all_scripts ' ] ) ? array_diff ( $ sanitized_data ['all_scripts ' ], $ sanitized_data ['scripts ' ] ) : array ();
150157
151158 // @TODO - the save settings function should allow saving by key
152159 $ settings = new Settings ();
153160 $ checkout_settings = $ settings ->get_checkout_settings ();
154- $ new_settings = array_replace_recursive (
161+ $ new_settings = array_merge (
155162 $ checkout_settings ,
156- array ( 'dequeue_style_handles ' => $ unchecked_styles ),
157- array ( 'dequeue_script_handles ' => $ unchecked_scripts )
163+ array (
164+ 'dequeue_style_handles ' => $ unchecked_styles ,
165+ 'dequeue_script_handles ' => $ unchecked_scripts ,
166+ )
158167 );
159168 $ settings ->save_settings ( 'checkout ' , $ new_settings );
160169 }
161170 }
162171
172+
173+ /**
174+ * @return void
175+ */
163176 public function get_template (): void {
164177 if ( ! defined ( 'WOOCOMMERCE_CHECKOUT ' ) ) {
165178 define ( 'WOOCOMMERCE_CHECKOUT ' , true );
0 commit comments