• Resolved pglock

    (@pglock)


    I’ve recently started using code snippets as I have several functions I want to reuse across my site and I want a simple way of managing them all.
    I created two simple functions to take a userid and return a sum of scores from sets of questions that user has answered. That total scores are used in a report. This was all originally in a functions.php file and working OK.

    I’ve created the report as a snippet. If I run the function code for the scores within the report snippet, it works fine. If I attempt to break the scoring function out into a separate snippet and then call it from the report I get
    `Uncaught Error: Call to undefined function bg_cost_of_breach()’
    Any idea what I’m doing wrong?

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

    (@bungeshea)

    It’s possible that the snippet where you use the function is being evaluated after the snippet where you define the function. To remedy this, you could try wrapping your use of the function in an action hook:

    add_action( 'init', function () {
          bg_cost_of_breach(); // do something with your function
    } );

    By using the init hook, the function should have already been defined before it is called.

Viewing 1 replies (of 1 total)
  • The topic ‘Uncaught Error: Call to undefined function’ is closed to new replies.