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:462
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
- Scaling
- Constant
- Instructions
- 4
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 62.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 62 | 4 | 5 | |
| 8.5 | 62 | 4 | 5 | |
| 8.4 | 62 | 4 | 5 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 65 | 4 | 5 | |
| 8.2 | 65 | 4 | 5 | |
| 8.1 | 65 | 4 | 5 | 4 more instructions than PHP 7.4 |
| 7.4 | 61 | 27–42 | 5 |
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
- WP_Community_Events::get_cached_events()Gets cached events.
- WP_Community_Events::get_events()Gets data about events near a particular location.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.