<?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>Kevin &#34;Skwerl&#34; Cogill &#187; Wordpress</title>
	<atom:link href="http://iamskwerl.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamskwerl.com</link>
	<description>I would never call what I do &#34;hacking.&#34;</description>
	<lastBuildDate>Wed, 07 Mar 2012 22:09:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Custom Embed Code With JW Player For WordPress Plugin</title>
		<link>http://iamskwerl.com/tech/2012/03/custom-embed-code-with-jw-player-for-wordpress-plugin/</link>
		<comments>http://iamskwerl.com/tech/2012/03/custom-embed-code-with-jw-player-for-wordpress-plugin/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 19:43:40 +0000</pubDate>
		<dc:creator>Skwerl</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[JW Player]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://iamskwerl.com/?p=215</guid>
		<description><![CDATA[If you care about this, I don&#8217;t need to give you too much background. Longtail&#8217;s JW Player is a great HTML5/Flash video player that has been around for years, with tons of plugins and a large user base, and at this point there&#8217;s very little you can&#8217;t do with it. At least as far as [...]]]></description>
			<content:encoded><![CDATA[<p>If you care about this, I don&#8217;t need to give you too much background. Longtail&#8217;s <a href="http://www.longtailvideo.com/players" target="_blank">JW Player</a> is a great HTML5/Flash video player that has been around for years, with tons of plugins and a large user base, and at this point there&#8217;s very little you can&#8217;t do with it. At least as far as playing audio and video goes.</p>
<p>The guy who coded most of JW Player&#8217;s core and plugins has also produced a handy <a href="http://www.longtailvideo.com/support/addons/jw-player-plugin-for-wordpress/11513/getting-started-with-the-wordpress-plugin-for-the-jw-pla" target="_blank">WordPress plugin</a> that lets you integrate JW Player into your WordPress site, and for the most part it works beautifully.</p>
<p>There&#8217;s at least one exception: While you have the option to integrate the sharing plugin via the plugin&#8217;s settings in WordPress, you have one global field for &#8220;embed code&#8221; that can&#8217;t really accept anything useful. You have to URI escape anything that goes in there (which wouldn&#8217;t be so bad if there was a way to URI unescape the output), and there&#8217;s no way to add a MEDIAID variable in there so that your embed code can be dynamic (which is a complete dealbreaker for almost every user).</p>
<p>Well, I needed this feature, so I found a workaround. And I didn&#8217;t want to go hacking into the plugin code (so that I could update it later, without clobbering my fix), so the way I did it was through a PHP regex in my theme&#8217;s functions.php.</p>
<p>I first did two things, only one of which should be necessary: In the plugin configuration, I set my custom embed code to <em>[FIXME]</em>, which is what my regex will look for, and replace with something useful.</p>
<p>Second, I edited sharing.xml in the WordPress plugin&#8217;s plugins directory, to use the sharing-3 repository, rather than sharing-1. I just prefer version 3&#8242;s interface, but I also figured newer was probably better. All I did was change the value of the &lt;repository&gt; field from <em>sharing-1</em> to <em>sharing-3</em>.</p>
<p>But here&#8217;s the fix: In my theme&#8217;s functions.php, I added a filter for the_content (set at priority 999 so it would run after the JW Player plugin has already replaced my shortcode with the complete embed code), which finds the MEDIAID, and finds my <em>[FIXME]</em> placeholder, and assembles a good embed code. &lt;embed id=&#8221;1&#8243; /&gt; is obviously not good embed code; that&#8217;s just for simplicity/illustration. You&#8217;ll want to replace that with <em>your</em> custom embed code, and <a href="http://www.longtailvideo.com/support/addons/sharing-plugin/14049/setting-clean-embed-codes" target="_blank">here are some ideas</a> on how to do that cleanly.</p>
<p><strong>Theme functions.php</strong></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> swap_embed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$good_code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;embed id=\&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\&quot; /&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$replaced</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$good_code</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">',&quot;mediaid&quot;:&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$replaced</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> fix_jw_embed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$regex</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/\&quot;(\[FIXME\])\&quot;(,.*)?,\&quot;mediaid\&quot;:\&quot;(\d{1,})\&quot;/i'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace_callback</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$regex</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'swap_embed'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fix_jw_embed'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Caveat: This only fixes the players in the post body, and not the one generated for the og:video tag for playable embedding on Facebook. I&#8217;ll be figuring that out later, and eventually adding the code to this piece, for anyone that needs it.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamskwerl.com/tech/2012/03/custom-embed-code-with-jw-player-for-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

