$tests Existing status tests. * @return array */ public function add_status_tests( array $tests ): array { if ( ! isset( $tests['direct'] ) || ! is_array( $tests['direct'] ) ) { $tests['direct'] = []; } $tests['direct']['webcalendar_timezone'] = [ 'label' => __( 'Calendar event times', 'agenticdaisy-calendar' ), 'test' => [ $this, 'timezone_status_test' ], ]; return $tests; } /** * Site Health test: flag a fixed-offset site timezone. * * A fixed offset cannot follow daylight saving time, and imported event * times are written to timezone-naive tables, so the error is permanent * once imported. See TimezoneCheck for the full rationale. * * @return array */ public function timezone_status_test(): array { $check = new TimezoneCheck(); $result = [ 'label' => __( 'Calendar event times follow daylight saving time', 'agenticdaisy-calendar' ), 'status' => 'good', 'badge' => [ 'label' => __( 'WebCalendar', 'agenticdaisy-calendar' ), 'color' => 'blue', ], 'description' => sprintf( '

%s

', esc_html( sprintf( /* translators: %s is a timezone name such as "America/New_York". */ __( 'Your site timezone is %s, which follows daylight saving time. Imported event times will be correct year-round.', 'agenticdaisy-calendar' ), $check->effective_label() ) ) ), 'actions' => '', 'test' => 'webcalendar_timezone', ]; if ( ! $check->is_fixed_offset() ) { return $result; } $result['status'] = 'recommended'; $result['label'] = __( 'Calendar event times cannot follow daylight saving time', 'agenticdaisy-calendar' ); $result['description'] = sprintf( '

%s

%s

', esc_html( sprintf( /* translators: %s is a UTC offset such as "UTC-5". */ __( 'Your site timezone is set to a fixed offset (%s) rather than a city. A fixed offset cannot follow daylight saving time, so if your region observes it, imported event times will be off by an hour for part of the year.', 'agenticdaisy-calendar' ), $check->offset_label() ) ), esc_html__( 'Event times are stored as local wall-clock at import, so correcting this afterwards will not repair events that have already been imported.', 'agenticdaisy-calendar' ) ); $result['actions'] = sprintf( '

%s

', esc_url( admin_url( 'options-general.php' ) ), esc_html__( 'Choose a city in General Settings', 'agenticdaisy-calendar' ) ); return $result; } /** * Add WebCalendar section to Site Health → Info. * * @param array $info Existing debug info sections. * @return array */ public function add_debug_info( array $info ): array { $info['webcalendar'] = [ 'label' => __( 'WebCalendar', 'agenticdaisy-calendar' ), 'fields' => $this->get_version_fields(), ]; return $info; } /** * Build the version fields array. * * @return array */ public function get_version_fields(): array { $fields = []; $fields['plugin-version'] = [ 'label' => __( 'Plugin version', 'agenticdaisy-calendar' ), 'value' => defined( 'WEBCALENDAR_WP_VERSION' ) ? WEBCALENDAR_WP_VERSION : __( 'Unknown', 'agenticdaisy-calendar' ), ]; $fields['core-version'] = [ 'label' => __( 'webcalendar-core', 'agenticdaisy-calendar' ), 'value' => self::get_package_version( 'craigk5n/webcalendar-core' ), ]; $fields['icalendar-version'] = [ 'label' => __( 'php-icalendar-core', 'agenticdaisy-calendar' ), 'value' => self::get_package_version( 'craigk5n/php-icalendar-core' ), ]; $fields['php-version'] = [ 'label' => __( 'PHP version', 'agenticdaisy-calendar' ), 'value' => PHP_VERSION, ]; // The zone imported event times are interpreted in — the first thing // to check when reported times are off by a whole hour. $fields['timezone'] = [ 'label' => __( 'Event timezone', 'agenticdaisy-calendar' ), 'value' => ( new TimezoneCheck() )->effective_label(), ]; return $fields; } /** * Get the installed version of a Composer package. * * @param string $package Package name (e.g. "craigk5n/webcalendar-core"). */ public static function get_package_version( string $package ): string { if ( ! class_exists( InstalledVersions::class ) ) { return __( 'Unknown', 'agenticdaisy-calendar' ); } if ( ! InstalledVersions::isInstalled( $package ) ) { return __( 'Not installed', 'agenticdaisy-calendar' ); } $version = InstalledVersions::getPrettyVersion( $package ); if ( $version === null ) { return __( 'Unknown', 'agenticdaisy-calendar' ); } // For dev-main, append the short commit ref for clarity. $ref = InstalledVersions::getReference( $package ); if ( str_starts_with( $version, 'dev-' ) && $ref !== null ) { return $version . ' (' . substr( $ref, 0, 7 ) . ')'; } return $version; } }