• If I use a plugin function inside index.php, everything fine.
    Using the same function call within another php file, stored in the same folder of index.php gives an error

    Fatal error: Call to undefined function pluginfunctionname() in

    Why is that?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Blutarsky

    (@blutarsky)

    Forgot to mention (maybe) something important: the offending call is in another php file, in the same folder as index.php, but loaded with jQuery. Could be this the problem? The php file loaded with jQuery holds an “environemnt” non WP friendly?

    Thread Starter Blutarsky

    (@blutarsky)

    I have made another test to include the external .php file loaded with jQuery, directly from PHP and it works, so yes, the problem is jQuery-related.

    Maybe do I have to include some credentials, or initialize something to allow jQuery to “see” WordPress correctly?

    if you want to use wordpress functions outside of wordpress, you need to include wp-blog-header.php

    Thread Starter Blutarsky

    (@blutarsky)

    I’am using the function inside WordPress.

    If I code the following include, inside index.php:

    <?php include "topposts.php" ?>

    The included file, holds the call to the plugin function.
    The sample above, works.

    ***********************************************************

    What doesn’t work is the inclusion of the same file, made with jquery:

    <script type="text/javascript">
    	jQuery.noConflict();
    	jQuery("#foo").load("/wp-content/themes/tgv1/topposts.php");
    </script>

    Basically jQuery is successful, it does load the external topposts.php file, but the function call fails.

    Any hint?

    Thread Starter Blutarsky

    (@blutarsky)

    I have tried to stuff into the external file (topposts.php) the following:

    wp_head();

    Now I get:

    “Call to undefined function wp_head()”

    I realize this is an old thread but I thought this information could still be useful to others who happen upon it.

    jQuery is a client-side language while PHP is a server-side language. Basically, jQuery (JavaScript, really) runs after PHP has already done its thing on the server. So loading an additional PHP script with jQuery basically makes you “late to the party.”

    You have to use the PHP include if you want to use a PHP function in another PHP file.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Calling a plugin function outside of index.php gives error’ is closed to new replies.