studio-arrenberg / quartiersplattform

🏡 Repo für die Quartiersplattform
https://arrenberg.app
MIT License
2 stars 3 forks source link

If event_end_time < event_time it's not checked #143

Open Uatschitchun opened 2 years ago

Uatschitchun commented 2 years ago

There's a check in download_calendar.php:

if (empty($time_end) || strtotime($start) > strtotime($ende) ) {
    // one hour after start
    $ende = date('Ymd', strtotime($start) + (60*60)) . "T" . date('His', strtotime($start) + (60*60));
}

in single_veranstaltungen.php there isn't.

Screenshot_20220903_191649

Uatschitchun commented 1 year ago

ACF provides filters for this, so I tried to add a check to pages/form-veranstaltungen.php like:

function my_acf_validate_save_post( $valid, $post_id, $field ) {
    // Check if start time and end time fields exist
    if ( isset( $_POST['acf'][ 'field_1234567890abc' ] ) && isset( $_POST['acf'][ 'field_0987654321xyz' ] ) ) {
        // Get start time and end time values from $_POST
        $start_time = $_POST['acf'][ 'field_1234567890abc' ];
        $end_time = $_POST['acf'][ 'field_0987654321xyz' ];

        // Check if end time is smaller than start time
        if ( $end_time < $start_time ) {
            $valid = 'End time cannot be smaller than start time.';
        }
    }

    // Return validation result
    return $valid;
}
add_filter( 'acf/validate_save_post', 'my_acf_validate_save_post', 10, 3 );

or

function my_acf_validate_post( $valid, $post_id, $field ) {

    $start_time = strtotime(get_field('start_time'));
    $end_time = strtotime(get_field('end_time'));

    if ( $end_time <= $start_time ) {
        $valid = __('End time must be greater than start time', 'my_textdomain');
    }

    return $valid;
}

add_filter('acf/validate_post', 'my_acf_validate_post', 10, 3);

But couldn't get it to work as those seem to interfere with function cpt_save_worker in functions.php. Getting undefined variable $time and others in log and check isn't working.