 <?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>Technixa &#187; wordpress</title>
	<atom:link href="http://www.technixa.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.technixa.com</link>
	<description></description>
	<lastBuildDate>Mon, 23 Nov 2009 00:58:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making an options page for Wordpress Plugin</title>
		<link>http://www.technixa.com/22/11/2009/making-an-options-page-for-wordpress-plugin/</link>
		<comments>http://www.technixa.com/22/11/2009/making-an-options-page-for-wordpress-plugin/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 00:51:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.technixa.com/?p=62</guid>
		<description><![CDATA[<p>Previous posts <a href="http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/" target="_blank">Creating a Widget for Wordpress</a>, <a href="http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/" target="_blank">Create a Simple Plugin for Wordpress</a> and <a href="http://www.technixa.com/16/11/2009/adding-options-to-wordpress-widget/" target="_blank">Adding Options to Wordpress Widget</a> have given an introduction on how I have created a plugin for wordpress.&#160; This final post will show how I added an options page.&#160; The plugin adds php files to different areas and the options will set which files will be active.&#160; This is based mainly on <a href="http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/">Handling Plugins Options in WordPress 2.8 with register_setting()</a>, another similar method can be found at <a href="http://ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/">WordPress Settings API Tutorial</a> which handles the input fields in a different way.</p>
<p>First we need to tell wordpress to create an options screen using </p>
<pre>

add_action('admin_menu', 'technixa_add_page');

function technixa_add_page() {

&#160;&#160;&#160; add_options_page('Technixa options Page', 'Technixa Options', 'manage_options', 'technixa-options', 'technixa_options_page');

}
</pre>
<p align="left">add_options_page creates a link to the page under settings in the admin pages, this can be changed to one of the following add_options_page, add_management_page (tools), add_pages_page, add_posts_page, add_comments_page, add_links_page, add_media_page, add_dashboard_page, add_object_page add_utility_page to change which menu it appears under.</p>
<p align="left">The page created will be titled “Technixa Options Page” and it will be listed under the menu as Technixa options.&#160; <em>manage_options</em> means only people with admin rights will see it available.&#160; the link to the page will be /wp-admin/options-general.php?page=technixa-options and the contents of the page will be contained in the function<em> technixa_options_page</em></p>
<p align="left">We also need to call a function to register the settings to be stored in the database using </p>
<pre>

add_action('admin_init', 'function_technixa_options_init');


function function_technixa_options_init() { 

&#160;&#160;&#160; register_setting('technixa_options', 'plugin_technixa_options', 'technixa_data_validate'); 

&#160;&#160;&#160; }
</pre>
<p>This will register a set of options called <em>technixa_options</em> which will be stored in the database under <em>plugin_technixa_options </em>and will use a function called <em>technixa_data_validate</em> to validate that the input is correct</p>
<p>The next function needed is the actual content of the options page</p>
<pre>

&lt;?php    function technixa_options_page() {
?&gt; 

&lt;div class=&quot;wrap&quot;&gt;  &lt;h2&gt;Technixa options&lt;/h2&gt;

&lt;form method=&quot;post&quot; action=&quot;options.php&quot;&gt;

&lt;?php settings_fields('technixa_options'); ?&gt;

&lt;?php $options = get_option('plugin_technixa_options'); ?&gt;

&lt;table class=&quot;form-table&quot;&gt;

&#160;

&lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;Use Header Addition.&lt;/th&gt;

&lt;td&gt;&lt;input name=&quot;plugin_technixa_options[useheaderfile]&quot; type=&quot;checkbox&quot; value=&quot;1&quot; &lt;?php checked('1', $options['useheaderfile']); ?&gt; /&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;Use footer Addition.&lt;/th&gt;


&lt;td&gt;&lt;input name=&quot;plugin_technixa_options[usefooterfile]&quot; type=&quot;checkbox&quot; value=&quot;1&quot; &lt;?php checked('1', $options['usefooterfile']); ?&gt; /&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;Add before post.&lt;/th&gt;
&lt;td&gt;&lt;input name=&quot;plugin_technixa_options[useprepostfile]&quot; type=&quot;checkbox&quot; value=&quot;1&quot; &lt;?php checked('1', $options['useprepostfile']); ?&gt; /&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;Add after posts.&lt;/th&gt;
&lt;td&gt;&lt;input name=&quot;plugin_technixa_options[useafterpostfile]&quot; type=&quot;checkbox&quot; value=&quot;1&quot; &lt;?php checked('1', $options['useafterpostfile']); ?&gt; /&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;

&lt;p class=&quot;submit&quot;&gt;
 &lt;input type=&quot;submit&quot; class=&quot;button-primary&quot; value=&quot;&lt;?php _e('Save Changes'); ?&gt;&quot; /&gt;
&lt;/p&gt;
&lt;/form&gt;


&lt;/div&gt;
 

&lt;?php } ?&gt;

&#160;
</pre>
<p>This uses php forms, more information on these can be found at <a href="http://www.tizag.com/phpT/forms.php" target="_blank">tizag.com</a> or <a href="http://www.w3schools.com/php/php_forms.asp" target="_blank">w3schools.com</a>.</p>
<p>The final function is the one to validate the input, here I used </p>
<pre>

function technixa_data_validate($input) {
    &#160;&#160;&#160; $input['usefooterfile']&#160;&#160;&#160; = ($input['usefooterfile'] == 1 ? 1 : 0);

&#160;&#160;&#160; $input['useheaderfile']&#160;&#160;&#160; = ($input['useheaderfile'] == 1 ? 1 : 0);

&#160;&#160;&#160; $input['useprepostfile']&#160;&#160; = ($input['useprepostfile'] == 1 ? 1 : 0);

&#160;&#160;&#160; $input['useafterpostfile'] = ($input['useafterpostfile'] == 1 ? 1 : 0);

&#160;&#160;&#160; $input['widget_title']&#160;&#160;&#160;&#160; = wp_filter_nohtml_kses($input['widget_title']);

&#160;&#160;&#160; return $input;

}
</pre>
<p>now that the options are saved they can be retrieved by using <em>get_option.&#160; </em>For example to choose whether to include the header addition in this plugin I use</p>
<pre>

add_action('wp_head', 'technixa_header');
    function technixa_header() {

&#160;&#160;&#160; $options = get_option(&quot;plugin_technixa_options&quot;);

&#160;&#160;&#160; if ($options['useheaderfile']) {

&#160;&#160;&#160;&#160;&#160;&#160;&#160; include &quot;phpfiles/header.php&quot;;

&#160;&#160;&#160; }

}
</pre>
<p> One final thing i added was a settings link in the plugin screen beside the activation link as in <a href="http://wpengineer.com/how-to-improve-wordpress-plugins/">wpengineer.com</a>.</p>
<pre>

add_filter('plugin_action_links', 'technixa_settings_link', 10, 2); 

&#160;&#160;&#160; function technixa_settings_link($links, $file) {
    &#160;&#160;&#160; static $this_plugin;

&#160;&#160;&#160; if( !$this_plugin ) $this_plugin = plugin_basename(__FILE__);

&#160;&#160;&#160; if( $file == $this_plugin ){

&#160;&#160;&#160;&#160;&#160;&#160;&#160; $settings_link = '&lt;a href=&quot;themes.php?page=plugin_technixa_options&quot;&gt;' . __('Settings') . '&lt;/a&gt;';

&#160;&#160;&#160;&#160;&#160;&#160;&#160; $links = array_merge( array($settings_link), $links);

&#160;&#160;&#160; }

&#160;&#160;&#160; return $links;

}
</pre>
<p><a href="http://www.technixa.com/22/11/2009/making-an-options-page-for-wordpress-plugin/">Making an options page for Wordpress Plugin</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
<p><a href="http://www.technixa.com/22/11/2009/making-an-options-page-for-wordpress-plugin/">Making an options page for Wordpress Plugin</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
]]></description>
		<wfw:commentRss>http://www.technixa.com/22/11/2009/making-an-options-page-for-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Options to Wordpress Widget</title>
		<link>http://www.technixa.com/16/11/2009/adding-options-to-wordpress-widget/</link>
		<comments>http://www.technixa.com/16/11/2009/adding-options-to-wordpress-widget/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:54:06 +0000</pubDate>
		<dc:creator>gbrown</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[widget options]]></category>

		<guid isPermaLink="false">http://www.technixa.com/?p=27</guid>
		<description><![CDATA[<p>In two previous Posts (<a href="http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/">Create a Widget for Wordpress</a> and <a href="http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/">Create a Simple Plugin for Wordpress</a>) I showed how I created a plug in to add content from files into the displayed theme.  Now I am going to also add an options page to the admin panel and an option to the widget for setting the displayed title.</p>
<p>First I&#8217;ll show how I added the option of changing the Title of the widget.  This was done following a post on <a href="http://www.lonewolfdesigns.co.uk/wordpress-widgets-control-panels/">Lonewolf Designs</a>.</p>
<p>Previously I activated the widget using</p>
<pre>&lt;?php
add_action("plugins_loaded", "init_technixa");

function init_technixa() {
     register_sidebar_widget("Technixa", "technixa_widget");
}
?&gt;</pre>
<p>Now we also need to activate a control page on the widget by adding a line to make it</p>
<pre><span style="background-color: #f1f1ff;">&lt;?php</span>

function init_technixa() {
    register_sidebar_widget("Technixa", "technixa_widget");
    register_widget_control('Technixa', 'technixa_widget_control');

}

?&gt;</pre>
<p>The extra line <strong>register_widget_control(&#8217;Technixa&#8217;, &#8216;technixa_widget_control&#8217;); </strong>registers the control panel which will be contained within the function called <strong>technixa_widget_control.</strong></p>
<pre>&lt;?php
function technixa_widget_control() {

    $options = get_option("plugin_technixa_options"); 

    if ($_POST['technixa-Submit']) {
        $options['widget_title'] = htmlspecialchars($_POST['technixa-WidgetTitle']);
        update_option("plugin_technixa_options", $options);
    }

// html to show input box

?&gt;

&lt;p&gt;
&lt;label for="technixa-WidgetTitle"&gt;Widget Title: &lt;/label&gt;
&lt;input type="text" id="technixa-WidgetTitle" name="technixa-WidgetTitle" value="&lt;?php echo $options['widget_title']; ?&gt;" /&gt;

&lt;input type="hidden" id="technixa-Submit"  name="technixa-Submit" value="1" /&gt;
&lt;/p&gt;

&lt;?php

}
?&gt;</pre>
<p>Here <strong>$options = get_option(&#8221;plugin_technixa_options&#8221;);</strong> will get any previously saved configuration options from the wordpress database.</p>
<p>Update option is what will store the content of $options in the wordpress database under plugin_technixa_options.  These saved options can be called upon using <strong>get_options</strong>.</p>
<p>For more on this try the following links</p>
<p><a href="http://valums.com/create-wordpress-widget/">Create a Wordpress Widget From Scratch.</a></p>
<p><a href="http://315cmc.tomupton.com/wp-content/uploads/2008/04/writing-a-php-plugin-widget-for-wordpress.pdf">Writing a WordPress Plugin using PHP</a> (PDF download from <a href="http://315cmc.tomupton.com/?p=77">here</a>)</p>
<p><a href="http://www.technixa.com/16/11/2009/adding-options-to-wordpress-widget/">Adding Options to Wordpress Widget</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
<p><a href="http://www.technixa.com/16/11/2009/adding-options-to-wordpress-widget/">Adding Options to Wordpress Widget</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
]]></description>
		<wfw:commentRss>http://www.technixa.com/16/11/2009/adding-options-to-wordpress-widget/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create a Simple Plugin for Wordpress</title>
		<link>http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/</link>
		<comments>http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 02:44:00 +0000</pubDate>
		<dc:creator>gbrown</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.technixa.com/?p=13</guid>
		<description><![CDATA[<p>In my previous <a href="http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/" target="_blank">post</a> I created a plugin which was intended to allow&#160; a widget to be created.&#160; Now I am going to expand on this to give it more functionality.</p>
<p>Already it allows for a custom widget to be added, now I also want it to be able to insert other additional code to various areas.&#160; The purpose is to make additions without editing the theme files themselves.</p>
<p>The previous widget only plugin I have altered to the following which registers the widget and takes the contents of phpfiles/widget.php as the content.</p>
<pre>

&lt;?php add_action(&quot;plugins_loaded&quot;, &quot;init_technixa&quot;);


function init_technixa(){     register_sidebar_widget(&quot;Technixa&quot;, &quot;technixa_widget&quot;); }
function technixa_widget($args) {      include &quot;phpfiles/widget.php&quot;; } 
</pre>
<p align="left">The first thing I want to add is the ability to add to the site header, this would allow additional meta data or javascript to be added.&#160; As long as the theme has <strong>&lt;php wp_head(); ?&gt;</strong> it is possible to easily add further information at this point, usually this if just before the &lt;/head&gt; in the template.&#160; This can be done by adding the following&#160; lines.</p>
<pre>&lt;?phpadd_action('wp_head', 'technixa_header');

function technixa_header() {&#160;&#160;&#160;&#160; include &quot;phpfiles/header.php&quot;;}?&gt;</pre>
<p>This uses <strong>add_action</strong> to execute the function <strong>technixa_header</strong> whenever the <strong>wp_head</strong> hook is encountered. In order for this to work the theme should have <strong>&lt;php wp_head(); ?&gt;</strong> in the header.&#160; If it doesn’t this can easily be added.&#160; I am currently using this method to add the meta tag for googles webmaster tools.</p>
<p>Similarly the following two lines can be used to do the same for the footer, the contents of the file being added where &lt;php wp_footer() ?&gt;</p>
<pre>

&lt;?phpadd_action('wp_footer', 'technixa_footer');

function technixa_footer() {&#160;&#160;&#160;&#160; include &quot;phpfiles/footer.php&quot;; }?&gt;
</pre>
<p>Currently my footer.php contains my Google Analytics code.</p>
<p>The Final thing I wanted to achieve was to add content before or after the post content itself.&#160; Again I managed this with a few lines.</p>
<pre>
<p align="left"><font style="background-color: #f1f1ff">&lt;?php</font>add_action('the_content', 'technixa_content'); 

function technixa_content($content) {     include &quot;phpfiles/content_top.php&quot;;
     echo $content;&#160;&#160;&#160;&#160;&#160; include &quot;phpfiles/content_bottom.php&quot;; }?&gt;
</pre>
<p align="left">This will show the post content with the two files before and after.&#160; At the moment I am using it to show the addthis button at the bottom and the google ad at the top.&#160; I was worried that this method would interfere with other addons, however, when I installed YARPP which adds related posts at the end of the post there didn’t seem to be any problem.</p>
<p align="left">I am not sure that the method I have used to add content to the post is the best way,&#160; if I discover a better way I will update this post.</p>
<p align="left">So there we have my first ever Wordpress Addon, this is a simple yet powerful addon which can be used to make additions to themes without the need to change the actual theme file.</p>
<p align="left">You can <a href="http://www.technixa.com/wp-content/uploads/2009/11/technixa_02.zip">download the full commented file here</a>.&#160; To make changes change the php files contained within the phpfiles folder with whatever content you want.</p>
<p><a href="http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/">Create a Simple Plugin for Wordpress</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
<p><a href="http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/">Create a Simple Plugin for Wordpress</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
]]></description>
		<wfw:commentRss>http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a Widget for Wordpress.</title>
		<link>http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/</link>
		<comments>http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 02:03:38 +0000</pubDate>
		<dc:creator>gbrown</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/</guid>
		<description><![CDATA[<h2>Why make your own widget?</h2>
<p>If you want to add something to your Blog sidebar you could either find a widget that already does the job or alternatively add it yourself to the template.  However with your own widget you can make it what you want and if you change theme it would cut down on the edits required to move the functionality to the new template.</p>
<h2>Create a Simple Plugin.</h2>
<p>The plugin will be a php file installed to the wp-content/plugins directory of your website, this could be in its own folder or just the php file on its own.  In this example I will create it as plugins/technixa/technixa.php.</p>
<p>In order for wordpress to recognise the plugin the php file needs some information added.  The following Header is what I used it contains the information wordpress will need to register the file as a plugin.</p>
<pre>&lt;?php
/*
Plugin Name: Technixa
Plugin URI: http://www.technixa.com/
Description: Test widget
Author: Gordon Brown
Version: 1
Author URI: http://www.technixa.com/
*/
?&gt;</pre>
<p>At this point Wordpress will show the file as an addon in the control panel and let you activate it, it doesn’t currently do anything or show as a widget.</p>
<p>First we need to define something for the widget to do so we will add a function.</p>
<pre>&lt;?php
function technixa_widget() {
   echo "HELLO WORLD";
}
?&gt;</pre>
<p>At this point we now have a fully functioning simple plugin, we could add <strong>&lt;?php technixa_widget(); ?&gt;</strong> somewhere in the template and it would insert the plugin function at that point.  However we want a widget we can drag and drop into the sidebar of a compatible theme so some more code is now required.</p>
<pre>&lt;?php
add_action("plugins_loaded", "init_technixa");
function init_technixa() {
     register_sidebar_widget("Technixa", "technixa_widget");
}
?&gt;</pre>
<p><strong>add_action</strong> tells wordpress to call a function whenever it does a certain action, in this case when the plugins are loaded it carries out the function called init_technixa.</p>
<p>One final thing we can also do is to use the layout from the Theme.  To do this we need to use <strong>import($args)</strong> which will import the information needed.  Now <strong>function technixa_widget()</strong> will change to:</p>
<pre>&lt;?php
function technixa_widget($args) {
   extract($args);
   echo $before_widget;
   echo $before_title; echo “Title”; echo $after_title;
   echo “HELLO WORLD”;
   echo $after_widget;
}
?&gt;</pre>
<p>The whole code together gives the basic widget, echo “HELLO WORLD”; can be replaced with whatever you want the widget to contain.</p>
<pre>&lt;?php
/*
Plugin Name: Technixa
Plugin URI: <a href="http://www.technixa.com/">http://www.technixa.com/</a>
Description: Test widget
Author: Gordon Brown
Version: 1
Author URI: <a href="http://www.technixa.com/">http://www.technixa.com/</a>
*/ 

add_action("plugins_loaded", "init_technixa");
function init_technixa() {

    register_sidebar_widget("Technixa", "technixa_widget");
} 

function technixa_widget($args) {    extract($args);    echo $before_widget;    echo $before_title; echo “Title”; echo $after_title;

    echo “HELLO WORLD”;

    echo $after_widget;

}
?&gt;</pre>
<p>The final file can be downloaded from <a rel="nofollow" href="http://www.technixa.com/wp-content/uploads/2009/11/technixa_01.zip">here</a>.</p>
<p>There is also an online tool to generate widgets called <a href="http://widgetifyr.com/startup">widgetifyr</a>.</p>
<p>See also the <a href="http://www.technixa.com/08/11/2009/create-a-simple-plugin-for-wordpress/">next post</a> which extends this into a full plugin with additional functionallity.</p>
<p><a href="http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/">Creating a Widget for Wordpress.</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
<p><a href="http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/">Creating a Widget for Wordpress.</a> is a post from: <a href="http://www.technixa.com">Technixa</a></p>
]]></description>
		<wfw:commentRss>http://www.technixa.com/06/11/2009/creating-a-widget-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
