<?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; hook</title>
	<atom:link href="http://wpengineer.com/tag/hook/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress Plugin Deinstall Data Automatically</title>
		<link>http://wpengineer.com/35/wordpress-plugin-deinstall-data-automatically/</link>
		<comments>http://wpengineer.com/35/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">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/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/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>
<pre lang="php">
/**
 * Delete options in database
 */
function example_deinstall() {

	delete_option(&#039;example&#039;);
}
</pre>
<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>
<pre lang="php">
delete_option(&#039;example&#039;);
</pre>
<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>
<pre lang="php">
if ( !defined(&#039;WP_UNINSTALL_PLUGIN&#039;) ) {
    exit();
}
delete_option(&#039;example&#039;);
</pre>
<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>
<pre lang="php">
 /**
 * Check for hook
 */
if ( function_exists(&#039;register_uninstall_hook&#039;) )
	register_uninstall_hook(__FILE__, &#039;example_deinstall&#039;);

 /**
 * Delete options in database
 */
function example_deinstall() {

	delete_option(&#039;example&#039;);
}
</pre>
<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 /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/35/wordpress-plugin-deinstall-data-automatically/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

