wppaste
WordPress

WP_Community_Events::trim_events( array $events ): array

Since
4.8.0, 4.9.7, 5.5.2, 6.0.0
Source
wp-admin/includes/class-wp-community-events.php:466
Prepares the event list for presentation.

Description

Discards expired events, and makes WordCamps "sticky." Attendees need more advanced notice about WordCamps than they do for meetups, so camps should appear in the list sooner. If a WordCamp is coming up, the API will "stick" it in the response, even if it wouldn't otherwise appear. When that happens, the event will be at the end of the list, and will need to be moved into a higher position, so that it doesn't get trimmed off.

Compatibility

WordPress
since 6.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$eventsarray
The events that will be prepared.

Return value

array
The response body with events trimmed.

Performance profile

How much work a call to WP_Community_Events::trim_events() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
4

Executed per call on PHP 8.5. The body compiles to 62.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Community_Events::trim_events() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always4none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6245
8.56245
8.462453 fewer instructions than PHP 8.3
8.36545
8.26545
8.165454 more instructions than PHP 7.4
7.46127–425

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 1

  • wp_list_pluck()Plucks a certain field out of each object or array in an array.

Used by · 2

Source code

	protected function trim_events( array $events ) {		$future_events = array(); 		foreach ( $events as $event ) {			/*			 * The API's `date` and `end_date` fields are in the _event's_ local timezone, but UTC is needed so			 * it can be converted to the _user's_ local time.			 */			$end_time = (int) $event['end_unix_timestamp']; 			if ( time() < $end_time ) {				// Decode HTML entities from the event title.				$event['title'] = html_entity_decode( $event['title'], ENT_QUOTES, 'UTF-8' ); 				array_push( $future_events, $event );			}		} 		$future_wordcamps = array_filter(			$future_events,			static function ( $wordcamp ) {				return 'wordcamp' === $wordcamp['type'];			}		); 		$future_wordcamps    = array_values( $future_wordcamps ); // Remove gaps in indices.		$trimmed_events      = array_slice( $future_events, 0, 3 );		$trimmed_event_types = wp_list_pluck( $trimmed_events, 'type' ); 		// Make sure the soonest upcoming WordCamp is pinned in the list.		if ( $future_wordcamps && ! in_array( 'wordcamp', $trimmed_event_types, true ) ) {			array_pop( $trimmed_events );			array_push( $trimmed_events, $future_wordcamps[0] );		} 		return $trimmed_events;	}

Changelog

Introduced in 4.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.0.0
Decode HTML entities from the event title.from the docblock
5.5.2
Accepts and returns only the events, rather than an entire HTTP response.from the docblock
4.9.7
Stick a WordCamp to the final list.from the docblock
4.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-admin/includes/class-wp-community-events.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.