Hyphens ignored in additional setting names.
-
I have this in my additional settings field for a contact form:
skip-mail: 1
But calling to $form->additional_setting(‘skip-mail’) throws up nothing; and that’s because of a regular expression the plugin uses to split key/value pairs apart line-by-line (located within the definition of WPCF7_ContactForm’s “additional_setting” method:
if ( preg_match('/^([a-zA-Z0-9_]+)[\t ]*:(.*)$/', $setting, $matches ) ) {
Ideally that should be changed to:
if ( preg_match('/^([a-zA-Z0-9_-]+)[\t ]*:(.*)$/', $setting, $matches ) ) {
Or even better:
if ( preg_match('/^([^\n:]+):(.*)$/', $setting, $matches ) ) {
The above line would permit users to specify virtually any property name that isn’t necessarily “slug-friendly”:
- Don’t send to: [email protected]
- Another property (that’s still valid): Blah-blah-blah
PHP’s trim function can, of course, be used to clear any leading and trailing whitespace from the property’s name within the aforementioned conditional block. Which prevents properties like “Property Name :” from having to be read in PHP as “additional_setting(‘Property Name ‘);
- The topic ‘Hyphens ignored in additional setting names.’ is closed to new replies.