wp_localize_community_events() WordPress Function

The wp_localize_community_events() function is used to display a list of upcoming community events in a sidebar widget. This function accepts two arguments: the first is the number of events to display, and the second is an array of arguments to customize the display. The function will return an array of event objects, each of which contains the following properties: - event_id: The event's post ID - event_title: The event's title - event_date: The event's date - event_time: The event's start time - event_end_time: The event's end time - event_location: The event's location - event_address: The event's address - event_description: The event's description You can use the following arguments to customize the display of the community events: - title: The widget's title (default: "Upcoming Community Events") - show_date: Whether to display the event's date (default: true) - show_time: Whether to display the event's start time (default: true) - show_end_time: Whether to display the event's end time (default: false) - show_location: Whether to display the event's location (default: true) - show_address: Whether to display the event's address (default: false) - show_description: Whether to display the event's description (default: false) You can use the following code to display the widget on your site: 'Upcoming Community Events', 'show_date' => true, 'show_time' => true, 'show_end_time' => false, 'show_location' => true, 'show_address' => false, 'show_description' => false, ) ); foreach ( $events as $event ) { // display event } }

wp_localize_community_events() #

Localizes community events data that needs to be passed to dashboard.js.


Source

File: wp-includes/script-loader.php

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   = isset( $saved_location['ip'] ) ? $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' ),
		)
	);
}


Top ↑

Changelog

Changelog
VersionDescription
4.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More