diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 983e64c9..fb4481f6 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- TMS-1083: Change event short description to be used from API + ## [1.59.2] - 2024-11-19 - TMS-1088: Add fields to redipress schema diff --git a/lib/Eventz.php b/lib/Eventz.php index 59425c8f..8cf3736b 100644 --- a/lib/Eventz.php +++ b/lib/Eventz.php @@ -109,7 +109,7 @@ public static function normalize_event( $event ) : array { return [ 'name' => $event->name ?? null, - 'short_description' => static::get_short_description( $event ) ?? null, + 'short_description' => nl2br( $event->descriptionShort ) ?? null, 'description' => nl2br( $event->description ) ?? null, 'date_title' => __( 'Dates', 'tms-theme-base' ), 'date' => static::get_event_date( $event ), @@ -164,7 +164,7 @@ public static function normalize_event_title( $event ) : array { */ public static function normalize_event_description( $event ) : array { return [ - 'short_description' => static::get_short_description( $event ) ?? null, + 'short_description' => nl2br( $event->descriptionShort ) ?? null, ]; } @@ -607,26 +607,4 @@ public static function compare_dates( $start, $end ) { $end_time->format( 'H.i' ) ); } - - /** - * Generate short description. - * - * @param object $event Event object. - * - * @return string|null - */ - public static function get_short_description( $event ) { - - if ( empty( $event->description ) ) { - return null; - } - - // Define a regular expression pattern to match the first two sentences - $pattern = '/^(.*?[.!?])\s+(.*?[.!?])/'; - - // Use preg_match() to find the first two sentences - if ( preg_match( $pattern, $event->description, $matches ) ) { - return $matches[1] . ' ' . $matches[2]; - } - } }