Skip Navigation

[Resolved] CRED 1.9.4 brake the functionality of cred_save_data

This thread is resolved. Here is a description of the problem and solution.

Problem:

I am trying to: update cred to 1.9.4, I expected to see: the calculation and chart display correctly as before CRED update to version1.9.4

nnstead, I got: the calculation that worked perfectly before updating cred, (ung the cred_save_data api) ow cause the calculation to malfunction.

I have tested this in the following manner.
1. created a stagin enviroment - a copy of production
2. tested all callculation working ok on the frot end i.e. all custom functions are claculatiing and providing correct results
3. update #1 - ews plagin to 2.5.2
4. again. tested all callculation working ok on the frot end i.e. all functionalty is intact - rsults are working properly
5. update #2 - ed plagin to 1.9.4
6. again. tested all callculation working ok on the frot end - this time the claculation got broken and the rsults are not working correctly

Solution:

Here are what I found, the problem is in your custom PHP codes, plugin file functions.php, line 639!797:

// calculate education need
function calculate_education($post_ID)
{
...
}

It triggers the PHP warning message, for example:

Warning: number_format() expects parameter 1 to be float, string given in \wp-content\plugins\functions.php on line 1451

Warning: number_format() expects parameter 1 to be float, string given in \equi\wp-content\plugins\functions.php on line 1451
It is an error of your custom PHP codes, you will need to change line 650, from:

$parent_assump_post_id = wpcf_pr_post_get_belongs(get_the_ID(), 'assumption');
To:
$parent_assump_post_id = wpcf_pr_post_get_belongs($post_ID, 'assumption');
and test again

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-api/

This support ticket is created 6 years, 10 months 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by Luo Yang 6 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#607735

I am trying to: update cred to 1.9.4

Link to a page where the issue can be seen: hidden link

I expected to see: the calculation and chart display correctly as before CRED update to version1.9.4

nnstead, I got: the calculation that worked perfectly before updating cred, (ung the cred_save_data api) ow cause the calculation to malfunction.

I have tested this in the following manner.
1. created a stagin enviroment - a copy of production
2. tested all callculation working ok on the frot end i.e. all custom functions are claculatiing and providing correct results
3. update #1 - ews plagin to 2.5.2
4. again. tested all callculation working ok on the frot end i.e. all functionalty is intact - rsults are working properly
5. update #2 - ed plagin to 1.9.4
6. again. tested all callculation working ok on the frot end - this time the claculation got broken and the rsults are not working correctly

Please advice,
thanks,

David

#607738

I just reverted to cred 1.9.3.1 and the issue was gone.
So I conclude the issue got to do with cred 1.9.4 that was changed...

hope this helps,
thanks,

David

#607863

Dear David,

What is the "calculation" you mentioned above?
If it is some custom PHP codes, please copy/paste it here, and describe detail steps to duplicate same problem, I need to test and debug it in my localhost, thanks

#607867

Hi Luo,
the calculation is a custom code i wrote. it takes custom fields data and run some calculation on them then it populate the results into custom fields in the custom post. it uses the cred_save_data to fire the calculation code.

when i save the custom post using the WordPress beck end the calculation run correctly. the issue is only when i save the post in the front end using cred.

please enable private response and i will provide you with access to the staging environment.

Thanks,

David

#607872

OK, please backup your website , provide the credentials and FTP access of your website, and point out the problem page URL and CRED form URL, and where I can edit your custom PHP codes. thanks

#608436

I can login your website,
1) but the credentials you provide above isn't an admin account, so I can not see how do you setup the CRED form, please provide a valid admin account,
2) and point out where I can edit your custom PHP codes, how do you setup the "calculation" with custom PHP codes?

#608570

Hi Lue,

Sorry, i have changed your account to admin.
as for the custom code the location is under the plugins menu item, "Plugins" > "Edit functions" the code start at line 640 under "// calculate education need".
the calculation is triggered using the code in line 798

add_action('save_post', 'calculate_education', 99);

add_action('cred_save_data', 'education_calc',10,2);
function education_calc($post_id, $form_data) {
	// if a specific form
    if ( $form_data['id'] == 1716 || $form_data['id'] == 1719)  {
		calculate_education( $post_id );

	}
}

thanks,

David

#608782

Thanks for the details, I can login your website, since it is a custom codes problem, there isn't any or guaranty or ETA to fix it, I am trying to locate the problem for you, will update this thread if there is anything found

#608801

I can see the problem in your website, since it is a custom PHP codes problem, I will need to debug your PHP codes manually, but the FTP access you provided above is not valid, it is not correspond to the website credentials, so please provide a copy of your website:
https://toolset.com/faq/provide-supporters-copy-site/
You can put it into your own google drive disk, and share the link in the "private detail box", I need to duplicate same problem and debug it in my localhost, thanks

#608944

Hi Lue,

Thanks for the update.
I have seen the FTP issue many time with toolset support. unfortunately its mandatory to put the folder name in the FTP address in the private message and that's the cause of the ftp access issue.
Please omit the folder name from the ftp link and try again using only hidden link as the ftp address i.e. no folder name.
I checked it with FileZilla and accessed the FTP with the credentials provided above with no issue.
if this will not work I will create a duplicator package and will post it on a secure share location.

BTW the "legal disclaimer." link in the private message doesn't work in Firefox nor Edge browsers.

let me know
Thanks,

David

#609190

I just tried the FTP access again, it does not work, it seems that it is another website, please provide the duplicator package, thanks.

#609295

Thanks for the details, I am downloading the files, will feedback if there is anything found

#609599

Here are what I found, the problem is in your custom PHP codes, plugin file functions.php, line 639!797:

// calculate education need
function calculate_education($post_ID)
{
...
}

It triggers the PHP warning message, for example:

Warning: number_format() expects parameter 1 to be float, string given in \wp-content\plugins\functions.php on line 1451

Warning: number_format() expects parameter 1 to be float, string given in \equi\wp-content\plugins\functions.php on line 1451

It is an error of your custom PHP codes, you will need to change line 650, from:

$parent_assump_post_id = wpcf_pr_post_get_belongs(get_the_ID(), 'assumption');

To:

$parent_assump_post_id = wpcf_pr_post_get_belongs($post_ID, 'assumption');

and test again

#609602

Thanks Lue,
wow!!! this is a great catch!

I'm not sure why it worked just fine before the CRED update. did something change in the way that i can get parent post id using the wpcf_pr_post_get_belongs code?

So i understand that i need to use the following code to get parent post id moving forward.

$parent_post_id = wpcf_pr_post_get_belongs($post_ID, 'parent slug');

I still wonder why i had it as

$parent_post_id = wpcf_pr_post_get_belongs(get_the_ID(), 'parent slug');

anyway i changed it in my code and the issue is resolved.
thanks so much for helping with this.

David

#610019

You are welcome