• adventurequalifications

    (@adventurequalifications)


    Hi – I have started getting this showing on each page after. I assume it to do with snippetts – I am not a coder so have no idea what it is.

    Warning: date_format() expects parameter 1 to be DateTimeInterface, bool given in /home/customer/www/mysitecom/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()’d code on line 7

    Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    This is an issue in one of your snippets – you are using the date_format() function correctly on line 7 of the code.

    I can’t tell you exactly how to fix it without being able to see the code you’re using, but if you find it and post a copy here, I can see what I can do.

    Thread Starter adventurequalifications

    (@adventurequalifications)

    Thanx – the only two snippetts I have with date sin them are:

    add_filter(‘frm_validate_field_entry’, ‘set_my_expiration_date’, 10, 3);
    function set_my_expiration_date($errors, $posted_field, $posted_value){
    if ( $posted_field->id == 929 ) { //change 929 to the ID of the date field to change

    // Get the first date in a UNIX timestamp
    $first_date = date_create_from_format( ‘Y/m/d’, $_POST[‘item_meta’][892] ); //Change 892 to the ID of the first date field
    $first_date = date_format( $first_date, ‘Y-m-d’ );
    $first_date = strtotime( $first_date );

    // Get the final date in Y-m-d format
    $final_date = strtotime(‘+1095 day’, $first_date);
    $final_date = date(‘Y-m-d’, $final_date);

    // Save the final date as the posted value
    $_POST[‘item_meta’][$posted_field->id] = $final_date;

    }
    return $errors;
    }

    AND

    add_filter(‘frm_validate_field_entry’, ‘set_wm_expiration_date’, 10, 3);
    function set_wm_expiration_date($errors, $posted_field, $posted_value){
    if ( $posted_field->id == 4444 ) { //change 4444 to the ID of the date field to change

    // Get the first date in a UNIX timestamp
    $first_date = date_create_from_format( ‘Y/m/d’, $_POST[‘item_meta’][4443] ); //Change 4443 to the ID of the first date field
    $first_date = date_format( $first_date, ‘Y-m-d’ );
    $first_date = strtotime( $first_date );

    // Get the final date in Y-m-d format
    $final_date = strtotime(‘+1095 day’, $first_date);
    $final_date = date(‘Y-m-d’, $final_date);

    // Save the final date as the posted value
    $_POST[‘item_meta’][$posted_field->id] = $final_date;

    }
    return $errors;
    }

    Plugin Author Shea Bunge

    (@bungeshea)

    Which one of these has date_format on line 7 of the snippet? I can’t see the line numbers after you copy them.

    Thread Starter adventurequalifications

    (@adventurequalifications)

    Hi Shea – I do not see line numbers… See this screenshot.

    https://www.dropbox.com/s/my0mhkhldldil89/Annotation%202020-08-17%20181429.jpg?dl=0

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @adventurequalifications,

    If you do want line numbers, you can turn them on with the settings page.

    The problem here is that date_create_from_format can return false if the parse fails. You should add a check to determine whether $first_date is valid before using it for formatting,

    You can do this by adding this:

    if ( ! $first_date ) return;

    just above the $first_date = strtotime( $first_date ); line.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Error showing on page’ is closed to new replies.