wp_localize_community_events()
- Since
- 4.8.0
- Source
wp-includes/script-loader.php:2056
Compatibility
- WordPress
- since 4.8.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.
Performance profile
How much work a call to wp_localize_community_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
- Moderate
- Scaling
- Constant
- Instructions
- 5–55
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 56.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below wp_localize_community_events() - cacheobject cache
wp_cache_get()one call below wp_localize_community_events() - serializeserialisation
maybe_unserialize()one call below wp_localize_community_events()
Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_localize_community_events() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!wp_script_is() | 5 | wp_script_is() |
wp_script_is() | 44–48 | wp_script_is(), get_current_user_id(), get_user_option(), ::WP_Community_Events(), wp_create_nonce(), ->get_cached_events(), get_option(), nonce() |
wp_script_is() && $current_ip_address !== false | 54–55 | wp_script_is(), get_current_user_id(), get_user_option(), ::WP_Community_Events(), update_user_meta(), wp_create_nonce(), ->get_cached_events(), get_option(), nonce() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 56 instructions, 5–55 executed per call, 5 branches. The work does not change between versions.
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 · 9
- wp_script_is()Determines whether a script has been added to the queue.
- get_current_user_id()Gets the current user's ID.
- get_user_option()Retrieves user option that can be either per Site or per Network.
- update_user_meta()Updates user meta field based on user ID.
- wp_localize_script()Localizes a script.
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- get_option()Retrieves an option value based on an option name.
- WP_Community_Events::get_unsafe_client_ip()Determines the user's actual IP address and attempts to partially anonymize an IP address by converting it to a network ID.
- WP_Community_Events::__construct()Constructor for WP_Community_Events.
Source code
function wp_localize_community_events() { if ( ! wp_script_is( 'dashboard' ) ) { return; } require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php'; $user_id = get_current_user_id(); $saved_location = get_user_option( 'community-events-location', $user_id ); $saved_ip_address = $saved_location['ip'] ?? false; $current_ip_address = WP_Community_Events::get_unsafe_client_ip(); /* * If the user's location is based on their IP address, then update their * location when their IP address changes. This allows them to see events * in their current city when travelling. Otherwise, they would always be * shown events in the city where they were when they first loaded the * Dashboard, which could have been months or years ago. */ if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) { $saved_location['ip'] = $current_ip_address; update_user_meta( $user_id, 'community-events-location', $saved_location ); } $events_client = new WP_Community_Events( $user_id, $saved_location ); wp_localize_script( 'dashboard', 'communityEventsData', array( 'nonce' => wp_create_nonce( 'community_events' ), 'cache' => $events_client->get_cached_events(), 'time_format' => get_option( 'time_format' ), ) );}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-includes/script-loader.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.