diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 0f0058127f..922d2760b4 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -129,46 +129,6 @@ function wp_dashboard_setup() { do_action( 'do_meta_boxes', $screen->id, 'side', '' ); } -/** - * Gets the community events data that needs to be passed to dashboard.js. - * - * @since 4.8.0 - * - * @return array The script data. - */ -function wp_get_community_events_script_data() { - require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' ); - - $user_id = get_current_user_id(); - $user_location = get_user_option( 'community-events-location', $user_id ); - $events_client = new WP_Community_Events( $user_id, $user_location ); - - $script_data = 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 occured. Please try again.' ), - - /* - * 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 in your locale, but test that they match the expected location before including them. Use endonyms (native locale names) whenever 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.' ), - ) - ); - - return $script_data; -} - /** * Adds a new dashboard widget. * @@ -1170,24 +1130,22 @@ function wp_dashboard_events_news() { * @since 4.8.0 */ function wp_print_community_events_markup() { - $script_data = wp_get_community_events_script_data(); - ?>

- +

- +
-

@@ -1211,7 +1169,7 @@ function wp_print_community_events_markup() { - + @@ -1235,8 +1193,6 @@ function wp_print_community_events_markup() { * @since 4.8.0 */ function wp_print_community_events_templates() { - $script_data = wp_get_community_events_script_data(); - ?> diff --git a/src/wp-admin/index.php b/src/wp-admin/index.php index 76628abbd7..5c73f19008 100644 --- a/src/wp-admin/index.php +++ b/src/wp-admin/index.php @@ -15,7 +15,6 @@ require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); wp_dashboard_setup(); wp_enqueue_script( 'dashboard' ); -wp_localize_script( 'dashboard', 'communityEventsData', wp_get_community_events_script_data() ); if ( current_user_can( 'edit_theme_options' ) ) wp_enqueue_script( 'customize-loader' ); diff --git a/src/wp-admin/network/index.php b/src/wp-admin/network/index.php index 38acec4b6e..f4a1aa6423 100644 --- a/src/wp-admin/network/index.php +++ b/src/wp-admin/network/index.php @@ -54,7 +54,6 @@ get_current_screen()->set_help_sidebar( wp_dashboard_setup(); wp_enqueue_script( 'dashboard' ); -wp_localize_script( 'dashboard', 'communityEventsData', wp_get_community_events_script_data() ); wp_enqueue_script( 'plugin-install' ); add_thickbox(); diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 84ad9cf340..8f0237028d 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -434,6 +434,7 @@ add_action( 'set_current_user', 'kses_init' ); add_action( 'wp_default_scripts', 'wp_default_scripts' ); add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); +add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' ); add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 410ac51691..5dad398001 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1000,6 +1000,46 @@ function wp_localize_jquery_ui_datepicker() { wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" ); } +/** + * Localizes community events data that needs to be passed to dashboard.js. + * + * @since 4.8.0 + */ +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(); + $user_location = get_user_option( 'community-events-location', $user_id ); + $events_client = new WP_Community_Events( $user_id, $user_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.' ), + + /* + * 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 in your locale, but test that they match the expected location before including them. Use endonyms (native locale names) whenever 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.' ), + ) + ) ); +} + /** * Administration Screen CSS for changing the styles. *