<?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>anilmakhijani.com &#187; Wordpress Development</title>
	<atom:link href="http://anilmakhijani.com/category/wordpress-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://anilmakhijani.com</link>
	<description></description>
	<lastBuildDate>Mon, 06 Jun 2011 17:19:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Planet WordPress Plugin Released</title>
		<link>http://anilmakhijani.com/2009/07/07/planet-wordpress-plugin-released/</link>
		<comments>http://anilmakhijani.com/2009/07/07/planet-wordpress-plugin-released/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 02:01:38 +0000</pubDate>
		<dc:creator>Anil</dc:creator>
				<category><![CDATA[Wordpress Development]]></category>
		<category><![CDATA[Planet]]></category>
		<category><![CDATA[planetdev]]></category>
		<category><![CDATA[Streetsblog.NET]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://anilmakhijani.com/?p=279</guid>
		<description><![CDATA[I love the Planet feed aggregator, but I hate managing it via a text configuration file. I created a WordPress plugin that automatically creates a Planet configuration file from the links that are stored in a WordPress database. Every time a link is updated, deleted, or created, a new planet configuration is generated. For more [...]]]></description>
			<content:encoded><![CDATA[<p>I love the <a href="http://planetplanet.org">Planet</a> feed aggregator, but I hate managing it via a text configuration file.  I created a WordPress plugin that automatically creates a Planet configuration file from the links that are stored in a WordPress database.  Every time a link is updated, deleted, or created, a new planet configuration is generated.</p>
<p>For more information on how to install and configure the plugin, visit the <a href="http://anilmakhijani.com/wordpress-dev/planet-wordpress/">plugin&#8217;s homepage</a>.  The source code for the plugin is hosted at <a href="http://wordpress.org/extend/plugins/planet-wordpress/">wordpress.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://anilmakhijani.com/2009/07/07/planet-wordpress-plugin-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geo Blogroll Plugin Released</title>
		<link>http://anilmakhijani.com/2009/01/07/geo-blogroll-plugin-released/</link>
		<comments>http://anilmakhijani.com/2009/01/07/geo-blogroll-plugin-released/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 22:18:22 +0000</pubDate>
		<dc:creator>Anil</dc:creator>
				<category><![CDATA[Wordpress Development]]></category>
		<category><![CDATA[planetdev]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://anilmakhijani.com/?p=170</guid>
		<description><![CDATA[I had promised to clean up and release some of the plugins that went into creating Streetsblog.net. Here is the first one: Geo Blogroll.]]></description>
			<content:encoded><![CDATA[<p>I had <a href="http://anilmakhijani.com/2008/12/03/streetsblognet-launch/">promised</a> to clean up and release some of the plugins that went into creating <a href="http://streetsblog.net">Streetsblog.net</a>.  Here is the first one: <a href="http://anilmakhijani.com/wordpress-dev/geo-blogroll/">Geo Blogroll</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://anilmakhijani.com/2009/01/07/geo-blogroll-plugin-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting Posts from WordPress 2.5</title>
		<link>http://anilmakhijani.com/2008/12/30/exporting-posts-from-wordpress-25/</link>
		<comments>http://anilmakhijani.com/2008/12/30/exporting-posts-from-wordpress-25/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 21:06:59 +0000</pubDate>
		<dc:creator>Anil</dc:creator>
				<category><![CDATA[Wordpress Development]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://anilmakhijani.com/?p=141</guid>
		<description><![CDATA[Recently I tried exporting some posts from one WordPress 2.5 blog to another WordPress 2.5 blog. The import worked perfectly, but then I realized that I had forgotten to import one of the posts. Rather than doing to the whole import again, I decided to just import the post that I had forgotten. Unfortunately, WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I tried exporting some posts from one WordPress 2.5 blog to another WordPress 2.5 blog.  The import worked perfectly, but then I realized that I had forgotten to import one of the posts.  Rather than doing to the whole import again, I decided to just import the post that I had forgotten.  Unfortunately, WordPress brought over all of my categories again, leaving me with duplicates of all of my categories.  Ugg.</p>
<p>I wrote a small python script that takes a wordpress export file and strips out information about categories and tags.  It&#8217;s a pretty simple script, but I will share it anyway: <a href="http://demos.anilmakhijani.com/scripts/rm_cats_wp_export.py">script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://anilmakhijani.com/2008/12/30/exporting-posts-from-wordpress-25/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Streetsblog.NET Launch</title>
		<link>http://anilmakhijani.com/2008/12/03/streetsblognet-launch/</link>
		<comments>http://anilmakhijani.com/2008/12/03/streetsblognet-launch/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 19:29:25 +0000</pubDate>
		<dc:creator>Anil</dc:creator>
				<category><![CDATA[Planet]]></category>
		<category><![CDATA[Steetsblog.NET]]></category>
		<category><![CDATA[Wordpress Development]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Streetsblog.NET]]></category>
		<category><![CDATA[TOPP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://anilmakhijani.com/?p=120</guid>
		<description><![CDATA[A few coworkers and I launched Streetsblog.NET yesterday. The website is actually a vanilla install of WordPress working in conjunction with a vanilla install of Planet with a bunch of custom WordPress plugins. I will release the plugins when I get some time to clean them up.]]></description>
			<content:encoded><![CDATA[<p>A few coworkers and I launched <a href="http://streetsblog.net">Streetsblog.NET</a> yesterday.  The website is actually a vanilla install of <a href="http://wordpress.org">WordPress</a> working in conjunction with a vanilla install of <a href="http://www.planetplanet.org/">Planet</a> with a bunch of custom WordPress plugins.  I will release the plugins when I get some time to clean them up.</p>
]]></content:encoded>
			<wfw:commentRss>http://anilmakhijani.com/2008/12/03/streetsblognet-launch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding Meta Information to a Blogroll</title>
		<link>http://anilmakhijani.com/2008/10/13/adding-meta-information-to-a-blogroll/</link>
		<comments>http://anilmakhijani.com/2008/10/13/adding-meta-information-to-a-blogroll/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 17:27:16 +0000</pubDate>
		<dc:creator>Anil</dc:creator>
				<category><![CDATA[Planet]]></category>
		<category><![CDATA[Wordpress Development]]></category>
		<category><![CDATA[Blogroll]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://anilmakhijani.com/?p=89</guid>
		<description><![CDATA[I found a useful blog post on how to add text fields to the &#8220;link management&#8221; admin menu in WordPress:  http://planetozh.com/blog/2008/02/wordpress-snippet-add_meta_box/ But how do you save this information into your database?  This is a three step approach. 1.  Add the fields to you database: add_action('activate_geo_blogroll.php','geo_blogroll_update_db'); function geo_blogroll_update_db(){ global $wpdb; $wpdb-&#62;query("ALTER TABLE $wpdb-&#62;links ADD COLUMN link_city [...]]]></description>
			<content:encoded><![CDATA[<p>I found a useful blog post on how to add text fields to the &#8220;link management&#8221; admin menu in WordPress:  <a href="http://planetozh.com/blog/2008/02/wordpress-snippet-add_meta_box/" target="_blank">http://planetozh.com/blog/2008/02/wordpress-snippet-add_meta_box/</a></p>
<p>But how do you save this information into your database?  This is a three step approach.</p>
<p>
1.  Add the fields to you database:
</p>
<pre>add_action('activate_geo_blogroll.php','geo_blogroll_update_db');

function geo_blogroll_update_db(){
   global $wpdb;
   $wpdb-&gt;query("ALTER TABLE $wpdb-&gt;links ADD COLUMN link_city varchar(255);");
   $wpdb-&gt;query("ALTER TABLE $wpdb-&gt;links ADD COLUMN link_state varchar(255);");
}</pre>
<p>
2.  Add text fields to the link admin screen:
</p>
<pre>add_action('admin_menu', 'add_geo_meta_to_links');

function add_geo_meta_to_links() {
   add_meta_box ('geo_link', 'Link Geography', 'geo_blogroll_form', 'link');
}

function geo_blogroll_form () {
  global $link;
?&gt;

&lt;table class="form-table" style="width: 100%;" cellspacing="2" cellpadding="5"&gt;
  &lt;tr class="form-field"&gt;
       &lt;th value="top" scope="row"&gt;&lt;label for="blog_city"&gt;&lt;?php _e('City'); ?&gt;&lt;/label&gt;&lt;/th&gt;
       &lt;td&gt;
           &lt;input name="blog_city" type="text" id="blog_city"
                  value="&lt;?php echo $link-&gt;link_city; ?&gt;" style="width: 95%" /&gt;
       &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="form-field"&gt;
    &lt;th value="top" scope="row"&gt;&lt;label for="blog_state"&gt;&lt;?php _e('State'); ?&gt;&lt;/label&gt;&lt;/th&gt;
    &lt;td&gt;
      &lt;input name="blog_state" type="text" id="blog_state"
             value="&lt;?php echo $link-&gt;link_state; ?&gt;"  style="width: 95%" /&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;?php } ?&gt;</pre>
<p>
3.  And finally save this information to the database every time someone saves a new link or updates an old link:
</p>
<pre>add_action('edit_link', 'geo_blogroll_save_meta');
add_action('add_link', 'geo_blogroll_save_meta');

function geo_blogroll_save_meta ($link_id){
  global $wpdb;
  $sql_statement =  "UPDATE wp_links SET link_city='".$_POST['blog_city'].
                              "', link_state='".$_POST['blog_state'].
                              "' WHERE link_id =".$link_id.";";
  $wpdb-&gt;query($sql_statement);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://anilmakhijani.com/2008/10/13/adding-meta-information-to-a-blogroll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress 2.6 and Captions</title>
		<link>http://anilmakhijani.com/2008/08/04/wordpress-26-and-captions/</link>
		<comments>http://anilmakhijani.com/2008/08/04/wordpress-26-and-captions/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 18:43:02 +0000</pubDate>
		<dc:creator>Anil</dc:creator>
				<category><![CDATA[Steetsblog.NET]]></category>
		<category><![CDATA[Wordpress Development]]></category>
		<category><![CDATA[Captions]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://anilmakhijani.com/?p=35</guid>
		<description><![CDATA[Last week, The Open Planning Project premiered a new blog called Gotham Schools.  As a blogging platform, we decided to give the newly released WordPress 2.6 a go.  The one feature WordPress added that excited us the most was the ability to add captions to images.  Soon, however, we realized that WordPress/TinyMCE strips any html [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, <a href="http://topp.openplans.org">The Open Planning Project</a> premiered a new blog called <a href="http://gothamschools.org">Gotham Schools</a>.  As a blogging platform, we decided to give the newly released WordPress 2.6 a go.  The one feature WordPress added that excited us the most was the ability to add captions to images.  Soon, however, we realized that WordPress/TinyMCE strips any html that is added to a caption.</p>
<p>I set out to fix this, and with the help of a couple of <a title="David Turner" href="http://novalis.org">co</a>-<a title="Chris Abraham" href="http://www.openplans.org/people/cabraham/profile" target="_blank">workers</a>, I think I got something that works (<a href="http://trac.openplans.org/openplans/changeset?new=19608%40gothamschools%2Ftrunk&#038;old=19534%40gothamschools%2Ftrunk" target="_blank">change set</a>).  After the jump I have an overview of the problem and how it was fixed.</p>
<p><span id="more-35"></span></p>
<p>When you insert an image with a caption into a blog post in WordPress 2.6, markup like this is generated and put into the &#8220;Visual&#8221; tab of your TinyMCE editor:</p>
<pre>&lt;div class="mceTemp"&gt;
  &lt;dl id="attachment_104" class="wp-caption alignnone" style="width: 310px;"&gt;
    &lt;dt class="wp-caption-dt"&gt;
       &lt;a mce_href="http://host/image.jpg" href="http://host/image.jpg"&gt;
          &lt;img class="size-medium wp-image-104" width="300" height="240" alt="Test Caption"
               mce_src="http://host/imagethumb.jpg" src="http://host/imagethumb.jpg"
               title="img00005"/&gt;
       &lt;/a&gt;
    &lt;/dt&gt;
    &lt;dd class="wp-caption-dd"&gt;
      Test Caption
    &lt;/dd&gt;
  &lt;/dl&gt;
&lt;/div&gt;</pre>
<p>When you click on the &#8220;HTML&#8221; tab of the TinyMCE editor, Javascript converts this code to something like this:</p>
<pre>〈caption id="attachment_104" align="alignnone" width="300" caption="Test Caption"〉&lt;a
href="http://host/image.jpg"&gt;&lt;img class="size-medium wp-image-104" title="img00005"
src="http://host/image.jpg" alt="Test Caption" width="300" height="240" /&gt;&lt;/a&gt;〈/caption〉</pre>
<p>WordPress calls the latter of these a &#8220;short code&#8221;.  It is the short code itself stored in the database, not the markup.  When you switch back and forth between the &#8220;Visual&#8221; and &#8220;HTML&#8221; tab, WordPress converts to and from the short code.</p>
<p>The first change we have to make to allow markup in captions in the file: /wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js in the function &#8220;_get_shcode&#8221;.  This is the Javascript function that turns markup into shortcode.  Lets look at line 120 in this file:</p>
<pre>cap = cap.replace(/&lt;\S[^&lt;&gt;]*&gt;/gi, '').replace(/'/g, '<span>&amp;#39;</span>').replace(/"/g, '&amp;quot;');</pre>
<p>The first &#8220;replace&#8221; in this line of code gets rid of anything that is within a left than sign (&lt;) and a greater than sign (&gt;).  The second and third &#8220;replace&#8221; turn single quote (&#8216;), and double quotes (&#8220;) into their respective HTML entities.  These three replaces together effectively remove all markup from our caption.  For this reason we have to comment it out, and replace it with this line:
</p>
<pre>cap = cap.replace(/(['"])/g, '\\$1');</pre>
<p>This line escapes all of the single and double quotes in our caption (it turns &#8216; into \&#8217; and &#8221; into \&#8221;).  Later on in this post, it will be obvious why we have to do this.</p>
<p>The next change we have to make is in line 91 of the same file.  This line is in the &#8220;_do_shcode&#8221; function.  This function is responsible for turning the short code into the markup described earlier.  Line 91 is as follows:
<pre>b = b.replace(/\\'|\\&amp;#39;|\\&amp;#039;/g, '&amp;#39;').replace(/\\"|\\&amp;quot;/g, '&amp;quot;');</pre>
<p>This line basically un-does the escaping that we just added in.   Lets comment it out.  The reason we want to leave the escaping in is because WordPress has to be certain where a short code attributes ends.  For example if we had:</p>
<pre>〈caption id="test" caption="test &lt;a href="test.com"&gt;Test&lt;/a&gt;"〉</pre>
<p>WordPress would think that the caption was &#8220;test &lt;a href=&#8221;.  However if we escape our quotes, we have something like this:</p>
<pre>〈caption id="test" caption="test &lt;a href=\"test.com\"&gt;Test&lt;/a&gt;"〉</pre>
<p>If we tell WordPress to ignore \&#8221; and \&#8217; and only look for &#8221; and &#8216; when looking for the end of a short code, it can be certain where the caption attribute ends.  So lets make that change to the second half of line 94 of the same file.  Change this:</p>
<pre>cap = b.match(/caption=['"]([^'"]+)/i);</pre>
<p>to this:</p>
<pre>cap = b.match(/caption=['"]((?:[^'"\\]+(?:\\[\\'"])*)+)/i);</pre>
<p>This change allows the caption to have back slashed single and double quotes in it.  Now that we have the caption, with its markup intact, we can get rid of the backslashes before the shortcode is turned back into markup.  To do this lets add this line following line (see the changeset for exact location):</p>
<pre>cap = cap.replace(/\\(["'])/g, "$1");</pre>
<p>Ok, now we are done with fixing the TinyMCE editor, we now have to make sure that when the WordPress backend converts short codes to markup, it know how to deal with back slashed quotes.  To do this lets change line 212 of wp-includes/shortcodes.php to:</p>
<pre>$pattern = '/(\w+)\s*=\s*"((?:\\\\.|[^"])*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|
(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';</pre>
<p>We are almost done.  The last problem is that when we upload and insert and image into TinyMCE, it assumes that the &#8220;alt&#8221; attribute of the image tag and the &#8220;caption&#8221; attribute of the caption short code will be the same.  The problem is that we probably do NOT want markup in the alt attributes of our image tags.  How do we lets fix this?  </p>
<p>When you insert an image with a caption into a WordPress blog post, the following function calles are made:</p>
<p>&#8220;image_media_send_to_editor&#8221; which calls &#8220;get_image_send_to_editor&#8221; which applies the filter &#8220;image_send_to_editor&#8221; which calls &#8220;image_add_caption&#8221;.</p>
<p>If we look at line 591 of wp-admin/includes/media.php (where &#8220;image_media_send_to_editor&#8221; calls &#8220;get_image_send_to_editor&#8221;) we see that the image &#8220;alt&#8221; text is passed through.  The &#8220;alt&#8221; text is locally referred to as the the &#8216;post_excerpt&#8217; field in the attachment array:</p>
<pre>
return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'],
                                                  $attachment['post_title'], $align, $url, $rel,
                                                  $size);
</pre>
<p>Instead of just passing in &#8220;alt&#8221; text, lets send a HTML stripped version of the text as well:</p>
<pre>
$stripped = strip_tags($attachment['post_excerpt']);
return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $stripped,
                                                  $attachment['post_title'], $align, $url, $rel,
                                                  $size);
</pre>
<p>This way we can use the unstripped version for the &#8220;caption&#8221; and the stripped version for the &#8220;alt&#8221; text.  Since we are now passing in a new variable into &#8220;get_image_send_to_editor&#8221; we have to alter its function definition in line 54 to:</p>
<pre>
function get_image_send_to_editor($id, $caption, $alt, $title, $align, $url='', $rel = false,
                                                     $size='medium') {
</pre>
<p>This new $caption variable should be be now passed along to &#8220;image_send_to_editor&#8221; in line 63:</p>
<pre>$html = apply_filters( 'image_send_to_editor', $html, $id, $caption,  $alt, $title, $align, $url,
                                          $size ); </pre>
<p>And finally passed to &#8220;image_add_caption&#8221; in line 68:</p>
<pre>
function image_add_caption( $html, $id, $caption, $alt, $title, $align, $url, $size ) {
</pre>
<p>This function &#8220;image_add_caption&#8221; generates the image caption short code on line 81:</p>
<pre>
 $shcode = '〈caption id="' . $id . '" align="align' . $align
                   . '" width="' . $width . '" caption="' . $alt . '"〉' . $html . '〈/caption〉';
</pre>
<p>Instead of using the $alt variable for our caption, lets use our newly created $caption variable like this:</p>
<pre>
$shcode = '〈caption id="' . $id . '" align="align' . $align
                . '" width="' . $width . '" caption="' . $caption . '"〉' . $html . '〈/caption〉';
</pre>
<p>Great!  We are finally done.  We can now have markup in our Wodpress captions.  Again, all the changes described on this page can be succinctly found here:  <a href="http://trac.openplans.org/openplans/changeset?new=19608%40gothamschools%2Ftrunk&#038;old=19534%40gothamschools%2Ftrunk" target="_blank">change set</a></p>
]]></content:encoded>
			<wfw:commentRss>http://anilmakhijani.com/2008/08/04/wordpress-26-and-captions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

