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 feel like I'm being really stupid.
I want to make use of some functions in wp-admin/includes/file.php (like download_url), but it doesn't seem to be included, not in the dashboard/admin, or in the front end.

I've put:

if (function_exists('download_url')) {
    echo "YES!";
} else {
    echo "NO!";
}

in my theme's functions.php, and it always prints "NO!".

Do I need to do something to make these functions available?
I'm normally pretty expert with WP but I'm stumped by this very simple thing.

Thanks in advance for help.

share|improve this question
    
Ah, OK, so - helping myself along the way - if I run the function_exists() code on the admin_init hook, I get a YES!, so wp-admin/includes/file.php is loaded somewhere later on. Hmm...I want to use this in an AJAX function. Can I include all admin scripts somehow? –  magicroundabout Mar 19 '13 at 11:06

1 Answer 1

OK, so there's a bunch of admin functions in wp-admin/includes. These are loaded at some point between the loading of the theme's functions.php and the admin_init hook. But that are ONLY loaded for admin-side pages. They are not loaded for front-end pages or AJAX calls.

If you want to use these functions in front-end pages of AJAX calls then you need to do:

require_once( ABSPATH . 'wp-admin/admin-functions.php' );

I would suggest using this sparingly as it will, inevitably, slow your site down.

share|improve this answer

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.