Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If event_end_time < event_time it's not checked #143

Open
Uatschitchun opened this issue Sep 3, 2022 · 1 comment
Open

If event_end_time < event_time it's not checked #143

Uatschitchun opened this issue Sep 3, 2022 · 1 comment

Comments

@Uatschitchun
Copy link
Collaborator

Uatschitchun commented Sep 3, 2022

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
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant