<?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>Shoultes.net &#187; PHP Everywhere</title> <atom:link href="http://shoultes.net/category/php-everywhere/feed/" rel="self" type="application/rss+xml" /><link>http://shoultes.net</link> <description>Seth Shoultes PHP Website</description> <lastBuildDate>Tue, 14 Feb 2012 03:16:49 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Adding Images to RSS Feeds</title><link>http://shoultes.net/adding-images-rss-feeds/</link> <comments>http://shoultes.net/adding-images-rss-feeds/#comments</comments> <pubDate>Tue, 31 Aug 2010 05:58:22 +0000</pubDate> <dc:creator>Seth</dc:creator> <category><![CDATA[Events]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[PHP Code Samples]]></category> <category><![CDATA[PHP Everywhere]]></category> <category><![CDATA[Ramblings]]></category> <category><![CDATA[Web Design]]></category> <category><![CDATA[WordCamp]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[Wordpress Plugins]]></category><guid isPermaLink="false">http://shoultes.net/?p=2099</guid> <description><![CDATA[I had the pleasure of meeting John Hawkins of (9Seeds) this weekend at WordCamp Utah. I also got see John give a great presentation on beginning plugin development. Now he has taken the events of this past weekend and has given us an example (and a plugin) of how to attach images to your WordPress [...]]]></description> <content:encoded><![CDATA[<p>I had the pleasure of meeting <a href="http://johnhawkinsunrated.com" target="_blank">John Hawkins</a> of (<a href="http://9seeds.com/" target="_blank">9Seeds</a>) this weekend at <a href="http://2010.utah.wordcamp.org/" target="_blank">WordCamp Utah</a>. I also got see John give a great presentation on beginning plugin development.</p><p>Now he has taken the events of this past weekend and has given us an example (and a plugin) of <a href="http://johnhawkinsunrated.com/attach-image-to-rss" target="_blank">how to attach images to your WordPress RSS feeds</a>.</p><div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy"><ul class="socials"><li class="shr-twitter"> <a href="http://twitter.com/home?status=Adding+Images+to+RSS+Feeds+-+http://bit.ly/aoL5KR&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="shr-facebook"> <a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://shoultes.net/adding-images-rss-feeds/&amp;t=Adding+Images+to+RSS+Feeds" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="shr-digg"> <a href="http://digg.com/submit?phase=2&amp;url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="shr-stumbleupon"> <a href="http://www.stumbleupon.com/submit?url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="shr-reddit"> <a href="http://reddit.com/submit?url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li class="shr-delicious"> <a href="http://delicious.com/post?url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="shr-gmail"> <a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=Adding+Images+to+RSS+Feeds&amp;body=Link: http://shoultes.net/adding-images-rss-feeds/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a></li><li class="shr-googlebookmarks"> <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a></li><li class="shr-blogger"> <a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://shoultes.net/adding-images-rss-feeds/&amp;n=Adding+Images+to+RSS+Feeds&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a></li><li class="shr-comfeed"> <a href="http://shoultes.net/adding-images-rss-feeds/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="shr-dzone"> <a href="http://www.dzone.com/links/add.html?url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds&amp;description=I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres" rel="nofollow" class="external" title="Add this to DZone">Add this to DZone</a></li><li class="shr-googlebuzz"> <a href="http://www.google.com/buzz/post?url=http://shoultes.net/adding-images-rss-feeds/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li class="shr-googlereader"> <a href="http://www.google.com/reader/link?url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds&amp;srcUrl=http://shoultes.net/adding-images-rss-feeds/&amp;srcTitle=Adding+Images+to+RSS+Feeds&amp;snippet=I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a></li><li class="shr-linkedin"> <a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://shoultes.net/adding-images-rss-feeds/&amp;title=Adding+Images+to+RSS+Feeds&amp;summary=I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres&amp;source=Shoultes.net" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li class="shr-mail"> <a href="mailto:?subject=%22Adding%20Images%20to%20RSS%20Feeds%22&amp;body=Link: http://shoultes.net/adding-images-rss-feeds/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="shr-squidoo"> <a href="http://www.squidoo.com/lensmaster/bookmark?http://shoultes.net/adding-images-rss-feeds/" rel="nofollow" class="external" title="Add to a lense on Squidoo">Add to a lense on Squidoo</a></li><li class="shr-yahoobuzz"> <a href="http://buzz.yahoo.com/submit/?submitUrl=http://shoultes.net/adding-images-rss-feeds/&amp;submitHeadline=Adding+Images+to+RSS+Feeds&amp;submitSummary=I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres&amp;submitCategory=business&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li><li class="shr-yahoomail"> <a href="http://compose.mail.yahoo.com/?Subject=Adding+Images+to+RSS+Feeds&amp;body=Link: http://shoultes.net/adding-images-rss-feeds/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20had%20the%20pleasure%20of%20meeting%20John%20Hawkins%20of%20%289Seeds%29%20this%20weekend%20at%20WordCamp%20Utah.%20I%20also%20got%20see%20John%20give%20a%20great%20presentation%20on%20beginning%20plugin%20development.%0D%0A%0D%0ANow%20he%20has%20taken%20the%20events%20of%20this%20past%20weekend%20and%20has%20given%20us%20an%20example%20%28and%20a%20plugin%29%20of%20how%20to%20attach%20images%20to%20your%20WordPres" rel="nofollow" class="external" title="Email this via Yahoo! Mail">Email this via Yahoo! Mail</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://shoultes.net/adding-images-rss-feeds/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Function for Creating Tables with WordPress Plugins</title><link>http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/</link> <comments>http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/#comments</comments> <pubDate>Sun, 07 Mar 2010 07:41:23 +0000</pubDate> <dc:creator>Seth</dc:creator> <category><![CDATA[My Plugins]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[PHP Code Samples]]></category> <category><![CDATA[PHP Developer News]]></category> <category><![CDATA[PHP Everywhere]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[Wordpress Plugins]]></category> <category><![CDATA[database]]></category> <category><![CDATA[dbDelta]]></category> <category><![CDATA[installing tables]]></category> <category><![CDATA[Plugin]]></category> <category><![CDATA[upgrade]]></category><guid isPermaLink="false">http://shoultes.net/?p=1807</guid> <description><![CDATA[Here is a very useful function I have written to install/update the database tables in your custom WordPress plugin. Basically I have used the examples given on the &#8220;Creating Tables with Plugins&#8221; page at WordPress.org. In your main plugin file (ex. my_plugin.php) I define my plugin version: define&#40;&#34;MY_PLUGIN_VERSION&#34;, &#34;2.16&#34; &#41;; //Declare the plugin version. This [...]]]></description> <content:encoded><![CDATA[<p>Here is a very useful function I have written to install/update the database tables in your custom WordPress plugin. Basically I have used the <a href="http://codex.wordpress.org/Creating_Tables_with_Plugins">examples</a> given on the &#8220;<a href="http://codex.wordpress.org/Creating_Tables_with_Plugins">Creating Tables with Plugins</a>&#8221; page at <a href="http://wordpress.org/">WordPress.org</a>.</p><p>In your main plugin file (ex. my_plugin.php) I define my plugin version:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MY_PLUGIN_VERSION&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;2.16&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Declare the plugin version. This way we know the tables are always up to date. I usually declare this in my main plugin file.</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;includes/functions.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;includes/database_install.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
register_activation_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;">'my_plugin_data_tables_install'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Then in my functions.php file:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_plugin_run_install <span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_version</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		   <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
		   <span style="color: #000088;">$wp_table_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prefix <span style="color: #339933;">.</span> <span style="color: #000088;">$table_name</span><span style="color: #339933;">;</span>
		   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW TABLES LIKE '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$table_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$table_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$sql_create_table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CREATE TABLE &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$wp_table_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ( &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ) ;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wp-admin/includes/upgrade.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				dbDelta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql_create_table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//create option for table version</span>
				<span style="color: #000088;">$option_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_tbl_version'</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$newvalue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table_version</span><span style="color: #339933;">;</span>
				  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					    update_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newvalue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					    <span style="color: #000088;">$deprecated</span><span style="color: #339933;">=</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
					    <span style="color: #000088;">$autoload</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'no'</span><span style="color: #339933;">;</span>
					    add_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newvalue</span><span style="color: #339933;">,</span> <span style="color: #000088;">$deprecated</span><span style="color: #339933;">,</span> <span style="color: #000088;">$autoload</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				  <span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">//create option for table name</span>
				<span style="color: #000088;">$option_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_tbl'</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$newvalue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_table_name</span><span style="color: #339933;">;</span>
				  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					    update_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newvalue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					    <span style="color: #000088;">$deprecated</span><span style="color: #339933;">=</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
					    <span style="color: #000088;">$autoload</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'no'</span><span style="color: #339933;">;</span>
					    add_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newvalue</span><span style="color: #339933;">,</span> <span style="color: #000088;">$deprecated</span><span style="color: #339933;">,</span> <span style="color: #000088;">$autoload</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				  <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Code here with new database upgrade info/table Must change version number to work.</span>
	<span style="color: #000088;">$installed_ver</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$table_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_tbl_version'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$installed_ver</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$table_version</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		  <span style="color: #000088;">$sql_create_table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CREATE TABLE &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$wp_table_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ( &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ) ;&quot;</span><span style="color: #339933;">;</span>
	      <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wp-admin/includes/upgrade.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	      dbDelta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql_create_table</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	      update_option<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$table_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_tbl_version'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_version</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	      <span style="color: #009900;">&#125;</span>
	    <span style="color: #009900;">&#125;</span></pre></div></div><p>Using the function is quite simple and can save a few lines of code. especially if you need to install several new tables.</p><p>Here is an example of database_install.php:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_plugin_data_tables_install <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$table_version</span> <span style="color: #339933;">=</span> MY_PLUGIN_VERSION<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Call the plugin version.</span>
