返回介绍

wp_localize_community_events()

发布于 2017-09-11 12:22:59 字数 4048 浏览 969 评论 0 收藏 0

wp_localize_community_events()

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


description


源代码

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_option( $user_id, 'community-events-location', $saved_location, true );
	}

	$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(),

		'l10n' => array(
			'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ),
			'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ),
			'attend_event_near_generic' => __( 'Attend an upcoming event near you.' ),

			/*
			 * These specific examples were chosen to highlight the fact that a
			 * state is not needed, even for cities whose name is not unique.
			 * It would be too cumbersome to include that in the instructions
			 * to the user, so it's left as an implication.
			 */
			/* translators: %s is the name of the city we couldn't locate.
			 * Replace the examples with cities 相关函数 to your locale. Test that
			 * they match the expected location and have upcoming events before
			 * including them. If no cities 相关函数 to your locale have events,
			 * then use cities 相关函数 to your locale that would be recognizable
			 * to most users. Use only the city name itself, without any region
			 * or country. Use the endonym (native locale name) instead of the
			 * English name if possible.
			 */
			'could_not_locate_city' => __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),

			// This one is only used with wp.a11y.speak(), so it can/should be more brief.
			/* translators: %s is the name of a city. */
			'city_updated' => __( 'City updated. Listing events near %s.' ),
		)
	) );
}

更新日志

Versiondescription
4.8.0Introduced.

相关函数

Uses

  • wp-admin/includes/class-wp-community-events.php: WP_Community_Events::get_unsafe_client_ip()
  • wp-admin/includes/class-wp-community-events.php: WP_Community_Events::__construct()
  • wp-includes/l10n.php: __()
  • wp-includes/pluggable.php: wp_create_nonce()
  • wp-includes/functions.wp-scripts.php: wp_script_is()
  • wp-includes/functions.wp-scripts.php: wp_localize_script()
  • wp-includes/user.php: update_user_option()
  • wp-includes/user.php: get_current_user_id()
  • wp-includes/user.php: get_user_option()
  • Show 4 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文