• Resolved ominem

    (@ominem)


    Hello, I created a file.php inside my theme folder that is called when a user clicks on a link on a page that has applied a page-template. Inside that file.php I clear some $_SESSION variables and the need to redirect to homepage. The problem is that this file doesn’t recognize any of wordpress constants or functions:
    1- Notice: Use of undefined constant ABSPATH – assumed ‘ABSPATH’
    2- Fatal error: Call to undefined function wp_redirect()
    What could be the problem?
    I’m using Twenty_Fourteen theme modified.
    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • hey!

    file.php is not part of wordpress, so without including some core wp classes it won’t have access to their vars or functions

    if you want to integrate it using the wp classes i believe you can add this line to the top of your php file (it assumes wordpress is *not* installed in a subdirectory)

    include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );

    another way: is it possible that at the point of link creation (the page before file.php gets called) that you could pass the needed vars as $_SESSION or $_GET vars you define?

    Thread Starter ominem

    (@ominem)

    it worked perfect, thank you very much.

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

The topic ‘Calling WordPress functions from a file.php inside the theme’ is closed to new replies.