Tribe__Events__API::sanitize_event_post_create_update_args( array $args )
Sanitize the arguments array before sending to create/update an event post.
Contents
Use this prior to sending arguments to post create/update function.
See also
Parameters
- $args
-
(array) (Required) The arguments sent to create/update an event post.
Return
(array|WP_Error)
Source
File: src/Tribe/API.php
public static function sanitize_event_post_create_update_args( $args ) {
if (
! is_array( $args )
|| empty( $args['post_type'] )
|| Tribe__Events__Main::POSTTYPE !== $args['post_type']
) {
return $args;
}
// Sanitize if valid, or fail with WP_Error if invalid.
// Could enhance this with more comprehensive checks in the future.
// Process meridian fields before hour fields to determine if hours are to be in the 12-hour or 24-hour format.
if ( ! empty( $args['EventStartMeridian'] ) ) {
$args['EventStartMeridian'] = self::sanitize_meridian_meta_value( $args['EventStartMeridian'] );
}
if ( ! empty( $args['EventEndMeridian'] ) ) {
$args['EventEndMeridian'] = self::sanitize_meridian_meta_value( $args['EventEndMeridian'] );
}
// If meridian is set but we can pretty easily guess the hour is a valid 24-hour format, discard meridian in attempt to be smarter/flexible, thus setting "14pm" (invalid) to "14" (equivalent to 2pm).
// We take this approach instead of just minus `12` from the integer value of the hour because meridian may be set by defaults.
// Watch out for sending "12pm" or "12am" as the meridian (12-hour format) will take precedence if it exists.
if (
! empty( $args['EventStartMeridian'] )
&& absint( $args['EventStartHour'] ) > 12
&& absint( $args['EventStartHour'] ) < 24
) {
$args['EventStartMeridian'] = '';
}
if (
! empty( $args['EventEndMeridian'] )
&& absint( $args['EventEndHour'] ) > 12
&& absint( $args['EventEndHour'] ) < 24
) {
$args['EventEndMeridian'] = '';
}
// Now process all but the meridians
foreach ( $args as $key => &$value ) {
if ( 'EventStartHour' === $key ) {
$twelve_hour = ! empty( $args['EventStartMeridian'] );
$value = self::sanitize_hour_meta_value( $value, $twelve_hour );
} elseif ( 'EventEndHour' === $key ) {
$twelve_hour = ! empty( $args['EventEndMeridian'] );
$value = self::sanitize_hour_meta_value( $value, $twelve_hour );
} elseif (
'EventStartMinute' === $key
|| 'EventEndMinute' === $key
) {
$value = self::sanitize_minute_meta_value( $value );
}
if ( is_wp_error( $value ) ) {
return $value;
}
}
return $args;
}
Changelog
| Version | Description |
|---|---|
| 4.6.20 | Introduced. |