<?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>Webmaster-Source &#187; hooks</title>
	<atom:link href="https://www.webmaster-source.com/tag/hooks/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.webmaster-source.com</link>
	<description>Useful Resources For Webmasters</description>
	<lastBuildDate>Thu, 24 Aug 2017 02:01:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Using the WordPress Uploader in Your Plugin or Theme</title>
		<link>https://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/</link>
		<comments>https://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 11:20:18 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=2905</guid>
		<description><![CDATA[WordPress has a nice media uploader dialog that it uses on the editor pages. Now wouldn&#8217;t it be nice if you could use it to handle image uploads for part of a plugin or theme you&#8217;re writing? Maybe you want to add an easy way to change the logo in a theme? A simple &#8220;Upload [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>WordPress has a nice media uploader dialog that it uses on the editor pages. Now wouldn&#8217;t it be nice if you could use it to handle image uploads for part of a plugin or theme you&#8217;re writing? Maybe you want to add an easy way to change the logo in a theme? A simple &#8220;Upload Image&#8221; button would work quite well for that, wouldn&#8217;t it?</p>
<p style="text-align: center;"><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-2906 imgborder" title="WordPress Uploader Dialog" src="//www.webmaster-source.com/wp-content/uploads/wordpress-uploader-dialog.jpg" alt="" width="415" height="324" /></p>
<p>It&#8217;s fairly simple to implement, providing you already have a bit of experience with the WordPress API.</p>
<p>The first step is to prepare your HTML. Put it wherever the code for your <a href="http://codex.wordpress.org/Adding_Administration_Menus">admin page</a> is. You want to have a text input for the image URL, and a button that will launch the uploader dialog.<span id="more-2905"></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;tr valign=&quot;top&quot;&gt;
&lt;th scope=&quot;row&quot;&gt;Upload Image&lt;/th&gt;
&lt;td&gt;&lt;label for=&quot;upload_image&quot;&gt;
&lt;input id=&quot;upload_image&quot; type=&quot;text&quot; size=&quot;36&quot; name=&quot;upload_image&quot; value=&quot;&quot; /&gt;
&lt;input id=&quot;upload_image_button&quot; type=&quot;button&quot; value=&quot;Upload Image&quot; /&gt;
&lt;br /&gt;Enter an URL or upload an image for the banner.
&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
</pre>
<p>Now that the easy part is out of the way, it&#8217;s time to start making it <em>do</em> something. You need to enqueue some scripts and styles. Here&#8217;s an example function to show how it&#8217;s done:</p>
<pre class="brush: php; title: ; notranslate">
function my_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script('my-upload', WP_PLUGIN_URL.'/my-script.js', array('jquery','media-upload','thickbox'));
wp_enqueue_script('my-upload');
}

function my_admin_styles() {
wp_enqueue_style('thickbox');
}

if (isset($_GET['page']) &amp;&amp; $_GET['page'] == 'my_plugin_page') {
add_action('admin_print_scripts', 'my_admin_scripts');
add_action('admin_print_styles', 'my_admin_styles');
}
</pre>
<p>We need the <em>media-upload</em> and <em>thickbox</em> scripts for starters, as well as jQuery, which is already included. Then we have to register and enqueue our own JavaScript file, <em>my-script.js</em>, which will handle the media uploader functionality. We also need to load the <em>thickbox</em> stylesheet in the next function.</p>
<p>The <em>if (&#8230;)</em> block ensures that the scripts and styles will only be included if the user is on a specific admin page. If you look at your plugin&#8217;s (or theme&#8217;s) admin page, the URL should have a <em>?page=some_string</em> at the end. Substitute <em>my_plugin_page</em> for that string.</p>
<p>Now for the part the actually invokes the uploader: the JavaScript. This will go in the my-script.js file we included earlier.</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery(document).ready(function() {

jQuery('#upload_image_button').click(function() {
 formfield = jQuery('#upload_image').attr('name');
 tb_show('', 'media-upload.php?type=image&amp;amp;TB_iframe=true');
 return false;
});

window.send_to_editor = function(html) {
 imgurl = jQuery('img',html).attr('src');
 jQuery('#upload_image').val(imgurl);
 tb_remove();
}

});
</pre>
<p>The first <em>click()</em> event listener opens a ThickBox dialog when the &#8220;Upload Image&#8221; button is clicked, and loads the uploader page inside it. It also stores the name of the URL input field in a variable, for later use.</p>
<p>The second function overrides the <em>send_to_editor()</em> function in the <em>media-upload</em> script. This is probably the most important part. When the &#8220;Insert into Post&#8221; button is clicked in the uploader dialog, this function fires. It collects the URL of the image that was uploaded, dumps it into the awaiting form field, and closes the ThickBox dialog.</p>
<p>That&#8217;s it. Providing everything went according to planned, you should have a form field that will either accept an arbitrary image URL, or allow a user to upload one on the spot.</p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-2907" title="WordPress Media Uploader Field" src="//www.webmaster-source.com/wp-content/uploads/wordpress-upload-field.jpg" alt="" width="414" height="67" /></p>
<p class="alertbubble"><strong>Update:</strong> If you want to use the fancy new media uploader introduced in WordPress 3.5, be sure to check out <a href="http://www.webmaster-source.com/2013/02/06/using-the-wordpress-3-5-media-uploader-in-your-plugin-or-theme/">the revised and updated post</a> that covers it.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/feed/</wfw:commentRss>
		<slash:comments>277</slash:comments>
		</item>
		<item>
		<title>Modifying The Contextual Help Menu in WordPress</title>
		<link>https://www.webmaster-source.com/2009/12/22/modifying-the-contextual-help-menu-in-wordpress/</link>
		<comments>https://www.webmaster-source.com/2009/12/22/modifying-the-contextual-help-menu-in-wordpress/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 11:57:22 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=2850</guid>
		<description><![CDATA[Starting in version 2.7, WordPress has a pull-down &#8220;Help&#8221; menu in the upper-right corner of the screen, often joined by another menu for configuring display options for the page in question. By default the &#8220;Help&#8221; menu doesn&#8217;t do much. It gives some useful pointers on the Dashboard and Write screen, but other than that it [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-2851 imgborder" title="Contextual help menu in WordPress" src="//www.webmaster-source.com/wp-content/uploads/wordpress-contextual-help.jpg" alt="Contextual help menu in WordPress" width="265" height="88" />Starting in version 2.7, WordPress has a pull-down &#8220;Help&#8221; menu in the upper-right corner of the screen, often joined by another menu for configuring display options for the page in question.</p>
<p>By default the &#8220;Help&#8221; menu doesn&#8217;t do much. It gives some useful pointers on the Dashboard and Write screen, but other than that it pretty much just shows links to the Codex and WordPress.org support forums.</p>
<p>What if you wanted to make the &#8220;contextual menu&#8221; actually&#8230;contextual? If you&#8217;re a plugin or theme developer, you can add your own helpful information to the menu. It&#8217;s as simple as hooking into the <em>contextual_help</em> filter:</p>
<pre class="brush: php; title: ; notranslate">
function my_contextual_help($text) {
$screen = $_GET['page'];
if ($screen == 'my_plugin') {
$text = &quot;&lt;h5&gt;Need help with this plugin?&lt;/h5&gt;&quot;;
$text .= &quot;&lt;p&gt;Check out the documentation and support forums for help with this plugin.&lt;/p&gt;&quot;;
$text .= &quot;&lt;a href=\&quot;http://example.org/docs\&quot;&gt;Documentation&lt;/a&gt;&lt;br /&gt;&lt;a href=\&quot;http://example.org/support\&quot;&gt;Support forums&lt;/a&gt;&quot;;
}
return $text;
}

add_action('contextual_help', 'my_contextual_help');
</pre>
<p>The basic idea is to take the default contents of the menu, <em>$text</em>, and replace it with your own content. The <em>$screen</em> variable is used to make sure that the menu is only changed on the plugin&#8217;s pages, rather than universally through the Admin.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2009/12/22/modifying-the-contextual-help-menu-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/


Served from: www.webmaster-source.com @ 2026-06-09 13:47:34 by W3 Total Cache
-->