Tribe__Events__API::sanitize_meridian_meta_value( string $value, bool $empty_if_invalid = true )
Sanitize a string to be used as an event meridian post meta value: am|pm.
Contents
Use this prior to sending value to the database.
Parameters
- $value
-
(string) (Required) The post meta value to be checked, such as 'am'.
- $empty_if_invalid
-
(bool) (Optional) If true, set an invalid value to an empty string, else generate WP_Error.
Default value: true
Return
(string|WP_Error)
Source
File: src/Tribe/API.php
public static function sanitize_meridian_meta_value( $value, $empty_if_invalid = true ) {
// lower-case to match the `a` PHP date format used elsewhere
$new_value = strtolower( trim( $value ) );
$is_valid = 'am' === $new_value || 'pm' === $new_value;
$invalid_value = '';
if ( ! $empty_if_invalid ) {
$error_message = sprintf(
esc_html__( 'An event having a post meta value of `%s` meridian is not valid. Make sure it is either `am` or `pm`, or remove it entirely if using the 24-hour format.', 'the-events-calendar' ),
$value
);
$invalid_value = new WP_Error( 'invalid-tribe-events-meridian-meta-value', $error_message );
}
return $is_valid ? $new_value : $invalid_value;
}
Changelog
| Version | Description |
|---|---|
| 4.6.20 | Introduced. |