settings = Plugin::get_settings( 'debug' );
add_filter( 'adminease_settings_fields', [ $this, 'adminease_settings_fields' ] );
add_action( 'adminease_settings_saved', [ $this, 'adminease_settings_saved' ] );
}
/**
* Adds custom settings fields related to debugging to the Adminease security settings section.
*
* @param array $fields The original array of settings fields before modification.
*
* @return array The modified array of settings fields with added debugging options.
*/
public function adminease_settings_fields( array $fields ): array {
$fields['debug']['fields'][] = [
'type' => 'switch',
'id' => 'wp-debug',
'name' => 'adminease[debug][wp_debug]',
'value' => $this->settings['wp_debug'] ?? '',
'label_class' => 'adminease-switch',
'input_class' => 'form-control toggle-field',
'label' => __( 'WP Debug', 'adminease' ),
'description' => __( 'The WP_DEBUG setting in WordPress is used to turn on debugging mode. When enabled, it displays PHP errors, warnings, and notices directly on your site—helping developers and site owners identify problems during development or troubleshooting. It’s especially useful when plugins or themes aren’t working as expected. However, it should never be left on in a live site as it can expose sensitive information to visitors.', 'adminease' ),
'child_fields' => [
[
'type' => 'switch',
'id' => 'wp-debug-log',
'name' => 'adminease[debug][wp_debug_log]',
'value' => $this->settings['wp_debug_log'] ?? '',
'label_class' => 'adminease-switch',
'input_class' => 'form-control',
'wrapper_class' => 'form-group-child',
'label' => __( 'WP Debug Log', 'adminease' ),
'description' => __( 'Enable WP Debug Log.', 'adminease' ),
'attributes' => [
'data-parent' => 'wp-debug',
],
],
[
'type' => 'switch',
'id' => 'wp-debug-display',
'name' => 'adminease[debug][wp_debug_display]',
'value' => $this->settings['wp_debug_display'] ?? '',
'label_class' => 'adminease-switch',
'input_class' => 'form-control',
'wrapper_class' => 'form-group-child',
'label' => __( 'WP Debug Display', 'adminease' ),
'description' => __( 'Enable WP Debug Display.', 'adminease' ),
'attributes' => [
'data-parent' => 'wp-debug',
],
],
],
];
return $fields;
}
/**
* Saves the sanitized settings and updates WordPress configuration constants based on provided settings.
*
* @param array $sanitized_settings An array of sanitized settings which includes debug options such as 'wp_debug', 'wp_debug_log', and 'wp_debug_display'.
*
* @return void
*/
public function adminease_settings_saved( array $sanitized_settings ): void {
$file_handler = Plugin::$FileHandler;
$file_handler->stack_wp_config_constant( 'WP_DEBUG', (bool) $sanitized_settings['debug']['wp_debug'] );
$file_handler->stack_wp_config_constant( 'WP_DEBUG_LOG', (bool) $sanitized_settings['debug']['wp_debug_log'] );
$file_handler->stack_wp_config_constant( 'WP_DEBUG_DISPLAY', (bool) $sanitized_settings['debug']['wp_debug_display'] );
}
}