WordPress.org

Making WordPress.org


Ignore:
Timestamp:
05/18/2016 04:01:28 PM (4 years ago)
Author:
Otto42
Message:

Meetings Plugin: catch exception when invalid time string is entered. Fixes #meta1712.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-meeting-posttype/wporg-meeting-posttype.php

    r3032 r3173  
    116116        array_walk( $posts, function ( &$post ) {
    117117            if ( $post->recurring == 'weekly' || $post->recurring === '1' ) {
    118                 // from the start date, advance the week until it's past now
    119                 $start = new DateTime( $post->start_date.' '.$post->time.' GMT' );
    120                 $now = new DateTime();
    121                 $interval = $start->diff($now);
    122                 // add one to days to account for events that happened earlier today
    123                 $weekdiff = ceil( ($interval->days+1) / 7 );
    124                 $next = strtotime( "{$post->start_date} + {$weekdiff} weeks" );
    125                 $post->next_date = date('Y-m-d', $next);
     118                try {
     119                    // from the start date, advance the week until it's past now
     120                    $start = new DateTime( $post->start_date.' '.$post->time.' GMT' );
     121                    $now = new DateTime();
     122                    $interval = $start->diff($now);
     123                    // add one to days to account for events that happened earlier today
     124                    $weekdiff = ceil( ($interval->days+1) / 7 );
     125                    $next = strtotime( "{$post->start_date} + {$weekdiff} weeks" );
     126                    $post->next_date = date('Y-m-d', $next);
     127                } catch (Exception $e) {
     128                    // if the datetime is invalid, then set the post->next_date to the start date instead
     129                    $post->next_date = $post->start_date;
     130                }
    126131            } else if ( $post->recurring == 'monthly' ) {
    127                 // advance the start date 1 month at a time until it's past now
    128                 $start = new DateTime( $post->start_date.' '.$post->time.' GMT' );
    129                 $next = $start;
    130                 $now = new DateTime();
    131                 while ( $now > $next ) {
    132                     $next->modify('+1 month');
     132                try {
     133                    // advance the start date 1 month at a time until it's past now
     134                    $start = new DateTime( $post->start_date.' '.$post->time.' GMT' );
     135                    $next = $start;
     136                    $now = new DateTime();
     137                    while ( $now > $next ) {
     138                        $next->modify('+1 month');
     139                    }
     140                    $post->next_date = $next->format('Y-m-d');
     141                } catch (Exception $e) {
     142                    // if the datetime is invalid, then set the post->next_date to the start date instead
     143                    $post->next_date = $post->start_date;
    133144                }
    134                 $post->next_date = $next->format('Y-m-d');
    135145            }
    136146            else {
Note: See TracChangeset for help on using the changeset viewer.