<?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>Weblimner &#187; Tutorial</title>
	<atom:link href="http://www.weblimner.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weblimner.com</link>
	<description></description>
	<lastBuildDate>Sun, 15 Aug 2010 23:49:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Making of Q-List Plugin for Wordpres &#8211; 1 of 2</title>
		<link>http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/</link>
		<comments>http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 03:35:30 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[plugin naming]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wpdb]]></category>
		<category><![CDATA[wp_options]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=193</guid>
		<description><![CDATA[This is the first article of a series of articles explaining how I created the Q-List WordPress plugin. First article will explain the administration section and the second will explain the user interface. This article consists of the following steps: Versioning your plugins database tables, and updating them Creating your administration interface Using wp options [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first article of a series of articles explaining how I created the Q-List WordPress plugin. First article will explain the administration section and the second will explain the user interface. This article consists of the following steps:</p>
<ul>
<li>Versioning your plugins database tables, and updating them</li>
<li>Creating your administration interface</li>
<li>Using wp options table in your database for your plugin options</li>
</ul>
<p><span id="more-193"></span><br />
First we are going to start with the naming of our plugin. This step is really important if you want your plugin to work correctly. You need to name the folder same as your plugin’s file name. In our example we are going to name our plugin file q-list-list-creator.php and store it in q-list-list-creator. So our file structure is;<br/><br />
<img src="http://www.weblimner.com/wp-content/uploads/2010/2/filestructure.gif" alt="File" /><br/><br />
After you place the file under the right place, now it’s time for our comment section. If you don’t put this into your plugin, WordPress won’t know your file is a plugin. The following is the way I kept my plugins comment section, it&#8217;s pretty simple and yet keeps track of updates. For the full list of comments section, you can check <a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">here</a>.<br/></p>
<pre class="php">/*
Plugin Name: Q-List
Plugin URI: http://www.weblimner.com/plugin/q-lists-list-creator/
Description: Create a list on your website and let members to vote the items of the list.
Author: Ali Sipahioglu
Author URI: http://www.weblimner.com
Version: 1.0
Change Log:
2010-30-01  1.0: In this version, users can vote without being a member of your website. Cookies are used. Design is changed. Percentages are shown for the results.
2010-20-01  0.6: Ability to see the results of the votes
2010-08-01  0.5: First release
*/</pre>
<p>The way the change log works is; you put your date first and then the version number and then briefly describe the updates you made. This is actually a good habit for when you go back to your code in the future, keeping track of an update and what it was.<br />
<br/><br />
<span class="important">Don&#8217;t forget to cover your whole file&#8217;s content with  tags.</span><br />
<br/><br />
At this point, WordPress will know the presence of your plugin, you will see it if you go to the wp-admin &gt; plugins.<br />
<br/><br />
Now we need to create the link to your plugin in your Settings menu. For that, create an action to hook your function to your admin menu. To do so;<br />
<br/></p>
<pre class="php">add_action('admin_menu', 'qlist_menu');</pre>
<p>qlist_menu is the function name that is going to create the menu item in your admin menu, so let&#8217;s create our qlist_menu function.</p>
<pre class="php">function qlist_menu(){
     add_options_page('Q-List Options', 'Q-List Options', 'administrator', 'qlist_unique', 'qlist_options');
}
</pre>
<p><br/><br />
Options are as follows;</p>
<ol>
<li>Title of your plugin in the administration.</li>
<li>Link that appears in the settings menu.</li>
<li>Capability required to see the menu link. In our case, you need to have administrator privileges to see it. You also have editor, author, contributor, subscriber options.</li>
<li>This has to be a unique name different from any plugin you might install to your WordPress installation so its better to keep your plugin name before it and then just but a string at the end like I did.</li>
<li>Name of the function that&#8217;s going to handle the administration view.</li>
</ol>
<p><br/>Now its time for your function.<br/></p>
<pre class="php">function qlist_options(){

}</pre>
<p><br/><br />
In our function we are going to use database calls so we need the database class of WordPress (<a href="http://codex.wordpress.org/Function_Reference/wpdb_Class" target="_blank">wpdb</a>). So lets add the following code to the first line of your function.</p>
<pre class="php">global $wpdb;</pre>
<p><br/>First we are going to create our form on the page.</p>
<pre class="php">$i=0;
echo '&lt;div class="wrap"&gt;
	 &lt;h2&gt;Q-List &lt;b&gt;Add New&lt;/b&gt;&lt;/h2&gt;
		 &lt;form method="post" action=""&gt;
		 &lt;table&gt;
			 &lt;tr&gt;
				&lt;th scope="row"&gt;Question&lt;/th&gt;
				&lt;td&gt;&lt;input type="text" name="question'.$i.'" size="60" /&gt;&lt;/td&gt;
				&lt;td&gt;Order: &lt;input type="text" name="order'.$i.'" size="5"/&gt;&lt;/td&gt;
			 &lt;/tr&gt;
			 &lt;tr&gt;
				 &lt;td colspan="3" align="center"&gt;
					 &lt;input type="hidden" name="addnewform" value="1"/&gt;
					 &lt;input type="submit" value="Save" /&gt;
				 &lt;/td&gt;
			 &lt;/tr&gt;
 ';
 echo     '&lt;/table&gt;&lt;/form&gt;';
 echo '&lt;h2&gt;Q-List &lt;b&gt;Edit&lt;/b&gt;&lt;/h2&gt;

 ';
 $db_questions = $wpdb-&gt;get_results("SELECT * from ".$wpdb-&gt;prefix."qlists order by q_order,question");
 foreach ($db_questions as $db_question) {$i++;
 echo
 '
 &lt;form method="post" action=""&gt;
	 &lt;table&gt;
		 &lt;tr&gt;
		 &lt;th scope="row"&gt;Question #'.($i-1).'&lt;/th&gt;
			 &lt;td&gt;&lt;input type="text" name="question" size="60" value="'.$db_question-&gt;question.'"/&gt;&lt;/td&gt;
			 &lt;td&gt;
			 Order: &lt;input type="text" name="order" size="5" value="'.$db_question-&gt;q_order.'"/&gt;
			 &lt;input type="hidden" name="updateform" value="'.$db_question-&gt;q_id.'"/&gt;
			 &lt;input type="submit" value="Update" /&gt;
			 &lt;a href="options-general.php?page=qlist_unique&amp;amp;delete='.$db_question-&gt;q_id.'" onclick="return confirm(\'You sure you want to delete?\');"&gt;Delete&lt;/a&gt;
			 &lt;/td&gt;
		 &lt;/tr&gt;
	 &lt;/table&gt;
 &lt;/form&gt;
 ';
 }

 echo     '&lt;/div&gt;';</pre>
<p>First part of our code only shows the empty form for a new step an admin might want to add. We set our action to nothing so when we submit it just comes back to the same page and then we query our database to see if there are any steps are already in. In our query we have &#8220;$wpdb-&gt;prefix&#8221; which creates that &#8220;wp_&#8221; in most cases that you have set when you set up your WordPress. And then its a foreach statement that goes through our array of results and prints them onto the page.<br />
<br/><br />
At this point besides our database updates, deletes, and adds our administration screen is set. Now its time to handle our form submissions.<br/></p>
<pre class="php">if($_POST['addnewform']){
 // Assign all the questions to an array
 $f_q= $HTTP_POST_VARS;
 for($a=0;$a&lt;((count($f_q)/2)-1);$a++){
	$form_questions[$a]["question"]=$_POST["question".($a+1)];
	$form_questions[$a]["order"]=$_POST["order".($a+1)];
 }
 // Get them into the database
 for($a=0;$a&lt;count($form_questions);$a++){
	 $wpdb-&gt;insert($wpdb-&gt;prefix."qlists",array('question'=&gt;$form_questions[$a]["question"],'q_order'=&gt;$form_questions[$a]["order"]),array( '%s', '%d' ));
 }
 }
 if($_POST['updateform']&gt;0){
	 $wpdb-&gt;update($wpdb-&gt;prefix."qlists",array('question'=&gt;$_POST['question'],'q_order'=&gt;$_POST["order"]),array( 'q_id' =&gt; $_POST['updateform'] ),array( '%s', '%d' ),array( '%d' ));
 }
 if($_GET['delete']){
	$wpdb-&gt;query("DELETE FROM ".$wpdb-&gt;prefix."qlists WHERE q_id = '".$_GET['delete']."'");
 }</pre>
<p>First if statement checks if it was a add new form by checking a hidden field that was set to 1 in our form. In our if statement I run through the array of post elements and save them into a multi-dimensional array and then I insert them into the WordPress database with the insert function. I am not going to explain how to do for loops in this article since I assume anyone that is creating a plugin for WordPress should know that much PHP. Now our insert function first gets the table name which is qlists with the prefix just like the way I explained earlier. Secondly it gets the an array for where you are going to put what so in our case its question that gets the question, q_order gets the order. And our last variable that we send in is an array that explains what type of data we are sending to each column in the database. &#8220;questions&#8221; is a string field so its %s and q_order is an integer field so its getting %d.  You can read more on this on the <a href="http://codex.wordpress.org/Function_Reference/wpdb_Class" target="_blank">wpdb</a> class page.<br />
<br/><br />
Next up is our update function. We update each step by itself, no loop going on here. All we do is check if it is an update form and if it is we update the database record. Only difference in this function is we need to tell what were going to update. In our case its determined by q_id that we got from the form and its an integer so we&#8217;ve set it at the end with %d.<br />
<br/><br />
That being said our administration section is done.<br />
<br/><br />
Now its time for our activation hook so that when someone activates/upgrades our plugin, our database is set up right. First we need to hook our function that is going to do that to the activation. We do this with the following code;<br />
<br/>
<pre class="php">register_activation_hook( __FILE__, 'qlist_activate' );</pre>
<p>Our function name is qlist_activate. Now its turn to create the function.</p>
<pre class="php">function qlist_activate() {
 global $wpdb;
 $qlist_db_version = "1.2";
 // Creating Questions Table
 $table_name = $wpdb-&gt;prefix . "qlists";
 if($wpdb-&gt;get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
	$sql = "CREATE TABLE " . $table_name . " (
	 `q_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
	 `question` VARCHAR( 250 ) NOT NULL ,
	 `q_order` INT NOT NULL
 );";

 // Creating Answers Table
 $answers_table_name = $wpdb-&gt;prefix . "qlists_answers";

 $sql .= "CREATE TABLE " . $answers_table_name . " (
	 `a_id` INT NOT NULL AUTO_INCREMENT  PRIMARY KEY ,
	 `q_id` INT NOT NULL ,
	 `u_id` CHAR ( 17 ) NOT NULL ,
	 `answer` INT NOT NULL
 );";
 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
 dbDelta($sql);

 }

 $client_qlist_db_version = get_option('qlist_db_version');
 if($client_qlist_db_version!=$qlist_db_version){
	$answers_table_name = $wpdb-&gt;prefix . "qlists_answers";
	 $sql_up = "CREATE TABLE " . $answers_table_name . " (
	 `a_id` INT NOT NULL AUTO_INCREMENT  PRIMARY KEY ,
	 `q_id` INT NOT NULL ,
	 `u_id` CHAR ( 17 ) NOT NULL ,
	 `answer` INT NOT NULL
 );";
 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
 dbDelta($sql_up);
 }

 add_option("qlist_db_version", $qlist_db_version); // If the database is ever needed to be updated
}</pre>
<p>We are going to do a database connection again so we need our global $wpdb in the first line. And right after that we&#8217;ve set up the version of our database.<br />
<br/><br />
First we create the table that is going to hold the questions in our list. We set the table name with the wpdb prefix with $table_name = $wpdb-&gt;prefix . &#8220;qlists&#8221;;<br />
<br/><br />
Now we check if the table is already created by just doing a show table statement in the database looking for our table name and if its not set we add our sql statement to create our table into a variable ($sql). Right after that we set the name for our answers table into a variable. Then we create an sql statement for that table and append that to our current $sql variable. Now the following two lines are important for versioning your database in WordPress. You need to call the upgrade.php file and then send your $sql into a function called dbDelta like I did in our example. This is fine if you are not planning on making any changes to your database in the future, which is probably not the case since there always is a change you might need.<br />
<br/><br />
Now we get the current version of our database if it is already set up with $client_qlist_db_version = get_option(&#8216;qlist_db_version&#8217;);<br />
<br/><br />
get_option is a function that gets an option that is set up in the WordPress options table in your database. You can use that table for other data too. Ill show you how to set data into that table on the last line of our activation function.<br />
<br/><br />
Now we compare our version of the tables to the version of our tables that are currently set. If an upgrade is needed we again create our sql statement that would create the table from scratch. Rest is simple, we call our upgrade file in and send our sql line to dbDelta function<br />
<br/><br />
NOTE: DO NOT CREATE AN UPGRADE STATEMENT, it should be a create table statement.<br />
<br/><br />
Now to create the option that is going to set the current db version into the WordPress options table; all you need to do is the following code;<br />
add_option(&#8220;qlist_db_version&#8221;, $qlist_db_version);<br />
<br/><br />
That concludes our administration section of our plugin. You can download the most current version of the plugin from <a href="http://wordpress.org/extend/plugins/q-lists-list-creator/">WordPress repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coming up Post &#8211; Making of Q-List Plugin for WordPress</title>
		<link>http://www.weblimner.com/weblimner/coming-up-post-making-of-q-list-plugin-for-wordpress/</link>
		<comments>http://www.weblimner.com/weblimner/coming-up-post-making-of-q-list-plugin-for-wordpress/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 23:38:01 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Weblimner]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[q-list]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=183</guid>
		<description><![CDATA[I am working on a series of articles about the making of the Q-List List Creator plugin. I will divide the series into two. First one will be about the administration section and the second one will be about the user interface. Please let me know if you want anything else included into the articles [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a series of articles about the making of the <a href="http://wordpress.org/extend/plugins/q-lists-list-creator/">Q-List List Creator</a> plugin. I will divide the series into two. First one will be about the administration section and the second one will be about the user interface. Please let me know if you want anything else included into the articles so I can incorporate them as I write the article.<br/><br/></p>
<p>The series will have;<br/><br/></p>
<ul>
<li><strong><a href="http://www.weblimner.com/tutorial/making-of-q-list-plugin-for-wordpres-1-of-2/">Administration Section</a></strong>
<ul>
<li>Versioning your plugins database tables, and updating them</li>
<li>Creating your administration interface</li>
<li>Using wp options table in your database for your plugin options</li>
</ul>
</li>
<li><strong><a href="http://www.weblimner.com/plugin/making-of-q-list-plugin-for-wordpres-2-of-2/">User Interface</a></strong>
<ul>
<li>Using tags in your posts like [qlist]</li>
<li>Handling cookies for your plugin</li>
<li>Handling forms</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/weblimner/coming-up-post-making-of-q-list-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use Google Calendar as your Default on your iPhone</title>
		<link>http://www.weblimner.com/tutorial/how-to-use-google-calendar-as-your-default-on-your-iphone/</link>
		<comments>http://www.weblimner.com/tutorial/how-to-use-google-calendar-as-your-default-on-your-iphone/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 22:44:33 +0000</pubDate>
		<dc:creator>Ali Sipahioglu</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[syncronize]]></category>

		<guid isPermaLink="false">http://www.weblimner.com/?p=141</guid>
		<description><![CDATA[I have been looking for a way to access a calendar on the go and also on my computer and if you are using a PC you don&#8217;t have iCal like Mac users you end up having multiple calendars. With this simple setup, you can use your Google Calendar on your iphone like it is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been looking for a way to access a calendar on the go and also on my computer and if you are using a PC you don&#8217;t have iCal like Mac users you end up having multiple calendars. With this simple setup, you can use your Google Calendar on your iphone like it is your default calendar and also your phone will sync itself to the google calendar too so if you view your calendar online, you will see your entries.<br />
<span id="more-141"></span><br/></p>
<h3>Here are the steps you need to follow</h3>
<ol>
<li>On your iPhone, go to Settings &gt; Mail, Contacts, Calendars &gt; Add Account &gt; Other &gt; Add CalDAV Account<br />

<a href="http://www.weblimner.com/wp-content/gallery/posts/img_0153.gif" title="" class="thickbox" rel="singlepic22" >
	<img class="ngg-singlepic ngg-left" src="http://www.weblimner.com/wp-content/gallery/cache/22__320x240_img_0153.gif" alt="img_0153" title="img_0153" />
</a>
 
<a href="http://www.weblimner.com/wp-content/gallery/posts/img_0154.gif" title="" class="thickbox" rel="singlepic23" >
	<img class="ngg-singlepic ngg-left" src="http://www.weblimner.com/wp-content/gallery/cache/23__320x240_img_0154.gif" alt="img_0154" title="img_0154" />
</a>

<div class="clear"></div>
</li>
<li>For the CalDAV settings, enter the following information. Note that your username should be the email address you use to access your Google calendar as well as the password.
<a href="http://www.weblimner.com/wp-content/gallery/posts/3.gif" title="" class="thickbox" rel="singlepic20" >
	<img class="ngg-singlepic" src="http://www.weblimner.com/wp-content/gallery/cache/20__240x220_3.gif" alt="3" title="3" />
</a>
</li>
<li>Then tap &#8220;Next&#8221; and your account will be verified.</li>
<li>Now your calendar is set up but you need to go to your &#8220;Mail, Contacts, Calendars&#8221; window again and scroll all the way down to your &#8220;Calendars&#8221; and choose your Google Account from there.<br />

<a href="http://www.weblimner.com/wp-content/gallery/posts/defaultcale.gif" title="" class="thickbox" rel="singlepic24" >
	<img class="ngg-singlepic" src="http://www.weblimner.com/wp-content/gallery/cache/24__320x240_defaultcale.gif" alt="defaultcale" title="defaultcale" />
</a>

</li>
</ol>
<p><br/></p>
<ul>
<li><strong>Note:</strong> If you run into any problems with the verification,tap &#8220;Advanced settings&#8221; and make sure that &#8220;Use SSL&#8221; is On, that the port is 443, and that your Account URL includes the sign &#8220;@&#8221; in your email address.<br />

<a href="http://www.weblimner.com/wp-content/gallery/posts/4.gif" title="" class="thickbox" rel="singlepic21" >
	<img class="ngg-singlepic ngg-left" src="http://www.weblimner.com/wp-content/gallery/cache/21__240x220_4.gif" alt="4" title="4" />
</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.weblimner.com/tutorial/how-to-use-google-calendar-as-your-default-on-your-iphone/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Object Caching 459/493 objects using disk

Served from: www.weblimner.com @ 2012-02-06 03:28:09 -->
