Limit length of soft descriptor in front and backend

This commit is contained in:
carmenmaymo 2025-02-05 15:12:35 +01:00
parent 606c1e27c0
commit d7829b11d3
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E
3 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,19 @@
import ControlTextInput from './ControlTextInput';
const SoftDescriptorInput = ( { value, onChange, placeholder } ) => {
const handleChange = ( newValue ) => {
if ( newValue.length <= 22 ) {
onChange( newValue );
}
};
return (
<ControlTextInput
value={ value }
onChange={ handleChange }
placeholder={ placeholder }
/>
);
};
export default SoftDescriptorInput;

View file

@ -9,6 +9,7 @@ import {
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
import Accordion from '../../../../../ReusableComponents/AccordionSection';
import { SettingsHooks } from '../../../../../../data';
import SoftDescriptorInput from '../../../../../ReusableComponents/Controls/SoftdescriptorInput';
const PaypalSettings = () => {
const {
@ -91,7 +92,7 @@ const PaypalSettings = () => {
'woocommerce-paypal-payments'
) }
>
<ControlTextInput
<SoftDescriptorInput
value={ softDescriptor }
onChange={ setSoftDescriptor }
placeholder={ __(

View file

@ -139,7 +139,8 @@ class SettingsModel extends AbstractDataModel {
* @param string $descriptor The soft descriptor to set.
*/
public function set_soft_descriptor( string $descriptor ) : void {
$this->data['soft_descriptor'] = $this->sanitizer->sanitize_text( $descriptor );
$trimmed_descriptor = substr( $descriptor, 0, 22 );
$this->data['soft_descriptor'] = $this->sanitizer->sanitize_text( $trimmed_descriptor );
}
/**