Skip Navigation

[Resolved] Error when updating Snippets: It throws an error for the sample code

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 3 voices.

Last updated by hui-suanC 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1142173
Screenshot 2018-11-07 at 7.57.27 PM.png

I am trying to:

Use the CRED API.
I tried putting in this:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
        if (isset($_POST['my_custom_field']))
        {
            // add it to saved post meta
            add_post_meta($post_id, '__my_custom_field', $_POST['my_custom_field'], true);
        }
    }
}

And separately, this:


//Calculate the difference from a start date and end date sent after the CRED form submission.
add_action('cred_save_data', 'calculate_days_func',10,2);
function calculate_days_func($post_id, $form_data) {
    if ($form_data["id"]==1160 || $form_data["id"]==1184)
    {
        if(isset($_POST['wpcf-start-date']['datepicker'])){
            $start_date = new DateTime(date('Y-m-d', $_POST['wpcf-start-date']['datepicker']));
        }
        if(isset($_POST['wpcf-end-date']['datepicker'])){
            $end_date = new DateTime(date('Y-m-d', $_POST['wpcf-end-date']['datepicker']));
        }
        $datediff = $start_date->diff($end_date);
        update_post_meta($post_id, 'wpcf-duration', $datediff->days + 1);
    }
}

into custom code on toolset settings but it refuses to accept it (There was an error when updating snippets.)

Is there something wrong with the code? Or the validation?

#1142217

This does not happen locally with those snippets. I can save them just fine.

Please delete the snippet and create a new one, if that does not work, please send us a copy of that site, after making sure that this is still happening with just Toolset and a native WordPress Theme like Twenty Seventeen.
We can then have a look at the issue from closer.

Thank you

#1142529

Hi, I don't see anything obviously wrong here. I'm able to edit these snippets without any problem...
1. Can you try disabling all caching systems temporarily, including drop-ins and mu-plugins?
2. Which snippet are you trying to edit when you see the error?
3. I can see several PHP parse errors in error_log.txt related to assignment_create_validation.php, have those been resolved?

#1142939

1. Can you try disabling all caching systems temporarily, including drop-ins and mu-plugins?
2. Which snippet are you trying to edit when you see the error?
3. I can see several PHP parse errors in error_log.txt related to assignment_create_validation.php, have those been resolved?

I found this and then disabled endurance cache:
[08-Nov-2018 09:15:11 UTC] PHP Fatal error: Call to undefined function is_user_logged_in() in /home/awesomep/public_html/swipeducation.com/wp-content/mu-plugins/endurance-page-cache.php on line 370

> mu-plugins: the endurance cache is disabled already.
> I am trying to edit 'save_assignment'
> Yes I think they have been resolved. I have also tried totally removing the whole assignment_create_validation.php file and trying to save again but that didnt work.

#1142952

I ended up using a third party plugin for the PHP snippet. Strangely, this PHP problem has also surfaced in a different installation of wordpress on the same server. Not sure what the issue is.