<?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>The Tutorial Blog &#187; wp</title>
	<atom:link href="http://www.thetutorialblog.com/tag/wp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetutorialblog.com</link>
	<description></description>
	<lastBuildDate>Wed, 07 Jul 2010 23:30:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
<link>http://www.thetutorialblog.com</link>
<url>http://www.thetutorialblog.com/wp-content/plugins/maxblogpress-favicon/icons/favicon-28.ico</url>
<title>The Tutorial Blog</title>
</image>
		<item>
		<title>Creating a WordPress plugin</title>
		<link>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/</link>
		<comments>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 17:10:34 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[makeuseof]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=38</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	The plugin that I'm going to show you how to create within this post is a plugin that I created for MakeUseOf. Creating plugins for WP is relatively easy and uses actions to call functions that are included in pages within the main WP files. To learn more about creating plugins for WP go here. [...]


Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Twitter-like pagination using CodeIgniter and jQuery'>Twitter-like pagination using CodeIgniter and jQuery</a> <small>If you use Twitter you'll notice that there is a...</small></li>
<li><a href='http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/' rel='bookmark' title='Permanent Link: Adding security to CodeIgniter forms with a custom library class'>Adding security to CodeIgniter forms with a custom library class</a> <small>The class that we are going to create within CI...</small></li>
<li><a href='http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/' rel='bookmark' title='Permanent Link: Creating a basic iPad application'>Creating a basic iPad application</a> <small>Because of the recent announcement of the iPad more people...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fcreating-a-wordpress-plugin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fcreating-a-wordpress-plugin%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Creating a Wordpress plugin" alt=" Creating a Wordpress plugin" /><br />
			</a>
		</div>
