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?
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
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?
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.
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.