Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
60.00% |
3 / 5 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\PremiumAnalytics\configure_date_format | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| Automattic\Jetpack\PremiumAnalytics\inject_date_format_script_data | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The locale's default date format, for sites whose own format the dashboard cannot use. |
| 4 | * |
| 5 | * @package automattic/jetpack-premium-analytics |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\PremiumAnalytics; |
| 9 | |
| 10 | /** |
| 11 | * Configures the default date format script data. |
| 12 | * |
| 13 | * @since 0.18.0 |
| 14 | * |
| 15 | * @return void |
| 16 | */ |
| 17 | function configure_date_format() { |
| 18 | add_filter( 'jetpack_admin_js_script_data', __NAMESPACE__ . '\\inject_date_format_script_data', 20 ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Injects the locale's default date format into JetpackScriptData. |
| 23 | * |
| 24 | * The dashboard falls back to it when the site's format lacks a day, month or year. Sent from |
| 25 | * PHP because core's JavaScript translations do not include this string. |
| 26 | * |
| 27 | * @since 0.18.0 |
| 28 | * |
| 29 | * @param array $data The script data passed by the assets package. |
| 30 | * @return array |
| 31 | */ |
| 32 | function inject_date_format_script_data( array $data ): array { |
| 33 | if ( ! isset( $data['premium_analytics'] ) || ! is_array( $data['premium_analytics'] ) ) { |
| 34 | $data['premium_analytics'] = array(); |
| 35 | } |
| 36 | |
| 37 | // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core's own string, the default Settings › General offers. |
| 38 | $data['premium_analytics']['default_date_format'] = __( 'F j, Y' ); |
| 39 | |
| 40 | return $data; |
| 41 | } |