<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>WP Engineer &#187; uninstall</title> <atom:link href="http://wpengineer.com/tag/uninstall/feed/" rel="self" type="application/rss+xml" /><link>http://wpengineer.com</link> <description>WordPress News, Hacks, Tipps, Tutorials, Plugins and Themes</description> <lastBuildDate>Wed, 28 Jul 2010 13:37:05 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=5427</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>WordPress Plugin Deinstall Data Automatically</title><link>http://wpengineer.com/wordpress-plugin-deinstall-data-automatically/</link> <comments>http://wpengineer.com/wordpress-plugin-deinstall-data-automatically/#comments</comments> <pubDate>Thu, 18 Sep 2008 17:49:27 +0000</pubDate> <dc:creator>Frank</dc:creator> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[hook]]></category> <category><![CDATA[Plugin]]></category> <category><![CDATA[uninstall]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[wp2.7]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=35</guid> <description><![CDATA[In version 2.7 of WordPress you will have the possibility to delete a Plugin directly in your backend, see version 2.7 info. To delete also the Plugin data from your database, the Plugin author has to accomplish some requirements. I hope the following tutorial will help some Plugin authors and they will implement this feature [...]]]></description> <content:encoded><![CDATA[<p>In version 2.7 of WordPress you will have the possibility to delete a Plugin directly in your backend, see <a
href="http://codex.wordpress.org/Version_2.7#Plugin_Uninstaller" class="liwp">version 2.7 info</a>. To delete also the Plugin data from your database, the Plugin author has to accomplish some requirements. I hope the following tutorial will help some Plugin authors and they will implement this feature in their current or future Plugins.<br
/> <span
id="more-35"></span><br
/> <img
src="http://wpengineer.com/blog/wp-content/uploads/wp27_delete.png" alt="since version 2.7 you can delete Plugins directly in your WordPress backend" width="243" height="105" class="alignnone size-full wp-image-117" /></p><p>Everybody who had the uninstall function in their Plugin, doesn&#8217;t have to change a lot. For everybody who likes to know, you can find the function for uninstall in <code>wp-admin/includes/plugin.php</code></p><ol><li><code>is_uninstallable_plugin($plugin)</code></li><li><code>uninstall_plugin($plugin)</code></li></ol><p>and the associated hook <code>wp-includes/plugin.php</code></p><ol><li><code>register_uninstall_hook($file, $callback)</code></li></ol><p>You can use <strong>two possibilities</strong> to add the additional function.</p><ol><li>A file with the name <code>uninstall.php</code> has to be in the Plugin.</li><li>A hook for uninstall <code>register_uninstall_hook</code> has to talk to.</li></ol><p>Up to Version 2.7 you were also able to delete the data from the database, but only if you deactivated the Plugin (Hook <code>register_deactivation_hook()</code>) or with help of a formular.</p><p>To use also other versions of WordPress, I suggest to use the constant <code>WP_UNINSTALL_PLUGIN</code>, because this one exists in version 2.7. Alternative you can use the hook <code>register_uninstall_hook()</code>, since this one is necessary to function via hook. Both possibles are listed in the following examples.</p><p><img
src="http://wpengineer.com/blog/wp-content/uploads/wp27_delete2.png" alt="in version 2.7 you can delete Plugins directly in your backend" width="450" height="284" class="alignnone size-full wp-image-118" /></p><p>The following function for example should be in the Plugin and deleting the entry <em>example</em> from the database table <code>options</code>.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Delete options in database
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> example_deinstall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'example'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h3>via Data <code>uninstall.php</code></h3><p>Easiest possibility is to create the file <code>unistall.php</code> with according entries to delete data in the table <code>options</code>.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'example'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>To avoid an error in older WordPress versions, I recommend to use a constant. Isn&#8217;t there a constant defined, it will just stop in this example.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_UNINSTALL_PLUGIN'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'example'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><h3>via hook <code>register_uninstall_hook()</code></h3><p>Alternatively you can register the deinstallation via hook, so that you are not depend on the file and you can use a easier possibility to integrate an uninstallation in your Plugin. For that you can use the hook <code>register_uninstall_hook()</code>.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #009933; font-style: italic;">/**
 * Check for hook
 */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_uninstall_hook'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	register_uninstall_hook<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'example_deinstall'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #009933; font-style: italic;">/**
 * Delete options in database
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> example_deinstall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	delete_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'example'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>The possibility, to delete Plugins directly in your backend, certainly makes it easier for the user to get rid off unused data. But for that, the Plugin authors have to support this feature and the table <code>options</code> certainly will be thankful for that.<br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/wordpress-ftp-data-with-constant/" rel="bookmark" title="Permanent Link: WordPress FTP Data With Constant" class="liinternal">WordPress FTP Data With Constant</a></li><li><a
href="http://wpengineer.com/use-wordpress-cron/" rel="bookmark" title="Permanent Link: Use WordPress Cron" class="liinternal">Use WordPress Cron</a></li><li><a
href="http://wpengineer.com/use-wordpress-cache/" rel="bookmark" title="Permanent Link: Use WordPress Cache" class="liinternal">Use WordPress Cache</a></li><li><a
href="http://wpengineer.com/embed-wordpress-functions-outside-wordpress/" rel="bookmark" title="Permanent Link: Embed WordPress Functions Outside WordPress" class="liinternal">Embed WordPress Functions Outside WordPress</a></li><li><a
href="http://wpengineer.com/exclude-category-from-turnoff-comments-automatically/" rel="bookmark" title="Permanent Link: Exclude A Category From Turn Off Comments Automatically" class="liinternal">Exclude A Category From Turn Off Comments Automatically</a></li></ul><hr
/><p><img
style="float:left;" src="http://wpengineer.com/favicon.ico" alt="WP Engineer Favicon"/> Thanks for subscribing our feed! <a
href="http://buysellads.com/buy/detail/3646/" class="liexternal">Sponsor the WP Engineer Blog</a> and get your brand in front of several hundred users per day!<br
/> &copy; <a
href="http://wpengineer.com/" class="liinternal">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p> ]]></content:encoded> <wfw:commentRss>http://wpengineer.com/wordpress-plugin-deinstall-data-automatically/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Database Caching 23/34 queries in 0.087 seconds using disk
Object Caching 458/522 objects using disk

Served from: wpengineer.com @ 2010-07-29 13:08:42 -->