Skip Navigation

[Resolved] Call to undefined function for a custom function

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 1 voice.

Last updated by Minesh 1 week, 1 day ago.

Assisted by: Minesh.

Author
Posts
#2790466

I am calling a function stored in toolset custom code snippet in another toolset custom code snippet.

This used to work just fine before and now the second snippet cannot discover the function stored in the first snippet.

Both snippets are stored as Toolset custom code files.

I tried to use include_once or require_once but I get errors in formatting.php which is not related to my two snippets.

What am I missing? What do I need to do to have the function available in the second snippet.

Second snippet --

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
include_once 'file-1-name.php'; // this stores the function_A
$user_id = get_current_user_id();
function_A($user_id);
?>

Error without include_once:
Call to undefined function function_A

Error with include_once:
E_DEPRECATED: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in file /nas/content/live/site-name/wp-includes/formatting.php on line 1596
E_DEPRECATED: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in file /nas/content/live/site-name/wp-includes/formatting.php on line 2262

#2790488

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I'm not sure you will have to call include_once as all code snippet you will add will automatically loaded if they are active. What if you try to add the function to once code snippet and check if that helps?

#2790492

I don't understand. I am already adding the function to the snippet.

Do you want me to add the the function and it's full code to the snippet?

#2790496

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What I'm suggesting is you can merge the code in one snippet and check if that helps.

#2790518

That beats the purpose of having a function. Doesn't it?

A function should be called from different snippets and maintained in one place avoiding duplicate code.

Has something changed in Toolset or PHP level to prevent functions from being called?

#2790549

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I'm not sure why its not working as I do not see any other user reported such issue.

May be you are calling function before its loaded or something else casing the issue?