Making WordPress.org


Ignore:
Timestamp:
10/15/2013 07:28:34 PM (11 years ago)
Author:
iandunn
Message:

Post Types: Simulate track for [schedule] shortcode if none exist.

Previously the [schedule] shortcode assumed that tracks were created and that sessions were assigned to them, and wouldn't properly display sessions if no tracks existed. Now, if no tracks exist, the shortcode will simulate a generic one and show all sessions within it.

File:
1 edited

Legend:

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

    r54 r104  
    405405
    406406        // Use tracks to form the columns.
    407         foreach ( $tracks as $track )
    408             $columns[ $track->term_id ] = $track->term_id;
     407        if ( $tracks ) {
     408            foreach ( $tracks as $track )
     409                $columns[ $track->term_id ] = $track->term_id;
     410        } else {
     411            $columns[ 0 ] = 0;
     412        }
    409413
    410414        unset( $tracks );
     
    412416        // Loop through all sessions and assign them into the formatted
    413417        // $sessions array: $sessions[ $time ][ $track ] = $session_id
     418        // Use 0 as the track ID if no tracks exist
    414419
    415420        $sessions = array();
     
    422427                $sessions[ $time ] = array();
    423428
    424             if ( ! empty( $tracks ) )
     429            if ( empty( $tracks ) ) {
     430                $sessions[ $time ][ 0 ] = $session->ID;
     431            } else {
    425432                foreach ( $tracks as $track )
    426433                    $sessions[ $time ][ $track->term_id ] = $session->ID;
     434            }
    427435        }
    428436
     
    451459        foreach ( $columns as $term_id ) {
    452460            $track = get_term( $term_id, 'wcb_track' );
    453             $html .= sprintf( '<th class="wcpt-col-track"><span class="wcpt-track-name">%s</span> <span class="wcpt-track-description">%s</span></th>', esc_html( $track->name ), esc_html( $track->description ) );
     461            $html .= sprintf(
     462                '<th class="wcpt-col-track"> <span class="wcpt-track-name">%s</span> <span class="wcpt-track-description">%s</span> </th>',
     463                isset( $track->term_id ) ? esc_html( $track->name ) : '',
     464                isset( $track->term_id ) ? esc_html( $track->description ) : ''
     465            );
    454466        }
    455467
Note: See TracChangeset for help on using the changeset viewer.