It appears to have happened between version 3.9 and 3.9.1
Around line 212-215 (depending on version) in includes/functions.php inside the function wpcf7_format_attrs an empty check has been dropped:
if ( ” !== $value ) {
$html .= sprintf( ‘ %s=”%s”‘, $att, esc_attr( $value ) );
}
Is now simply:
$html .= sprintf( ‘ %s=”%s”‘, $att, esc_attr( $value ) );
hi,
I use your version 4.2.1. this is code you mention in includes/functions.php.
function wpcf7_format_atts( $atts ) {
$html = '';
$prioritized_atts = array( 'type', 'name', 'value' );
foreach ( $prioritized_atts as $att ) {
if ( isset( $atts[$att] ) ) {
$value = trim( $atts[$att] );
$html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
unset( $atts[$att] );
}
}
foreach ( $atts as $key => $value ) {
$key = strtolower( trim( $key ) );
if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $key ) ) {
continue;
}
$value = trim( $value );
if ( '' !== $value ) {
$html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) );
}
}
$html = trim( $html );
return $html;
}
But it still has error.
Yes, that’s exactly the point – the first foreach block has no empty-check:
if ( isset( $atts[$att] ) ) {
$value = trim( $atts[$att] );
$html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
unset( $atts[$att] );
}
should be:
if ( isset( $atts[$att] ) ) {
$value = trim( $atts[$att] );
if ($value !== '') {
$html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
}
unset( $atts[$att] );
}
…well actually I can’t say what it should be – but that would take care of the empty name attribute 🙂
Great find! Is there a way to include this fix without losing it in the next update? Any more word on the developer re-adding?
I gave a try and it doesn’t seem to solve the issue in 4.4.2 – did the update break this solution?