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 have a unique plugin whose purpose is to set up a new WordPress site with a theme, default widgets, default plugins, custom menus, pages, posts, etc.

The plugin does everything it needs to do when activated and never runs again.

I'm looking for suggestions on how I might, as the last step in the activation routine, deactivate and delete the plugin.

Any help, suggestions, or example references appreciated.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You can deactivate it with:

deactivate_plugins( basename( __FILE__ ) );

I don't think you can delete it. It would be a big security risk, IMO. But if the folder has the correct (but insecure) permissions, you could use the PHP function rmdir

share|improve this answer
    
thanks for the help. The plugin is designed to be uploaded once and ran once, then it sets a flag so it cannot run again. Curious about security risk of allowing the plugin to self destruct once its done. –  Scott B May 9 '11 at 18:59
    
I think it's bad security policy allow a plugin to delete files in your server. But if you set write permissions to that particular plugin php, you can delete it with the unlink(__FILE__); function. Remember to deactivate before deletion –  MZAweb May 9 '11 at 19:16
    
I think I understand, but just wanted to clarify, the plugin is deleting itself, not other files. Maybe the same difference as far as your premise is concerned. It adds some files to the site, inserts some custom settings, creates some widgets, etc, then it deactivates and deletes ITSELF. –  Scott B May 9 '11 at 20:13
    
All PHPs in apache run under the same user. If you give that user write permission for a file, any PHP could delete or modify it. But as i said, if you set permissions (eg: 777) to your plugin, I didn't test it, but I think you'll be able to delete it. –  MZAweb May 9 '11 at 20:26
    
are you planning on sharing the plugin? –  anu May 11 '11 at 9:35
add comment

You can use WordPress's "filesystem api" for deleting files, same as wp core can. It's a neat little system that asks politely for ftp user credentials if it doesn't have permission to do it itself transparently. (I don't think it's really a security issue, since wordpress has install, auto update, and removal of plugins capabilities out of the box.)

share|improve this answer
add comment

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.