<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Justin Tadlock</title>
	
	<link>http://justintadlock.com</link>
	<description>Life, Blogging, and WordPress</description>
	<lastBuildDate>Mon, 09 Nov 2009 10:11:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/JustinTadlock" type="application/rss+xml" /><feedburner:emailServiceId>JustinTadlock</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Excerpts and taxonomies for pages in WordPress 2.9</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/oDLD7QcyfjI/excerpts-and-taxonomies-for-pages-in-wordpress-2-9</link>
		<comments>http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9#comments</comments>
		<pubDate>Mon, 09 Nov 2009 10:11:00 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=2122</guid>
		<description><![CDATA[How to make use of a simple file change in WordPress 2.9 to add an excerpt box and custom taxonomy boxes to your page editor.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>hile the information in this tutorial <em>will</em> be focused on excerpts and taxonomies, the big change in WordPress 2.9 is that the meta box functions have been included in a new file: <code>/wp-admin/include/meta-boxes.php</code>.  This change allows us to do some fun things because the code is not limited to a single area anymore.</p>
<p>In this tutorial, you&#8217;ll learn how to utilize the <code>add_meta_box()</code> functionality to add two things to your pages:</p>
<ol>
<li>Excerpt box.</li>
<li>Custom taxonomies boxes.</li>
</ol>
<p>Being able to add these meta boxes to pages isn&#8217;t the limit.  This tutorial should serve as a starting point.  You could do the same for custom post types, links, or anything that fires the <code>do_meta_boxes</code> action hook.</p>
<h2>Adding an excerpt box to your page editor</h2>
<p>The first thing you should do is open your theme&#8217;s <code>functions.php</code> file in your favorite text editor.  Paste the following <acronym title="Hypertext Preprocessor">PHP</acronym> code into it:</p>
<pre><code>add_action( 'admin_menu', 'my_page_excerpt_meta_box' );

function my_page_excerpt_meta_box() {
	add_meta_box( 'postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core' );
}</code></pre>
<p>Now, you&#8217;ll be able to add excerpts to your pages, just like posts.  This can come in handy with themes that display search results in excerpt form.</p>
<h2>Adding custom taxonomies to your page editor</h2>
<p>This one will be a bit trickier.  I&#8217;ll have to assume you&#8217;ve created a custom taxonomy specifically for pages.  If you&#8217;re unfamiliar with this process, you need to familiarize yourself with <a href="http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28" title="Custom taxonomies in WordPress 2.8">creating custom taxonomies</a>.</p>
<p>Let&#8217;s assume you&#8217;ve created a &#8220;People&#8221; taxonomy for pages.  Your custom taxonomy code should look a little like this.  </p>
<pre><code>register_taxonomy( 'people', 'page', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );</code></pre>
<p>The important thing in that line is <code>page</code>.  We&#8217;ll be adding meta boxes for all taxonomies that have been registered for pages.</p>
<p>Again, we&#8217;ll go to our theme&#8217;s <code>functions.php</code> file.  Paste this <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre><code>add_action( 'admin_menu', 'my_page_taxonomy_meta_boxes' );

function my_page_taxonomy_meta_boxes() {
	foreach ( get_object_taxonomies( 'page' ) as $tax_name ) {
		if ( !is_taxonomy_hierarchical( $tax_name ) ) {
			$tax = get_taxonomy( $tax_name );
			add_meta_box( "tagsdiv-{$tax_name}", $tax->label, 'post_tags_meta_box', 'page', 'side', 'core' );
		}
	}
}</code></pre>
<p>Once that&#8217;s done, you&#8217;ll be able to use your page-based custom taxonomies.</p>
<p class="note">Please note that hierarchical taxonomies aren&#8217;t going to be available yet.  Maybe in WordPress 3.0?</p>
<h2>A good move by WordPress</h2>
<p>I&#8217;m glad WordPress is moving in this direction with some of its functionality.  Average Joe might not realize the implications of something as simple as moving code to another file, but developers should rejoice.  The reuse of code is a cornerstone of good development practice.  By making things more modular, it becomes easier to create new things without rewriting a lot of code.</p>
<p>I&#8217;ve shown you how to do these things with pages.  Just imagine being able to make these simple and quick changes for custom post types (i.e., content types), essentially having the ability to create any type of site you want with WordPress.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/oDLD7QcyfjI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9</feedburner:origLink></item>
		<item>
		<title>Plugin and theme authors should force users to upgrade</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/LCK6eGFT-nA/plugin-and-theme-authors-should-force-users-to-upgrade</link>
		<comments>http://justintadlock.com/archives/2009/09/22/plugin-and-theme-authors-should-force-users-to-upgrade#comments</comments>
		<pubDate>Wed, 23 Sep 2009 01:01:36 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Discussion]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1829</guid>
		<description><![CDATA[By cutting off backwards compatibility, WordPress theme and plugin developers can help keep users' sites more secure.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">A</span> common thing we do in the WordPress community within our themes and plugins is provide backwards compatibility with older versions of WordPress.  This usually seems like a smart idea.  We want the largest possible audience, right?</p>
<p>The problem with providing backwards compatibility is twofold:</p>
<ol>
<li>Users continue using old versions of WordPress.</li>
<li>We have extra code to worry about.</li>
</ol>
<h2>Force users to upgrade</h2>
<p>With the <a href="http://lorelle.wordpress.com/2009/09/04/old-wordpress-versions-under-attack/" title="Old WordPress versions under attack">recent security scare</a> that targeted older versions of WordPress, <a href="http://weblogtoolscollection.com/archives/2009/09/12/are-you-responsible-enough-to-run-wordpress/" title="Are you responsible enough to run WordPress?">blame is being thrown around</a> left and right, from everyone to users to the WordPress developers.  While staying updated with the latest version of WordPress isn&#8217;t going to make your site 100% secure, it will make it secure from known security exploits.</p>
<p>By providing backwards compatibility in our plugins/themes, developers are partly responsible.  We&#8217;re giving users an excuse to not upgrade.  Obviously, developers are not to blame for people not upgrading their sites, but we can do our part in helping them stay secure by not supporting older versions of WordPress.</p>
<p><em>How do we not support older versions?</em>  Some things are simply going to be backwards compatible because they require no new WordPress functions, so we can&#8217;t do anything about those plugins.  The best thing to do is to use new WordPress functions as they become available and are useful to your plugin or theme.</p>
<p>Why would you want to support older versions of WordPress?  There&#8217;s no point in doing so.</p>
<h2>Get rid of code you don&#8217;t need</h2>
<p>Maybe you really don&#8217;t care if users&#8217; sites are hacked from staying on an older version.  That&#8217;s fine.  Another valid reason for keeping with the latest WordPress trends is that you don&#8217;t have to check for functions.</p>
<p>How often do you use the <code>function_exists()</code> and/or the <code>class_exists()</code> functions?</p>
<p>If you&#8217;re checking if a WordPress function exists, you&#8217;re doing so because you&#8217;re supporting older versions.  Do yourself and your users a favor and just call the function.  If it breaks a user&#8217;s site, tell them they need to upgrade.  Maybe even take a moment to explain the benefits of upgrading to them.</p>
<h2>Provide the best possible themes and plugins</h2>
<p>The WordPress developers have done about all they can do to make sure people upgrade, but we should take a bit more initiative as developers within community, the people that end users actually interact with.  By forcing users to upgrade, we&#8217;re helping them stay secure.</p>
<p>Before writing this post, I tried to think of valid reasons to provide backwards compatibility and only thought of one, and that&#8217;s the crossover period between major version upgrades.  This period should last about one month.  This gives users ample time to upgrade and provides support for people with WordPress MU.</p>
<p>I&#8217;m certainly open to other ideas about how plugin and theme developers can get more involved in the security of their users&#8217; sites.  Feel free to leave your thoughts on how they can.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/LCK6eGFT-nA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/22/plugin-and-theme-authors-should-force-users-to-upgrade/feed</wfw:commentRss>
		<slash:comments>44</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/09/22/plugin-and-theme-authors-should-force-users-to-upgrade</feedburner:origLink></item>
		<item>
		<title>Custom capabilities in plugins and themes</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/oljUB_AWm58/custom-capabilities-in-plugins-and-themes</link>
		<comments>http://justintadlock.com/archives/2009/09/18/custom-capabilities-in-plugins-and-themes#comments</comments>
		<pubDate>Sat, 19 Sep 2009 02:33:50 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1821</guid>
		<description><![CDATA[How to make your WordPress plugin or theme more flexible by allowing users to select who has access to its settings page(s).]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> can probably list a million reasons I think my recent <a href="http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin" title="Members: WordPress plugin">Members plugin</a> is neat.  Not only have I deployed it on about five of my own blogs in the last few days, I&#8217;ve also started integrating it with some of my other plugins and themes.</p>
<p>One of the features I feel that&#8217;s lacking in most plugins and themes is the ability to define custom capabilities to access certain content.  This is one of the reasons I&#8217;ve developed this plugin.</p>
<p>If you&#8217;re a plugin or theme developer and add admin menus, this tutorial should be helpful.  What I&#8217;ll be showing you is a way to give users of your plugin <em>smarter</em> control over its settings.</p>
<h2>Adding an admin menu page the normal way</h2>
<p>There are several functions for adding <a href="http://codex.wordpress.org/Adding_Administration_Menus" title="Adding administration menus">admin menus</a>, which all work basically the same way.  I&#8217;ll use <code>add_submenu_page()</code> as an example since it&#8217;s fairly common.</p>
<p>When adding a page, you&#8217;ll use the function like this:</p>
<pre><code>add_submenu_page( $parent_page, $page_title, $menu_title, $capability, $file, $function );</code></pre>
<p>What we&#8217;ll be focusing on here is the <code>$capability</code> variable.  Typically, this is hardcoded, but we need to be able to change this.  So, when writing that code, you should replace <code>$capability</code> with a filter hook:</p>
<pre><code>add_submenu_page( $parent_page, $page_title, $menu_title, apply_filters( 'plugin_name_capability', $capability ), $file, $function );</code></pre>
<p><code>plugin_name_capability</code> should be something unique to your plugin.  Just leave <code>$capability</code> as  whatever capability you would normally use.  It can now be changed.</p>
<p>Making this change does two important things:</p>
<ol>
<li>Allows users to change the capability if they want to with a filter.</li>
<li>Allows you to integrate your plugin with the <em>Members</em> plugin.</li>
</ol>
<p>You can stop reading here and will have done your part in making your plugin more flexible.  However, you can offer integration with my <em>Members</em> plugin, which will make it even easier for users to use.</p>
<h2>Integrating your plugin/theme with the Members plugin</h2>
<p>Here&#8217;s where the real neat stuff comes into play.  You can run a check to see if the <em>Members</em> plugin is installed.  If the plugin is indeed installed, you can create a custom capability just for your plugin&#8217;s settings page.</p>
<p>Let&#8217;s assume that filter hook was something like this:</p>
<pre><code>apply_filters( 'plugin_name_capability', 'manage_options' );</code></pre>
<p>People without the <em>Members</em> plugin would need the <code>manage_options</code> capability to change the settings for your plugin.  To me, that doesn&#8217;t sound like a great solution, and it definitely doesn&#8217;t offer the site owner much flexibility.</p>
<p>If the <em>Members</em> plugin is installed, we&#8217;ll change that capability to something like <code>edit_my_plugin_settings</code> (change to something unique):</p>
<pre><code>if ( function_exists( 'members_plugin_init' ) )
	add_filter( 'plugin_name_capability', 'plugin_name_unique_capability' );

function plugin_name_unique_capability( $cap ) {
	return 'edit_my_plugin_settings';
}</code></pre>
<p>Now, only users of a role with the <code>edit_my_plugin_settings</code> capability will be able to access that plugin&#8217;s page.</p>
<h2>Adding the capability to the role edit page</h2>
<p>You can offer even more integration with the <em>Members</em> plugin if you like.  You can add a checkbox to the <em>Edit Role</em> page that allows users to easily select this capability rather than typing it in.</p>
<pre><code>if ( function_exists( 'members_get_capabilities' ) )
	add_filter( 'members_get_capabilities', 'plugin_name_extra_caps' );

function plugin_name_extra_caps( $caps ) {
	$caps[] = 'edit_my_plugin_settings';
	return $caps;
}</code></pre>
<h2>Why is all this important?</h2>
<p>Imagine running a site with 20 different writers, publishers, administrators, and so on.  Some people of that site need specific access to certain things but no access to other things.</p>
<p>For example, a friend and I are both running this site with all these people.  The friend doesn&#8217;t need access to the WordPress options, but he does need access to your plugin&#8217;s options.  Those should be controlled by two separate capabilities rather than one.</p>
<p>I created <em>Members</em> to allow site owners to have as much flexibility as possible.  But, the plugin itself can only do so much on its own.  As developers in the WordPress community, we can make WordPress infinitely flexible by working together, and I&#8217;m definitely trying to make it as easy as possible to integrate other plugins with my own.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/oljUB_AWm58" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/18/custom-capabilities-in-plugins-and-themes/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/09/18/custom-capabilities-in-plugins-and-themes</feedburner:origLink></item>
		<item>
		<title>Members: WordPress Plugin</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/GHbsvSTjpOw/members-wordpress-plugin</link>
		<comments>http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:38:54 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1812</guid>
		<description><![CDATA[<em>Members</em> is a plugin that extends your control over your blog.  It's a user, role, and content management plugin that was created to make WordPress a more powerful <acronym title="Content Management System">CMS</acronym>.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">T</span>he <em>Members</em> plugin is a user, role, and content management plugin.  Its purpose is to make WordPress a more powerful <acronym title="Content Management System">CMS</acronym> by giving you fine-grain control over the users of your site.</p>
<p>I created this plugin because I wasn&#8217;t satisfied with the current user, role, and permissions plugins available.  Yes, some of them are good, but nothing fit what I had in mind perfectly.  Some offered few features.  Some worked completely outside of the WordPress role and capability system.  Others lacked an appropriate license.</p>
<p>This plugin is still a long way away from my goals, but it&#8217;ll get there eventually.</p>
<h2>What does the plugin do?</h2>
<p><em>Members</em> has what I call &#8220;components.&#8221;  Instead of normal plugin settings, you get a components-selection page that allows you to choose only the features that you want to use.  </p>
<p>The current components are (more will come in future versions):</p>
<ul>
<li><strong>Edit Roles:</strong> Edit your user roles and their capabilities.</li>
<li><strong>New Roles:</strong>  Create new roles for use on your site.</li>
<li><strong>Content Permissions:</strong>  Adds a meta box on your write post/page editor that allows you to restrict content to specific roles.</li>
<li><strong>Widgets:</strong>  Adds a login form widget and user-listing widget that you can use in any widget area on your site.</li>
<li><strong>Shortcodes:</strong>  Creates shortcodes that you can use to restrict or allow access to certain parts of your posts and pages (or any other shortcode-capable area).</li>
<li><strong>Template Tags:</strong>  New functions for use within your WordPress theme for various things.</li>
<li><strong>Private Blog:</strong>  Allows you to create a private blog that can only be accessed by users that are logged in (redirects them to the login page).</li>
</ul>
<h2>Screenshots of the plugin</h2>
<p>I&#8217;ve uploaded a few screenshots so you can see what part of the plugin looks like:</p>
<ul>
<li><a href="http://justintadlock.com/blog/wp-content/uploads/2009/09/members-components.png" title="Members select components">Select Components Screen</a></li>
<li><a href="http://justintadlock.com/blog/wp-content/uploads/2009/09/edit-roles-component.png" title="Edit Roles component">Edit Roles Component</a></li>
<li><a href="http://justintadlock.com/blog/wp-content/uploads/2009/09/new-roles-component.png" title="New Roles component">New Roles Component</a></li>
<li><a href="http://justintadlock.com/blog/wp-content/uploads/2009/09/content-permissions.png" title="Content Permissions component">Content Permissions Component</a></li>
</ul>
<h2>Ideas for future versions</h2>
<p>Version 0.1 has been all about role and capability management, but that&#8217;s just the beginning.  Version 0.2 will be about user management.</p>
<p>But, it&#8217;s not all about my ideas.  I&#8217;ll be working through many of the ideas presented in my original <a href="http://justintadlock.com/archives/2009/07/22/developing-a-user-management-plugin" title="Developing a user management plugin">post on this plugin</a>.  I&#8217;m also open to any new ideas you might have.</p>
<h2>Download the plugin</h2>
<p>Before using this plugin, please read the <code>readme.html</code> file included in the plugin download.  It will guide you through everything you need to know about using it.</p>
<ul>
<li><strong>Version:</strong> 0.1</li>
<li><strong>Requires:</strong> WordPress 2.8+</li>
<li><strong>Support:</strong> <a href="http://themehybrid.com/support" title="Support forums at Theme Hybrid">Support forums</a></li>
<li><a href="http://wordpress.org/extend/plugins/members" title="Download the Members plugin from WordPress.org">Download</a> (from WP.org)</li>
</ul>
<p class="note">Please don&#8217;t use my contact page or the comments section below to ask support questions.  Use my <a href="http://themehybrid.com/support" title="Theme Hybrid support forums">support forums</a> at Theme Hybrid, which is where I handle all support questions for my WordPress projects.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/GHbsvSTjpOw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin/feed</wfw:commentRss>
		<slash:comments>95</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin</feedburner:origLink></item>
		<item>
		<title>Adding and using custom user profile fields</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/9GNbvy-_-r4/adding-and-using-custom-user-profile-fields</link>
		<comments>http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields#comments</comments>
		<pubDate>Fri, 11 Sep 2009 04:40:09 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1796</guid>
		<description><![CDATA[How to create and display custom user profile fields in WordPress that allow users to input additional information about themselves.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">S</span>ince I&#8217;ve been playing around with user management a lot lately, I thought I&#8217;d share a simple technique I picked up.  This technique will allow you to easily add new user profile fields that your blog&#8217;s users can use to input more information about themselves.</p>
<p>Management of these fields will be coming in a later version of my user management plugin, but some of you may want to do this now.</p>
<p>In this tutorial, I&#8217;ll show you how to add an input box for a Twitter username and how to display it on your site, which will look a little something like this:</p>
<div id="attachment_1797" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/09/pop-critics-profile.png" alt="My profile and Twitter link" title="Twitter link" width="600" height="145" class="size-full wp-image-1797" /><p class="wp-caption-text">My profile and Twitter link</p></div>
<p>If you want to see a live example, check out <a href="http://popcritics.com/2009/09/the-cw-adds-the-vampire-diaries-to-its-supernatural-lineup" title="Pop Critics: The CS adds the Vampire Diaries to its supernatural lineup">one of my latests posts</a> on Pop Critics.</p>
<h2>Adding custom user fields</h2>
<p>Open your theme&#8217;s <code>functions.php</code> file and drop this <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre class="php"><code>add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

	&lt;h3>Extra profile information&lt;/h3>

	&lt;table class="form-table">

		&lt;tr>
			&lt;th>&lt;label for="twitter">Twitter&lt;/label>&lt;/th>

			&lt;td>
				&lt;input type="text" name="twitter" id="twitter" value="&lt;?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" />&lt;br />
				&lt;span class="description">Please enter your Twitter username.&lt;/span>
			&lt;/td>
		&lt;/tr>

	&lt;/table>
&lt;?php }</code></pre>
<p>This will create a new area in the user edit screen that looks like this:</p>
<div id="attachment_1798" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/09/extra-fields.png" alt="Additional profile fields" title="Profile fields" width="600" height="151" class="size-full wp-image-1798" /><p class="wp-caption-text">Additional profile fields</p></div>
<p>The custom part of the code is this bit:</p>
<pre><code>&lt;tr>
	&lt;th>&lt;label for="twitter">Twitter&lt;/label>&lt;/th>

	&lt;td>
		&lt;input type="text" name="twitter" id="twitter" value="&lt;?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" />&lt;br />
		&lt;span class="description">Please enter your Twitter username.&lt;/span>
	&lt;/td>
&lt;/tr></code></pre>
<p>Note that if you want to add more fields, copy that and change <code>twitter</code> to something unique for each additional field.  Just make sure you change each instance of <code>twitter</code>.</p>
<h2>Saving the custom user fields</h2>
<p>Just because we&#8217;re displaying these extra fields, doesn&#8217;t mean they&#8217;ll be saved when the user profile is updated.  So, we need one more function to handle this.  Drop this <acronym title="Hypertext Preprocessor">PHP</acronym> code in your theme&#8217;s <code>functions.php</code> file.</p>
<pre><code>add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

	if ( !current_user_can( 'edit_user', $user_id ) )
		return false;

	/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
	update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
}</code></pre>
<p>Now, your information will be saved.</p>
<h2>Displaying custom user fields on the site</h2>
<p>For getting these additional fields, WordPress has two nifty functions: <code>the_author_meta()</code> and <code>get_the_author_meta()</code>.  The former displays the meta information, and the latter returns it for use in <acronym title="Hypertext Preprocessor">PHP</acronym>.  Each takes in two parameters:</p>
<pre><code>the_author_meta( $meta_key, $user_id );</code></pre>
<p>You can use this to grab the information from any of the fields you&#8217;ve created.  For example, the <code>$meta_key</code> for our Twitter field is <code>twitter</code>.  We just need to call it up somewhere in our theme.</p>
<p>So, what we&#8217;re going to do is build an author box to add to the end of our single posts.  Once again, we visit our theme&#8217;s <code>functions.php</code> file and drop some <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre><code>function my_author_box() { ?>
	&lt;div class="author-profile vcard">
		&lt;?php echo get_avatar( get_the_author_meta( 'user_email' ), '96' ); ?>

		&lt;h4 class="author-name fn n">Article written by &lt;?php the_author_posts_link(); ?>&lt;/h4>

		&lt;p class="author-description author-bio">
			&lt;?php the_author_meta( 'description' ); ?>
		&lt;/p>

		&lt;?php if ( get_the_author_meta( 'twitter' ) ) { ?>
			&lt;p class="twitter clear">
				&lt;a href="http://twitter.com/&lt;?php the_author_meta( 'twitter' ); ?>" title="Follow &lt;?php the_author_meta( 'display_name' ); ?> on Twitter">Follow &lt;?php the_author_meta( 'display_name' ); ?> on Twitter&lt;/a>
			&lt;/p>
		&lt;?php } // End check for twitter ?>
	&lt;/div>&lt;?php
}</code></pre>
<p>Now, all you need to do call the function in your theme&#8217;s <code>single.php</code> file somewhere after the post has been displayed:</p>
<pre><code>&lt;?php my_author_box(); ?></code></pre>
<p>If you&#8217;re using a child theme, your theme author can probably tell you a more appropriate action hook to add this function to so you don&#8217;t mess up your theme&#8217;s template files.</p>
<h2>What other custom user field uses can you think of?</h2>
<p>This is just another one of those powerful features of WordPress that I don&#8217;t see used much.  I have several things in mind that I could use this technique for, but I&#8217;d like to hear what you&#8217;d do with it.</p>
<p>Surely we can do some cooler stuff than just displaying a link to Twitter?</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/9GNbvy-_-r4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields/feed</wfw:commentRss>
		<slash:comments>49</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields</feedburner:origLink></item>
		<item>
		<title>Beta test my upcoming user, role, and content management plugin</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/0bMiJG3dm2s/beta-test-my-upcoming-user-role-and-content-management-plugin</link>
		<comments>http://justintadlock.com/archives/2009/09/07/beta-test-my-upcoming-user-role-and-content-management-plugin#comments</comments>
		<pubDate>Mon, 07 Sep 2009 07:34:24 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1792</guid>
		<description><![CDATA[The first test release of my user, role, and content management plugin for WordPress.  I'm looking for people to test it and provide feedback.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">O</span>n July 16, I sent out a message to my Twitter followers that I was building a user management plugin for WordPress.  At the time, I had been playing around with several plugins that offer similar functionality, but nothing really satisfied me.  I just wanted a nice interface that didn&#8217;t get in the way of the things I normally do with WordPress.</p>
<p>I had no idea how popular the idea would be, even warranting itself a blog post, a forum topic, and loads of emails and replies on Twitter.  So, I thought it&#8217;d be best to get the feel of the community and <a href="http://justintadlock.com/archives/2009/07/22/developing-a-user-management-plugin" title="Developing a user management plugin">see what everyone&#8217;s thoughts were</a>.</p>
<p>Many were in the same boat as me &mdash; not quite satisfied.</p>
<p>I don&#8217;t mean to build my plugin up too much though.  There&#8217;s an extremely long road ahead if I&#8217;m going to implement as many features as we all want.  The first release is about building a solid foundation for future development.  I want to get the essentials down first.  Then, I can start building new things in.</p>
<h2>What does this plugin do?</h2>
<p>First and foremost, it&#8217;s a role management plugin.  This is the foundation of everything.  It will allow you to control each of your site&#8217;s roles and their accompanying capabilities.</p>
<p>But, it&#8217;s not <em>only</em> a role management plugin.  It has a components-based system that allows you to only use the components you wish to use.  The current components are:</p>
<ul>
<li><strong>Edit Roles:</strong> Edit your user roles and their capabilities.</li>
<li><strong>New Roles:</strong>  Create new roles for use on your site.</li>
<li><strong>Content Permissions:</strong>  Adds a meta box on your write post/page editor that allows you to restrict content to specific roles.</li>
<li><strong>Widgets:</strong>  Adds a login form widget and user-listing widget that you can use in any widget area on your site.</li>
<li><strong>Shortcodes:</strong>  Creates shortcodes that you can use to restrict or allow access to certain parts of your posts and pages (or any other shortcode-capable area).</li>
<li><strong>Template Tags:</strong>  New functions for use within your WordPress theme for various things.</li>
<li><strong>Private Blog:</strong>  Allows you to create a private blog that can only be accessed by users that are logged in (redirects them to the login page).</li>
</ul>
<p>This is just the beginning though.  You&#8217;ve given me loads of ideas in my original post on this, and I plan on implementing as much as possible in later versions.</p>
<h2>What I need from you all</h2>
<p>Testing.  Testing.  Testing.  And, feedback, of course.</p>
<p>This is one of the larger projects I&#8217;ve worked on, so a lot of the stuff is new terrain, even for me.  With enough feedback and testing, this can be a great project for the WordPress community.</p>
<p>I know many of you will have ideas about new things to be added, but let&#8217;s try to hold those ideas until later.  What you see here will be in version 0.1 of the plugin, but new things will come in later versions.  Right now, I want to focus on making sure the current components work.</p>
<p>Some specific things I&#8217;m looking for:</p>
<ul>
<li>Is anything too hard to understand?</li>
<li>Does something not work the way you expect it to?</li>
<li>Do you recieve any error messages?</li>
<li>Each component and each component&#8217;s options need to be tested.</li>
<li>Testing on various browsers definitely needs to be done.</li>
<li>Needs to be tested on the WordPress 2.8 branch and the current trunk.</li>
</ul>
<p>Some questions:</p>
<ul>
<li>How should restricted pages (<em>Content Permissions</em> component) be handled? Remove from page lists if user isn&#8217;t allowed to view them?</li>
<li>Will someone check to make sure content isn&#8217;t showing in feeds (<em>Content Permissions</em> component) unless it&#8217;s supposed to?</li>
<li>Is there anything else you&#8217;d like to see done with the current widgets (<em>Widgets</em> component)?</li>
</ul>
<p>I&#8217;m hoping to officially launch this plugin in another week or two (depending on what bugs are found).</p>
<h2>How to use the plugin</h2>
<p>I&#8217;ve written a fairly comprehensive guide, which is included within the plugin download.  It is the <code>readme.html</code> file.</p>
<p>If you have questions about usage, please refer to that guide first.  Also, I encourage you to read my guide on <a href="http://justintadlock.com/archives/2009/08/30/users-roles-and-capabilities-in-wordpress" title="Users, roles, and capabilities in WordPress">users, roles, and capabilities</a> in Wordpress.  It&#8217;ll give you a better understanding of how things work.</p>
<h2>Beta test the plugin</h2>
<p class="alert">Please do not use this plugin on a live site.  It is for test environments only.  If you use it on a live site and it breaks that site, you are responsible for fixing it.</p>
<p>Sorry for such a stern warning, but I&#8217;ve locked myself out of my test install on more than one occasion while developing this plugin.  Let&#8217;s make sure it works before using it on live sites, okay?</p>
<ul>
<li><a href="http://justintadlock.com/downloads/members.zip" title="Download the beta version of the WordPress plugin">Download Version 0.1 Beta 1</a></li>
</ul>
<h2>Help me name the plugin</h2>
<p>I&#8217;m currently calling it the <em>Members</em> plugin because I haven&#8217;t given a name to it yet.  If you have ideas about what to call it, feel free to let me know.</p>
<p>The plugin is supposed to be a complete user, role, and content management plugin.  While it&#8217;s not quite there yet, I hope that it&#8217;ll become the &#8220;must-install&#8221; plugin for all multi-user WordPress sites in the future.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/0bMiJG3dm2s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/09/07/beta-test-my-upcoming-user-role-and-content-management-plugin/feed</wfw:commentRss>
		<slash:comments>45</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/09/07/beta-test-my-upcoming-user-role-and-content-management-plugin</feedburner:origLink></item>
		<item>
		<title>Users, roles, and capabilities in WordPress</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/OpeYWCJE9Zw/users-roles-and-capabilities-in-wordpress</link>
		<comments>http://justintadlock.com/archives/2009/08/30/users-roles-and-capabilities-in-wordpress#comments</comments>
		<pubDate>Mon, 31 Aug 2009 03:50:32 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1786</guid>
		<description><![CDATA[An explanation of how the user, role, and capability system in WordPress works and why it is important to grasp this concept..]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> recently announced my intention of <a href="http://justintadlock.com/archives/2009/07/22/developing-a-user-management-plugin" title="Developing a user management plugin">creating a user/role/capability management plugin</a> for WordPress.  One of the things I&#8217;ve noticed from the comments on that post is that people don&#8217;t understand exactly how the WordPress role and capability system work.  Since I&#8217;m developing a plugin based on that system, I feel it&#8217;s my responsibility to explain how it all fits together.</p>
<p>What I&#8217;m proposing in this post is not something new to the WordPress world.  I&#8217;m not creating new ideas with my upcoming plugin.  This is how it works in WordPress.  The plugin will just put a face to these ideas.</p>
<p>If you do not grasp this concept, you won&#8217;t understand the inherent limitations of the plugin nor the features of it.</p>
<h2>What are users?</h2>
<p>For the sake of thoroughness (even though you probably understand this), users are people that have registered on your site.  They have a user account.  Users, in this context, are not people who have visited your site or someone that leaves a comment.</p>
<p>Being a registered user doesn&#8217;t mean anything though.  Users are given context through a role.  Roles define each user&#8217;s place on the site.</p>
<h2>What are roles?</h2>
<p>Roles are a way of grouping users.  By default, WordPress gives you several roles to work with:</p>
<ul>
<li>Administrator</li>
<li>Editor</li>
<li>Author</li>
<li>Contributor</li>
<li>Subscriber</li>
</ul>
<p>These are all pretty straightforward.  Average Joe shouldn&#8217;t have much trouble figuring out what roles can do certain things.  But, let me present what&#8217;s really going on here.</p>
<p>There are two important things you need to understand about roles in WordPress before moving forward:</p>
<ol>
<li>Roles are not hierarchical.</li>
<li>Roles have no meaning without capabilities.</li>
</ol>
<p>Many of you might want to argue with that first point.  You might want to say that &#8220;administrator&#8221; is a higher level than &#8220;subscriber.&#8221;  But, that&#8217;s not entirely true.  It&#8217;s the wrong way to look at how roles work.  The default administrator role simply has more capabilities.  You could give the default subscriber role more capabilities than the administrator (if you wanted to).</p>
<p>If you learn nothing else from this post, remember this &mdash; roles are defined by what capabilities they are granted.  There is no hierarchy.</p>
<h2>What are capabilities?</h2>
<p>This is the real beauty of how the system works.  Capabilities are <em>permissions</em>.  They&#8217;re a way of saying a role <em>can</em> or <em>can&#8217;t</em> do something.</p>
<p>Capabilities are given to roles.  So, users of a certain role are limited by that role&#8217;s capabilities.</p>
<p>For example, the administrator role (by default) is granted the capability of <code>edit_themes</code>.  You don&#8217;t get to edit your theme because you&#8217;re an administrator.  You are allowed to edit your theme because your role (administrator) has the capability of <code>edit_themes</code>.  If you took away that capability, you would no longer be able to edit your theme in the WordPress admin, no matter how important you think your role is.</p>
<h2>Putting it all together</h2>
<p>Here&#8217;s the short and simple version of this concept:</p>
<ul>
<li>Users are people that have registered on your site.</li>
<li>Each user is given a role on your site.</li>
<li>Each role is given a set of capabilities (i.e., permissions) that grant/restrict their access.</li>
</ul>
<h2>Why is all this important?</h2>
<p>It&#8217;s important to understand how the platform you&#8217;re using works.  I was amazed at the number of comments I recieved that focused on a hierarchical role system, which is not how WordPress works.</p>
<p>That&#8217;s the thing that troubles me the most.  If people are going to be using a plugin that extends the current role and capability system, they must understand how things work.</p>
<h2>A sneak-peek at the plugin</h2>
<p>Since many of you have been patiently awaiting news on this plugin and have read through this post, it&#8217;s only fair that I offer you a little teaser.  This preview is of the <em>Edit Roles</em> component, which is one of several components I&#8217;m building into the plugin:</p>
<ul>
<li><a href="http://justintadlock.com/blog/wp-content/uploads/2009/08/edit-roles-component.png" title="View a screenshot of the Edit Roles component">Screenshot of the <em>Edit Roles</em> component</a></li>
</ul>
<p>For those of you interested in beta testing the plugin, look for a blog post later this week.  The plugin is coming along quite nicely.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/OpeYWCJE9Zw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/08/30/users-roles-and-capabilities-in-wordpress/feed</wfw:commentRss>
		<slash:comments>47</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/08/30/users-roles-and-capabilities-in-wordpress</feedburner:origLink></item>
		<item>
		<title>Some thoughts on success</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/_0iBSIfBlYE/some-thoughts-on-success</link>
		<comments>http://justintadlock.com/archives/2009/08/26/some-thoughts-on-success#comments</comments>
		<pubDate>Wed, 26 Aug 2009 06:44:50 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1778</guid>
		<description><![CDATA[Some random thoughts about success I've been thinking about lately in my journey to find a hard-working group of people to build a business together.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>hen I first told my family that I wanted to work online and not a traditional 9-to-5 job, I received some funny faces and plenty of serious talks meant to bring me back down to earth.  I like that my family keeps me in the realm of reality.  It helps balance out some of my crazier ideas.</p>
<p>It&#8217;s one thing to try and convince your family that you&#8217;re doing the right thing.  It&#8217;s an entirely different beast trying to get other people to take the plunge with you.</p>
<p>Over the summer, I&#8217;ve been talking to a few folks about expanding my projects online.  Sure, many people are <em>interested</em> in the idea.  But, when you tell them that you have no financial backing for certain projects and that the projects can fail at any time, they lose interest fast.</p>
<h2>Motivation is key</h2>
<p>If you&#8217;re not entirely convinced you can be successful, you won&#8217;t be.</p>
<p>Even if I convince people that things will work out financially in the long run, it&#8217;s tough instilling self-confidence and motivation into everyone.  The thing people most often tell me is, &#8220;I don&#8217;t really have the time.&#8221;  They want success, but they don&#8217;t have time for it.  Or, they want someone to hand it to them.</p>
<p>If you don&#8217;t think you have enough time, let me introduce you to a few people I know.  How about a single mother with two kids, two jobs, and college classes to attend?  I know few people with busier schedules than her.</p>
<p>Not having time means you don&#8217;t have motivation.</p>
<p>I can&#8217;t even begin to tell you how many people I&#8217;ve referred to Ian Stewart&#8217;s website <a href="http://therereallyisnosecret.com/" title="There Really Is No Secret">There Really Is No Secret</a>.  If you haven&#8217;t checked out that site, it&#8217;ll tell you all you need to know to be successful in all things.</p>
<h2>Finding the right people</h2>
<p>My journey to find the <em>right</em> kind of people for my team has been tough.  I have a handful of people that are on board right now for some upcoming projects.</p>
<p>I know plenty of folks online that have the right amount of determination, but right now, I want people that are close to home.  I like being able to meet people face to face and having the ability to have weekly meetings where we can all get together and run over ideas.</p>
<p>To find the right kind of people, you have to put yourself out there.  Get out there and make things happen.  Be open and honest.</p>
<p>My selling point is:  <em>If you&#8217;re not willing to put your heart and soul behind a project, we&#8217;re not going to be a good fit.</em>  That&#8217;s what it all comes down to for me.  I don&#8217;t care if you&#8217;re a genius or have never even touched a computer.  You need to be willing to work hard and see it through.</p>
<h2>What the heck am I talking about?</h2>
<p>These are just a few thoughts I&#8217;ve been playing through my head lately.</p>
<p>I&#8217;ve been building a team of people that are willing to work hard and have fun on some online projects.  I&#8217;ll keep everyone updated on the status of these projects (and what they are) as they near their launch.</p>
<p>In the meantime, if you live or know someone that lives around Montgomery, Alabama, that might be interested in working on the Web, shoot me a message through my <a href="http://justintadlock.com/contact" title="Contact page">contact form</a>.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/_0iBSIfBlYE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/08/26/some-thoughts-on-success/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/08/26/some-thoughts-on-success</feedburner:origLink></item>
		<item>
		<title>How to disable scripts and styles</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/Q9vSJOGswig/how-to-disable-scripts-and-styles</link>
		<comments>http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles#comments</comments>
		<pubDate>Thu, 06 Aug 2009 07:08:57 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1773</guid>
		<description><![CDATA[Does using multiple WordPress plugins load so many files to your site that it becomes unbearably slow?  If so, you can easily disable scripts and styles and load them only when needed.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">M</span>any plugins and themes add JavaScript and <acronym title="Cascading Style Sheets">CSS</acronym> files to your site.  While this alone isn&#8217;t necessarily a bad thing, using several plugins that do this can bog down your site with loads of requests for these files.  </p>
<p>The good news is that WordPress has a built-in system that allows us to deregister these scripts and styles.</p>
<p><em>Wait, don&#8217;t the plugins require this code?</em>  Probably.  But, we want to take control of these files and make our sites run faster.  Disabling these scripts and styles will allow us to do a few things:</p>
<ol>
<li>Combine multiple files into single files (mileage may vary with JavaScript here).</li>
<li>Load the files only on the pages we&#8217;re using the script or style.</li>
<li>Stop having to use <code>!important</code> in our <code>style.css</code> file to make simple <acronym title="Cascading Style Sheets">CSS</acronym> adjustments.</li>
</ol>
<p>For this exercise, I&#8217;ve chosen two popular plugins from the plugin repository:  <a href="http://wordpress.org/extend/plugins/contact-form-7/" title="Contact Form 7">Contact Form 7</a> and <a href="http://wordpress.org/extend/plugins/wp-pagenavi/" title="WP-PageNavi">WP-PageNavi</a>.</p>
<h2>The dirty truth</h2>
<p>Not all plugins use the appropriate methods for loading scripts and styles.  Some developers just drop stuff right in the header.  This is usually because they&#8217;re not familar with two important WordPress functions: <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script" title="WordPress Codex: wp_enqueue_script()">wp_enqueue_script()</a> and <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style" title="WordPress Codex: wp_enqueue_style()">wp_enqueue_style()</a>.  If your plugin/theme author isn&#8217;t using these functions, please encourage them to do so.  It allows the rest of us to work with their code using the methods WordPress provides.</p>
<p>While figuring out what scripts or styles you want to disable, you might have to get your hands dirty.  This means looking in code.  Unless your plugin author has documented the script or style <code>handle</code>, you&#8217;ll need to find it.</p>
<h2>Disabling JavaScript</h2>
<p>For this example, we&#8217;ll be disabling the <em>Contact Form 7</em> plugin&#8217;s JavaScript.  The first thing you need to do is find the <code>handle</code> for the script.  Open the <code>wp-contact-form-7.php</code> file in your favorite text editor and do a search for <code>wp_enqueue_script</code>.  Doing so will turn up this bit of code:</p>
<pre><code>wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'contact-form-7.js' ), array('jquery', 'jquery-form'), WPCF7_VERSION, $in_footer );</code></pre>
<p>The <code>handle</code> for this plugin&#8217;s JavaScript is <code>contact-form-7</code>.  Now, you can close this file and move on.</p>
<p>Open your theme&#8217;s <code>functions.php</code> file and add this <acronym title="Hypertext Preprocessor">PHP</acronym> in:</p>
<pre><code>add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );

function my_deregister_javascript() {
	wp_deregister_script( 'contact-form-7' );
}</code></pre>
<p>Once saved, the script will no longer load.  You can deregister as many scripts as you want within this function.</p>
<h2>Disabling styles</h2>
<p>In this example, we&#8217;ll be disabling <em>WP-PageNavi&#8217;s</em> stylesheet.  This is something I almost always do because I add the style rules to my theme&#8217;s <code>style.css</code> file.</p>
<p>The first thing you should do is open <code>wp-pagenavi.php</code> in a text editor and search for <code>wp_enqueue_style</code>.  This will turn up this code:</p>
<pre><code>wp_enqueue_style('wp-pagenavi', get_stylesheet_directory_uri().'/pagenavi-css.css', false, '2.50', 'all');</code></pre>
<p>And this:</p>
<pre><code>wp_enqueue_style('wp-pagenavi', plugins_url('wp-pagenavi/pagenavi-css.css'), false, '2.50', 'all');</code></pre>
<p>What we&#8217;re looking for is <code>wp-pagenavi</code>, which is the <code>handle</code> for the style.  Once you&#8217;ve found that, close the file and add this to your theme&#8217;s <code>functions.php</code> file.</p>
<pre><code>add_action( 'wp_print_styles', 'my_deregister_styles', 100 );

function my_deregister_styles() {
	wp_deregister_style( 'wp-pagenavi' );
}</code></pre>
<p>That&#8217;ll disable the stylesheet for this plugin.  Feel free to deregister as many styles as you want within this function.</p>
<h2>Tips on making this work better</h2>
<p>You&#8217;ve disabled several scripts and styles, but you need to do something with them.  Here&#8217;s a list of tips on how to make use of the methods described in this tutorial:</p>
<ul>
<li>Append styles that you&#8217;ve disabled to the end of your theme&#8217;s <code>style.css</code> file and edit them from there to get the look you want.</li>
<li>Combine several scripts into a single file and load it yourself.  I would only do this for things that use the same JavaScript library.  For example, I often combine scripts that are built on jQuery.</li>
<li>Use <a href="http://codex.wordpress.org/Conditional_Tags" title="WordPress Codex: Conditional Tags">conditional tags</a> for fine-grained control over when a script or style is loaded.</li>
</ul>
<p>If you disable something, it may cause the plugin/theme not to work correctly.  Most styles can easily be added to your theme&#8217;s stylesheet so that you&#8217;re not loading a ton of stylesheets on your site.  JavaScript is a different beast altogether, and I only recommend combining multiple files into one if you know what you&#8217;re doing.</p>
<p>Have fun with this.  Experiment.  Share your experience with others in the comments.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/Q9vSJOGswig" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles/feed</wfw:commentRss>
		<slash:comments>57</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles</feedburner:origLink></item>
		<item>
		<title>Contextually changing your theme’s stylesheet</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/cGRlrHo7u70/contextually-changing-your-themes-stylesheet</link>
		<comments>http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet#comments</comments>
		<pubDate>Tue, 28 Jul 2009 03:49:54 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1767</guid>
		<description><![CDATA[How to dynamically load different stylesheets when you need to drastically alter the style of specific pages on your WordPress-powered site.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>ordPress 2.8 introduced the <code>body_class()</code> function, which allows you to contextually style elements in your theme&#8217;s <code>style.css</code>.  Few themes allowed this sort of functionality before this release.  </p>
<p>While it&#8217;s cool to be able to style a particular post or page (or tons of other things) with a simple <acronym title="Cascading Style Sheets">CSS</acronym> selector in a single stylesheet, it&#8217;s not always enough.  Sometimes, you may need to drastically change the appearance of a page.  To do this, you&#8217;d need to load a different stylesheet.</p>
<p>Many tutorials will tell you to dive directly into your theme&#8217;s <code>header.php</code> file.  Of course, you know I&#8217;m more interested in doing things the <em>smart</em> way by taking advantage of a theme&#8217;s <code>functions.php</code> file.  This technique will allow you to easily transfer your custom code from theme to theme, use within a plugin, and it&#8217;s the best method when working from a child theme.</p>
<h2>Dynamically changing your theme&#8217;s stylesheet</h2>
<p>For this example, we have two pages we want use separate stylesheets on:  About and Portfolio.  The first thing you should do is create your stylesheets.  Drop them into your theme (or child theme) folder and name them <code>style-about.css</code> and <code>style-portfolio.css</code>.</p>
<p>Once that&#8217;s done, add this code to your <code>functions.php</code> file:</p>
<pre><code>&lt;?php

add_filter( 'stylesheet_uri', 'my_stylesheet', 10, 2 );

function my_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {

	if ( is_page( 'about' ) )
		$stylesheet_uri = $stylesheet_dir_uri . '/style-about.css';
	elseif ( is_page( 'portfolio' ) )
		$stylesheet_uri = $stylesheet_dir_uri . '/style-portfolio.css';

	return $stylesheet_uri;
}

?></code></pre>
<p>Just save and check out your new styles.</p>
<h2>The code explained</h2>
<p>What we&#8217;ve done with the few lines of code above is filter <code>stylesheet_uri</code>, which is a hook that returns your currently active theme&#8217;s stylesheet.  This hook gives us two parameters we can use:</p>
<ul>
<li><code>$stylesheet_uri</code><br />
	The <acronym title="Uniform Resource Identifier">URI</acronym> to the current theme&#8217;s stylesheet, which needs to be returned.</li>
<li><code>$stylesheet_dir_uri</code><br />
	The <acronym title="Uniform Resource Identifier">URI</acronym> of the current theme&#8217;s directory, which we can use in our own function and not have to figure out where our styleheets are.</li>
</ul>
<p>The <code>is_page()</code> function is one of many <a href="http://codex.wordpress.org/Conditional_Tags" title="WordPress Codex: Conditional Tags">conditional tags</a> at your disposal for determining what page a visitor is currently viewing.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/cGRlrHo7u70" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet</feedburner:origLink></item>
	</channel>
</rss>
