woogists
3/11/2018 - 3:55 PM

Sanitize data in WooCommerce

[Extending][Implementing the WC Integration Class] Sanitize data in WooCommerce

/**
 * Init and hook in the integration.
 */
public function __construct() {
	
    // do other constructor stuff first

	// Filters.
	add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array( $this, 'sanitize_settings' ) );

}

/**
 * Sanitize our settings
 */
public function sanitize_settings( $settings ) {
	// We're just going to make the api key all upper case characters since that's how our imaginary API works
	if ( isset( $settings ) &&
	     isset( $settings['api_key'] ) ) {
		$settings['api_key'] = strtoupper( $settings['api_key'] );
	}
	return $settings;
}