<?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>WP Engineer &#187; development</title>
	<atom:link href="http://wpengineer.com/tag/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress Options Passed To JavaScript #2</title>
		<link>http://wpengineer.com/2457/wordpress-options-passed-to-javascript-2/</link>
		<comments>http://wpengineer.com/2457/wordpress-options-passed-to-javascript-2/#comments</comments>
		<pubDate>Fri, 18 May 2012 10:08:39 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2457</guid>
		<description><![CDATA[In our first article of this mini series, I explained how to pass with JSON from PHP to JS. Alternativly you can do this with the WordPress function wp_localize_script(), but contains some pitfalls. Therefore this little tutorial, also you should think about it in advance about these two solutions. The functions serves to pass strings, [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://wpengineer.com/?p=2315" title="Article: WordPress Options Passed To JavaScript #1">our first article</a> of this mini series, I explained how to pass with JSON from PHP to JS. Alternativly you can do this with the WordPress function <code>wp_localize_script()</code>, but contains some pitfalls. Therefore this little tutorial, also you should think about it in advance about these two solutions.<br />
<span id="more-2457"></span><br />
The functions serves to pass strings, at first to localize; so for the translate theme via Javascript. Therefore you can easily pass value and query them in Javascript. The most important point is, that this function can decode HTML Entities. Also important, that the script is recognized in advance; include it via <code>wp_enqueue_script()</code>.</p>
<p>This example should explain it.</p>
<pre>
// on admin area enqueue the scripts
add_action( &#039;admin_enqueue_scripts&#039;, &#039;fb_admin_enqueue_scripts&#039; );
function fb_admin_enqueue_scripts( $where ) {
	// separation in dev and live
	$suffix = defined(&#039;SCRIPT_DEBUG&#039;) &amp;&amp; SCRIPT_DEBUG ? &#039;.dev&#039; : &#039;&#039;;

	// enqueue of script, identifikation on the string-ID
	wp_enqueue_script(
		&#039;example_script_id&#039;,
		plugins_url( &#039;/js/my-example-script&#039; . $suffix. &#039;.js&#039;, __FILE__ ),
		array( &#039;jquery&#039; ),
		&#039;&#039;,
		TRUE
	);

	// data via Array
	// array with data; also possible via get_option( &#039;my_option_string&#039; )
	$data = array(
		&#039;some_string&#039; =&gt; __( &#039;Some string to translate&#039; ),
		&#039;a_value&#039; =&gt; &#039;10&#039;
	);
	// localize the data, identifier via script-ID and create object for JS
	wp_localize_script( &#039;example_script_id&#039;, &#039;js_object_name&#039;, $data );
}
</pre>
<p>With this little example everything is done on the PHP-side; the content of the array are known now as object <code>js_object_name</code> and can be use via the name-string <code>js_object_name</code> in JS.</p>
<p>Now some hints, which should help, if it comes to problems or which link to <a href="http://wpengineer.com/?p=2315">solutions via JSON</a> directly.<br />
The function <code>wp_localize_script()</code> decodes HTML Entities, which is kind of important, but not always the perfect solution. The function uses <code>json_encode()</code>, which can let to problems in multi-dimensional arrays in connection with the decoding of entities. As soon as the array has more than one dimension, I recommend <a href="http://wpengineer.com/?p=2315">JSON without the WP Core solution</a> via <code>wp_localize_script()</code>.</p>
<p>With WordPress 3.4 it will get better and the function will be more useful - let's see. I currently use on multiple dimensions rather JSON directly. The solution from the core would be nice, I like the handling and it would be clearly and comprehensively utilizable.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2457/wordpress-options-passed-to-javascript-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress Options Passed To JavaScript #1</title>
		<link>http://wpengineer.com/2315/wordpress-options-passed-to-javascript-1/</link>
		<comments>http://wpengineer.com/2315/wordpress-options-passed-to-javascript-1/#comments</comments>
		<pubDate>Wed, 16 May 2012 09:08:02 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2315</guid>
		<description><![CDATA[In WordPress you are not always in the PHP world and so you have to pass settings and data from the database to scripts sometimes. In many Plugins you can find solutions in loading the wp-load.php and therefore access to all features of WordPress. Long ago Otto (Samuel Wood) already referred to this fact and [...]]]></description>
			<content:encoded><![CDATA[<p>In WordPress you are not always in the PHP world and so you have to pass settings and data from the database to scripts sometimes. In many Plugins you can find solutions in loading the wp-load.php and therefore access to all features of WordPress. Long ago <a href="http://ottopress.com/2010/dont-include-wp-load-please/">Otto (Samuel Wood)</a> already referred to this fact and this articles shows solutions. Questions still there and still there are Plugins that load the wp-load.php precisely because of such problems.</p>
<p>A similar problem arises when the source of the scripts is not just written in the footer area of WordPress, but outsourced to a file and via <code>wp_enqueue_script()</code> included. Only then WordPress can manage, compromises and optimizes these scripts for delivery. Therefore I would like to show two examples, how to pass data from PHP to JS.<br />
<span id="more-2315"></span><br />
The first snippet uses the pass of values ​​via JSON to get the values ​​from the database with the current resources in PHP and the script stores directly in the header of the page the values ​​as an object.</p>
<pre>
add_action( &#039;admin_enqueue_scripts&#039;, &#039;fb_print_scripts&#039; );

function fb_print_scripts() {
	global $current_screen;

	if ( isset( $current_screen -&gt; id ) &amp;&amp; ! in_array( $current_screen -&gt; id, array( &#039;post&#039;, &#039;page&#039; ) ) )
		return;

	if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
		$options = get_site_option( &#039;my_options_id&#039; );
	else
		$options = get_option( &#039;my_options_id&#039; );

	if ( ! $options )
		return;
	?&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		var my_json_object = &lt;?php echo json_encode( $options ); ?&gt;;
	&lt;/script&gt;
	&lt;?php
}
</pre>
<p>The above function gives the values ​​from the database as a JSON object in the head of the backend, as the page was requested in the first step of the function. Via <code>$current_screen</code> it will be checked so it will be only delivered if you are on one of the defined pages (post, page).</p>
<p>The next step is common practice and best solution to include scripts in WordPress. Thereby I will include the JS file, which then has accesses to the JSON object.</p>
<pre>
add_action( &#039;admin_enqueue_scripts&#039;, &#039;fb_admin_enqueue_scripts&#039; );

function fb_admin_enqueue_scripts( $where ) {

	if ( ! in_array( $where, array( &#039;post.php&#039;, &#039;post-new.php&#039;, ) )
		return;

	$suffix = defined(&#039;SCRIPT_DEBUG&#039;) &amp;&amp; SCRIPT_DEBUG ? &#039;.dev&#039; : &#039;&#039;;

	wp_enqueue_script(
		self :: get_textdomain() . &#039;_script&#039;,
		plugins_url( &#039;/js/my_script&#039; . $suffix. &#039;.js&#039;, __FILE__ ),
		array( &#039;jquery&#039;, &#039;my_other_script&#039; ),
		&#039;&#039;,
		TRUE
	);

}
</pre>
<p>The script accesses directly the object that is processed.</p>
<pre>
jQuery( document ).ready( function( $ ) {

	if ( typeof my_json_object == &#039;undefined&#039; )
		return;

// debug in console of Browser
console.dir( my_json_object ); 

});
</pre>
<p>Another solution will be presented in the following post at this series.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2315/wordpress-options-passed-to-javascript-1/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>First or Last Page in Page-Structures of WordPress</title>
		<link>http://wpengineer.com/2440/first-or-last-page-in-page-structures-of-wordpress/</link>
		<comments>http://wpengineer.com/2440/first-or-last-page-in-page-structures-of-wordpress/#comments</comments>
		<pubDate>Tue, 08 May 2012 10:16:26 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2440</guid>
		<description><![CDATA[Now and then little snippets are pretty useful. For a fix in a Premium-Theme, I needed a kind of evaluation, where I am in the site structure and with little effort I was able to expand the classes and react with CSS. The following code shows the basic for it and get_pages() is the key [...]]]></description>
			<content:encoded><![CDATA[<p>Now and then little snippets are pretty useful. For a fix in a Premium-Theme, I needed a kind of evaluation, where I am in the site structure and with little effort I was able to expand the classes and react with CSS.</p>
<p>The following code shows the basic for it and <code>get_pages()</code> is the key from the core of WordPress to get to these results. This function provides the necessary result of using the parameter and the output via the parameter <code>sort_order</code> provides the sequence and identification of the first page, which is then either the first or last page in this structure.<br />
<span id="more-2440"></span></p>
<pre>
// First post in structure
// simple, but usefull <img src='http://wpengineer.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
global $post;

$page_childs = get_pages( &#039;child_of=&#039; . $post-&gt;post_parent . &#039;&amp;sort_order=ASC&#039; );
$first_child = $page_childs&#091;0&#093;;

if ( get_the_ID() === (int) $first_child-&gt;ID )
 echo &#039;First Child&#039;;
</pre>
<pre>
// Last post in structure
global $post;

$page_childs = get_pages( &#039;child_of=&#039; . $post-&gt;post_parent . &#039;&amp;sort_order=DESC&#039; );
$last_child  = $page_childs&#091;0&#093;;

if ( get_the_ID() === (int) $last_child-&gt;ID )
 echo &#039;Last Child&#039;;
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2440/first-or-last-page-in-page-structures-of-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Load Minimum of WordPress</title>
		<link>http://wpengineer.com/2449/load-minimum-of-wordpress/</link>
		<comments>http://wpengineer.com/2449/load-minimum-of-wordpress/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 05:44:39 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2449</guid>
		<description><![CDATA[A small contribution for all those using WordPress as a backend, framework or something similar. The applications, especially in the B2B sector, becoming more and more, as do the questions. So far, I've always liked to recommended BackPress. But even a well-maintained standard is feasible, with all its advantages in the context of the philosophy [...]]]></description>
			<content:encoded><![CDATA[<p>A small contribution for all those using WordPress as a backend, framework or something similar. The applications, especially in the B2B sector, becoming more and more, as do the questions.</p>
<p>So far, I've always liked to recommended <a href="http://backpress.org/">BackPress</a>. But even a well-maintained standard is feasible, with all its advantages in the context of the philosophy of updates. WordPress reduces initializing to a minimum, if the constant <code>SHORTINIT</code> is set.<br />
<span id="more-2449"></span><br />
The <code>wp-settings.php</code> of WordPress is the key.</p>
<pre>
// Stop most of WordPress from being loaded if we just want the basics.
if ( SHORTINIT )
	return false;
</pre>
<p>Thus, the loading process is much slimmer and files that are loaded later, must be integrated via a Plugin or Theme functions. The ability is worth it and not infrequently, the part of WordPress in some projects is so small compared to your own developments, that this is worth to do.</p>
<p>Activating in <code>wp-config.php</code> via <code>define( 'SHORTINIT', TRUE );</code> is done quickly and you can start the test, but note: the globals <code>$wp, $wp_query, $wp_the_query</code> was set as <code>NULL</code>.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2449/load-minimum-of-wordpress/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Don’t use strlen()</title>
		<link>http://wpengineer.com/2410/dont-use-strlen/</link>
		<comments>http://wpengineer.com/2410/dont-use-strlen/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 09:08:49 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[WPengineer Misc]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2410</guid>
		<description><![CDATA[Each time I see someone use strlen() I cringe. It will break. Despite its name, strlen() doesn’t count characters. It counts bytes. In UTF-8 a character may be up to four bytes long. So what happens if we use strlen() and its companion substr() to shorten the title of post? &#60;?php # -*- coding: utf-8 [...]]]></description>
			<content:encoded><![CDATA[<p>Each time I see someone <a href="http://www.google.com/cse?cx=008094839757605916882%3Af6pwe-gmjka&amp;q=strlen">use <code>strlen()</code></a> I cringe. It <strong>will</strong> break.</p>
<p>Despite its name, <code>strlen()</code> doesn’t count characters. It counts bytes. In <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> a character may be up to four bytes long.</p>
<p>So what happens if we use <code>strlen()</code> and its companion <code>substr()</code> to shorten the title of post?</p>
<pre>&lt;?php # -*- coding: utf-8 -*-
declare( encoding = &#039;UTF-8&#039; );
header(&#039;Content-Type: text/plain;charset=utf-8&#039;);

$string = &#039;Doppelgänger&#039;;
print &#039;strlen():    &#039; . strlen( $string ) . &quot;\n&quot;;
print &#039;mb_strlen(): &#039; . mb_strlen( $string, &#039;utf8&#039; ) . &quot;\n\n&quot;;

print &#039;substr():    &#039; . substr( $string, 0, 8 ) . &quot;\n&quot;;
print &#039;mb_substr(): &#039; . mb_substr( $string, 0, 8, &#039;utf8&#039; );</pre>
<p>Output:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/broken-doppelgaenger.png" alt="" width="200" height="150" class="alignnone size-full wp-image-2411" /></p>
<p>I have to use an image here. If I had used the plain text output our newsfeed would break. And that’s what happens each time you use strlen() and substr() on strings encoded in UTF-8: You end up with partial characters and invalid UTF-8.</p>
<h2>Alternatives for <code>mb_strlen()</code></h2>
<p>You can use different methods to get the real string length.</p>
<pre>$length = preg_match_all( &#039;(.)su&#039;, $string, $matches );</pre>
<p>See also <a href="http://hakre.wordpress.com/2011/12/13/php-utf-8-string-length/">Hakre: PHP UTF-8 string Length</a>.</p>
<p>Or just use …</p>
<pre>$length = strlen( utf8_decode( $string ) );</pre>
<p>There is also a nice <a href="https://github.com/FSX/php-utf8">php-utf8 library on GitHub</a> from <a href="http://61924.nl/">Frank Smit</a>.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2410/dont-use-strlen/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>WP_List_Table &#8211; a step by step guide</title>
		<link>http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/</link>
		<comments>http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 08:47:32 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2426</guid>
		<description><![CDATA[Throughout WordPress the class WP_List_Table is used to display data, e.g. users, plugins, comments, or posts. The class contains almost all necessary methods for displaying, sorting, paginating, and searching data and and what is more obvious than to use it for your own plugins? This article tries to give you a comprehensive walk-through all necessary [...]]]></description>
			<content:encoded><![CDATA[<p>Throughout WordPress the class <code>WP_List_Table</code> is used to display data, e.g. users, plugins, comments, or posts. The class contains almost all necessary methods for displaying, sorting, paginating, and searching data and and what is more obvious than to use it for your own plugins?</p>
<p>This article tries to give you a comprehensive walk-through all necessary steps to create a table tailored to your needs.</p>
<ol>
<li><a href="#preliminary">Preliminary work</a></li>
<li><a href="#basics">Basics</a></li>
<li><a href="#sorting">Sorting</a></li>
<li><a href="#actions">Actions</a></li>
<li><a href="#bulk">Bulk actions</a></li>
<li><a href="#pagination">Pagination</a></li>
<li><a href="#searching">Searching</a></li>
<li><a href="#screen-options">Screen options</a></li>
<li><a href="#styling">Styling the table</a></li>
<li><a href="#other">Other customizations</a></li>
<li><a href="#links">Weblinks</a></li>
</ol>
<h3 id="preliminary">Preliminary work</h3>
<p>For testing purposes we create a small plugin which adds a menu item:</p>
<pre lang="php">
&lt;?php
/*
Plugin Name: My List Table Example
*/
?&gt;
&lt;div class=&quot;wrap&quot;&gt;
&lt;div id=&quot;icon-users&quot; class=&quot;icon32&quot;&gt;&lt;/div&gt;
&lt;h2&gt;My List Table Test/h2&gt;
&lt;/div&gt;
&lt;?php
</pre>
<h3 id="basics">Basics</h3>
<p>For a start we're creating a list table with only the basic functionality. First we have to make sure that the necessary class is available since the <code>WP_List_Table</code> isn't loaded automatically:</p>
<pre class="brush: php">if( ! class_exists( &#039;WP_List_Table&#039; ) ) {
    require_once( ABSPATH . &#039;wp-admin/includes/class-wp-list-table.php&#039; );
}</pre>
<p>To create a table to your needs you have to derive a class from <code>WP_List_Table</code>:</p>
<pre lang="PHP">class My_List_Table extends WP_List_Table {
}

$myListTable = new My__List_Table();</pre>
<p>For demonstration purposes we create some sample data. Usually this data would be read from the database:</p>
<pre lang="PHP">var $example_data = array(
  array(&#039;ID&#039; =&gt; 1,&#039;booktitle&#039; =&gt; &#039;Quarter Share&#039;, &#039;author&#039; =&gt; &#039;Nathan Lowell&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0982514542&#039;),
  array(&#039;ID&#039; =&gt; 2, &#039;booktitle&#039; =&gt; &#039;7th Son: Descent&#039;,&#039;author&#039; =&gt; &#039;J. C. Hutchins&#039;,
        &#039;isbn&#039; =&gt; &#039;0312384378&#039;),
  array(&#039;ID&#039; =&gt; 3, &#039;booktitle&#039; =&gt; &#039;Shadowmagic&#039;, &#039;author&#039; =&gt; &#039;John Lenahan&#039;,
        &#039;isbn&#039; =&gt; &#039;978-1905548927&#039;),
  array(&#039;ID&#039; =&gt; 4, &#039;booktitle&#039; =&gt; &#039;The Crown Conspiracy&#039;, &#039;author&#039; =&gt; &#039;Michael J. Sullivan&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0979621130&#039;),
  array(&#039;ID&#039; =&gt; 5, &#039;booktitle&#039;     =&gt; &#039;Max Quick: The Pocket and the Pendant&#039;, &#039;author&#039;    =&gt; &#039;Mark Jeffrey&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0061988929&#039;),
  array(&#039;ID&#039; =&gt; 6, &#039;booktitle&#039; =&gt; &#039;Jack Wakes Up: A Novel&#039;, &#039;author&#039; =&gt; &#039;Seth Harwood&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0307454355&#039;)
);</pre>
<p>Before we can display the data in the table we have to define some methods and variables:</p>
<pre lang="PHP">
function get_columns(){
  $columns = array(
    &#039;booktitle&#039; =&gt; &#039;Title&#039;,
    &#039;author&#039;    =&gt; &#039;Author&#039;,
    &#039;isbn&#039;      =&gt; &#039;ISBN&#039;
  );
  return $columns;
}

function prepare_items() {
  $columns = $this-&gt;get_columns();
  $hidden = array();
  $sortable = array();
  $this-&gt;_column_headers = array($columns, $hidden, $sortable);
  $this-&gt;items = $this-&gt;example_data;;
}</pre>
<p>The method <code>get_columns()</code> is needed to label the columns on the top and bottom of the table. The keys in the array have to be the same as in the data array otherwise the respective columns aren't displayed.</p>
<p><code>prepare_items</code> defines two arrays controlling the behaviour of the table:</p>
<ul>
<li>$hidden defines the hidden columns (see <a href="#screen-options">Screen Options</a>),</li>
<li>$sortable defines if the table can be sorted by this column.</li>
</ul>
<p>Finally the method assigns the example data to the class' data representation variable <code>items</code>.</p>
<p>Before actually displaying each column WordPress looks for methods called <code>column_{key_name}</code>, e.g. <code>function column_booktitle</code>. There has to be such a method for every defined column. To avoid the need to create a method for each column there is <code>column_default</code> that will process any column for which no special method is defined:</p>
<pre lang="php">
function column_default( $item, $column_name ) {
  switch( $column_name ) {
    case &#039;booktitle&#039;:
    case &#039;author&#039;:
    case &#039;isbn&#039;:
      return $item&#091; $column_name &#093;;
    default:
      return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
  }
}
</pre>
<p>In our example the method will return the title for every column and if the column is not found it displays the content of the $item array for debugging purposes.</p>
<p>These are the essential ingredients to define a custom list table class. All you have to do now is to add an admin page to the backend, create an instance of our class, prepare the items and call <code>display()</code> to actually display the table:</p>
<pre class="brush: php">
function my_add_menu_items(){
    add_menu_page( &#039;My Plugin List Table&#039;, &#039;My List Table Example&#039;, &#039;activate_plugins&#039;, &#039;my_list_test&#039;, &#039;my_render_list_page&#039; );
}
add_action( &#039;admin_menu&#039;, &#039;my_add_menu_items&#039; );

function my_render_list_page(){
  $myListTable = new My_Example_List_Table();
  echo &#039;&lt;div class=&quot;wrap&quot;&gt;&lt;h2&gt;My List Table Test&lt;/h2&gt;&#039;;
  $myListTable-&gt;prepare_items();
  $myListTable-&gt;display();
  echo &#039;&lt;/div&gt;&#039;;
}
</pre>
<p>This is the minimal version of a WP_List_Table possible:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-13-23-07.png" alt="" title="Minimal WP_List_Table" width="646" height="276" class="aligncenter size-full wp-image-2427" /><br />
<a href="https://gist.github.com/gists/2147390/download">Download minimal WP_List_Table example</a> (gist)</p>
<h3 id="sorting">Sorting</h3>
<p>At the moment the items appear in the order they are defined in the code since the WP_List_Table class does not contain any code for sorting. What it does contain is some code to mark certain columns as sortable. In section "Basics" there already was a line <code>$sortable = array();</code> which now will be changed to:</p>
<pre lang="PHP">$sortable = $this-&gt;get_sortable_columns();</pre>
<p>Additionally we need the method:</p>
<pre lang="PHP">function get_sortable_columns() {
  $sortable_columns = array(
    &#039;booktitle&#039;  =&gt; array(&#039;booktitle&#039;,false),
    &#039;author&#039; =&gt; array(&#039;author&#039;,false),
    &#039;isbn&#039;   =&gt; array(&#039;isbn&#039;,false)
  );
  return $sortable_columns;
}</pre>
<p>This way the above mentioned column headers are changed to links and display small triangles if the mouse hovers over them. The second parameter in the value array of <code>$sortable_columns</code> takes care of a possible pre-ordered column. If the value is <code>true</code> the column is assumed to be ordered ascending, if the value is <code>false</code> the column is assumed descending or unordered. This is needed for the small triangle beside the column name indicating the sort order to show in the correct direction:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/22.02.014.png" alt="" title="Sorting" width="450" height="78" class="aligncenter size-full wp-image-2428" /></p>
<p>If you click on the column header the page is reloaded and <code>$_GET</code> contains something like this:</p>
<pre lang="PHP">array
  &#039;page&#039; =&gt; string &#039;my_list_test&#039; (length=12)
  &#039;orderby&#039; =&gt; string &#039;booktitle&#039; (length=5)
  &#039;order&#039; =&gt; string &#039;asc&#039; (length=3)</pre>
<p>With this information you can write a method for sorting our example data:</p>
<pre lang="PHP">function usort_reorder( $a, $b ) {
  // If no sort, default to title
  $orderby = ( ! empty( $_GET&#091;&#039;orderby&#039;&#093; ) ) ? $_GET&#091;&#039;orderby&#039;&#093; : &#039;booktitle&#039;;
  // If no order, default to asc
  $order = ( ! empty($_GET&#091;&#039;order&#039;&#093; ) ) ? $_GET&#091;&#039;order&#039;&#093; : &#039;asc&#039;;
  // Determine sort order
  $result = strcmp( $a&#091;$orderby&#093;, $b&#091;$orderby&#093; );
  // Send final sort direction to usort
  return ( $order === &#039;asc&#039; ) ? $result : -$result;
}</pre>
<p>To actually sort the data we have to extend <code>prepare_items()</code>:</p>
<pre lang="PHP">function prepare_items() {
  &#091;..&#093;
  usort( $this-&gt;example_data, array( &amp;$this, &#039;usort_reorder&#039; ) );
  $this-&gt;items = $this-&gt;example_data;
}</pre>
<p>If you're retrieving the data from the database (which is most likely) it's of course best to use SQL's <code>ORDERBY</code> directly.</p>
<h3 id="actions">Actions</h3>
<p>If you not only want to display the items but also want to manipulate them you have to define some actions:
<pre lang="PHP">
function column_booktitle($item) {
  $actions = array(
            &#039;edit&#039;      =&gt; sprintf(&#039;&lt;a href=&quot;?page=%s&amp;action=%s&amp;book=%s&quot;&gt;Edit&lt;/a&gt;&#039;,$_REQUEST&#091;&#039;page&#039;&#093;,&#039;edit&#039;,$item&#091;&#039;ID&#039;&#093;),
            &#039;delete&#039;    =&gt; sprintf(&#039;&lt;a href=&quot;?page=%s&amp;action=%s&amp;book=%s&quot;&gt;Delete&lt;/a&gt;&#039;,$_REQUEST&#091;&#039;page&#039;&#093;,&#039;delete&#039;,$item&#091;&#039;ID&#039;&#093;),
        );

  return sprintf(&#039;%1$s %2$s&#039;, $item&#091;&#039;booktitle&#039;&#093;, $this-&gt;row_actions($actions) );
}
</pre>
<p>These actions will appear if the user hovers the mouse cursor over the table:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/actions4.png" alt="" title="Actions" width="427" height="126" class="aligncenter size-full wp-image-2429" /></p>
<p>If you click on one of the action links the form will return for example the following data in <code>$_GET</code>:</p>
<pre lang="PHP">array
  &#039;page&#039; =&gt; string &#039;my_list_test&#039; (length=12)
  &#039;action&#039; =&gt; string &#039;delete&#039; (length=6)
  &#039;book&#039; =&gt; string &#039;2&#039; (length=1)</pre>
<h3 id="bulk">Bulk actions</h3>
<p>Bulk action are implemented by overwriting the method <code>get_bulk_actions()</code> and returning an associated array:</p>
<pre lang="PHP">function get_bulk_actions() {
  $actions = array(
    &#039;delete&#039;    =&gt; &#039;Delete&#039;
  );
  return $actions;
}</pre>
<p>This only puts the dropdown menu and the apply button above and below the table:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-17-08-00.png" alt="" title="21-03-2012 17-08-00" width="477" height="219" class="aligncenter size-full wp-image-2436" /></p>
<p>The checkboxes for the rows have to be defined separately. As mentioned above there is a method column_{column} for rendering a column. The <code>cb</code>-column is a special case:</p>
<pre lang="PHP">
function column_cb($item) {
        return sprintf(
            &#039;&lt;input type=&quot;checkbox&quot; name=&quot;book&#091;&#093;&quot; value=&quot;%s&quot; /&gt;&#039;, $item&#091;&#039;ID&#039;&#093;
        );
    }
</pre>
<p>This method currently will not be processed because we have to tell the class about the new column by extending the method <code>get_columns()</code>:</p>
<pre lang="php">
function get_columns() {
  $columns = array(
    &#039;cb&#039;        =&gt; &#039;&lt;input type=&quot;checkbox&quot; /&gt;&#039;,
&#091;..&#093;
}
</pre>
<p>This will also put the "select all" checkbox in the title bar:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-17-14-30.png" alt="" title="Bulk 1" width="491" height="236" class="aligncenter size-full wp-image-2430" /></p>
<p>If you don't want to display the checkbox in the title you simply set the value to an empty string. Nevertheless you still have to define the key/value pair otherwise no checkboxes are shown at all:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/22-03-2012-15-11-51.png" alt="" title="22-03-2012 15-11-51" width="503" height="233" class="aligncenter size-full wp-image-2438" /></p>
<p>If "Apply" is pressed the form will return various variables: <code>action</code> and <code>action2</code> contain the selected action or <code>-1</code> if the user chose no action, and if any checkbox was selected the marked rows, in our case <code>books</code>, for example:</p>
<pre class="brush: php">
&#039;action&#039; =&gt; string &#039;delete&#039; (length=6)
&#039;book&#039; =&gt;
  array
    0 =&gt; string &#039;2&#039; (length=1)
    1 =&gt; string &#039;6&#039; (length=1)
&#039;action2&#039; =&gt; string &#039;-1&#039; (length=2)
</pre>
<p><code>action</code> contains the selection from the upper select box, <code>action2</code> the selection from the lower select box, and <code>book</code> the id of the selected rows, if any. You can  use the method <code>current_action()</code> to query <code>action/action2</code>:</p>
<pre lang="php">
$action = $this-&gt;current_action();
</pre>
<p>It will return <code>action</code> if it's set, otherwise <code>action2</code>. If nothing is set the method returns <code>FALSE</code>.</p>
<h3 id="pagination">Pagination</h3>
<p>First things first: WordPress does not paginate your data in any way. It only contains a method to display a navigation bar on the top and bottom right of the table:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-17-38-38.png" alt="" title="Pagination" width="392" height="206" class="aligncenter size-full wp-image-2432" /></p>
<p>You have to tell the method how many items you have in total, how many items shall be displayed on a page, and most important, the data to be displayed on the page:</p>
<pre lang="PHP">function prepare_items() {
  &#091;...&#093;
  $per_page = 5;
  $current_page = $this-&gt;get_pagenum();
  $total_items = count($this-&gt;example_data);

  // only ncessary because we have sample data
  $this-&gt;found_data = array_slice($this-&gt;example_data,(($current_page-1)*$per_page),$per_page);

  $this-&gt;set_pagination_args( array(
    &#039;total_items&#039; =&gt; $total_items,                  //WE have to calculate the total number of items
    &#039;per_page&#039;    =&gt; $per_page                     //WE have to determine how many items to show on a page
  ) );
  $this-&gt;items = $this-&gt;found_data;
}</pre>
<p>As pointed out in the comment the <code>array_slice</code> is only necessary because we use sample data. If you're retrieving the data from a database you only need to load the necessary data by using SQL's <code>LIMIT</code>.</p>
<h3 id="searching">Searching</h3>
<p>If you have a huge amount of data a search field will simplify accessing certain items:</p>
<pre lang="PHP">$myListTable-&gt;search_box(&#039;search&#039;, &#039;search_id&#039;);</pre>
<p>The button text <code>search</code> is defined by the first parameter, the id of the input by the second parameter. The method creates the following output:</p>
<pre lang="xhtml">
&lt;p class=&quot;search-box&quot;&gt;
&lt;label class=&quot;screen-reader-text&quot; for=&quot;search_id-search-input&quot;&gt;
search:&lt;/label&gt;
&lt;input id=&quot;search_id-search-input&quot; type=&quot;text&quot; name=&quot;s&quot; value=&quot;&quot; /&gt;
&lt;input id=&quot;search-submit&quot; class=&quot;button&quot; type=&quot;submit&quot; name=&quot;&quot; value=&quot;search&quot; /&gt;
&lt;/p&gt;
</pre>
<p>The method will place the input field and the search button on the right side and style it correctly. The <code>&lt;form></code> element is not generated. You have to add it manually, in our case this would be:</p>
<pre lang="xhtml">
&lt;form method=&quot;post&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;page&quot; value=&quot;my_list_test&quot; /&gt;
  &lt;?php $this-&gt;search_box(&#039;search&#039;, &#039;search_id&#039;); ?&gt;
&lt;/form&gt;
</pre>
<p>(The hidden element is needed to load the right page.)<br />
To react to the search command you need to check the content of <code>$_POST['s']</code> and filter your data accordingly before displaying the table.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-18-17-33.png" alt="" title="Searching" width="381" height="151" class="aligncenter size-full wp-image-2433" /></p>
<h3 id="screen-options">Screen options</h3>
<p>All core backend pages containing a <code>WP_List_Table</code> provide a "Screen Options" slide-in where the user can adjust the columns to be shown and the number of rows to be displayed.<br />
To add options to your plugin you need to change your current code. First you have to make sure that the screen options are displayed only on the current page:</p>
<pre lang="PHP">$hook = add_menu_page(&#039;My Plugin List Table&#039;, &#039;My List Table Example&#039;, &#039;activate_plugins&#039;, &#039;my_list_test&#039;, &#039;my_render_list_page&#039;);
add_action( &quot;load-$hook&quot;, &#039;add_options&#039; );

function add_options() {
  $option = &#039;per_page&#039;;
  $args = array(
         &#039;label&#039; =&gt; &#039;Books&#039;,
         &#039;default&#039; =&gt; 10,
         &#039;option&#039; =&gt; &#039;books_per_page&#039;
         );
  add_screen_option( $option, $args );
}</pre>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-18-25-17.png" alt="" title="Screen options 1" width="568" height="116" class="aligncenter size-full wp-image-2434" /></p>
<p>This only displays the option field and apply button, saving and loading the data has to be defined separately. WordPress provides a filter called <code>set-screen-option</code> to take care of this:</p>
<pre lang="php">
add_filter(&#039;set-screen-option&#039;, &#039;test_table_set_option&#039;, 10, 3);
function test_table_set_option($status, $option, $value) {
  return $value;
}
</pre>
<p>The option is stored in the table <code>usermeta</code> in the database so each user has his own setting. To retrieve the option and adjust the table display accordingly the method <code>prepare_items</code> has to be altered (excerpt):</p>
<pre lang="php">
function prepare_items() {
&#091;..&#093;

  //paging
  $per_page = $this-&gt;get_items_per_page(&#039;books_per_page&#039;, 5);
  $current_page = $this-&gt;get_pagenum();

  &#091;...&#093;
</pre>
<p>Instead of simply assigning a number the user specified value is loaded. If the user hasn't changed the value there is no such option stored in the database and a default value is taken.</p>
<p>Adding the checkboxes for hiding/showing the columns is done by WordPress automatically. You just have to make sure that your derived class is instantiated before the screen option panel is rendered so that the parent class can retrieve the column names. To accomplish this the corresponding code is moved into the method <code>add_options()</code>:</p>
<pre lang="php">
function add_options() {
    global $myListTable;

    $option = &#039;per_page&#039;;
    $args = array(
        &#039;label&#039; =&gt; &#039;Books&#039;,
        &#039;default&#039; =&gt; 10,
        &#039;option&#039; =&gt; &#039;books_per_page&#039;
    );
    add_screen_option( $option, $args );

    $myListTable = new My_Example_List_Table;
}</pre>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-18-32-02.png" alt="" title="Screen options 2" width="574" height="170" class="aligncenter size-full wp-image-2435" /></p>
<p>The user's selections are automatically saved via Ajax functions. Nevertheless you have take care by yourself that the columns are hidden if the page is loaded initially. The method <code>get_column_info()</code> returns all, the hidden and the sortable columns. In the method <code>prepare_items()</code> instead of</p>
<pre lang="php">
$columns = $this-&gt;get_columns();
$hidden = array();
$sortable = $this-&gt;get_sortable_columns();
$this-&gt;_column_headers = array($columns, $hidden, $sortable);
</pre>
<p>it's now</p>
<pre lang="php">
$this-&gt;_column_headers = $this-&gt;get_column_info();
</pre>
<p>and the columns are set according to the screen options.</p>
<p>Annotation: you should avoid some strings as keynames since they are treated by WordPress specially:</p>
<pre lang="php">
$special = array(&#039;_title&#039;, &#039;cb&#039;, &#039;comment&#039;, &#039;media&#039;, &#039;name&#039;, &#039;title&#039;, &#039;username&#039;, &#039;blogname&#039;);
</pre>
<p>Your table would still work, but you won't be able to show/hide the columns.</p>
<h3 id="styling">Styling the table</h3>
<p>Currently the table is styled to the WordPress defaults. To change this you have to adapt the CSS classes which are automatically assigned to each column. The class name consists of the string "column-" and the key name of the <code>$columns</code> array, e.g. "column-isbn" or "column-author". As an example the width of the columns will be redefined (for simplicity the style data is written directly into the HTML header):</p>
<pre lang="php">
function _construct() {
  &#091;...&#093;
  add_action( &#039;admin_head&#039;, array( &amp;$this, &#039;admin_header&#039; ) );
  &#091;...&#093;
}

function admin_header() {
  $page = ( isset($_GET&#091;&#039;page&#039;&#093; ) ) ? esc_attr( $_GET&#091;&#039;page&#039;&#093; ) : false;
  if( &#039;my_list_test&#039; != $page )
    return; 

  echo &#039;&lt;style type=&quot;text/css&quot;&gt;&#039;;
  echo &#039;.wp-list-table .column-id { width: 5%; }&#039;;
  echo &#039;.wp-list-table .column-booktitle { width: 40%; }&#039;;
  echo &#039;.wp-list-table .column-author { width: 35%; }&#039;;
  echo &#039;.wp-list-table .column-isbn { width: 20%; }&#039;;
  echo &#039;&lt;/style&gt;&#039;;
}
</pre>
<h3 id="other">Other customizations</h3>
<p>If there are no items in the list the standard message is "No items found." is displayed. If you want to change this message you can overwrite the method <code>no_items()</code>:</p>
<pre lang="php">
function no_items() {
  _e( &#039;No books found, dude.&#039; );
}
</pre>
<p><a href="https://gist.github.com/gists/7f923479a4ed135e35b2/download" title="Download Gist">Download complete WP_List_Table example</a> (gist) or <a href="https://gist.github.com/7f923479a4ed135e35b2" title="Gist: Sample plugin for usage of WP_List_Table class (complete version)">see the Gist</a></p>
<h3 id="links">Weblinks</h3>
<ul>
<li><a href="http://wp.smashingmagazine.com/2011/11/03/native-admin-tables-wordpress/">Create Native Admin Tables In WordPress The Right Way</a> (Smashing Magazine)</li>
<li><a href="http://wordpress.org/extend/plugins/custom-list-table-example/">Custom List Table Example plugin</a> (wordpress.org)</li>
</ul>
</li>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Best Practice for Multilanguage WordPress Content? New Plugin!</title>
		<link>http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/</link>
		<comments>http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 07:00:20 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[language plugin]]></category>
		<category><![CDATA[Multilanguage]]></category>
		<category><![CDATA[multilnual]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2389</guid>
		<description><![CDATA[Since the beginning of WordPress the desire to publish the content in different languages is huge. But the topic can quickly become complex, because not only the rendering of content in the form of text in different languages ​​is an issue, we also have to take care of the meta data for content, for images [...]]]></description>
			<content:encoded><![CDATA[<p>Since the beginning of WordPress the desire to publish the content in different languages is huge. But the topic can quickly become complex, because not only the rendering of content in the form of text in different languages ​​is an issue, we also have to take care of the meta data for content, for images that can be different depending on the language and the use of the admin interface in the preferred language. Thus, only a part would be covered depending on the requirements (<a href="http://wordpress.stackexchange.com/questions/1552/best-practices-for-localizing-wordpress-content">a example on StackExchange</a>) it would quickly become an project and WordPress would be just a "small" framework behind it. There are already many <a href="http://codex.wordpress.org/Multilingual_WordPress">Plugins available</a>, the different approaches - new tables in the system or separation of content for each language in a table entry to post, or other solutions.</p>
<p>All these solutions have their limitations, are inflexible and you go into a dependency that will be hard to get out and with each update of WordPress you have to check if the Plugin is still working or has any bugs with the new version. Therefore, I would suggest a solution that we use in our <a title="Inpsyde photo" href="http://inpsyde.com">Inpsyde Team</a> frequently for customers and maintained their strength in the flexibility, in extensibility and in its capacity to use the WordPress standard without changing the core or anything else. You can deactivate the Plugin at any time, you won't lose anything, your website remains the same.</p>
<p><span id="more-2389"></span><br />
<img class="aligncenter size-medium wp-image-2390" title="banner-772x250" src="http://wpengineer.com/wp-content/uploads/banner-772x250-300x97.png" alt="" width="300" height="97" /></p>
<h3>Why multilanuage?</h3>
<ul>
<li>2/3, if not even more, of the worldwide population speak another language</li>
<li>Globale Aufstellung von Unternehmen</li>
<li>Better distribution of content</li>
<li>Service for the client</li>
<li>Search Engine Optimization</li>
</ul>
<h3>The solution</h3>
<p>WordPress Multi-site provides the solution already.<br />
This makes the management of different instances, with similarities and differences, with the help of an installation possible. The exchange of data is possible via core functions, which get united and simplified via Plugin.</p>
<h3>Advantages</h3>
<ul>
<li>WordPress Core Functions</li>
<li>No dependency to Plugins</li>
<li>Independent to WordPress development*</li>
<li>Control Themes, Plugins at a central place, use them decentralized</li>
<li>Low maintenance</li>
<li>Seperating languages in Backend/Frontend (user dependent)</li>
<li>Complete mirrored or in every content form seperated</li>
<li>Subdomains or Subdirectories</li>
<li>de.example.com, example.com/de</li>
<li>Seperate Domains via Domainmapping</li>
<li>example.de, example.com</li>
<li>Free in development in design and usability</li>
<li>Optimization not only on frontend, also lang-attributes, SEO</li>
</ul>
<h3>Plugin</h3>
<p>With all these requirements and benefits, we use a base that is available as a Plugin in the official repository of WordPress: <a href="http://wordpress.org/extend/plugins/multilingual-press/"> Multilingual Press </a>. The plugin provides several convenient tools to use Multisite for the implementation of multilingualism.</p>
<p>
<a href='http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/banner-772x250/' title='banner-772x250'><img width="150" height="150" src="http://wpengineer.com/wp-content/uploads/banner-772x250-150x150.png" class="attachment-thumbnail" alt="banner-772x250" title="banner-772x250" /></a>
<a href='http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/screenshot-1-3/' title='screenshot-1'><img width="150" height="150" src="http://wpengineer.com/wp-content/uploads/screenshot-12-150x150.png" class="attachment-thumbnail" alt="screenshot-1" title="screenshot-1" /></a>
<a href='http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/screenshot-2-3/' title='screenshot-2'><img width="150" height="150" src="http://wpengineer.com/wp-content/uploads/screenshot-22-150x150.png" class="attachment-thumbnail" alt="screenshot-2" title="screenshot-2" /></a>
<a href='http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/screenshot-3/' title='screenshot-3'><img width="150" height="150" src="http://wpengineer.com/wp-content/uploads/screenshot-3-150x150.png" class="attachment-thumbnail" alt="screenshot-3" title="screenshot-3" /></a>
<a href='http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/screenshot-4/' title='screenshot-4'><img width="150" height="150" src="http://wpengineer.com/wp-content/uploads/screenshot-4-150x150.png" class="attachment-thumbnail" alt="screenshot-4" title="screenshot-4" /></a>
<a href='http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/wordpress-christmas-2010-24-2/' title='WordPress-Christmas-2010-24'><img width="150" height="150" src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-241-150x150.jpg" class="attachment-thumbnail" alt="WordPress-Christmas-2010-24" title="WordPress-Christmas-2010-24" /></a>
</p>
<p>This plugin simplifies the identification of different blogs in the network to a language and linking to other blogs, so that when you publish the content in blog A, it will create a post as draft in blog B. Thus, the articles are in relation, the system knows this and with the help of some functions, it may be used in the frontend and backend.<br />
The Plugin provides in the article or page the ability to see a meta box with the content of the linked data, in the simplest case as a translation aid. Similarly, there is a widget that simplifies the frontend to change. In each blog you can be make ​​some adjustments, assigning a flag and language.</p>
<h3>An outlook</h3>
<p>We are in the midst of the development, which adds the extra help. For example a dashboard widget with the overview of article and all links, an extension of the mediathek to seperate global content across all blogs and independent content per blog. Similarly, there are helpers for updating existing installations. In addition there is the possibility to directly load the language in the backend, without the need of FTP/SSH and assign the languages accordingly​​. We will also add the function to copy existing blogs with all the content and options if you want to.</p>
<h3>Summary</h3>
<p>WordPress Multisite provides the basis and with some adjustments, a clean, controlled solution exists for the use of WordPress in a multilingual environment. Now it's up to you - use Multisite, Test the Plugin and give us a feedback, preferable on <a href="https://github.com/inpsyde/multilingual-press">our repo on Github</a>.</h3>
<p>.</p>
<p>This was our last door of our Advent Calendar. We hope you enjoyed it! </p>
<p>We wish you a Merry Christmas and thanks a lot for reading our posts!<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2389/best-practice-for-multilanguage-wordpress-content-new-plugin/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Separate Logic From Output</title>
		<link>http://wpengineer.com/2355/separate-logic-from-output/</link>
		<comments>http://wpengineer.com/2355/separate-logic-from-output/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 06:58:57 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2355</guid>
		<description><![CDATA[Once HTML is defined within a function for output, the HTML will be separated from the logic! In this case the function is defined twice. A function contains only logic and values ​​are returned only as return. The second function will contain HTML, test logic, loops or hooks and outputs values ​​as echo. Ok, the [...]]]></description>
			<content:encoded><![CDATA[<p>Once HTML is defined within a function for output, the HTML will be separated from the logic! In this case the function is defined twice. A function contains only logic and values ​​are returned only as return. The second function will contain HTML, test logic, loops or hooks and outputs values ​​as echo. Ok, the smart asses will say <a href="http://de.wikipedia.org/wiki/Model_View_Controller">MVC</a>, yeah you right, but WordPress does not pursue a Consistent MVC pattern!</p>
<p><span id="more-2355"></span></p>
<h4>Why WordPress doesn't follow MVC pattern consistently?</h4>
<p>If we have a close look on WordPress, we can detect an MVC pattern. By separating the Themes (view) from the core (model) it gives the impression WordPress pursues an MVC pattern. But this patternn is found only in the frontend. Let's take a closer look and we see that there is no such logic for the admin area. So, the view for the admin area has to be anchored somewhere in the core. We can also notice that in the core itself are lose SQL queries within PHP. Well, a general separation of view and logic is not equal MVC. An MVC-Pattern is principally composed of a sort of object-oriented programming paradigm, in WordPress, these can also be found occasionally, but we find much more procedural than object-oriented programming paradigms. Conclusion WordPress itself does not pursue a MVC pattern, but it is quite possible MVC principles, as we used in the following.</p>
<pre>
function get_some_foo() {
	$my_foo = &#039;This is Foo!&#039;;
	return $my_foo;
}

function some_foo() {
	$foo = get_some_foo();
	echo $foo;
}
</pre>
<p>Why is this useful? We want the function <code>some_foo()</code> returns a predefined output. In another template we want to change the default behavior of the function <code>some_foo()</code>. In order to effectively reflect both requirements, two functions are defined. The first function consists only the elementary logic and is only returned as return values​​, it is always preceded by a <code>get_...</code>. The second function includes predefined information, which in turn can be HTML, test logic, loops, or a hook.</p>
<pre>
function get_some_foo() {
	$foo_bar_array = array( &#039;Foo&#039;, &#039;Bar&#039;, &#039;FooBar&#039;, &#039;BarFoo&#039; );
	$foo_bar_array = apply_filters( &#039;some_foo_array&#039;, $foo_bar_array );

	return $foo_bar_array ;
}

function some_foo() {
    $foo_list = &#039;&lt;ul&gt;&#039;; 

    foreach( get_some_foo() as $foo_key =&gt; $foo_value ){
		$foo_list .= &#039;&lt;li&gt;&#039; . $foo_value . &#039;&lt;/li&gt;&#039;;
    }

    $foo_list .= &#039;&lt;/ul&gt;&#039;;

    echo apply_filters( &#039;some_foo&#039;, $foo_list );
}
</pre>
<p>In the previous example in each of the two functions with the function <a href="http://codex.wordpress.org/Function_Reference/apply_filter"> <code>apply_filters()</code></a> the possibility will be created, to change returned values later as you desired. A manipulation can take place via the so-defined hooks <code>some_foo_array</code> or <code>some_foo</code>. Here is an example of how a possible manipulation can look with the two defined hooks.</p>
<p>In the next code example, we change an array <code>$foo_bar_array</code> and the HTML output. This involves the two hooks <code>some_foo_array</code> and <code>some_foo</code>, which were set with <code>apply_filters('some_foo' ...</code>. With the function <a href="http://codex.wordpress.org/Function_Reference/add_filter"><code>add_filter()</code></a> filter functions for further processing in the global variable <code>$wp_filter</code> will be registered.</p>
<pre>
function get_my_some_foo( $foo_bar_array ) {
	$foo_bar_array&#091; count( $foo_bar_array ) + 1 &#093; = &#039;FuuBoo&#039;;

	return $foo_bar_array ;
}

function my_some_foo( $foo_list ) {
    $foo_list = str_replace( &#039;ul&#039;, &#039;ol&#039;, $foo_list ); 

    return $foo_list;
}

add_filter( &#039;some_foo_array&#039;, &#039;get_my_some_foo&#039;);
add_filter( &#039;some_foo&#039;, &#039;my_some_foo&#039;);

// do not forget, call some_foo()
some_foo();
</pre>
<p>Let's look briefly what's happening. What outputs <code>some_foo()</code> has without manipulation we see in the following example.</p>
<pre>
function get_some_foo() {
	$foo_bar_array = array( &#039;Foo&#039;, &#039;Bar&#039;, &#039;FooBar&#039;, &#039;BarFoo&#039; );
	$foo_bar_array = apply_filters( &#039;some_foo_array&#039;, $foo_bar_array );

	return $foo_bar_array ;
}

function some_foo() {
    $foo_list = &#039;&lt;ul&gt;&#039;; 

    foreach(get_some_foo() as $foo_key =&gt; $foo_value){
		$foo_list .= &#039;&lt;li&gt;&#039; . $foo_value . &#039;&lt;/li&gt;&#039;;
    }

    $foo_list .= &#039;&lt;/ul&gt;&#039;;

    echo apply_filters( &#039;some_foo&#039;, $foo_list );
}
?&gt; 

// output
&lt;ul&gt;
	&lt;li&gt;Foo&lt;/li&gt;
	&lt;li&gt;Bar&lt;/li&gt;
	&lt;li&gt;FooBar&lt;/li&gt;
	&lt;li&gt;BarFoo&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>In the next example we use the functions defined in the hooks <code>some_foo_array</code> and <code>some_foo</code> to add the array another element to make the unordered list, an ordered list.</p>
<pre>
function get_my_some_foo( $foo_bar_array ) {
	$foo_bar_array&#091; count( $foo_bar_array ) + 1 &#093; = &#039;FuuBoo&#039;;

	return $foo_bar_array ;
}

function my_some_foo( $foo_list ) {
    $foo_list = str_replace( &#039;ul&#039;, &#039;ol&#039;, $foo_list ); 

    return $foo_list;
}

// register Hooks in the stack ($wp_filter)
add_filter( &#039;some_foo_array&#039;, &#039;get_my_some_foo&#039;);
add_filter( &#039;some_foo&#039;, &#039;my_some_foo&#039;);
?&gt;

//output
&lt;ol&gt;
	&lt;li&gt;Foo&lt;/li&gt;
	&lt;li&gt;Bar&lt;/li&gt;
	&lt;li&gt;FooBar&lt;/li&gt;
	&lt;li&gt;BarFoo&lt;/li&gt;
	&lt;li&gt;FuuBoo&lt;/li&gt;
&lt;/ol&gt;
</pre>
<p>How does <code>add_filter</code> and <code>apply_filters</code> work in the program flow?<br />
Each hook which should be executed is registered with <code>add_filter</code> or <code>add_action</code> in the global variable <code>$wp_filter</code>. If the function <code>apply_filters()</code> is called, an appropriate filter function based on the transmitted variables will be searched in the <code>$wp_filter</code>, if this is registered with <code>add_filter</code>, the appropriate function will execute. Now values will be manipulated now and then passed back to <code>apply_filters</code>.</p>
<p>Let's take our example from above, it looks like this.</p>
<pre>
&lt;?php
// the default function
function get_some_foo() {
	$foo_bar_array = array( &#039;Foo&#039;, &#039;Bar&#039;, &#039;FooBar&#039;, &#039;BarFoo&#039; );
	$foo_bar_array = apply_filters( &#039;some_foo_array&#039;, $foo_bar_array );

	return $foo_bar_array ;
}

// the filter function
function get_my_some_foo( $foo_bar_array ) {
	$foo_bar_array&#091; count( $foo_bar_array ) + 1 &#093; = &#039;FuuBoo&#039;;

	return $foo_bar_array ;
}

// register function in $wp_filter
add_filter( &#039;some_foo_array&#039;, &#039;get_my_some_foo&#039; );
?&gt;
</pre>
<p>Without hook functionality the whole thing would look like the following. Although we have much less code, but this is not reusable.</p>
<pre>
&lt;?php
//Das ist unsere default Funktion
function get_some_foo() {
	$foo_bar_array = array( &#039;Foo&#039;, &#039;Bar&#039;, &#039;FooBar&#039;, &#039;BarFoo&#039; );
	$foo_bar_array&#091; count( $foo_bar_array ) + 1 &#093; = &#039;FuuBoo&#039;;

	return $foo_bar_array ;
}
?&gt;
</pre>
<div class="incontent">
<h4>Guest Post</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/rene-reimann-150x150.jpg" alt="Rene Reimann Avatar" title="Rene Reimann" width="150" height="150" class="alignleft size-thumbnail wp-image-2356" /><a href="http://www.rene-reimann.de/" title="rene-reimann.de">René</a> lives in Halle at Saale, he is married, has a daughter (8) and a dog (12). He is a professional media designer for digital and print media, with a flair for design and color combinations. He is a creative WordPress developer, designer and media consultant who always has a suitable solution. <a href="https://plus.google.com/u/0/116520935691953756105/posts" title="Is G+ profile"> René </a> is an instructor and member of the Examination Board of the Chamber of Halle/Dessau for the education of media designer for digital and print media.
</div>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2355/separate-logic-from-output/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Custom Fields to WordPress User Profile</title>
		<link>http://wpengineer.com/2173/custom-fields-wordpress-user-profile/</link>
		<comments>http://wpengineer.com/2173/custom-fields-wordpress-user-profile/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 07:08:34 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2173</guid>
		<description><![CDATA[The user profile of WordPress can be fairly easily adapted to add your own values​​. So you can add the necessary fields according to your requirements. Here is how you do it, we add a field for the address and the content will be stored in the database. Various hooks in WordPress make sure that [...]]]></description>
			<content:encoded><![CDATA[<p>The user profile of WordPress can be fairly easily adapted to add your own values​​. So you can add the necessary fields according to your requirements. Here is how you do it, we add a field for the address and the content will be stored in the database. Various hooks in WordPress make sure that you only have to worry about the fields.<br />
<span id="more-2173"></span><br />
<img src="http://wpengineer.com/wp-content/uploads/custom-profile-fields.png" alt="" title="custom-profile-fields" width="630" height="162" class="aligncenter size-full wp-image-2174" /></p>
<p>The function to store the entries is <code>fb_save_custom_user_profile_fields()</code> and here it is important to check the rights of each active user, only if the rights are available, in this case for editing users (<code>edit_user</code>), then data may be stored.<br />
The actual saving of data takes place via <code>update_usermeta()</code>.</p>
<p>It can pass all kinds of fields of course, the input field is just an example. It is advisable to outsource the functions in a Plugin, an alternative is also the <code>functions.php</code> of the Theme, but is certainly not the best way.</p>
<p>Each function of the small sample was referred to two hooks. Because WordPress differentiate between editing of user profiles and update personal data. This is done using the constant <code>IS_PROFILE_PAGE</code>. On default this constant is on TRUE and so would the hooks <code>show_user_profile</code> and <code>personal_options_update</code> be enough to bring in new fields and save them. But this can vary depending on the installation and this way the admin cannot maintain these new fields. In particular, two more hooks are needed. Otherwise there might be many cases, where the admin has to maintain data which the user doesn't even see in his profile.</p>
<pre>
function fb_add_custom_user_profile_fields( $user ) {
?&gt;
	&lt;h3&gt;&lt;?php _e(&#039;Extra Profile Information&#039;, &#039;your_textdomain&#039;); ?&gt;&lt;/h3&gt;

	&lt;table class=&quot;form-table&quot;&gt;
		&lt;tr&gt;
			&lt;th&gt;
				&lt;label for=&quot;address&quot;&gt;&lt;?php _e(&#039;Address&#039;, &#039;your_textdomain&#039;); ?&gt;
			&lt;/label&gt;&lt;/th&gt;
			&lt;td&gt;
				&lt;input type=&quot;text&quot; name=&quot;address&quot; id=&quot;address&quot; value=&quot;&lt;?php echo esc_attr( get_the_author_meta( &#039;address&#039;, $user-&gt;ID ) ); ?&gt;&quot; class=&quot;regular-text&quot; /&gt;&lt;br /&gt;
				&lt;span class=&quot;description&quot;&gt;&lt;?php _e(&#039;Please enter your address.&#039;, &#039;your_textdomain&#039;); ?&gt;&lt;/span&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
&lt;?php }

function fb_save_custom_user_profile_fields( $user_id ) {

	if ( !current_user_can( &#039;edit_user&#039;, $user_id ) )
		return FALSE;

	update_usermeta( $user_id, &#039;address&#039;, $_POST&#091;&#039;address&#039;&#093; );
}

add_action( &#039;show_user_profile&#039;, &#039;fb_add_custom_user_profile_fields&#039; );
add_action( &#039;edit_user_profile&#039;, &#039;fb_add_custom_user_profile_fields&#039; );

add_action( &#039;personal_options_update&#039;, &#039;fb_save_custom_user_profile_fields&#039; );
add_action( &#039;edit_user_profile_update&#039;, &#039;fb_save_custom_user_profile_fields&#039; );
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2173/custom-fields-wordpress-user-profile/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Register Settings on WordPress Multisite</title>
		<link>http://wpengineer.com/2324/register-settings-on-wordpress-multisite/</link>
		<comments>http://wpengineer.com/2324/register-settings-on-wordpress-multisite/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 07:08:59 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2324</guid>
		<description><![CDATA[The use of WordPress for several blogs in the network can be useful to simplify several steps and is becoming increasingly popular. Whether you want the classical scenarios of blog hosting service or like to create multilingual websites or other ideas. Therefore, it is also important for plugin developers to use the functions and to [...]]]></description>
			<content:encoded><![CDATA[<p>The use of WordPress for several blogs in the network can be useful to simplify several steps and is becoming increasingly popular. Whether you want the classical scenarios of blog hosting service or like to create multilingual websites or other ideas. Therefore, it is also important for plugin developers to use the functions and to expand or develop their own Plugins for it specifically.</p>
<p>Much is the same, but not all, and in this small article I would like to briefly explain how you set settings in the database when you activate a Plugin. <span id="more-2324"></span> </p>
<p>The best case for this is a Function of WordPress, which is triggered when activating a plugin <code>register_activation_hook()</code>. This Function will be called in init or constructor of the Plugin. In the called Function are the functions to store the settings of WordPress in the table options - <code>add_option()</code>. In Multisite there is also a function for it - <code>add_site_option()</code>.</p>
<p>Now you have to separate, if the Plugin is activated within the Network, in the management of Multisite installation, or if it is only used in one of the blogs in the network or a single installation. There are currently no functions, but a value that is passed. The following example illustrates it:</p>
<pre>
register_activation_hook( __FILE__, &#039;fb_add_config&#039; );
function fb_add_config() {

	$data = array(
		&#039;active&#039; =&gt; 0,
		&#039;radio&#039;  =&gt; 0,
		&#039;link&#039;   =&gt; 1,
		&#039;theme&#039;  =&gt; 1,
		&#039;role&#039;   =&gt; &#039;administrator&#039;,
		&#039;unit&#039;   =&gt; 1,
	);
	// if is active in network of multisite
	if ( is_multisite() &amp;&amp; isset($_GET&#091;&#039;networkwide&#039;&#093;) &amp;&amp; 1 == $_GET&#091;&#039;networkwide&#039;&#093; ) {
		add_site_option( &#039;my_settings_id&#039;, $data );
	} else {
		add_option( &#039;my_settings_id&#039;, $data );
	}
}
</pre>
<p>The query of the value in the global <code>GET</code> can be integrated in the long time ago <a href="http://wpengineer.com/2221/wordpress-multisite-plugins-and-activation/">mentioned solution for Multisite</a> and settings.</p>
<p>To solve other queries in a Multisite environment and to remove the setup or integrate menus in the admin area, the function <code>is_plugin_active_for_network()</code> is useful.</p>
<pre>
if ( is_multisite() &amp;&amp; is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
	$values = get_site_option( &#039;my_settings_id&#039; );
else
	$values = get_option( &#039;my_settings_id&#039; );
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2324/register-settings-on-wordpress-multisite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

