<?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>Web Argument &#187; Tutorials</title>
	<atom:link href="http://web-argument.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://web-argument.com</link>
	<description>tutorials, tools and tips</description>
	<lastBuildDate>Sun, 14 Feb 2010 01:55:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wordpress Plugin &#8211; Simple Option Page</title>
		<link>http://web-argument.com/wordpress-plugin-simple-option-page/</link>
		<comments>http://web-argument.com/wordpress-plugin-simple-option-page/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 22:26:51 +0000</pubDate>
		<dc:creator>Alain</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[option page]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://web-argument.com/?p=42</guid>
		<description><![CDATA[After writing your plugin maybe you want to allow the users to costumize it. One way to do this is including an option page on the wordpress admin section.
To write a simple option page I&#8217;ll use the previews example  Happy Face Replacer Plugin. And I&#8217;ll allow the user to set the happy face image url.
Admin [...]]]></description>
			<content:encoded><![CDATA[<p>After writing your plugin maybe you want to allow the users to costumize it. One way to do this is including an option page on the wordpress admin section.<br />
To write a simple option page I&#8217;ll use the previews example  <a href="http://web-argument.com/writing-a-simple-wordpress-plugin/">Happy Face Replacer Plugin</a>. And I&#8217;ll allow the user to set the happy face image url.</p>
<p><strong>Admin Menus/Submenus<br />
</strong><br />
First of all you need to figure out where is the best place to include your administration page on the wordpress admin sections: <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Settings_-_Configuration_Settings">Settings</a>,  <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Manage_-_Change_your_content">Manage</a>, <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Plugins_-_Add_Functionality_to_your_Blog">Plugins</a>,  <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Presentation_-_Change_the_Look_of_your_Blog">Presentation</a>, <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Write_-_Make_some_content">Write</a>, <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Users_-_Your_Blogging_Family">Users</a>.<br />
In this case I&#8217;ll use the &#8220;Manage&#8221; panel.</p>
<p><strong>The Action<br />
</strong><br />
To tell wordpress about your option page you need to use an action &#8216;hook&#8217; called <a href="http://codex.wordpress.org/Plugin_API/Action_Reference" target="_blank">admin_menu</a> (on the <a href="http://web-argument.com/writing-a-simple-wordpress-plugin/">previews post</a> you can read more about wordpress actions, filters and hooks).<br />
In our main plugin file &#8220;happy_face_replacer.php&#8221; we need to include something like this:</p>
<pre>add_action('admin_menu', 'function_to_create_your_menu');</pre>
<p>Inside of the &#8216;funtion to create your menu&#8217; you need to use one of the &#8216;add_menu/submenu_page&#8217; functions :</p>
<pre>add_menu_page(<em>page_title</em>, <em>menu_title</em>, <em>access_level/capability</em>, <em>file</em>, <em>[function]</em>);</pre>
<p>for the menus or:</p>
<pre>add_submenu_page(<em>parent</em>, <em>page_title</em>, <em>menu_title</em>, <em>access_level/capability</em>, <em>file</em>, <em>[function]</em>);</pre>
<p>for the submenus.</p>
<p>In this example we need to call the function:</p>
<pre>add_management_page</pre>
<p>As your plugin your admin menu, page and functions must have a unique name.<span id="more-42"></span></p>
<p>Let&#8217;s use:<br />
&#8220;<strong>Happy Face Replacer Page</strong>&#8221; as the <em>page_tile</em>.<br />
&#8220;<strong>Happy Face Replacer Menu</strong>&#8221; as the <em>menu_title</em>.<br />
&#8220;<strong>happy_face_replacer_setting_file</strong>&#8221; as the file. This is the file that handles the display of the menu page content but in this case we will use the same file.<br />
&#8220;<strong>happy_face_replacer_setting</strong>&#8221; as <em>funtion</em> name (<a href="http://codex.wordpress.org/Adding_Administration_Menus" target="_blank">&#8230;</a><em><a href="http://codex.wordpress.org/Adding_Administration_Menus" target="_blank">function</a></em><a href="http://codex.wordpress.org/Adding_Administration_Menus" target="_blank"> parameter is optional, but if it is not supplied, then WordPress will basically assume that including the PHP file will generate the administration screen, without calling a function. Most plugin authors choose to put the page-generating code in a function within their main plugin file</a>).</p>
<p>The <em>access_level/capability</em> refers to the <a title="User Levels" href="http://codex.wordpress.org/User_Levels">user level</a> or the <a title="Roles and Capabilities" href="http://codex.wordpress.org/Roles_and_Capabilities">capability</a> to show and use this menu. We will use the number <strong>10</strong> corresponding to &#8220;admin user&#8221;.</p>
<p>Then our hooks action and functions could be:</p>
<pre>&lt;?
add_action('admin_menu', 'function_to_create_your_menu');

function function_to_create_your_menu (){

add_management_page('Happy Face Replacer Page', 'Happy Face Replacer Manu', 10, 'happy_face_replacer_setting_file', 'happy_face_replacer_setting');

}

function happy_face_replacer_setting (){

/*  The content of your setting page here */

}

?&gt;</pre>
<p><strong>The Form</strong></p>
<p>Now we need to create our custom form to receive the values that modifies the plugin. The html tags on your Option Page reponds to the css files of the admin section. So, the div, tables, and other html tags will look like the others wordpress admin page if you want.<br />
In this case we will process the content of the form in the same page, then our form &#8220;target&#8221;  parameter is &#8220;_self&#8221; .<br />
Here is the simple form.</p>
<pre>&lt;div class="wrap"&gt;

&lt;form method="post" name="options" target="_self"&gt;

&lt;h2&gt;Select Your Better Happy Face&lt;/h2&gt;

&lt;table width="100%" cellpadding="10" class="form-table"&gt;

&lt;tr&gt;
&lt;td align="left" scope="row"&gt;

&lt;label&gt;Image URL&lt;/label&gt;&lt;input name="happy_face_image_url" value="&lt;?php echo $happy_face_image_url_saved ?&gt;" /&gt;

&lt;/td&gt; 
&lt;/tr&gt;

&lt;/table&gt;
&lt;p class="submit"&gt;

&lt;input type="submit" name="Submit" value="Update" /&gt;

&lt;/p&gt;

&lt;/form&gt;

&lt;/div&gt;</pre>
<p><strong>Get and Update Options</strong></p>
<p>Wordpress allows to save some amount of data on the options table, but if you need more than that you can implement your own table on the database. Read more on <a title="Creating Tables with Plugins" href="http://codex.wordpress.org/Creating_Tables_with_Plugins">Creating Tables with Plugins.</a></p>
<p>The simplest way to save you options is using the functions <a title="Function Reference/add option" href="http://codex.wordpress.org/Function_Reference/add_option">add_option</a>, <a title="Function Reference/update option" href="http://codex.wordpress.org/Function_Reference/update_option">update_option</a> and <a href="http://codex.wordpress.org/Function_Reference/get_option" target="_blank">get_option</a> that allows to save and read data easily.  This allows us to replace the image url on the main function &#8220;happy_face_replacer&#8221; by the value saved:</p>
<pre>$happy_face_image = "&lt;img src='".get_option('$happy_face_image_url_op')."'&gt;";</pre>
<p>Now, the only thing we need is to check if the form was submitted in order to update the &#8220;happy face image url&#8221; on the database and print the message &#8220;Option Saved&#8221; . So, let&#8217;s add this piece of code at the top of the form:</p>
<pre>&lt;?php 
$happy_face_image_url_saved = get_option('$happy_face_image_url_op');

if(isset($_POST['Submit'])) <span> </span>{

        $happy_face_image_url_saved = $_POST["happy_face_image_url"];

        update_option( '$happy_face_image_url_op', $happy_face_image_url_saved );

?&gt;

&lt;div class="updated"&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e('Options saved.', 'mt_trans_domain' ); ?&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;

&lt;?php  }  ?&gt;</pre>
<p>Here is the final code and other related tutorials:<br />
<a href="http://web-argument.com/wp-content/uploads/2008/11/happy_face_replacer1.zip">happy face replacer </a></p>
<p><a href="http://codex.wordpress.org/Creating_Options_Pages" target="_blank">Creating Options Pages</a><br />
<a href="http://codex.wordpress.org/Adding_Administration_Menus"> Adding Administration Menus</a><br />
<a href="http://codex.wordpress.org/Plugin_Resources" target="_blank">Plugin Resources</a></p>
]]></content:encoded>
			<wfw:commentRss>http://web-argument.com/wordpress-plugin-simple-option-page/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<enclosure url='http://web-argument.com/wp-content/uploads/2009/03/000_0998_03-150x150.jpg' length ='6319'  type='image/jpg' />	</item>
		<item>
		<title>Writing a simple Wordpress Plugin</title>
		<link>http://web-argument.com/writing-a-simple-wordpress-plugin/</link>
		<comments>http://web-argument.com/writing-a-simple-wordpress-plugin/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 16:59:46 +0000</pubDate>
		<dc:creator>Alain</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://web-argument.com/?p=3</guid>
		<description><![CDATA[There is two words to describe wordpress: &#8220;Simplicity&#8221; and &#8220;Flexibility&#8221;.  You can do almost whatever you want with this application and its tons of free themes and plugins. This is a simple plugin example that include the steps I used to write my first plugin.
In this case I will replace the phrase &#8220;happy_face&#8221; inside [...]]]></description>
			<content:encoded><![CDATA[<p>There is two words to describe wordpress: &#8220;Simplicity&#8221; and &#8220;Flexibility&#8221;.  You can do almost whatever you want with this application and its tons of free themes and plugins. This is a simple plugin example that include the steps I used to write my first plugin.<br />
In this case I will replace the phrase &#8220;happy_face&#8221; inside the post by an image.</p>
<p><strong>The Standards.</strong></p>
<p><em>The Name</em></p>
<p>If you want to share your plugin with the community it has to be unique. No other plugin on the <a href="http://http://wordpress.org/extend/plugins/">Wordpress Plugin Directory</a> can share this name.</p>
<p>In this example let&#8217;s use:</p>
<pre>Happy Face Replacer</pre>
<p><em>The  Files</em></p>
<p>You need at least one &#8220;main file&#8221; .php with your principal functions. The name of this file could be derived from your plugin name.   Besides you can use the others necessaries folders and .php, .js,  .css files.<br />
Our main file could be:</p>
<pre>happy_face_replacer.php</pre>
<p><em>The Header</em></p>
<p>At the top of your main file you need to include this header.</p>
<pre>&lt;?php
/*
Plugin Name: Happy Face Replacer
Plugin URI: http://www.pluginURI.com
Description: Plugin Description Here.
Version: 1.0
Author: Your Name
Author URI: http://www.yoursite.com
*/
?&gt;</pre>
<p><em></em></p>
<p><strong></strong></p>
<p>It will make your plugin look like this at the plugins panel:</p>
<p><a href="http://web-argument.com/wp-content/uploads/2008/11/pg-admin.jpg"><img class="aligncenter size-full wp-image-24" title="pg-admin" src="http://web-argument.com/wp-content/uploads/2008/11/pg-admin.jpg" alt="" width="500" height="54" /><br />
</a></p>
<p><strong>The Hooks.</strong></p>
<p>Beftore the version 1.2 to change the functionality of Wordpress modifications (hacks) of the source code was needed.  Now you can  interact with the core of the application using the hooks.<br />
The hooks intercepts the default wordpress behavior. For example, before wordpress shows the content of a post it check if there is a function (hook) registered that modified &#8220;the content&#8221;, if so the content is passed to this function before to print the final result.</p>
<p>There is two principal hooks:</p>
<p><strong>Actions</strong> related to specific events like: add_category, get_header, get_footer.<br />
To use the hook action you need to use this function:<a href="http://codex.wordpress.org/Plugin_API/Action_Reference"><br />
</a></p>
<pre>add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );</pre>
<p>On this link <a href="http://codex.wordpress.org/Plugin_API/Action_Reference">Plugin API/Action Reference</a> you can find the &#8216;hook_name&#8217; that you need to intercept.</p>
<p>The &#8216;priority&#8217; is optional and specifies the order in which the functions associated with a particular action are executed (default: 10).</p>
<p>The last parameter defines how many arguments your function can accept (accepted_args = 1 by default).</p>
<p><strong>Filters</strong> are function to modified the wordpress data like: the_excerpt, the_title, category_description. Visit <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference">Plugin API/Filter Reference</a>.<br />
<strong></strong><br />
If you want to &#8216;hook&#8217; a function to a specific filter action you need this similar function.</p>
<pre>add_filter ( 'hook_name', 'your_function_name', [priority], [accepted_args] );</pre>
<p>In my example I will use a filter hook. So the main file could be something like this:</p>
<pre>&lt;?
add_filter('the_content', 'happy_face_replacer');

function happy_face_replacer ($content) {
     $happy_face_image = "&lt;img src='happy face image URL'&gt;";
     return preg_replace('/happy_face/', $happy_face_image, $content);
}
?&gt;</pre>
<p>The function &#8220;happy_face_replacer&#8221; takes the content of your post ($content) before to be printed and replace the phase &#8220;happy_face&#8221; by the image.</p>
<p>That&#8217;s it.</p>
<p>If you want to try this simple plugin just <a href="http://web-argument.com/wp-content/uploads/2008/11/happy_face_replacer.zip">download </a>the file and install it: <img class="alignnone size-medium wp-image-34" title="happy_face" src="http://web-argument.com/wp-content/uploads/2008/11/happy_face.jpg" alt="" width="32" height="31" /></p>
<p>Here you have some useful links:<br />
<a href="http://codex.wordpress.org/Writing_a_Plugin">Writing a Plugin</a><br />
<a href="http://codex.wordpress.org/Plugin_API/Hooks_2.0.x">Plugin API/Hooks 2.0.x</a><br />
<a href="http://codex.wordpress.org/Plugin_Resources">Plugin Resources</a><br />
<a href="http://codex.wordpress.org/Custom_Queries">Custom Queries</a></p>
]]></content:encoded>
			<wfw:commentRss>http://web-argument.com/writing-a-simple-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	<enclosure url='http://web-argument.com/wp-content/uploads/2008/11/pg-admin-150x60.jpg' length ='4005'  type='image/jpg' />	</item>
		<item>
		<title>Videos</title>
		<link>http://web-argument.com/videos/</link>
		<comments>http://web-argument.com/videos/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 04:42:47 +0000</pubDate>
		<dc:creator>Alain</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://web-argument.com/?p=98</guid>
		<description><![CDATA[Watch the latest videos on YouTube.com

]]></description>
			<content:encoded><![CDATA[<div id="vu_ytplayer_vjVQa1PpcFOBRQMNTkuFEBpgDhU7Kfzteriu5CZEUOA=" style="text-align: center;"><a href="http://www.youtube.com/browse">Watch the latest videos on YouTube.com</a></div>
<p><script src="http://www.youtube.com/watch_custom_player?id=vjVQa1PpcFOBRQMNTkuFEBpgDhU7Kfzteriu5CZEUOA=" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://web-argument.com/videos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
