Making WordPress.org

Changeset 12823


Ignore:
Timestamp:
08/09/2023 07:29:59 PM (10 months ago)
Author:
coffee2code
Message:

Jobs plugin: Add missing 'id' attribute to input fields to associate them with their labels.

Also change to late-escape attributes and improve markup construction.

Props viralsampat, dd32, coffee2code.
Fixes #6695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/jobs.wordpress.net/public_html/wp-content/plugins/jobswp/jobswp-template.php

    r9455 r12823  
    128128 */
    129129function jobswp_text_field( $field_name, $field_label, $required = false, $type = 'text', $help_text = '' ) {
    130     $field_name  = esc_attr( $field_name );
    131     $field_label = esc_html( $field_label );
    132 
    133     echo '<div class="post-job-input post-job-input-' . $field_name . '">' . "\n";
    134     echo "<label for='$field_name'>$field_label" . ( $required ? '*' : '' ) . "</label>\n";
     130    echo '<div class="post-job-input post-job-input-' . esc_attr( $field_name ) . '">' . "\n";
     131    echo '<label for="' . esc_attr( $field_name ) . '">' . esc_html( $field_label ) . ( $required ? '*' : '' ) . "</label>\n";
    135132
    136133    $html5_input_types = array( 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'number',
     
    139136        $type = 'text';
    140137
    141     echo "<input type='$type' name='$field_name' class='" .
    142         ( $required ? jobswp_required_field_classes( $field_name ) : '' ) .
    143         "' " .
    144         jobswp_field_value( $field_name ) .
    145         ( $required ? ' required' : '' ) .
    146         " />\n";
     138    $classes = $required ? jobswp_required_field_classes( $field_name ) : '';
     139    printf(
     140        '<input type="%s" name="%s" id="%s" class="%s" %s%s />' . "\n",
     141        esc_attr( $type ),
     142        esc_attr( $field_name ),
     143        esc_attr( $field_name ),
     144        esc_attr( $classes ),
     145        jobswp_field_value( $field_name ),
     146        ( $required ? ' required' : '' )
     147    );
    147148
    148149    if ( $help_text ) {
Note: See TracChangeset for help on using the changeset viewer.