<?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 Hacks</title>
	<atom:link href="http://wpengineer.com/category/wordpress-hacks/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>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>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>Easier Plugin Development by Moving Plugin Directory</title>
		<link>http://wpengineer.com/2374/easier-plugin-development-by-moving-plugin-directory/</link>
		<comments>http://wpengineer.com/2374/easier-plugin-development-by-moving-plugin-directory/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 07:07:50 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2374</guid>
		<description><![CDATA[If you're a experienced programmer you're testing your programs not only with the latest version of WordPress but also with some older versions since there are many dated installations. So you have several versions installed on your development server and want to test your newly created code with every single version. You could copy your [...]]]></description>
			<content:encoded><![CDATA[<p>If you're a experienced programmer you're testing your programs not only with the latest version of WordPress but also with some older versions since there are <a title="WordPress Infographic" href="http://hackertarget.com/wordpress-infographic/">many dated installations</a>. So you have several versions installed on your development server and want to test your newly created code with every single version.<br />
<span id="more-2374"></span><br />
You could copy your plugin files to all installed version's plugin directory manually every time you change the code... but you're a programmer, so this is no option, is it?<br />
If your dev server works under a *nix system you probably have tried to use symbolic links but it didn't work. This is not a bug of WordPress but <a href="https://bugs.php.net/bug.php?id=46260">of PHP</a>. So this does not work either.</p>
<p>Fortunately WordPress defines two constants which can help you to simplify things nonetheless: <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>. These constants point to the plugin directory of the respective WordPress installation. They are defined since WordPress 2.6 and supporting older versions is most likely unnecessary<br />
.<br />
To make your plugins accessible to all your installed WordPress versions you simply move them to a central directory and define the constants accordingly:</p>
<pre lang="php">
define( &#039;WP_PLUGIN_DIR&#039;, &#039;/var/www/plugins&#039; ); // or with XAMPP C:/xampp/htdocs/plugins
define( &#039;WP_PLUGIN_URL&#039;, &#039;http://localhost/plugins&#039; );
</pre>
<p>In this example the plugins reside in the directory 'plugins' in the root directory of the webserver. If you now define the above constants in every WordPress installation you have easy access to them to test your code with every version. </p>
<p>(Thanks to <a href="http://profiles.wordpress.org/users/johnbillion">John Blackbourn</a> on the <a href="http://lists.automattic.com/mailman/listinfo/wp-hackers">wp-hackers</a> list for having the idea.)</p>
<h4>Hint for Multisite-Users</h4>
<p>Also usable for WordPress Multisite</p>
<pre lang="php">
define( &#039;WPMU_PLUGIN_DIR&#039;, &#039;/var/www/multisite-plugins&#039; );
define( &#039;WPMU_PLUGIN_URL&#039;, &#039;http://localhost/multisite-plugins&#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/2374/easier-plugin-development-by-moving-plugin-directory/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>unserialize() Error at Offset&#8230; Different solutions</title>
		<link>http://wpengineer.com/2327/unserialize-error-at-offset-different-olutions/</link>
		<comments>http://wpengineer.com/2327/unserialize-error-at-offset-different-olutions/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 07:00:12 +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[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2327</guid>
		<description><![CDATA[The problem is not always obvious, for example the error message in relation to the function unserialize(). If you look around the net to help you find countless search and few answers, because usually the problem lies in the source, in the passed value. But not always you can control it, especially in debugging helpers [...]]]></description>
			<content:encoded><![CDATA[<p>The problem is not always obvious, for example the error message in relation to the function <code>unserialize()</code>. If you look around the net to help you find countless search and few answers, because usually the problem lies in the source, in the passed value. But not always you can control it, especially in debugging helpers there are different contents.</p>
<p>To help some people who are seeking help, here are some solutions you can work with. Some are to be used only in conjunction with WordPress, because the function comes from the core. But there are similar things, of course, even without WP.<br />
<span id="more-2327"></span><br />
The first solution can be found directly in the comments for the function of <a href="http://www.php.net/manual/de/function.unserialize.php#71270">PHP.net</a>. </p>
<pre>
$object = preg_replace( &#039;!s:(\d+):&quot;(.*?)&quot;;!e&#039;, &quot;&#039;s:&#039;.strlen(&#039;$2&#039;).&#039;:\&quot;$2\&quot;;&#039;&quot;, $object );
</pre>
<p>Similar this approach:</p>
<pre>
$object = preg_replace( &#039;/;n;/&#039;, &#039;;N;&#039;, $object );
</pre>
<p>Alternative <a href="http://ryanbosinger.com/blog/2009/php-unserialize-error-at-offset-simple-solution/">others</a> prefer to use <code>trim()</code></p>
<pre>
$object = trim( $object );
</pre>
<p>But even with these solutions you can't always get what you want, you need a queries which gives you the answer whether it is serialized data or not. Usually <code>unserialize()</code> takes care of it, but as I said, this does not always help. WordPress provides its own functions for this.</p>
<ul>
<li>is_serialized( $data )</li>
<li>is_serialized_string( $data )</li>
</ul>
<p>With these two functions it can be queried in a clean way.<br />
But also there you can use a simple snippet. Not the best practice maybe, therefore, I prefer to use the functions or outside of WP, a separate function, see <a href="https://gist.github.com/1415653" title="gist.github.com/1415653">Gist 1415653</a>.</p>
<pre>
$is_serialized = preg_match( &quot;/^(O:|a:)/&quot;, $object );
</pre>
<p>It may help one or the other, otherwise I use it as a memory aid.<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/2327/unserialize-error-at-offset-different-olutions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Activate WordPress Plugins Automatically via a Function</title>
		<link>http://wpengineer.com/2300/activate-wordpress-plugins-automatically-via-a-function/</link>
		<comments>http://wpengineer.com/2300/activate-wordpress-plugins-automatically-via-a-function/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 07:11:17 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></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=2300</guid>
		<description><![CDATA[WordPress stores the active Plugins in the database table options, field activate_plugins, so it is easy to change this value to activate various Plugins by WordPress; either as a Plugin solution after setting up a new installation or because some Plugins need some other Plugins. I show you as an example a solution. It is [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress stores the active Plugins in the database table <code>options</code>, field <code>activate_plugins</code>, so it is easy to change this value to activate various Plugins by WordPress; either as a Plugin solution after setting up a new installation or because some Plugins need some other Plugins.<br />
<span id="more-2300"></span><br />
I show you as an example a solution. It is important that you don't use the Plugin names, but the string of the file, which is also required in various hooks. Below you will also find a simple solution to get to this string in your backend.</p>
<pre>
// example on admin init, control about register_activation_hook()
add_action( &#039;admin_init&#039;, &#039;fb_activate_plugins&#039; );
// the exmple function
function fb_activate_plugins() {

	if ( ! current_user_can(&#039;activate_plugins&#039;) )
		wp_die(__(&#039;You do not have sufficient permissions to activate plugins for this site.&#039;));
	$plugins = FALSE;
	$plugins = get_option(&#039;active_plugins&#039;); // get active plugins

	if ( $plugins ) {
		// plugins to active
		$pugins_to_active = array(
			&#039;hello.php&#039;, // Hello Dolly
			&#039;adminimize/adminimize.php&#039;, // Adminimize
			&#039;akismet/akismet.php&#039; // Akismet
		);

		foreach ( $pugins_to_active as $plugin ) {
			if ( ! in_array( $plugin, $plugins ) ) {
				array_push( $plugins, $plugin );
				update_option( &#039;active_plugins&#039;, $plugins );
			}
		}

	} // end if $plugins

}
</pre>
<p>The following function and its hook provides a direct output of the string of the Plugin file on the Plugin page in your backend, so please use it only for a quick finding.</p>
<pre>
add_filter( &#039;plugin_row_meta&#039;, &#039;fb_get_plugin_string&#039;, 10, 4 );
function fb_get_plugin_string( $plugin_meta, $plugin_file, $plugin_data, $status ) {
	// echo plugin file string
	echo &#039;&lt;code&gt;&#039; . $plugin_file . &#039;&lt;/code&gt;&lt;br&gt;&#039;;
	return $plugin_meta;
}
</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/2300/activate-wordpress-plugins-automatically-via-a-function/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Advent Calendar – WordPress, WPCron and the right Time</title>
		<link>http://wpengineer.com/2350/advent-calendar-wordpress-wpcron-and-the-right-time/</link>
		<comments>http://wpengineer.com/2350/advent-calendar-wordpress-wpcron-and-the-right-time/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 07:52:59 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2350</guid>
		<description><![CDATA[WordPress offers a pseudo-cronjob functionality, which allows the developer to execute scheduled events. For example, the whole Update Notification does it. In these so-called Scheduled Events you can define your own jobs. Thereby you should however pay attention to one important thing: time. The wp-cron.php works outside the core and loads only the most important [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress offers a pseudo-cronjob functionality, which allows the developer to execute scheduled events. For example, the whole Update Notification does it. In these so-called <em>Scheduled Events</em> you can define your own jobs. Thereby you should however pay attention to one important thing: time.<br />
<span id="more-2350"></span><br />
The <code>wp-cron.php</code> works outside the core and loads only the most important things and leaves all settings of WordPress open. In the <em>Settings -> General</em> set time zone is not included. <code>wp-cron.php</code> runs on UTC.</p>
<p>That means: Are we in the time zone of Berlin, the local time is UTC +1. Are we performing a scheduled event, it will always be one hour after the actual time we like to execute. To change this, we use the following function:</p>
<pre>
function get_offset_to_gmt_in_seconds() {

	$current_timezone_offset = get_option( &#039;gmt_offset&#039; );
	$offset = $current_timezone_offset * 3600;

	return $offset;
}
</pre>
<div class="incontent">
<h4>Guest Post</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/dasllama-150x150.png" alt="" title="dasllama" width="150" height="150" class="alignleft size-thumbnail wp-image-2223" />This post is written by Thomas Herzog - <a href="http://hughwillfayle.de/">hughwillfayle.de</a> and is a guest post on WP Engineer about WordPress.<br />
Thank you very much from my part to Thomas. Please see <a href="http://profiles.wordpress.org/users/hughwillfayle/">his nice plugins</a> on the official WordPress repository.<br />
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!
</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/2350/advent-calendar-wordpress-wpcron-and-the-right-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comment Length Limiter</title>
		<link>http://wpengineer.com/2321/comment-length-limiter/</link>
		<comments>http://wpengineer.com/2321/comment-length-limiter/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 07:02:14 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2321</guid>
		<description><![CDATA[If you have used Twitter, then you know that you are only allowed to type 140 characters in a single Tweet. There is a nice little number below the text field indicating how much is left to write. It would be nice to have this feature for WordPress comments too. Or any text field, for [...]]]></description>
			<content:encoded><![CDATA[<p>If you have used Twitter, then you know that you are only allowed to type 140 characters in a single Tweet. There is a nice little number below the text field indicating how much is left to write.<br />
<span id="more-2321"></span><br />
<img src="http://wpengineer.com/wp-content/uploads/Screen-Shot-2011-12-02-at-11.27.23-AM.png" alt="" title="Screen Shot 2011-12-02 at 11.27.23 AM" width="508" height="153" class="aligncenter size-full wp-image-2322" /></p>
<p>It would be nice to have this feature for WordPress comments too. Or any text field, for that matter. It can be done with the following piece of JavaScript:</p>
<pre>
jQuery(function($) {
	// configure
	var comment_input = $( &#039;#commentform textarea&#039; );
	var submit_button = $( &#039;#commentform .form-submit&#039; );
	var comment_limit_chars = 1000;
	// stop editing here

	// display how many characters are left
	$( &#039;&lt;div class=&quot;comment_limit_info&quot;&gt;&lt;span&gt;&#039; + comment_limit_chars + &#039;&lt;/span&gt; characters left&lt;/div&gt;&#039; ).insertAfter( comment_input );

	comment_input.bind( &#039;keyup&#039;, function() {
		// calculate characters left
		var comment_length = $(this).val().length;
		var chars_left = comment_limit_chars - comment_length;

		// display characters left
		$( &#039;.comment_limit_info span&#039; ).html( chars_left );

		// hide submit button if too many chars were used
		if (submit_button)
			( chars_left &lt; 0 ) ? submit_button.hide() : submit_button.show();
	});
});
</pre>
<p><cite><a href="https://gist.github.com/1422754">https://gist.github.com/1422754</a></cite></p>
<p>The first three <code>var</code>s below the <code>// configure</code> comment can be edited.<br />
<code>comment_input</code> is the DOM element of the text field.<br />
<code>submit_button</code> is the DOM element for the button to submit the form.<br />
Finally, <code>comment_limit_chars</code> is the amount of characters allowed.</p>
<p>This snippet automatically inserts a <code>div</code> tag below the text field and updates the character count when the user types. The <code>submit_button</code> is optional. Set the <code>var</code> to <code>null</code> if you don't want it to be grayed out.</p>
<p>Please keep in mind that this only validates the input on the client side. If you have to rely on the maximum text length, like Twitter does, you need to check the length on the back end side with PHP too.</p>
<div class="incontent">
<h4>Guest Post</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/eric-teubert.jpg" alt="" title="selbst" width="150" height="150" class="alignleft size-full wp-image-2163" />This post is written by Eric Teubert - <a href="http://www.satoripress.com/">www.satoripress.com</a> and is a post in our Advent Calendar on WP Engineer about WordPress.<br />
Thank you very much from my part to <a href="http://twitter.com/#!/ericteubert" title="see Eric also on Twitter">Eric</a>.<br />
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!
</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/2321/comment-length-limiter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Pretty permalinks without mod_rewrite</title>
		<link>http://wpengineer.com/2318/pretty-permalinks-without-mod_rewrite/</link>
		<comments>http://wpengineer.com/2318/pretty-permalinks-without-mod_rewrite/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 06:58:35 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[permalink]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2318</guid>
		<description><![CDATA[There are still some third-class web hosters who do allow the .htaccess files … and turn off the standard module mod_rewrite. But without mod_rewrite, WordPress cannot use pretty permalinks, right? Wrong! There’s another directive we can use: ErrorDocument. ErrorDocument 404 /index.php This will do almost the same as the rewrite rules WordPress offers. It will [...]]]></description>
			<content:encoded><![CDATA[<p>There are still some third-class web hosters who do <em>allow</em> the .htaccess files … and turn off the standard module <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html">mod_rewrite</a>. But without mod_rewrite, WordPress cannot use pretty permalinks, right? Wrong!</p>
<p>There’s another directive we can use: <a href="http://httpd.apache.org/docs/current/mod/core.html#errordocument">ErrorDocument</a>.</p>
<p><code>ErrorDocument 404 /index.php</code></p>
<p>This will do almost the same as the rewrite rules WordPress offers. It will <em>not</em> work with caching plugins like <a href="http://wordpress.org/extend/plugins/w3-total-cache/">W3 Total Cache</a>, it will <em>not</em> <a href="http://wpengineer.com/2162/fix-empty-searches/">catch empty searches</a> and other .htaccess tricks you may want to use. So consider this trick as a temporary solution until you have found a real web hoster.<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/2318/pretty-permalinks-without-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>XML to Array</title>
		<link>http://wpengineer.com/2316/xml-to-array/</link>
		<comments>http://wpengineer.com/2316/xml-to-array/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 07:09:01 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2316</guid>
		<description><![CDATA[In terms of importing data is often set to be XML and have to pass an array in WordPress, which passes into the database. To get an array in PHP after parsing XML, you will always find a variety of threads and questions. In the following, therefore, a simple and quick solution that works great [...]]]></description>
			<content:encoded><![CDATA[<p>In terms of importing data is often set to be XML and have to pass an array in WordPress, which passes into the database. To get an array in PHP after parsing XML, you will always find a variety of threads and questions. In the following, therefore, a simple and quick solution that works great for PHP5.<br />
<span id="more-2316"></span></p>
<pre>
// only for errors an parse
$filename = preg_replace(
    &quot;/\&lt;\!\&#091;CDATA\&#091;(.*?)\&#093;\&#093;\&gt;/ies&quot;,
    &quot;&#039;&#091;CDATA&#093;&#039; . base64_encode(&#039;$1&#039;) . &#039;&#091;/CDATA&#093;&#039;&quot;,
    $filename
);
// load xml file
$xml      = simplexml_load_string( $filename );
// seesaw <img src='http://wpengineer.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
$json     = json_encode( $xml );
$options  = json_decode( $json, TRUE );
// see result
var_dump( $options );

// update in WordPress
update_option( &#039;my_settings_id&#039;, $options );
</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/2316/xml-to-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

