<?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; WordPress</title>
	<atom:link href="http://wpengineer.com/tag/wordpress/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>We&#8217;ve Lost A Very Good Friend, WordPress Enthusiast And An Important Part Of WPEngineer!</title>
		<link>http://wpengineer.com/2421/weve-lost-a-very-good-friend-wordpress-enthusiast-and-an-important-part-of-wpengineer/</link>
		<comments>http://wpengineer.com/2421/weve-lost-a-very-good-friend-wordpress-enthusiast-and-an-important-part-of-wpengineer/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 11:10:56 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[WPengineer Misc]]></category>
		<category><![CDATA[Friend]]></category>
		<category><![CDATA[Michael]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Xtreme Theme]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2421</guid>
		<description><![CDATA[Sadness has descended on WPEngineer last week. Michael Preuß, one of our WPEngineer Team, died suddenly after a short illness and after a memorable life. Frank and I are still in shock and we can't realize that Michael left us without saying goodbye. He leaves a big gap in our life. He was not only [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/Michael-Preuss-216x300.jpg" alt="" title="Michael-Preuss" width="150" height="208" class="alignleft size-medium wp-image-2422" />Sadness has descended on WPEngineer last week. Michael Preuß, one of our WPEngineer Team, died suddenly after a short illness and after a memorable life. </p>
<p>Frank and I are still in shock and we can't realize that Michael left us without saying goodbye. He leaves a big gap in our life. He was not only our teammate at WPEngineer, he also was a very good friend, who have shared the same love for WordPress and the community as we do.</p>
<p>We didn't meet us very often in person, since we live quite far away from each other. But when we did, we always had a blast and fun talking about WordPress and other stuff that was going on right now around the world. But most of the time we were talking on the phone for hours, literally. </p>
<p>This time our reunion was one of Frank's and my saddest moment. We had to carry Michael to his grave. It was painful, incomprehensible and unbearable at once. Unlikely for us, not one word about WordPress, this time we had to mourn the loss of our beloved friend Michael.</p>
<p>
<div id="attachment_838" class="wp-caption aligncenter" style="width: 460px"><img alt="Feb 2009 - Matt meets WPEngineer: Frank, Michael, Matt, Alex" src="http://wpengineer.com/wp-content/uploads/matt-meets-wpengineer.jpg" title="Feb 2009 - Matt meets WPEngineer: Frank, Michael, Matt, Alex" class="aligncenter" width="450" height="338" />
<p class="wp-caption-text">Feb 2009 - Matt meets WPEngineer: Frank, Michael, Matt, Alex</p>
</div>
<p>Just 4 years ago we got to know each other and became very good friends. Michael, Frank and I had the urge to give the WordPress community something back, a platform for writing tips, tricks and solutions for the WordPress community - WPEngineer was born! Frank and I will continue to publish future posts, despite the loss we have.</p>
<p>We will also help his partner and friend Heiko, to continue Michael's life's work <a href="http://xtreme-theme.com/" title="Xtreme Theme WordPress Framework">Xtreme Theme</a>.</p>
<p>He left his wonderful and caring wife Carola and his two sons Robert and Alexander behind, and I'm sure, many other WordPress Junkies, like we are, who still can't believe he is gone forever!</p>
<p>You will always be in our Source Code!</p>
<p>In deepest sympathy</p>
<p>Alex &#038; Frank<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/2421/weve-lost-a-very-good-friend-wordpress-enthusiast-and-an-important-part-of-wpengineer/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Stop SOPA!</title>
		<link>http://wpengineer.com/2401/stop-sopa/</link>
		<comments>http://wpengineer.com/2401/stop-sopa/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 07:34:50 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WPengineer Misc]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[sopa]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2401</guid>
		<description><![CDATA[What is this all about: Help Stop SOPA/PIPA Turn off your website on January 18th for 12 hours. Simple and fast solution for turn the website off; use the Plugin WP Maintenance Mode, original for the activation of the maintenance mode; but its easy for this requirement. As useful; the plugin send an 503 Service [...]]]></description>
			<content:encoded><![CDATA[<p>What is this all about: <a href="http://wordpress.org/news/2012/01/help-stop-sopa-pipa/" title="Stop SOPA" target="_blank">Help Stop SOPA/PIPA</a><br />
Turn off your website on January 18th for 12 hours.</p>
<p>Simple and fast solution for turn the website off; use the Plugin <a href="http://wordpress.org/extend/plugins/wp-maintenance-mode/">WP Maintenance Mode</a>, original for the activation of the maintenance mode; but its easy for this requirement. As useful; the plugin send an 503 Service Unavailable header.</p>
<p>Set the following settings in the plugin<br />
<a href="http://wpengineer.com/wp-content/uploads/wp-maintenance-mode-sopa.png"><img src="http://wpengineer.com/wp-content/uploads/wp-maintenance-mode-sopa-300x274.png" alt="" title="wp-maintenance-mode-sopa" width="300" height="274" class="aligncenter size-medium wp-image-2403" /></a></p>
<p>Code for the field text, the video markup:</p>
<pre>
&lt;iframe src=&quot;http://player.vimeo.com/video/31100268?byline=0&amp;portrait=0&quot; width=&quot;400&quot; height=&quot;225&quot; frameborder=&quot;0&quot; webkitAllowFullScreen mozallowfullscreen allowFullScreen&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;a href=&quot;http://vimeo.com/31100268&quot;&gt;PROTECT IP / SOPA Breaks The Internet&lt;/a&gt; from &lt;a href=&quot;http://vimeo.com/fightforthefuture&quot;&gt;Fight for the Future&lt;/a&gt;.&lt;/p&gt;
</pre>
<p>Here is the result for not signed in visitors:<br />
<a href="http://wpengineer.com/wp-content/uploads/stop-sopa.png"><img src="http://wpengineer.com/wp-content/uploads/stop-sopa-300x210.png" alt="" title="stop-sopa" width="300" height="210" class="aligncenter size-medium wp-image-2402" /></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/2401/stop-sopa/feed/</wfw:commentRss>
		<slash:comments>1</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>
	</channel>
</rss>

