<?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>Orange Splotch &#187; api</title>
	<atom:link href="http://orangesplotch.com/tags/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://orangesplotch.com</link>
	<description>Web developing in the middle of the night.</description>
	<lastBuildDate>Sun, 06 Jan 2013 06:30:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>WordPress Media Plugin Tutorial 1: Custom media tabs</title>
		<link>http://orangesplotch.com/wordpress-media-plugin-tutorial-1-custom-media-tabs/</link>
		<comments>http://orangesplotch.com/wordpress-media-plugin-tutorial-1-custom-media-tabs/#comments</comments>
		<pubDate>Thu, 29 May 2008 15:31:47 +0000</pubDate>
		<dc:creator>mattc</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[media library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[series]]></category>
		<category><![CDATA[wordpress 2.5]]></category>

		<guid isPermaLink="false">http://orangesplotch.com/blog/?p=98</guid>
		<description><![CDATA[The first part in the WordPress 2.5 Media API tutorial series. This article discusses how to customize the tabs available in the WordPress media library using hooks made available in the latest WordPress release.]]></description>
				<content:encoded><![CDATA[<p class="intro">This is the first tutorial in a series covering the media hooks available in the WordPress 2.5 API. This article shows how to add a custom media tab to WordPress's built in media library. We'll be using the WordPress API to do this, so no code hacks are required. All examples are based on<a href="http://wordpress.org/extend/plugins/swfobj/"> the SwfObj plugin</a> I developed. Feel free to <a href="http://wordpress.org/extend/plugins/swfobj/download/">download SwfObj</a> as a reference.</p>
<h3>WordPress hooks</h3>
<p>WordPress has conveniently added hooks to its core code, allowing developers the ability to modify content and add functionality without having to hack WordPress source files.  These include filters and actions. For these tutorials we will be using both the '<code>add_filter</code>' and '<code>add_action</code>' functions.</p>
<p>If you are unfamiliar with WordPress's hooks, I'd recommend <a href="http://codex.wordpress.org/Plugin_API">reading their API documentation first</a>.</p>
<h3>Creating a media tab</h3>
<p>When viewing media in WordPress's media library, there are tabs for images, video, and audio. I am going to add a "Flash" tab to the list. You can add whatever media tab you require.</p>
<p><a href="http://orangesplotch.com/blog/wp-content/uploads/2008/05/swfobj_ss1.png"><img class="alignnone size-full wp-image-96" title="A screenshot of the Media Library showing the Flash tab" src="http://orangesplotch.com/blog/wp-content/uploads/2008/05/swfobj_ss1.png" alt="\" width="400" height="171" /></a></p>
<p><strong>Adding file type categories is actually quite easy to do.</strong> To add a tab, you first need to know the MIME type of your category. Flash files (<code>.swf</code> files) use the '<code>application/x-shockwave-flash</code>'  MIME type. If you don't happen to know the MIME type for your files, upload one using the WordPress media button. Once it is uploaded, WordPress displays its type right under the file name.</p>
<p>The WordPress hook to add a category tab to your library is the '<code>post_mime_types</code>' filter. WordPress uses an array called <code>$post_mime_types</code> to store all of the MIME types it lists in the Media Library. To add a new media type, you simply need to add it to this array. The following code adds a "Flash" media category that lists all .swf files in the library.</p>
<pre>function modify_post_mime_types($post_mime_types) {
    $post_mime_types['application/x-shockwave-flash'] = array('Flash', 'Manage Flash', 'Flash (%s)');
    return $post_mime_types;
}

add_filter('post_mime_types', 'modify_post_mime_types');</pre>
<p>The array that is stored in the new <code>$post_mime_types</code> entry holds the following values</p>
<ol>
<li>The title of the media type <em>('Flash')</em>.</li>
<li>The title to display when viewing this category in the Media Library <em>('Manage Flash')</em>.</li>
<li>And the title to put on the tab in the Media Library <em>('Flash (%s)')</em>. The <code>%s</code> is replaced by the number of items in this category.</li>
</ol>
<h3>Extras</h3>
<p>WordPress allows you to add both general and specific MIME types. You can add an '<code>application</code>' type which will show all objects whose MIME type starts with '<code>application/</code>'. To only show a specific file type, use the full MIME type, such as '<code>application/x-shockwave-flash</code>'. Make sure if you are declaring something specific, that you use the full MIME type, not just the value after the '<code>/</code>'.</p>
<p>Here are a few file types you may be interested in.</p>
<ul>
<li>PNG: <code>image/png</code></li>
<li>PDF: <code>application/pdf</code></li>
<li>ZIP: <code>application/zip</code></li>
</ul>
<p>You can also remove media types from the list if you'd like. To do this, use the <code>unset</code> function. Here is an example that removes the 'audio' category from the Media Library.</p>
<pre>function modify_post_mime_types($post_mime_types) {
    unset ($post_mime_types['audio']);
    return $post_mime_types;
}</pre>
<p>And there you have it. Total control over the media types listed in WordPress using the WordPress API. In future posts we'll discuss how to customize uploading, editing and embedding media into your posts. Please post any comments or questions you have. </p>
<p class="aside">If anyone has a better name for the "WordPress 2.5 Media API tutorial series" please let me know. That's a monster to type out.</p>
]]></content:encoded>
			<wfw:commentRss>http://orangesplotch.com/wordpress-media-plugin-tutorial-1-custom-media-tabs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress Media API tutorial series</title>
		<link>http://orangesplotch.com/wordpress-media-api-tutorial-series/</link>
		<comments>http://orangesplotch.com/wordpress-media-api-tutorial-series/#comments</comments>
		<pubDate>Wed, 28 May 2008 00:45:14 +0000</pubDate>
		<dc:creator>mattc</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[media library]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[series]]></category>
		<category><![CDATA[wordpress 2.5]]></category>

		<guid isPermaLink="false">http://orangesplotch.com/blog/?p=99</guid>
		<description><![CDATA[While developing the SwfObj WordPress plugin, I realized there is a large gap in documentation on WordPress media library API. In an attempt to help fill in that gap a little, I am developing a tutorial series based on the API hooks I used to develop SwfObj.]]></description>
				<content:encoded><![CDATA[<p class="intro">Recently I developed the <a href="http://orangesplotch.com/blog/swfobj/">SwfObj WordPress plugin</a>. This required using several newly available WordPress media hooks. Unfortunately, few of these are documented and it took a lot of trial and error to get things working. In the hopes of helping other developers save a few hours, I'm putting together a series of tutorials based on what I learned.</p>
<h3>Coming Soon to a Feed near you</h3>
<p>The plan is to make these short and simple. Each one will highlight one or two API hooks available in WordPress and how they work. The first in this series will be released later this week. If you are interested, <a href="http://orangesplotch.com/blog/feed/">subscribe to the feed</a> and you'll be ready to go. Or just check in later this week</p>
<p>If you have any questions or requests, please let me know.  Feedback will drive the development of future articles. And as always, <a href="http://orangesplotch.com/freelunch">donations are very much appreciated</a>.</p>
<p class="aside">I am also looking for sponsors of this series if anyone is interested. All the articles will be published freely here irregardless of whether I get any funding. It doesn't hurt to ask, <em>I hope</em>.<br />If interested, <a href="http://orangesplotch.com/contact/">contact me for terms</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://orangesplotch.com/wordpress-media-api-tutorial-series/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
