<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Hijack the WordPress Media Gallery</title>
	<atom:link href="http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 03 Sep 2010 11:39:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Simon</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-383</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Fri, 09 Jul 2010 21:15:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-383</guid>
		<description>This is great, thanks so much for posting.

I was having problems using the wp_enqueue_script(&#039;media-upload&#039;); - I was getting the properly sized editor but my custom send_to_editor() function wasn&#039;t being triggered. I found that if I listed the dependencies on my own custom JS code, that solved the problem. 

Like so:

function admin_add_scripts() {
	add_thickbox();
	wp_enqueue_script(&#039;media-upload&#039;);
// My js file, with an array of dependencies
	wp_enqueue_script( &#039;admin.js&#039;, get_stylesheet_directory_uri() . &quot;/scripts/admin.js&quot;, array(&#039;jquery&#039;, &#039;media-upload&#039;) );
}
add_action(&#039;admin_init&#039;, &#039;admin_add_scripts&#039;);

Simon</description>
		<content:encoded><![CDATA[<p>This is great, thanks so much for posting.</p>
<p>I was having problems using the wp_enqueue_script(&#8216;media-upload&#8217;); &#8211; I was getting the properly sized editor but my custom send_to_editor() function wasn&#8217;t being triggered. I found that if I listed the dependencies on my own custom JS code, that solved the problem. </p>
<p>Like so:</p>
<p>function admin_add_scripts() {<br />
	add_thickbox();<br />
	wp_enqueue_script(&#8216;media-upload&#8217;);<br />
// My js file, with an array of dependencies<br />
	wp_enqueue_script( &#8216;admin.js&#8217;, get_stylesheet_directory_uri() . &#8220;/scripts/admin.js&#8221;, array(&#8216;jquery&#8217;, &#8216;media-upload&#8217;) );<br />
}<br />
add_action(&#8216;admin_init&#8217;, &#8216;admin_add_scripts&#8217;);</p>
<p>Simon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Hoff</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-282</link>
		<dc:creator>John Hoff</dc:creator>
		<pubDate>Sat, 17 Apr 2010 15:12:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-282</guid>
		<description>The media-upload script needs to be called before wordpress starts sending content to the browser.  By the time it starts parsing banner.php, it is already too late.  You&#039;ll see how I addressed part of this in the &#039;hijack_thickbox_include&#039; action in hijack.php.  I placed your wp_enqueue_script call in there, and everything appears to have worked:&lt;br /&gt;
&lt;code&gt;add_action(&#039;admin_init&#039;, &#039;hijack_thickbox_include&#039;);
function hijack_thickbox_include() {
    add_thickbox();
    wp_enqueue_script(&#039;media-upload&#039;);
}&lt;/code&gt;&lt;br /&gt;

That should fix your problems with the media upload.  There is likely a better method for including it, but I&#039;ll have to do more digging to find it.</description>
		<content:encoded><![CDATA[<p>The media-upload script needs to be called before wordpress starts sending content to the browser.  By the time it starts parsing banner.php, it is already too late.  You&#8217;ll see how I addressed part of this in the &#8216;hijack_thickbox_include&#8217; action in hijack.php.  I placed your wp_enqueue_script call in there, and everything appears to have worked:<br />
<code>add_action('admin_init', 'hijack_thickbox_include');<br />
function hijack_thickbox_include() {<br />
    add_thickbox();<br />
    wp_enqueue_script('media-upload');<br />
}</code></p>
<p>That should fix your problems with the media upload.  There is likely a better method for including it, but I&#8217;ll have to do more digging to find it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rofflox</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-273</link>
		<dc:creator>rofflox</dc:creator>
		<pubDate>Thu, 08 Apr 2010 19:38:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-273</guid>
		<description>Thanks John for your great article.

I&#039;m currently working on a theme using WP 2.9.2. Out of the box, your script doesn&#039;t work properly here. I&#039;d to change the following things:

1) In my custom admin-option-page the required thickbox css and js file wouldn&#039;t be load by default. To add the required fields to the wordpress list of loaded files, just call &lt;code&gt;add_thickbox();&lt;/code&gt; in your init-function of your admin-page or before wp_head();.

2) Same goes for my custom js file: Put the line &lt;code&gt;wp_enqueue_script(&#039;&lt;a&gt;_custom_js&#039;, &#039;/js/custom.js&#039;);&lt;/code&gt; in your init-function.

3) I&#039;d the problem, that the value attribute of my input field wasn&#039;t updated. If you use the built-in jquery support from wordpress, you have to &quot;wrap&quot; every jquery call since WP 2.8+. Instead of using $();, you have to write jQuery();. This took me some time to figure out.

So you have to change the function send_to_editor to the following:

&lt;code&gt;
function send_to_editor(html) { 
var source = html.match(/src=\&quot;.*\&quot; alt/); 
source = source[0].replace(/^src=\&quot;/, &quot;&quot;).replace(/&quot; alt$/, &quot;&quot;); 
&lt;b&gt;jQuery&lt;/b&gt;(&quot;#banner_image&quot;).attr(&#039;src&#039;, source); 
&lt;b&gt;jQuery&lt;/b&gt;(&#039;#banner_image_input&quot;).attr(&#039;value&#039;, source);
tb_remove(); 
} 
&lt;/code&gt;

However, one problem remains:

The thickbox window isn&#039;t loaded at full size. I&#039;ve tried to load the built-in js script &quot;media-upload&quot; with &lt;code&gt;wp_enqueue_script(&#039;media-upload&#039;);&lt;/code&gt; which seems to work, but this breaks the whole script.

If anybody has a solution, please post ;)</description>
		<content:encoded><![CDATA[<p>Thanks John for your great article.</p>
<p>I&#8217;m currently working on a theme using WP 2.9.2. Out of the box, your script doesn&#8217;t work properly here. I&#8217;d to change the following things:</p>
<p>1) In my custom admin-option-page the required thickbox css and js file wouldn&#8217;t be load by default. To add the required fields to the wordpress list of loaded files, just call <code>add_thickbox();</code> in your init-function of your admin-page or before wp_head();.</p>
<p>2) Same goes for my custom js file: Put the line <code>wp_enqueue_script('<a>_custom_js', '/js/custom.js');</a></code> in your init-function.</p>
<p>3) I&#8217;d the problem, that the value attribute of my input field wasn&#8217;t updated. If you use the built-in jquery support from wordpress, you have to &#8220;wrap&#8221; every jquery call since WP 2.8+. Instead of using $();, you have to write jQuery();. This took me some time to figure out.</p>
<p>So you have to change the function send_to_editor to the following:</p>
<p><code><br />
function send_to_editor(html) {<br />
var source = html.match(/src=\".*\" alt/);<br />
source = source[0].replace(/^src=\"/, "").replace(/" alt$/, "");<br />
<b>jQuery</b>("#banner_image").attr('src', source);<br />
<b>jQuery</b>('#banner_image_input").attr('value', source);<br />
tb_remove();<br />
}<br />
</code></p>
<p>However, one problem remains:</p>
<p>The thickbox window isn&#8217;t loaded at full size. I&#8217;ve tried to load the built-in js script &#8220;media-upload&#8221; with <code>wp_enqueue_script('media-upload');</code> which seems to work, but this breaks the whole script.</p>
<p>If anybody has a solution, please post <img src='http://www.braindonor.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Hoff</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-255</link>
		<dc:creator>John Hoff</dc:creator>
		<pubDate>Mon, 15 Mar 2010 19:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-255</guid>
		<description>That error message originates from the menu.php page inside wp-admin.  I believe it is happening because the user that is trying to update the page is not an administrator.  You&#039;ll want to check the documentation for adding an administration menus: &lt;a href=&quot;http://codex.wordpress.org/Adding_Administration_Menus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://codex.wordpress.org/Adding_Administration_Menus&lt;/a&gt;.  Currently, I have the plugin set to user level 8--which is an older, legacy user level.  Since I snipped this plugin out of older code, it remained.  You&#039;ll likely want to play around with the capability required by the menu page to get it working.  All of that is in hijack.php file.</description>
		<content:encoded><![CDATA[<p>That error message originates from the menu.php page inside wp-admin.  I believe it is happening because the user that is trying to update the page is not an administrator.  You&#8217;ll want to check the documentation for adding an administration menus: <a href="http://codex.wordpress.org/Adding_Administration_Menus" target="_blank" rel="nofollow">http://codex.wordpress.org/Adding_Administration_Menus</a>.  Currently, I have the plugin set to user level 8&#8211;which is an older, legacy user level.  Since I snipped this plugin out of older code, it remained.  You&#8217;ll likely want to play around with the capability required by the menu page to get it working.  All of that is in hijack.php file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Paul Young</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-254</link>
		<dc:creator>Ryan Paul Young</dc:creator>
		<pubDate>Mon, 15 Mar 2010 16:52:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-254</guid>
		<description>Hey John,

I installed the plugin with NO issues, THANKS so much. BUT... when I choose an image from the media gallery, and Save Changes, I get the &quot;You do not have sufficient permissions to access this page.&quot; error... any ideas?</description>
		<content:encoded><![CDATA[<p>Hey John,</p>
<p>I installed the plugin with NO issues, THANKS so much. BUT&#8230; when I choose an image from the media gallery, and Save Changes, I get the &#8220;You do not have sufficient permissions to access this page.&#8221; error&#8230; any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Hoff</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-229</link>
		<dc:creator>John Hoff</dc:creator>
		<pubDate>Wed, 24 Feb 2010 15:52:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-229</guid>
		<description>Adam,

The goal of writing to the plugin was to demonstrate how to use the built-in image gallery as a selection tool.  I select an image, and it is passed along to a Wordpress option, custom field, etc.  The core assumption that allows this technique to work is that you are already working on something in the wp-admin, or back-end side of Wordpress.  In my case, it was how to create a page to update banner ads without reinventing the wheel--a task that would only be performed inside wp-admin.

Because this technique requires the wp-admin functionality, it cannot be used within a theme without bootstrapping the entire admin interface.  I&#039;m not even sure that this is possible.  If it is, I certainly would advise against it.

If you are looking for the ability to display a gallery, I highly recommend &lt;a href=&quot;http://wordpress.org/extend/plugins/nextgen-gallery/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;NextGEN Gallery&lt;/a&gt;.  If you are looking for the ability to have users upload the images to the gallery, I recommend that look into having them log into the wp-admin side of things and upload the content.  If you are looking for image submissions from public users, I recommend that you use a form that collects the image and stores it to a safe directory location.</description>
		<content:encoded><![CDATA[<p>Adam,</p>
<p>The goal of writing to the plugin was to demonstrate how to use the built-in image gallery as a selection tool.  I select an image, and it is passed along to a WordPress option, custom field, etc.  The core assumption that allows this technique to work is that you are already working on something in the wp-admin, or back-end side of WordPress.  In my case, it was how to create a page to update banner ads without reinventing the wheel&#8211;a task that would only be performed inside wp-admin.</p>
<p>Because this technique requires the wp-admin functionality, it cannot be used within a theme without bootstrapping the entire admin interface.  I&#8217;m not even sure that this is possible.  If it is, I certainly would advise against it.</p>
<p>If you are looking for the ability to display a gallery, I highly recommend <a href="http://wordpress.org/extend/plugins/nextgen-gallery/" target="_blank" rel="nofollow">NextGEN Gallery</a>.  If you are looking for the ability to have users upload the images to the gallery, I recommend that look into having them log into the wp-admin side of things and upload the content.  If you are looking for image submissions from public users, I recommend that you use a form that collects the image and stores it to a safe directory location.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-228</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Wed, 24 Feb 2010 10:29:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-228</guid>
		<description>This is great.

How do I work this into the front end though?
I&#039;m trying to create a portfolio image gallery on the homepage of the blog.

Got the plugin all set up and customized, but no idea how to get the images on the front page (in my theme).</description>
		<content:encoded><![CDATA[<p>This is great.</p>
<p>How do I work this into the front end though?<br />
I&#8217;m trying to create a portfolio image gallery on the homepage of the blog.</p>
<p>Got the plugin all set up and customized, but no idea how to get the images on the front page (in my theme).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jazib</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-192</link>
		<dc:creator>Jazib</dc:creator>
		<pubDate>Fri, 29 Jan 2010 21:47:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-192</guid>
		<description>Hey I can&#039;t make it work with custom meta values on post/page editor, can you explain what do you mean by &quot;wrap the existing send_to_editor in an anonymous function&quot;</description>
		<content:encoded><![CDATA[<p>Hey I can&#8217;t make it work with custom meta values on post/page editor, can you explain what do you mean by &#8220;wrap the existing send_to_editor in an anonymous function&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-184</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 20 Jan 2010 06:06:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-184</guid>
		<description>Perfect! Thanks John!</description>
		<content:encoded><![CDATA[<p>Perfect! Thanks John!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Hoff</title>
		<link>http://www.braindonor.net/coding-blog/hijack-the-wordpress-media-gallery/228/comment-page-1/#comment-183</link>
		<dc:creator>John Hoff</dc:creator>
		<pubDate>Wed, 20 Jan 2010 03:16:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.braindonor.net/?p=228#comment-183</guid>
		<description>At the end of your send_to_editor function, call:
&lt;code&gt;tb_remove();&lt;/code&gt;
It was already in the example attachment I provided in the post, but not in the body of the post.  I&#039;ve updated my post so that it is included.&lt;br /&gt;&lt;br /&gt;

Sorry for the confusion.</description>
		<content:encoded><![CDATA[<p>At the end of your send_to_editor function, call:<br />
<code>tb_remove();</code><br />
It was already in the example attachment I provided in the post, but not in the body of the post.  I&#8217;ve updated my post so that it is included.</p>
<p>Sorry for the confusion.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