<p>The plugin that I'm going to show you how to create within this post is a plugin that I created for <a href="http://www.makeuseof.com" target="_blank">MakeUseOf</a>.</p>
<p>Creating plugins for WP is relatively easy and uses actions to call functions that are included in pages within the main WP files. To learn more about creating plugins for WP go <a href="http://codex.wordpress.org/Main_Page" target="_blank">here</a>.</p>
<p>Ok so lets get started with creating the plugin.</p>
<p>When creating a plugin for WP make sure that you include your own unique word or acronym to your functions so that they don't conflict with any other plugins that may be installed.</p>
<p>Because I created this for MakeUseOf the acronym I use is MUO and then AF because I named the plugin author footer so every function within this plugin begins with MUO_AF.<br />
<span id="more-38"></span><br />
So to start our plugin we add this<br />
<div id="code_div">&lt;?php<br />
/*<br />
Plugin Name: MUO Author Footer<br />
Description: Authors type in the footer that will be attached to the end of their articles with modifications<br />
Author: Wez<br />
Version: 1.0<br />
*/<br />
</div></p>
<p>Here is where we add the name of our plugin, a description, your name and the version number of your plugin.</p>
<p>The next bit of code that we add is the <em>register_activation_hook</em> and <em>register_deactivation_hook</em> so that when the plugin is activated and deactivated the code within functions that we will create in our next step will be executed.<br />
<div id="code_div">register_activation_hook(__FILE__, 'MUO_AF_activate');<br />
register_deactivation_hook(__FILE__, 'MUO_AF_deactivate');</div></p>
<p>We're now going to create two functions called MUO_AF_activate and MUO_AF_deactivate so that the register hooks work correctly.<br />
<div id="code_div">function MUO_AF_activate() {<br />
	$query = mysql_query("CREATE TABLE `muo_author_footer` (<br />
	  `author_id` int(11) NOT NULL,<br />
	  `author_name` varchar(50) NOT NULL,<br />
	  `author_signature` text NOT NULL,<br />
	  PRIMARY KEY  (`author_id`)<br />
	) ENGINE=MyISAM DEFAULT CHARSET=latin1;");<br />
}</p>
<p>function MUO_AF_deactivate(){<br />
	$query = mysql_query("DROP TABLE `muo_author_footer`");<br />
}</div><br />
What this code does is when the plugin is activated it will create a table within the MySQL database that the plugin will use to store and retrieve information. When the plugin is deactivated it will delete the table that was created in the database.</p>
<p>In the next step we will write code that will be called and displayed within the Your Profile page in the admin-cp.<br />
<div id="code_div">function MUO_AF_profile() {<br />
	global $userdata;<br />
	get_currentuserinfo();<br />
	$query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='$userdata->ID'");<br />
	$row = mysql_fetch_array($query);<br />
	$author_signature = $row['author_signature'];<br />
	echo '&lt;table class="form-table"><br />
	&lt;tr>&lt;th>Author Post Signature</th>
<p>	&lt;td>&lt;p><br />
	&lt;textarea name="MUO_Author_Sig" cols="30" rows="5">'.$author_signature.'&lt;/textarea><br />
	&lt;/p><br />
	&lt;h2>Preview:&lt;/h2>&lt;p>&lt;em>';<br />
	echo $author_signature;<br />
	echo '&lt;/em>&lt;/p><br />
	&lt;/td>&lt;/tr><br />
	&lt;/table>';<br />
}</div></p>
<p>When the Update Profile button is clicked the information from the previous bit of code will be retrieved in the next bit of code and the database will be updated.<br />
<div id="code_div">function MUO_AF_edit(){<br />
	global $userdata, $current_user;<br />
	get_currentuserinfo();</p>
<p>	$MUO_Author_Sig = $_POST['MUO_Author_Sig'];</p>
<p>	$query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='$userdata->ID'");</p>
<p>	if( mysql_num_rows($query) > 0 ) {<br />
		$query = mysql_query("UPDATE muo_author_footer SET author_signature='$MUO_Author_Sig' WHERE author_id='$userdata->ID'");<br />
	} else {<br />
		$query = mysql_query("INSERT INTO muo_author_footer VALUES ('$userdata->ID','$userdata->user_login','$MUO_Author_Sig')");<br />
	}</p>
<p>}</div></p>
<p>The code we will write now is the code that will grab the contents of the post and then attach the authors signature to the end of that post.<br />
<div id="code_div">function MUO_AF_publish_post( $content ) {<br />
	global $wpdb;<br />
	$num = 0;<br />
	if (get_the_ID() > $num) {<br />
		$the_author_id = get_the_author_id();<br />
		$author_query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='". $the_author_id ."'");<br />
		$author_row = mysql_fetch_array($author_query);<br />
		$author_signature = $author_row['author_signature'];</p>
<p>		$content .= '&lt;style><br />
					.muo_af_style { background-color: #B4D0E1; border: 2px solid #4275B8; }<br />
					&lt;/style>';</p>
<p>		if(strstr($author_signature, 'by') == false) :</p>
<p>		$content .= '&lt;p class="muo_af_style">&lt;em>(By) '.$author_signature.'&lt;/em>&lt;/p>';</p>
<p>		else :</p>
<p>		$content .= '&lt;p class="muo_af_style">&lt;em>'.$author_signature.'&lt;/em>&lt;/p>';</p>
<p>		endif;</p>
<p>		return $content;<br />
	}<br />
	else {<br />
		return $content;<br />
	}<br />
}</div></p>
<p>We will now add the functions to actions, this is the most important part of the code because without this none of the functions would be called and nothing would happen.<br />
<div id="code_div">add_action('show_user_profile', 'MUO_AF_profile');<br />
add_filter('profile_update', 'MUO_AF_edit');<br />
add_action('the_content', 'MUO_AF_publish_post');<br />
</div></p>
<p>Then at the end of the file close the php tags with<br />
<div id="code_div">?></div></p>
<p>I have not been very descriptive in this tutorial of what the actual code within the plugin is doing because I created this tutorial wanting to show people the basics bit of code that are needed to call functions and make a plugin work.</p>
<p>I hope that you have learnt something by reading this tutorial and feel free to post a comment with your thoughts on this post.</p>


<p>Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Twitter-like pagination using CodeIgniter and jQuery'>Twitter-like pagination using CodeIgniter and jQuery</a> <small>If you use Twitter you'll notice that there is a...</small></li>
<li><a href='http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/' rel='bookmark' title='Permanent Link: Adding security to CodeIgniter forms with a custom library class'>Adding security to CodeIgniter forms with a custom library class</a> <small>The class that we are going to create within CI...</small></li>
<li><a href='http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/' rel='bookmark' title='Permanent Link: Creating a basic iPad application'>Creating a basic iPad application</a> <small>Because of the recent announcement of the iPad more people...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>