<span style="color: #666666; font-style: italic;">//Install the first table</span>
<span style="color: #000088;">$table_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;my_first_plugin_tbl&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id mediumint(9) NOT NULL AUTO_INCREMENT,
	  time bigint(11) DEFAULT '0' NOT NULL,
	  name tinytext NOT NULL,
	  text text NOT NULL,
	  url VARCHAR(100) NOT NULL,
	  UNIQUE KEY id (id)&quot;</span><span style="color: #339933;">;</span>
my_plugin_run_install  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_version</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Install the second table</span>
<span style="color: #000088;">$table_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;my_second_plugin_tbl&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id mediumint(9) NOT NULL AUTO_INCREMENT,
	   category_name VARCHAR(100) DEFAULT NULL,
	   category_identifier VARCHAR(45) DEFAULT NULL,
	   category_desc TEXT,
	   display_desc VARCHAR (4) DEFAULT NULL,
	  UNIQUE KEY id (id)&quot;</span><span style="color: #339933;">;</span>
my_plugin_run_install  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$table_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table_version</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>I hope this helps some of the WordPress plugin authors out there.</p><div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy"><ul class="socials"><li class="shr-twitter"> <a href="http://twitter.com/home?status=Function+for+Creating+Tables+with+Wordpress+Plugins+-+http://b2l.me/ugq7n&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="shr-facebook"> <a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;t=Function+for+Creating+Tables+with+Wordpress+Plugins" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="shr-digg"> <a href="http://digg.com/submit?phase=2&amp;url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="shr-stumbleupon"> <a href="http://www.stumbleupon.com/submit?url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="shr-reddit"> <a href="http://reddit.com/submit?url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li class="shr-delicious"> <a href="http://delicious.com/post?url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="shr-gmail"> <a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;body=Link: http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a></li><li class="shr-googlebookmarks"> <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a></li><li class="shr-blogger"> <a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;n=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a></li><li class="shr-comfeed"> <a href="http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="shr-dzone"> <a href="http://www.dzone.com/links/add.html?url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;description=Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi" rel="nofollow" class="external" title="Add this to DZone">Add this to DZone</a></li><li class="shr-googlebuzz"> <a href="http://www.google.com/buzz/post?url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li class="shr-googlereader"> <a href="http://www.google.com/reader/link?url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;srcUrl=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;srcTitle=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;snippet=Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a></li><li class="shr-linkedin"> <a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;title=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;summary=Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi&amp;source=Shoultes.net" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a></li><li class="shr-mail"> <a href="mailto:?subject=%22Function%20for%20Creating%20Tables%20with%20Wordpress%20Plugins%22&amp;body=Link: http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="shr-squidoo"> <a href="http://www.squidoo.com/lensmaster/bookmark?http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/" rel="nofollow" class="external" title="Add to a lense on Squidoo">Add to a lense on Squidoo</a></li><li class="shr-yahoobuzz"> <a href="http://buzz.yahoo.com/submit/?submitUrl=http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/&amp;submitHeadline=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;submitSummary=Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi&amp;submitCategory=business&amp;submitAssetType=text" rel="nofollow" class="external" title="Buzz up!">Buzz up!</a></li><li class="shr-yahoomail"> <a href="http://compose.mail.yahoo.com/?Subject=Function+for+Creating+Tables+with+Wordpress+Plugins&amp;body=Link: http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Here%20is%20a%20very%20useful%20function%20I%20have%20written%20to%20install%2Fupdate%20the%20database%20tables%20in%20your%20custom%20Wordpress%20plugin.%20Basically%20I%20have%20used%20the%20examples%20given%20on%20the%20%22Creating%20Tables%20with%20Plugins%22%20page%20at%20Wordpress.org.%0D%0A%0D%0AIn%20your%20main%20plugin%20file%20%28ex.%20my_plugin.php%29%20I%20define%20my%20plugin%20version%3A%0D%0Adefi" rel="nofollow" class="external" title="Email this via Yahoo! Mail">Email this via Yahoo! Mail</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded> <wfw:commentRss>http://shoultes.net/function-for-creating-tables-with-wordpress-plugins/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)

Served from: shoultes.net @ 2012-05-18 03:57:44 -->
