<?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>Gabriel &#187; Code</title>
	<atom:link href="http://www.gabrielserafini.com/tags/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gabrielserafini.com</link>
	<description>Web Design, Development and Business</description>
	<lastBuildDate>Wed, 11 Jan 2012 00:17:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to locate your php.ini file</title>
		<link>http://www.gabrielserafini.com/blog/2010/07/15/how-to-locate-your-php-ini-file/</link>
		<comments>http://www.gabrielserafini.com/blog/2010/07/15/how-to-locate-your-php-ini-file/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 23:23:47 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://gabrielserafini.com/?p=1236</guid>
		<description><![CDATA[When you need to know where the php.ini configuration file is on your server, here is a handy way to find it: php -i &#124; grep php.ini Give it a try.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/gserafini/4406502623/" title="Macbook Pro keys by gserafini, on Flickr"><img src="http://farm5.static.flickr.com/4036/4406502623_70904720c1_m.jpg" width="240" height="160" alt="Macbook Pro keys"/></a></p>
<p>When you need to know where the php.ini configuration file is on your server, here is a handy way to find it:</p>
<p><code>php -i | grep php.ini</code></p>
<p>Give it a try.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gabrielserafini.com/blog/2010/07/15/how-to-locate-your-php-ini-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix 301 error when importing blog posts including images from a WordPress.com blog into a new WordPress.org blog</title>
		<link>http://www.gabrielserafini.com/blog/2009/12/02/how-to-fix-301-error-when-importing-blog-posts-including-images-from-a-wordpress-com-blog-into-a-new-wordpress-org-blog/</link>
		<comments>http://www.gabrielserafini.com/blog/2009/12/02/how-to-fix-301-error-when-importing-blog-posts-including-images-from-a-wordpress-com-blog-into-a-new-wordpress-org-blog/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 18:40:21 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.gabrielserafini.com/?p=1152</guid>
		<description><![CDATA[The current import script (as of WordPress 2.8.6) is broken when it comes to successfully importing images from WordPress.com. The error you see is something like Remote file error: Remote file returned error response 301 Moved Permanently Fixing this involves adding a couple of lines to a core WordPress file. Hopefully a future version of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/gserafini/4102762843/" title="Fourth of July night - Driving home by gserafini, on Flickr"><img src="http://farm3.static.flickr.com/2658/4102762843_2bda3dfac3_m.jpg" width="240" height="180" alt="Fourth of July night - Driving home" /></a></p>
<p>The current import script (as of WordPress 2.8.6) is broken when it comes to successfully importing images from WordPress.com.  The error you see is something like</p>
<p><code>Remote file error: Remote file returned error response 301 Moved Permanently</code></p>
<p>Fixing this involves adding a couple of lines to a core WordPress file.  Hopefully a future version of WordPress will include the working version.</p>
<p><strong>Note that these instructions are for WordPress 2.8.6.  Your version may be different, and you may need to play with this to get it to work for you.  This worked for me, YMMV.</strong></p>
<ol>
<li>Open <code>wp-includes/functions.php</code></li>
<li>Around line 1208 or so, you&#8217;ll find the <code>wp_get_http</code> function.</li>
<li>Right below where it says <code>$headers['response'] = $response['response']['code'];</code>, add the following code (around line 1227):
<pre><code>
// added to fix 301 redirects for blog import code from WordPress.com
if ((string)$response['response']['code'] == '301') {
	$response = wp_remote_request($headers['location'], $options);
	$headers = wp_remote_retrieve_headers($response);
	$headers['response'] = $response['response']['code'];
}
</code></pre>
</li>
<li>Save the functions.php file and copy it back to the server.</li>
<li>Re-run the import function (Tools > Import > WordPress).  Don&#8217;t worry, it won&#8217;t make copies of the posts you&#8217;ve already imported, it will just download the images to your new blog.</li>
</ol>
<p>To fix the references to the images so they&#8217;re being served off your new blog, you can either go through every post and manually correct them all, (not very fun), or better yet, download the <a href="http://wordpress.org/extend/plugins/search-and-replace/">Search and Replace</a> plugin, activate it and do a search for all instances of the WordPress.com image server URL in all your posts (something like <code>http://BLOGNAME.files.wordpress.com/</code> with your own new URL &#8212; <code>http://BLOGNAME.com/wp-content/uploads/</code>).  Don&#8217;t forget to test the new URL structure before you do the search and replace, otherwise you&#8217;ll have to go back and fix it.</p>
<p>Hat-tip to <a href="http://zitomerconsulting.com/blog/tag/wordpress-import-export-301/">Bill Zitomer</a> for pointing out the link to this <a href="http://en.forums.wordpress.com/topic/downloading-images-for-import?replies=4">WordPress support forum page</a> that had a good clue to the solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gabrielserafini.com/blog/2009/12/02/how-to-fix-301-error-when-importing-blog-posts-including-images-from-a-wordpress-com-blog-into-a-new-wordpress-org-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Get rid of widows in your WordPress posts with Widon&#8217;t plugin</title>
		<link>http://www.gabrielserafini.com/blog/2009/02/20/how-to-get-rid-of-widows-in-your-wordpress-posts-with-widont-plugin/</link>
		<comments>http://www.gabrielserafini.com/blog/2009/02/20/how-to-get-rid-of-widows-in-your-wordpress-posts-with-widont-plugin/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 08:42:35 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[typography]]></category>
		<category><![CDATA[widont]]></category>
		<category><![CDATA[widow]]></category>

		<guid isPermaLink="false">http://www.gabrielserafini.com/?p=1027</guid>
		<description><![CDATA[I was just working on making some updates to the backend WordPress code for the Principia Pilot website (http://principiapilot.org/) and noticed widows in some of the stories. Widows are the typographic term for a single word on a line at the end of a paragraph. I thought about the solution to this problem (basically add [...]]]></description>
			<content:encoded><![CDATA[<p>I was just working on making some updates to the backend WordPress code for the Principia Pilot website (<a href="http://principiapilot.org/">http://principiapilot.org/</a>) and noticed widows in some of the stories.</p>
<p>Widows are the typographic term for a single word on a line at the end of a paragraph.  I thought about the solution to this problem (basically add a non-breaking space before the last word of a paragraph) and then realized probably someone had written a plugin to do exactly this.</p>
<p>I tried two different plugins and like this one the best because it doesn&#8217;t overwrite the rest of the excellent WordPress typographic niceties like converting straight quotes to curly quotes:</p>
<p><strong>Widon&#8217;t</strong> <a href="http://www.shauninman.com/archive/2008/08/25/widont_2_1_1">Download latest version here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gabrielserafini.com/blog/2009/02/20/how-to-get-rid-of-widows-in-your-wordpress-posts-with-widont-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Automatically add a default set of Custom Fields to each post in WordPress</title>
		<link>http://www.gabrielserafini.com/blog/2009/02/12/how-to-automatically-add-a-default-set-of-custom-fields-to-each-post-in-wordpress/</link>
		<comments>http://www.gabrielserafini.com/blog/2009/02/12/how-to-automatically-add-a-default-set-of-custom-fields-to-each-post-in-wordpress/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 05:51:46 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[custom field template]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[recommendation]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.gabrielserafini.com/?p=1006</guid>
		<description><![CDATA[One of the neat things about WordPress is how easy it is to add custom metadata to a given page or post that you can then use in a template to display structured information. I&#8217;ve been using this technique for a while now to extend the basic WordPress elements of title, body, excerpt, etc and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/gserafini/3273843546/" title="PrincipiaPilot.org screenshot showing Custom Fields being used in a template by gserafini, on Flickr"><img src="http://farm4.static.flickr.com/3381/3273843546_254621abd7.jpg" width="478" height="500" alt="PrincipiaPilot.org screenshot showing Custom Fields being used in a template" /></a></p>
<p>One of the neat things about <a href="http://wordpress.org/">WordPress</a> is how easy it is to add custom metadata to a given page or post that you can then use in a template to display structured information.  I&#8217;ve been using this technique for a while now to extend the basic WordPress elements of title, body, excerpt, etc and allow the creation of easily editable information-rich content.</p>
<p>Before now I&#8217;ve used the built-in WordPress Custom Field functionality in the <strong>Add New</strong> screen where you select previously created custom fields from a drop-down list that is limited to only showing 30 items.  This is quite cumbersome as you have select each field you want to add to the entry and enter the value, click the <strong>Add Custom Field</strong> button, then repeat for however many custom fields you want to use.  Needless to say, this can be frustrating to have to remember to do every time, especially for non-technical clients.</p>
<h3>The Old Way:</h3>
<p><a href="http://www.flickr.com/photos/gserafini/3273783642/" title="Selecting a Custom Field (the old way) by gserafini, on Flickr"><img src="http://farm4.static.flickr.com/3111/3273783642_4a7b16b7e1.jpg" width="500" height="287" alt="Selecting a Custom Field (the old way)" /></a></p>
<p>During a recent site conversion to WordPress that involves 4-6 custom fields for each post, we finally decided that there must be a better way, and ended up finding a WordPress plugin that is so good that it should probably be added to WordPress core, it is so highly useful.  The plugin is called <a href="http://wordpress.org/extend/plugins/custom-field-template/">Custom Field Template</a> and is developed by <a href="http://wordpressgogo.com/development/custom-field-template.html">Hiroaki Miyashita</a>.</p>
<h3>The New Way:</h3>
<p><a href="http://www.flickr.com/photos/gserafini/3272963785/" title="Custom Field Template WordPress plugin screenshot by gserafini, on Flickr"><img src="http://farm4.static.flickr.com/3429/3272963785_1ed10e51f7.jpg" width="500" height="357" alt="Custom Field Template WordPress plugin screenshot" /></a></p>
<p>Using a simple set of options to define the template you want to use is easy.  After downloading and activating the plugin, go to <strong>Settings > Custom Field Template</strong> to define your template.  One is provided for you to show you the possible template values.  You can set up two separate custom field template designs.</p>
<p>This is the code used to generate the Custom Field Template form shown in the screenshot above:</p>
<h3>Template Instruction</h3>
<p><code>&lt;strong&gt;Story Template Metadata Instructions &lt;em&gt;(All fields are optional)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;<br />
1. Use this form to enter metadata about this story.&lt;br /&gt;<br />
2. Each item will get assigned to the correct Custom Field for use in the display template.&lt;br /&gt;<br />
3. Click the &lt;strong&gt;Save&lt;/strong&gt; button to save the values.&lt;br /&gt;<br />
&lt;br /&gt;</code></p>
<h3>Template Content</h3>
<p><code>[summary_deck]<br />
type = textarea<br />
rows = 3<br />
cols = 50<br />
label = Summary Deck:</code></p>
<p><code>[byline_writer_name]<br />
type = text<br />
size = 35<br />
label = Byline Writer Name: </code></p>
<p><code>[byline_writer_title]<br />
type = text<br />
size = 35<br />
label = Byline Writer Title: </code></p>
<p><code>[byline_writer_picture_url]<br />
type = text<br />
size = 54<br />
label = Byline Writer Picture URL: </code></p>
<p><code>[lead_photo_caption]<br />
type = textarea<br />
rows = 3<br />
cols = 50<br />
label = Lead Photo Caption:</code> </p>
<p><code>[lead_photo_credit]<br />
type = text<br />
size = 35<br />
label = Lead Photo Credit: </code></p>
<p><code>[lead_photo_url]<br />
type = text<br />
size = 54<br />
label = Lead Photo URL: </code></p>
<p>Then set this setting to true by checking the box to make the form look prettier:<br />
<a href="http://www.flickr.com/photos/gserafini/3272980295/" title="Custom Field Template WordPress plugin setting by gserafini, on Flickr"><img src="http://farm4.static.flickr.com/3372/3272980295_dedd546cd3_o.png" width="445" height="54" alt="Custom Field Template WordPress plugin setting" /></a></p>
<p>Next, I tweaked the Admin CSS settings to right-justify the labels:<br />
<code><br />
#cft dl { clear:both; margin:0; padding:0; width:100%; }<br />
#cft dt { float:left; font-weight:bold; margin:0; padding: 0 8px 0 0; text-align:right; width: 20%; }<br />
#cft dt .hideKey { visibility:hidden; }<br />
#cft dd { float:left; margin:0; text-align:left; width:70%; }<br />
#cft dd p.label { font-weight:bold; margin:0; }<br />
#cft_instruction { margin:10px; }<br />
</code></p>
<p>Click <strong>Update Options</strong> to save the settings and then go to <strong>Posts > Add New</strong> to see the form in action.  You may need to go back and forth a couple of times to get your text field sizes just right and to put them in the right order you want them in.</p>
<h3>Using the Custom Fields in a template</h3>
<p>So how do these values get displayed on your page?</p>
<p>Simply edit your template PHP file to look for custom field values and then display them where you want them if they&#8217;re present.</p>
<p>This is how I do it for the <a href="http://principiapilot.org/">Principia Pilot</a> site.  This code goes at the top of the template for <strong>single.php</strong><br />
<code><br />
&lt;?php<br />
// Retrieve custom meta values from post if they're present<br />
$byline_writer_name = htmlspecialchars(get_post_meta($post-&gt;ID, "byline_writer_name", true));<br />
$byline_writer_title = htmlspecialchars(get_post_meta($post-&gt;ID, "byline_writer_title", true));<br />
$byline_writer_picture_url = htmlspecialchars(get_post_meta($post-&gt;ID, "byline_writer_picture_url", true));<br />
$lead_photo_url = htmlspecialchars(get_post_meta($post-&gt;ID, "lead_photo_url", true));<br />
$lead_photo_credit = htmlspecialchars(get_post_meta($post-&gt;ID, "lead_photo_credit", true));<br />
$lead_photo_caption = htmlspecialchars(get_post_meta($post-&gt;ID, "lead_photo_caption", true));<br />
$summary_deck = wptexturize(get_post_meta($post-&gt;ID, "summary_deck", true));<br />
?&gt;<br />
</code></p>
<p>Now each of the possible Custom Fields are available as PHP variables that can be checked for content.</p>
<p>This code example shows the &#8220;summary deck&#8221; being displayed on the page if it has been entered on the create content screen:<br />
<code><br />
&lt;?php<br />
// Show summary deck if we have one<br />
if ($summary_deck != "") {<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo '&lt;h3 class="summary-deck"&gt;' . $summary_deck . '&lt;/h3&gt;';<br />
}<br />
?&gt;<br />
</code></p>
<p>Using this excellent plugin, you can set up select lists, radio buttons, check boxes and more to help you populate your Custom Fields more easily if you prefer that to using simple text fields.  You can also specify default values to use for the custom fields so you don&#8217;t have to type them in every time.</p>
<h3>Plugin Default Template Options</h3>
<p>These are the default options included by the plugin:<br />
<code>[Plan]<br />
type = text<br />
size = 35<br />
label = Where are you going to go?</code></p>
<p><code>[Plan]<br />
type = textfield<br />
size = 35<br />
hideKey = true</code></p>
<p><code>[Favorite Fruits]<br />
type = checkbox<br />
value = apple # orange # banana # grape<br />
default = orange # grape</code></p>
<p><code>[Miles Walked]<br />
type = radio<br />
value = 0-9 # 10-19 # 20+<br />
default = 10-19<br />
clearButton = true</code></p>
<p><code>[Temper Level]<br />
type = select<br />
value = High # Medium # Low<br />
default = Low</code></p>
<p><code>[Hidden Thought]<br />
type = textarea<br />
rows = 4<br />
cols = 40<br />
tinyMCE = true<br />
mediaButton = true</code></p>
<p>Which displays a form that looks like this:<br />
<a href="http://www.flickr.com/photos/gserafini/3273016259/" title="Custom Field Template WordPress plugin screenshot - Default form options by gserafini, on Flickr"><img src="http://farm4.static.flickr.com/3380/3273016259_4d6095b2f4.jpg" width="500" height="363" alt="Custom Field Template WordPress plugin screenshot - Default form options" /></a></p>
<h3>Summary</h3>
<p>This plugin addresses a key need when using Custom Meta Fields in a WordPress custom template design &#8212; making it as easy as possible to enter values time after time on multiple pages or posts.  There are a bunch of other neat options this plugin offers to make the authoring experience even easier.  This is now on my &#8220;must install&#8221; list of essential WordPress plugins.</p>
<h3>Please support Open Source by donating to the plugin author</h3>
<p>If you use this and like it, I highly recommend sending a nice donation to the plugin author to help support ongoing development and to say thanks. This plugin will save you and your clients a lot of time and frustration.  <em>Thanks Hiroaki!</em></p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="100156" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" border="0" name="submit" alt="" style="border:0;" /><img alt="" border="0" src="https://www.paypal.com/ja_JP/i/scr/pixel.gif" width="1" height="1" /></form>
<h3>Requirements</h3>
<p>Requires WordPress 2.1 or higher.</p>
<h3><a href="http://wordpress.org/extend/plugins/custom-field-template/">Click here to download Custom Field Template plugin from WordPress.org</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://www.gabrielserafini.com/blog/2009/02/12/how-to-automatically-add-a-default-set-of-custom-fields-to-each-post-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

