11

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?

4
  • 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, 2011 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, 2011 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, 2011 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, 2011 at 1:06

1 Answer 1

21
+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.

9
  • I added require_once('full_path_to/plugin.php'); but it didn't help. Header is now commented out.
    – Radek
    May 28, 2011 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).
    – aendra
    May 31, 2011 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, 2011 at 2:31
  • do you put this code in wp-config.php or functions?
    – v3nt
    Jul 18, 2017 at 13:35
  • 1
    @v3nt This is the worst place for that code. Really, please use a plugin. :)
    – fuxia
    Jul 21, 2017 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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