Skip to content

Commit

Permalink
better eme_isFloat function
Browse files Browse the repository at this point in the history
  • Loading branch information
liedekef committed Apr 18, 2024
1 parent f2e15a7 commit 0bf38ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eme-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ function eme_init_event_props( $props = [] ) {
}

// for sure integers
$numbers = [ 'create_wp_user', 'auto_approve', 'ignore_pending', 'email_only_once', 'person_only_once', 'invite_only', 'all_day', 'take_attendance', 'require_user_confirmation', 'captcha_only_logged_out', 'dyndata_all_fields', 'task_registered_users_only', 'task_requires_approval', 'task_allow_overlap', 'attendancerecord', 'waitinglist_seats' ];
$numbers = [ 'create_wp_user', 'auto_approve', 'ignore_pending', 'email_only_once', 'person_only_once', 'invite_only', 'all_day', 'take_attendance', 'require_user_confirmation', 'captcha_only_logged_out', 'dyndata_all_fields', 'task_registered_users_only', 'task_requires_approval', 'task_allow_overlap', 'attendancerecord', 'waitinglist_seats', 'check_free_waiting', 'ticket_template_id', 'skippaymentoptions' ];
foreach ( $numbers as $opt ) {
$props[$opt]=intval($props[$opt]);
}
// for integers or floats
$numbers = [ 'rsvp_end_number_days', 'rsvp_end_number_hours', 'rsvp_start_number_days', 'rsvp_start_number_hours', 'check_free_waiting', 'cancel_rsvp_days', 'cancel_rsvp_age', 'attendance_begin', 'attendance_end', 'ticket_template_id', 'skippaymentoptions', 'task_reminder_days', 'rsvp_pending_reminder_days', 'rsvp_approved_reminder_days' ];
$numbers = [ 'rsvp_end_number_days', 'rsvp_end_number_hours', 'rsvp_start_number_days', 'rsvp_start_number_hours', 'cancel_rsvp_days', 'cancel_rsvp_age', 'attendance_begin', 'attendance_end', 'task_reminder_days', 'rsvp_pending_reminder_days', 'rsvp_approved_reminder_days' ];
foreach ( $numbers as $opt ) {
if (eme_isFloat($props[$opt])) {
$props[$opt]=floatval($props[$opt]);
Expand Down
3 changes: 3 additions & 0 deletions eme-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4014,6 +4014,9 @@ function eme_mkdir_with_index( $targetPath ) {
}

function eme_isFloat($amount ): bool {
// if not numeric, return false
if (!is_numeric($amount)) return false;
$amount +=0; // this converts strings to int or float
return is_float( $amount ) && intval( $amount ) != $amount;
}

Expand Down

0 comments on commit 0bf38ff

Please sign in to comment.