Making WordPress.org


Ignore:
Timestamp:
06/07/2017 07:19:43 PM (8 years ago)
Author:
coreymckrill
Message:

WordCamp Post Types: Fix sanitization of [speakers] params

In r5545 and r5546 some changes were made to the speakers shortcode
to enable a track and a groups parameter, both of which accept
a comma-separated list of term slugs. To sanitize these parameters,
the values went through an array map that trimmed whitespace. The
unintended side effect of this was that if the parameter wasn't
included in the shortcode, the sanitization would set the default value
to a non-empty array containing an empty string. This in turn caused
a tax_query parameter to be added to the WP_Query args, and the
shortcode would return an empty list for the speakers.

It turns out that trimming the whitespace isn't necessary for this case,
but removing empty array items is, so the array_map was swapped out
for array_filter. This seems to fix the empty speaker list issue, and
shortcodes using track or groups can include whitespace in their
comma-separated lists without a problem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    r5546 r5547  
    280280            'orderby'        => 'date',
    281281            'order'          => 'desc',
     282            'speaker_link'   => '',
    282283            'track'          => '',
    283             'speaker_link'   => '',
    284284            'groups'         => '',
    285285        ), $attr );
    286286
    287         foreach ( array( 'orderby', 'order', 'track', 'speaker_link' ) as $key_for_case_sensitive_value ) {
     287        foreach ( array( 'orderby', 'order', 'speaker_link' ) as $key_for_case_sensitive_value ) {
    288288            $attr[ $key_for_case_sensitive_value ] = strtolower( $attr[ $key_for_case_sensitive_value ] );
    289289        }
     
    293293        $attr['order']        = in_array( $attr['order'],        array( 'asc', 'desc'           ) ) ? $attr['order']        : 'desc';
    294294        $attr['speaker_link'] = in_array( $attr['speaker_link'], array( 'permalink'             ) ) ? $attr['speaker_link'] : '';
    295         $attr['track']        = array_map( 'trim', explode( ',', $attr['track'] ) );
    296         $attr['groups']       = array_map( 'trim', explode( ',', $attr['groups'] ) );
     295        $attr['track']        = array_filter( explode( ',', $attr['track'] ) );
     296        $attr['groups']       = array_filter( explode( ',', $attr['groups'] ) );
    297297
    298298        // Fetch all the relevant sessions
Note: See TracChangeset for help on using the changeset viewer.