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 am getting function deactivate_plugins does not exist error when calling this function

function deactivateSelf(){
    deactivate_plugins(RSD_PLUGIN, true); //gives error: function deactivate_plugins does not exist
    header("Location: plugins.php?deactivate=true"); //redirect to plugin management with message
    die();
}
  • the function deactivate_plugins is on the server in /wp-admin/wp-includes/plugin.php
  • the function deactivateSelf works on my developer's computer but not on my linode server
  • I downloaded http://www.turnkeylinux.org/wordpress, which should have pretty standard configuration and I got the same error. I tried to upgrade wp to the latest version and still got the same error.

Any idea how to make it work?

share|improve this question
    
Just for clarity: Did you add that bounty to give an extra reward to toscho or do you need extra help? –  Jan Fabry May 31 '11 at 5:59
    
@Jan: I added bounty after I tried what @toscho suggested. Unfortunatelly I tried to add not the correct plugin.php. toscho edided the answer and I saw that I have to use different path to plugin.php –  Radek May 31 '11 at 6:10
    
so, now everything is fine and working. I need to wait to give toscho the bounty ... I already accepted the answer because it answered my question. –  Radek May 31 '11 at 6:12
    
also noticed that 'wp-admin/includes/plugin.php ' is not valid in PHP. Notice the extra space after php –  Radek Jun 6 '11 at 1:06

1 Answer 1

up vote 7 down vote accepted
+50

The file wp-admin/includes/plugin.php is not always included. You may have to do this in your plugin.

And your Location header is invalid: You have to send a complete URL.

You should use:

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

When do you call this function? Maybe too early.

share|improve this answer
    
I added require_once('full_path_to/plugin.php'); but it didn't help. Header is now commented out. –  Radek May 28 '11 at 7:43
    
If you're still getting "function does not exist" errors after supplying the full path to the file that initializes the function, either the function is getting unregistered somewhere or your path is incorrect. I'd try this again, but try using require_once(get_bloginfo('wpurl').'/wp-admin/includes/plugin.php');. You should probably be logged in for this to work; I remember reading somewhere that function doesn't work outside wp-admin (though I may be wrong). –  aendrew May 31 '11 at 1:40
    
there are two includes directories one in wp-admin and wp-includes in wp root directory. The first one is the right one. Thank you. –  Radek May 31 '11 at 2:31

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.