Support » Plugins » Hacks » using require_once in functions.php

  • Hi,
    I have a feeling there’s going to be a really simple answer to this, but I can’t see it and it’s driving me mad! Hope someone can help.

    I have a load of custom functions in my theme’s functions.php that I want to shift into another file to tidy things up a bit. They deal with creating a theme options admin panel.
    I cut and paste these functions into said new file, and include it with require_once(TEMPLATEPATH . '/filename.php');
    I reload the admin panel. WP gives the error “You do not have sufficient permissions to access this page.”

    Why?! I’ve checked the new file’s actually being included by adding echo "test"; in it, which promptly displays above the wordpress error. I’ve also checked the logs and PHP doesn’t throw an error.

    Any ideas anyone? I’m completely at a loss!


Viewing 2 replies - 1 through 2 (of 2 total)
  • Then it must be something you’re calling in one of the functions..

    I do something similar for my test install. I have a plugin which basically includes a pile functions from outside root (that way i can run the plugin across several installs and not need to keep several copies), but it’s just a simple include statement to a main file housing several functions. I also include another file inside that one because it got too big.

    Cut out a few functions at a time and test the install, if you can narrow it down to a particular function, then post the code (use a pastebin if doing so please), i can probably take a good guess at what the problem code is.

    Ha! Turned out to be the line:
    header("Location: themes.php?page=functions.php&saved=true);
    that was the problem.
    Didn’t realise that even though it was an include, this would still need changing to:
    header("Location: themes.php?page=the_included_file.php&saved=true);

    You learn something every day!

    Thanks very very much for your reply anyway 🙂
    Sorry I didn’t get back sooner – I couldn’t narrow it down to a single function to put in a pastebin really!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘using require_once in functions.php’ is closed to new replies.