Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've split my functions.php into multiple files using require_once, which works perfectly. However when I add admin functionality (extra panels) in one of the included files, it doesn't work? It's making me put the code in functions.php which I don't want to do.

This is the top of my functions.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', True);

// Includes
require_once('includes/admin.php'); // Admin stuff
share|improve this question
    
You'll have to check if you're in admin: if ( is_admin() ). If you're asking the oposite, then your're denying access. –  kaiser Apr 19 '12 at 13:46
    
There is no condition for the included files, I've just tried adding if(is_admin()) but no luck. –  Vertaxe Apr 19 '12 at 13:52
    
In short: If you're questioning if ( is_admin() ) then the following stuff only triggers if you're on an admin page. So you maybe have something wrapped into such a statement (or the ! is_admin() opposite) and therefore your files aren't loading. –  kaiser Apr 19 '12 at 13:56
    
There are no conditions for the included file, I have require_once('includes/admin.php'); at the top of my functions.php :) –  Vertaxe Apr 19 '12 at 14:03
    
Turn on all your DEBUG stuff including all php error stuff. –  kaiser Apr 19 '12 at 14:04

1 Answer 1

up vote 2 down vote accepted

The problem here is that you're not including yourtheme/includes/admin.php, you're actually including wp-admin/includes/admin.php, so pass a full path to the require statement rather than a relative one e.g.:

require(get_template_directory().'includes/admin.php');
share|improve this answer
1  
Ahah! Thank you very much :) –  Vertaxe Apr 19 '12 at 14:43
    
And why did this work for public files? /wp-admin? –  kaiser Apr 19 '12 at 15:41
    
it's to do with the order that PHP looks for files, remember when you're in admin the point of entry is inside the wp-admin folder, whereas for frontend it's one folder up. I imagine if there was an includes/admin.php in the same folder as wp-config.php it would also fail for the same reason without the above fix –  Tom J Nowell Apr 19 '12 at 15:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.