<?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>Apartment One Six &#187; Functions</title>
	<atom:link href="http://apartmentonesix.com/category/wordpress/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://apartmentonesix.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 Dec 2009 22:59:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Display Properly Formatted Content From a $post Object in WordPress</title>
		<link>http://apartmentonesix.com/2009/05/how-to-display-properly-formatted-content-from-a-post-object-in-wordpress/</link>
		<comments>http://apartmentonesix.com/2009/05/how-to-display-properly-formatted-content-from-a-post-object-in-wordpress/#comments</comments>
		<pubDate>Fri, 22 May 2009 02:49:05 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Writing Plugins]]></category>
		<category><![CDATA[$post]]></category>
		<category><![CDATA[the_content]]></category>

		<guid isPermaLink="false">http://apartmentonesix.com/?p=185</guid>
		<description><![CDATA[Occasionally, I&#8217;ll run into a situation where I need to call a post specifically using the get_post() function.  get_post() returns a Post object, with a number of member variables &#8211; the one that stores the actual content of the post being post_content.
However, if you try just echoing $post-&#62;post_content, you&#8217;ll get completely unformatted text &#8211; which [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally, I&#8217;ll run into a situation where I need to call a post specifically using the <a title="Wordpress get_post() codex page" href="http://codex.wordpress.org/Function_Reference/get_post" target="_blank">get_post()</a> function.  get_post() returns a Post object, with a number of member variables &#8211; the one that stores the actual content of the post being post_content.</p>
<p>However, if you try just echoing $post-&gt;post_content, you&#8217;ll get completely unformatted text &#8211; which is frustrating, because WordPress uses a great visual text editor on the backend &#8211; it&#8217;s a shame to not take advantage of it.  Fortunately, WordPress provides a filter to display the text just as it would be displayed in the the_content() function inside the loop.  Here&#8217;s how it works:</p>
<p>To get the content formatted properly, we need to apply a filter (which is different from adding a filter &#8211; here, we&#8217;re registering it so that other filter functions can modify it before it&#8217;s displayed).</p>
<pre class="brush: php">

apply_filters(&#039;the_content&#039;, $post-&gt;post_content);
</pre>
<p>So, we&#8217;re just applying the the_content filter to the $post-&gt;post_content variable.  Doing so means that any plugin which adds a filter function to the_content like this:</p>
<pre class="brush: php">

add_filter(&#039;the_content&#039;, &#039;my_content_manipulator&#039;);

function my_content_manipulator($content){

//do stuff here

return $content;

}
</pre>
<p>will be applied to your variable.  Fortunately, it also means that the WordPress core functions which format the post content correctly can also work on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://apartmentonesix.com/2009/05/how-to-display-properly-formatted-content-from-a-post-object-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How To:  Get an Overview of all Action and Filter Hooks</title>
		<link>http://apartmentonesix.com/2009/04/how-to-get-an-overview-of-all-action-and-filter-hooks/</link>
		<comments>http://apartmentonesix.com/2009/04/how-to-get-an-overview-of-all-action-and-filter-hooks/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 03:17:46 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Writing Plugins]]></category>
		<category><![CDATA[$wp_filter]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://apartmentonesix.com/?p=150</guid>
		<description><![CDATA[Here&#8217;s a very cool little tidbit I found today (strangely enough, I found it in the bbpress codebase, while working on a bbpress plugin..)  Wordpress keeps track of which function/filter combinations are registered, along with which action hooks have been called at any point.  If you&#8217;re having trouble trying to figure out which action hook [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a very cool little tidbit I found today (strangely enough, I found it in the bbpress codebase, while working on a bbpress plugin..)  Wordpress keeps track of which function/filter combinations are registered, along with which action hooks have been called at any point.  If you&#8217;re having trouble trying to figure out which action hook you should use to run some code for your plugin or theme, give this a try (on a test install, of course).</p>
<h3>$wp_filter()</h3>
<p>As far as I can tell, this holds every currently registered function/filter combination, and all the relevant information.  I can&#8217;t quite figure out exactly what determines which filters this grabs &#8211; I&#8217;ve tried calling it from a few places, and the results are slightly different, but I can&#8217;t seem to find a pattern.  I initially assumed that you wouldnt be able to see about admin side hooks from the front end, but this isn&#8217;t the case.  At any rate, you get lots of information from anywhere. Not getting the info you want?  Call it from somewhere else!  This is a great debugging tool if you&#8217;re having trouble with plugin incompatibility &#8211; it gives you a list of the filters and actions being called,the matching functions that are working on them, the priority specified for each hook call, the accepted args, and even the order in which same-priority-level hooks are called.  An example:</p>
<pre class="brush: php">
    [the_title] =&gt; Array
        (
            [10] =&gt; Array
                (
                    [wptexturize] =&gt; Array
                        (
                            [function] =&gt; wptexturize
                            [accepted_args] =&gt; 1
                        )

                    [convert_chars] =&gt; Array
                        (
                            [function] =&gt; convert_chars
                            [accepted_args] =&gt; 1
                        )

                    [trim] =&gt; Array
                        (
                            [function] =&gt; trim
                            [accepted_args] =&gt; 1
                        )

                )

        )
</pre>
<p>This is a small snippet I pulled after displaying the contents of this variable in the footer of a theme.  As you can see, the referenced hook is a filter, specifically &#8220;the_title&#8221;.  It has 3 functions attached to it: wptexturize, convert_chars, and trim.  Each one is at priority level 10 (which is the default), but they are called in the order listed.   Each accepts 1 argument.</p>
<h3>Try it Out</h3>
<p>If you want to have a look yourself, display the contents of wp_filter with this code snippet:</p>
<pre class="brush: php">
&lt;?php
global $wp_filter;
print_r($wp_filter);
?&gt;
</pre>
<p>This is going to dump the contents right to the screen, so you don&#8217;t want to do it on a live blog.  As with any use of the print_r() function, the results will be formatted nicely in the source code &#8211; but not in the rendered html.</p>
<p>Roundup:<br />
<a href="http://www.shankrila.com/tech-stuff/top-wordpress-plugins/" title="Top &#038; Best 65+ WordPress Plugins | ShanKri-la" target="_blank">Top wordpress plugins</a><br />
<a href="http://www.pingable.org/20-of-the-best-free-magazine-wordpress-themes/" title="wordpress magazine theme" target="_blank">wordpress magazine theme</a></p>
]]></content:encoded>
			<wfw:commentRss>http://apartmentonesix.com/2009/04/how-to-get-an-overview-of-all-action-and-filter-hooks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating User Friendly Custom Fields by Modifying the Post Page</title>
		<link>http://apartmentonesix.com/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/</link>
		<comments>http://apartmentonesix.com/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 03:57:12 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Customization]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Writing Plugins]]></category>
		<category><![CDATA[add_meta_box()]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[Edit Post]]></category>
		<category><![CDATA[Post Page]]></category>

		<guid isPermaLink="false">http://apartmentonesix.com/?p=78</guid>
		<description><![CDATA[Ralph over at ForTheLose.org wrote up a great post on how to use custom fields in wordpress a few days ago, and I thought I&#8217;d expand on it with another feature that I use for clients quite often.  Custom fields are a great way to store extra post information, and they can really make for [...]]]></description>
			<content:encoded><![CDATA[<p>Ralph over at <a href="http://forthelose.org" target="_blank">ForTheLose.org</a> wrote up a great post on <a href="http://forthelose.org/how-to-use-custom-fields-in-wordpress" target="_blank">how to use custom fields in wordpress</a> a few days ago, and I thought I&#8217;d expand on it with another feature that I use for clients quite often.  Custom fields are a great way to store extra post information, and they can really make for some more interesting layouts.</p>
<p>Sometimes, however, they can be a little much for a non-tech savvy client or user to handle &#8211; they&#8217;ve got to choose the right custom field from the dropdown, or type it in properly, or it won&#8217;t work &#8211; and what if you&#8217;ve got a few specific option values you&#8217;d like them to choose from for the custom field?  Sometimes it&#8217;s just too risky to expect the user to be able to handle it.</p>
<p>With this in mind, I started looking into how to modify the Add Post and Edit Post pages (ok, they&#8217;re really the same page).  As it turns out, its not too terribly difficult to add in a few options of your own on the post page, giving the user attractive, easy to use access to more advanced features of your theme or plugin.  A few examples:</p>
<h3>Allowing the user to choose his own sidebars</h3>
<p><a href="http://apartmentonesix.com/wp-content/uploads/2009/03/picture-3.png"><img class="size-full wp-image-83 alignleft" title="picture-3" src="http://apartmentonesix.com/wp-content/uploads/2009/03/picture-3.png" alt="picture-3" width="292" height="308" /></a>This one was a fun project for me &#8211; I had a client who wanted to  have a different sidebar on his &#8220;testimonials&#8221; page (he was a consultant).  Now, I started to just set up a new post template for him, but I realized that he really wasnt going to want to call me every time he wanted to add a new testimonial &#8211; that would be ridiculous.  I had really helped sell him on the idea of using wordpress so he wouldn&#8217;t need to call me a few times a month to make small changes to his website &#8211; so forcing him to do so to change his testimonials wouldnt be acceptable.</p>
<p>After giving that some thought, I decided to make another widgetized sidebar for use with the testimonials page template.  This way, he could add text widgets to just that sidebar.  I got to work, and got it set up, and decided that wasn&#8217;t quite right either &#8211; what if down the road he decided he wanted to show those testimonials on a sales page, or some other page I hadn&#8217;t thought of?  He&#8217;d be out of luck.  I decided what I really wanted to do was set up a number of sidebars (I ended up with 6), and allow him to choose the sidebars (it was a 3 column theme) for each page.  Custom Fields were the perfect fit for the job, but that meant he&#8217;d have to remember the name of each of the sidebars when he wanted to change them.  A custom post options box seemed just the right fit.  And it did &#8211; he was really excited about the functionality, and I was excited to have learned something new.</p>
<h3>Required Post Info for a Theme Site</h3>
<p><a href="http://apartmentonesix.com/wp-content/uploads/2009/03/picture-22.png"><img class="alignright size-full wp-image-80" title="picture-22" src="http://apartmentonesix.com/wp-content/uploads/2009/03/picture-22.png" alt="picture-22" width="299" height="524" /></a>Another project tasked me with creating a wordpress theme site for a client.  He wanted each theme post to have a number of fields relating to its layout and structure &#8211; things like number of columns, if it was widgetized, etc.  I decided that the easy way would be to just put the info into the post body, maybe in some custom tags or something &#8211; but wouldn&#8217;t it be cool if users could search by this info?  I got to work.  What I ended up with was a custom post options box with all the relevant theme info &#8211; dropdowns and checkboxes, which removed any possibility of error from user input.  The client was happy, and as always, I had a good time doing it.</p>
<h3>Implementation</h3>
<p>Before we get to how to actually implement this, a word of warning:  with great power comes great responsibility.  In this case, you&#8217;ve got great power to annoy your users &#8211; if you&#8217;re releasing a plugin with minor functionality that probably doesnt need a decision made on a per-post basis, it&#8217;s probably best to leave it off of the post page.  There is no sense in cluttering and slowing down the post page if it isn&#8217;t completely necessary.</p>
<p>The actual implementation of this isn&#8217;t too hairy &#8211; we&#8217;ve basically got 4 parts:</p>
<ol>
<li>Tell WordPress what we want</li>
<li>Display the options box</li>
<li>Retrieve the options</li>
<li>Insert them into custom fields</li>
</ol>
<h3>Finding Room on the Post Page with add_meta_box()</h3>
<p>First things first &#8211; we&#8217;ve got to reserve a spot on the oh-so-exclusive edit post page.  Here&#8217;s how we do it:</p>
<pre class="brush: php">
add_action(&#039;admin_menu&#039;, &#039;my_post_options_box&#039;);

function my_post_options_box() {
add_meta_box(&#039;post_info&#039;, &#039;Post Information&#039;, &#039;custom_post_info&#039;, &#039;post&#039;, &#039;side&#039;, &#039;high&#039;);
}
</pre>
<p>First things first &#8211; we hook into the admin_menu action, with our callback function my_post_options_box().  With this callback function, we initiate the actual box &#8211; with the add_meta_box() call.  Add meta box works like this:</p>
<p>add_meta_box(&#8216;id&#8217;, &#8216;title&#8217;, &#8216;callback&#8217;, &#8216;page&#8217;, &#8216;context&#8217;, &#8216;priority&#8217;)</p>
<ul>
<li>id &#8211; This is the identifier for your box.  Choose wisely.</li>
<li>title &#8211; This holds the string that will display to the user, so make it informative, and properly formatted.</li>
<li>callback &#8211; This references the function that is actually going to display your  option box.</li>
<li>page &#8211; This determines where your post box shows up and your options are post, page, or link.    As far as I know, its not possible to call more than a single option here &#8211; so if you want your box on posts and pages, you&#8217;ll need to make the call twice.</li>
<li>context &#8211; Where your post box will end up &#8211; your options are normal, advanced, and side.  Side shows up on the right side (only available since 2.7), obviously, and, as far as I can tell, both normal and advanced show up below the post box.</li>
<li>priority &#8211; Where (vertically) your box will show up.  Your options are high and low, low putting your option at the bottom of the other boxes, and high putting it at the top.  Both screenshots shown above are set to side and high priority.</li>
</ul>
<h3>Displaying Your Options Box</h3>
<p>Now we&#8217;re going to actually display the options on the page:</p>
<pre class="brush: php">
function custom_post_info() {
global $post;
?&gt;
&lt;fieldset id=&quot;mycustom-div&quot;&gt;
&lt;div&gt;
&lt;p&gt;
&lt;label for=&quot;cpi_dropdown_options&quot; &gt;Dropdown Options:&lt;/label&gt;&lt;br /&gt;
&lt;select name=&quot;cpi_dropdown_options&quot; id=&quot;cpi_dropdown_options&quot;&gt;
&lt;option&lt;?php selected( get_post_meta($post-&gt;ID, &#039;cpi_dropdown_options&#039;, true), &#039;Option 1&#039; ); ?&gt;&gt;Option 1&lt;/option&gt;
&lt;option&lt;?php selected( get_post_meta($post-&gt;ID, &#039;cpi_dropdown_options&#039;, true), &#039;Option 2&#039; ); ?&gt;&gt;Option 2&lt;/option&gt;
&lt;option&lt;?php selected( get_post_meta($post-&gt;ID, &#039;cpi_dropdown_options&#039;, true), &#039;Option 3&#039; ); ?&gt;&gt;Option 3&lt;/option&gt;
&lt;/select&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;label for=&quot;cpi_text_option&quot;&gt;Text Option:&lt;/label&gt;&lt;br /&gt;
&lt;input type=&quot;text&quot; name=&quot;cpi_text_option&quot; id=&quot;cpi_text_option&quot; value=&quot;&lt;?php echo get_post_meta($post-&gt;ID, &#039;cpi_text_option&#039;, true); ?&gt;&quot;&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/fieldset&gt;
&lt;?php
}
</pre>
<p>Nothing too fancy going on here &#8211; but a couple of important points &#8211; we grab the $post global at the top &#8211; we do this so we can check against already stored values in the database (for editing posts instead of creating them).   The entire section is wrapped in a fieldset, a div, and a paragraph &#8211; this ensures that the display matchces the rest of the boxes.  Other than that, its a pretty standard form, we&#8217;ve got a dropdown menu and a text box waiting to be populated.</p>
<h3>Retrieving the Options and Inserting Them Into Custom Fields</h3>
<p>We&#8217;ve had the user set the options, all that is left is to retrieve them on &#8220;Save Draft&#8221; or &#8220;Publish&#8221;, and put them where they really belong &#8211; in custom fields.  This is a little trickier than I expected it to be (and maybe I&#8217;ve made it too difficult.  If somebody can think of a way to simplify this, please let me know).</p>
<pre class="brush: php">
add_action(&#039;save_post&#039;, &#039;custom_add_save&#039;);
function custom_add_save($postID){
// called after a post or page is saved
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}

if ($_POST[&#039;cpi_dropdown_options&#039;]) {
update_custom_meta($postID, $_POST[&#039;cpi_dropdown_options&#039;], &#039;cpi_dropdown_options&#039;);
}
if ($_POST[&#039;cpi_text_option&#039;]) {
update_custom_meta($postID, $_POST[&#039;cpi_text_option&#039;], &#039;cpi_text_option&#039;);
}
}
</pre>
<p>The first thing we do is hook into the save_post action.  This is called on both saving and publishing, so we should be covered.  Our custom_add_save takes a post id as input from the save_post action, and we need it to tell wordpress where to save our options.</p>
<p>Next, we need to figure out if the post id we got matches a real post, or just a revision.  Revisions are stored in the database right alongside posts, with their own id and all &#8211; so we use the <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/post.php.source.html#l3400" target="_blank">wp_is_post_revision</a> function to determine if we&#8217;re working with a revision.  If we are,  <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/post.php.source.html#l3400" target="_blank">wp_is_post_revision</a> conveniently hands off the id of the parent post for us to use.</p>
<p>Now we&#8217;ll check to see if our options were posted.    If we find a $_POST option matching one of our fields, we use that to update the custom field relating to it &#8211; but since we have to do this a few times, I&#8217;ve sent the actual work of updating the custom fields to another function &#8211; update_custom_meta().  Here, we check if the post_meta (custom field) is already set &#8211; if it is, we just update it.  If it isn&#8217;t, we add a new one.</p>
<h3>All Together Now</h3>
<pre class="brush: php">

// ===================
// = POST OPTION BOX =
// ===================

add_action(&#039;admin_menu&#039;, &#039;my_post_options_box&#039;);

function my_post_options_box() {
add_meta_box(&#039;post_info&#039;, &#039;Post Information&#039;, &#039;custom_post_info&#039;, &#039;post&#039;, &#039;side&#039;, &#039;high&#039;);
}

//Adds the actual option box
function custom_post_info() {
global $post;
?&gt;
&lt;fieldset id=&quot;mycustom-div&quot;&gt;
&lt;div&gt;
&lt;p&gt;
&lt;label for=&quot;cpi_dropdown_options&quot; &gt;Dropdown Options:&lt;/label&gt;&lt;br /&gt;
&lt;select name=&quot;cpi_dropdown_options&quot; id=&quot;cpi_dropdown_options&quot;&gt;
&lt;option&lt;?php selected( get_post_meta($post-&gt;ID, &#039;cpi_dropdown_options&#039;, true), &#039;Option 1&#039; ); ?&gt;&gt;Option 1&lt;/option&gt;
&lt;option&lt;?php selected( get_post_meta($post-&gt;ID, &#039;cpi_dropdown_options&#039;, true), &#039;Option 2&#039; ); ?&gt;&gt;Option 2&lt;/option&gt;
&lt;option&lt;?php selected( get_post_meta($post-&gt;ID, &#039;cpi_dropdown_options&#039;, true), &#039;Option 3&#039; ); ?&gt;&gt;Option 3&lt;/option&gt;
&lt;/select&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;label for=&quot;cpi_text_option&quot;&gt;Text Option:&lt;/label&gt;&lt;br /&gt;
&lt;input type=&quot;text&quot; name=&quot;cpi_text_option&quot; id=&quot;cpi_text_option&quot; value=&quot;&lt;?php echo get_post_meta($post-&gt;ID, &#039;cpi_text_option&#039;, true); ?&gt;&quot;&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/fieldset&gt;
&lt;?php
}

add_action(&#039;save_post&#039;, &#039;custom_add_save&#039;);
function custom_add_save($postID){
// called after a post or page is saved
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}

if ($_POST[&#039;cpi_dropdown_options&#039;]) {
update_custom_meta($postID, $_POST[&#039;cpi_dropdown_options&#039;], &#039;cpi_dropdown_options&#039;);
}
if ($_POST[&#039;cpi_text_option&#039;]) {
update_custom_meta($postID, $_POST[&#039;cpi_text_option&#039;], &#039;cpi_text_option&#039;);
}
}

function update_custom_meta($postID, $newvalue, $field_name) {
// To create new meta
if(!get_post_meta($postID, $field_name)){
add_post_meta($postID, $field_name, $newvalue);
}else{
// or to update existing meta
update_post_meta($postID, $field_name, $newvalue);
}
}
?&amp;gt;
</pre>
<p style="text-align: center;"><a href="http://apartmentonesix.com/wp-content/uploads/2009/03/picture-5.png"><img class="aligncenter size-full wp-image-93" title="picture-5" src="http://apartmentonesix.com/wp-content/uploads/2009/03/picture-5.png" alt="picture-5" width="600" height="380" /></a></p>
<p>And there you have it.  Quick, go make something interesting!</p>
]]></content:encoded>
			<wfw:commentRss>http://apartmentonesix.com/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Maybe_Serialize and the Magic of Wordpress</title>
		<link>http://apartmentonesix.com/2009/03/maybe_serialize-and-the-magic-of-wordpress/</link>
		<comments>http://apartmentonesix.com/2009/03/maybe_serialize-and-the-magic-of-wordpress/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 15:33:52 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Options]]></category>
		<category><![CDATA[Post Meta]]></category>
		<category><![CDATA[Serialize]]></category>
		<category><![CDATA[User Meta]]></category>

		<guid isPermaLink="false">http://apartmentonesix.com/?p=72</guid>
		<description><![CDATA[As you may have noticed in a post I made a few days ago about widetizing wordpress plugins,  I mentioned that we needed to serialize our variables before we created them as options in wordpress.  As it turns out, this isn&#8217;t the case &#8211; WordPress does it for you when you go to update or [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed in a post I made a few days ago about <a href="http://apartmentonesix.com/2009/03/widgetizing-a-wordpress-plugin-example-widget-code/">widetizing wordpress plugins</a>,  I mentioned that we needed to serialize our variables before we created them as options in wordpress.  As it turns out, this isn&#8217;t the case &#8211; WordPress does it for you when you go to update or create an option.  This morning, while reading a<a href="http://wpengineer.com/wordpress-working-with-options/" target="_blank"> post on wpengineer.com</a> about wordpress options, I noticed that in their sample code, they weren&#8217;t serializing arrays or objects before creating them as options.  <a href="http://wpengineer.com/about/" target="_blank">Michael</a>, the author, set me straight on why this is ok.</p>
<h3>Maybe Serialize?</h3>
<p>As it turns out, WordPress is one step ahead of me.  <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/functions.php.source.html#l795" target="_blank">Maybe_serialize()</a> is called a number of times throughout wordpress, relating to these items:</p>
<ul>
<li>Post Meta:  It&#8217;s called on <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/post.php.source.html#l497" target="_blank">add_post_meta()</a> and <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/post.php.source.html#l612" target="_blank">update_post_meta()</a>.</li>
<li>User Meta:  It&#8217;s called on <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/user.php.source.html#l323" target="_blank">update_usermeta()</a></li>
<li>Options:  And, of course, its called on <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/functions.php.source.html#l557" target="_blank">add_option()</a> and <a href="http://xref.apartmentonesix.com/2.7.1/wp-includes/functions.php.source.html#l487" target="_blank">update_option()</a></li>
</ul>
<p>So there you go.  Use all the arrays and objects you want in post meta, user meta, and options &#8211; throw caution to the wind, and put them straight in.  Wordpress will handle the boring stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://apartmentonesix.com/2009/03/maybe_serialize-and-the-magic-of-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
