Support » Plugins » Hacks » Undefined Function Fatal Error In Plugin Class

  • Resolved edtiley


    Building a plugin using Class structure.

    Want to display the result of a formula, so I created a public function so it could be done as needed. Something like:

    public function foo($x,$y) {
       return strval(($x+$y)*2.2) ;

    I keep getting an undefined function. Finally I put the function in functions.php and it works like a champ. So it’s obvious the function isn’t getting loaded.

    I’ve tried using init and plugins_loaded in add_action calls, but the function is still not available.

    Surely there’s a fairly simple way of making the function available inside the plugin without having to hook it. Isn’t there?


Viewing 2 replies - 1 through 2 (of 2 total)
  • If foo() is in a class are you calling it correctly ?

    e.g. within the plugin class,


    or from outside the class, you need a class instance,

    $x = new MyPluginClass();

    or make foo static,


    Once foo() in is functions.php, depedning how it’s declared, foo() is probably in global scope, so just calling


    would work.


    Putting it in functions.php makes it globally available.

    Bingo! I searched unsuccessfully for that for hours. In all the tuts I’ve read on building class based plugins I don’t think that little construct was explicitly mentioned. Or at least failed to penetrate my grayRAM.



Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Undefined Function Fatal Error In Plugin Class’ is closed to new replies.