PluginProbe
Gutenberg / 14.7.0
Gutenberg v14.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / compat / wordpress-6.1 / date-settings.php

date-settings.php in Gutenberg 14.7.0, at lib/compat/wordpress-6.1/date-settings.php

83 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Updates to the settings given to @wordpress/date.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Removes the call to wp.date.setSettings() added by Core and adds our own call
10 * to wp.date.setSettings().
11 *
12 * This lets us add a new l10n.dayOfWeek setting.
13 *
14 * To merge this into Core, simply update the wp.date.setSettings() call in
15 * wp_default_packages_inline_scripts.
16 *
17 * @param WP_Scripts $scripts WP_Scripts object.
18 */
19 function gutenberg_update_date_settings( $scripts ) {
20 global $wp_locale;
21
22 $inline_scripts = $scripts->get_data( 'wp-date', 'after' );
23 if ( $inline_scripts ) {
24 foreach ( $inline_scripts as $index => $inline_script ) {
25 if ( str_starts_with( $inline_script, 'wp.date.setSettings' ) ) {
26 unset( $scripts->registered['wp-date']->extra['after'][ $index ] );
27 }
28 }
29 }
30
31 // Calculate the timezone abbr (EDT, PST) if possible.
32 $timezone_string = get_option( 'timezone_string', 'UTC' );
33 $timezone_abbr = '';
34
35 if ( ! empty( $timezone_string ) ) {
36 $timezone_date = new DateTime( 'now', new DateTimeZone( $timezone_string ) );
37 $timezone_abbr = $timezone_date->format( 'T' );
38 }
39
40 $scripts->add_inline_script(
41 'wp-date',
42 sprintf(
43 'wp.date.setSettings( %s );',
44 wp_json_encode(
45 array(
46 'l10n' => array(
47 'locale' => get_user_locale(),
48 'months' => array_values( $wp_locale->month ),
49 'monthsShort' => array_values( $wp_locale->month_abbrev ),
50 'weekdays' => array_values( $wp_locale->weekday ),
51 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
52 'meridiem' => (object) $wp_locale->meridiem,
53 'relative' => array(
54 /* translators: %s: Duration. */
55 'future' => __( '%s from now', 'gutenberg' ),
56 /* translators: %s: Duration. */
57 'past' => __( '%s ago', 'gutenberg' ),
58 ),
59 'startOfWeek' => (int) get_option( 'start_of_week', 0 ),
60 ),
61 'formats' => array(
62 /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
63 'time' => get_option( 'time_format', __( 'g:i a', 'gutenberg' ) ),
64 /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
65 'date' => get_option( 'date_format', __( 'F j, Y', 'gutenberg' ) ),
66 /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
67 'datetime' => __( 'F j, Y g:i a', 'gutenberg' ),
68 /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
69 'datetimeAbbreviated' => __( 'M j, Y g:i a', 'gutenberg' ),
70 ),
71 'timezone' => array(
72 'offset' => get_option( 'gmt_offset', 0 ),
73 'string' => $timezone_string,
74 'abbr' => $timezone_abbr,
75 ),
76 )
77 )
78 ),
79 'after'
80 );
81 }
82 add_action( 'wp_default_scripts', 'gutenberg_update_date_settings' );
83