<?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>Flav36rs &#187; WordPress</title>
	<atom:link href="http://flav36rs.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://flav36rs.com</link>
	<description>Just another technical blog</description>
	<lastBuildDate>Mon, 12 Sep 2011 16:56:36 +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>Using front-end AJAX requests in your WordPress plugins</title>
		<link>http://flav36rs.com/2011/09/12/using-front-end-ajax-requests-in-your-wordpress-plugins/</link>
		<comments>http://flav36rs.com/2011/09/12/using-front-end-ajax-requests-in-your-wordpress-plugins/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 16:55:37 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://flav36rs.com/?p=843</guid>
		<description><![CDATA[Although it is fairly uncommon to be adding AJAX functionality to your WordPress plugins, it can be necessary for it to be added. Luckily it is quite easy and straight forward to integrate the required components as and when they &#8230; <a href="http://flav36rs.com/2011/09/12/using-front-end-ajax-requests-in-your-wordpress-plugins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Although it is fairly uncommon to be adding AJAX functionality to your WordPress plugins, it can be necessary for it to be added. Luckily it is quite easy and straight forward to integrate the required components as and when they are required.</p>
<p>To help explain how this can be achieved, we will be creating a plugin called &#8220;<strong>Ajax Example</strong>&#8220;, stored in the folder &#8220;<strong>ajax-example</strong>&#8221; inside the plugin directory of your WordPress install.</p>
<p><span id="more-843"></span>Further information on <a title="Writing a Plugin" href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">creating a WordPress plugin</a> can be found on <a title="WordPress.org" href="http://wordpress.org/" target="_blank">WordPress.org</a> and other resources, so won&#8217;t go into too much detail here.</p>
<p>First we need to create a file called &#8220;<strong>index.html</strong>&#8221; and copy the following into this file:</p>
<pre>&lt;?php
/*
Plugin Name: Ajax Example
Plugin URI: http://wp.me/pWbfz-dB
Description: Simple example of how to integrate front-end ajax requests via your plugin.
Version: 0.1
Date: 2011-09-01
Author: Steve Whiteley
Author URI: http://flav36rs.com
*/

class Ajax_Example
{
	public function __construct()
	{
		// ...
 	}
}

$ajaxExample = new Ajax_Example();

?&gt;</pre>
<p>We will be using the OOP structure for this plugin instead of the prefixed function format, however could be converted with ease. This class provides the skeleton structure of our plugin, you should save this file to our &#8220;<strong>ajax-example</strong>&#8221; folder before we start to add more functionality.</p>
<p>The next step is to include the <strong>JavaScript</strong> file that performs the AJAX request, which is called by the &#8220;<a title="Init Action Hook" href="http://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank">init</a>&#8221; action hook added to the class constructor method:</p>
<pre>add_action( 'init', array( &amp;$this, 'init' ) );</pre>
<p>Then we add the init function to the plugin, which includes calls to insert the JavaScript file <em>(wp_enqueue_script)</em> and set the parameters required by the external file <em>(wp_localize_script)</em>.</p>
<pre>public function init()
{
	wp_enqueue_script( 'ajax-example', plugin_dir_url( __FILE__ ) . 'ajax.js', array( 'jquery' ) );
	wp_localize_script( 'ajax-example', 'AjaxExample', array(
		'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ),
		'nonce' =&gt; wp_create_nonce( 'ajax-example-nonce' )
	) );
}</pre>
<p>Additional parameters can be added to array if they are required, the two mentioned should be the minimum that are required.</p>
<p>While we&#8217;re here, we should add the function that handles the response generated by the AJAX request. Notice here that we check the nonce value that is defined in the function above and set the content type before returning the encoded JSON array.</p>
<pre>public function ajax_call()
{
	if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'ajax-example-nonce' ) )
		die ( 'Invalid Nonce' );
	header( "Content-Type: application/json" );
	echo json_encode( array(
		'success' =&gt; true,
		'time' =&gt; time()
	) );
	exit;
}</pre>
<p>Create &#8220;<strong>ajax-example/ajax.js</strong>&#8221; and copy the following snippet into this file. In order to perform the AJAX request, we use the jQuery .getJSON() method. <a title="jQuery AJAX methods" href="http://api.jquery.com/category/ajax/" target="_blank">Alternative methods</a> could be used depending on the type of request you are performing.</p>
<pre>jQuery.getJSON(
    AjaxExample.ajaxurl,
    {
        action: 'ajax-example',
        nonce: AjaxExample.nonce
    },
    function( response ) {
    	alert( response.success );
    }
);</pre>
<p>Unfortunately this won&#8217;t actually do anything until we add two hooks to extend the built in AJAX functionality. These are added to the class constructor, the first <em>(wp_ajax_nopriv_ajax-example)</em> provides access for logged in users, the second <em>(wp_ajax_ajax-example)</em> for anonymous / non-logged in visitors.</p>
<pre>if ( is_admin() ) {
	add_action( 'wp_ajax_nopriv_ajax-example', array( &amp;$this, 'ajax_call' ) );
	add_action( 'wp_ajax_ajax-example', array( &amp;$this, 'ajax_call' ) );
}</pre>
<p>Please be aware that when using these hooks, they are called from within <strong>is_admin()</strong>, otherwise they are not correctly set.</p>
<p>The full contents of the plugin file &#8220;<strong>ajax-example/index.php</strong>&#8221; should be as follows:</p>
<pre>&lt;?php
/*
Plugin Name: Ajax Example
Plugin URI: http://wp.me/pWbfz-dB
Description: Simple example of how to integrate front-end ajax requests via your plugin.
Version: 0.1
Date: 2011-09-01
Author: Steve Whiteley
Author URI: http://flav36rs.com
*/

class Ajax_Example
{
	public function __construct()
	{
		if ( is_admin() ) {
			add_action( 'wp_ajax_nopriv_ajax-example', array( &amp;$this, 'ajax_call' ) );
			add_action( 'wp_ajax_ajax-example', array( &amp;$this, 'ajax_call' ) );
		}
		add_action( 'init', array( &amp;$this, 'init' ) );
	}

	public function init()
	{
		wp_enqueue_script( 'ajax-example', plugin_dir_url( __FILE__ ) . 'ajax.js', array( 'jquery' ) );
		wp_localize_script( 'ajax-example', 'AjaxExample', array(
		    'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ),
		    'nonce' =&gt; wp_create_nonce( 'ajax-example-nonce' )
		) );
	}

	public function ajax_call()
	{
		if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'ajax-example-nonce' ) )
			die ( 'Invalid Nonce' );
		header( "Content-Type: application/json" );
		echo json_encode( array(
			'success' =&gt; true,
			'time' =&gt; time()
		) );
		exit;
	}

}

$ajaxExample = new Ajax_Example();

?&gt;</pre>
<p>Other things to consider when using the example code provided above are that you should probably ensure jQuery is loaded and possibly only add the the scripts to the pages that they are required, rather than globally.</p>
<p>This functionality was tested with <strong>WordPress 3.2.1</strong>, it may however change and be simplified in future releases.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2011/09/12/using-front-end-ajax-requests-in-your-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Forcing a WordPress plugin to be loaded before all other plugins</title>
		<link>http://flav36rs.com/2011/09/03/forcing-a-wordpress-plugin-to-be-loaded-before-all-other-plugins/</link>
		<comments>http://flav36rs.com/2011/09/03/forcing-a-wordpress-plugin-to-be-loaded-before-all-other-plugins/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 14:05:20 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[force]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[order]]></category>

		<guid isPermaLink="false">http://flav36rs.com/?p=829</guid>
		<description><![CDATA[When you activate a plugin via the WordPress admin panel it calls the action hook &#8220;activated_plugin&#8220;, which updates the &#8220;active_plugins&#8221; site option stored in the database to determine which plugins your site should load. The option value is a serialized &#8230; <a href="http://flav36rs.com/2011/09/03/forcing-a-wordpress-plugin-to-be-loaded-before-all-other-plugins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you activate a plugin via the WordPress admin panel it calls the action hook &#8220;<em>activated_plugin</em>&#8220;, which updates the &#8220;<em>active_plugins</em>&#8221; site option stored in the database to determine which plugins your site should load.</p>
<p>The option value is a serialized array of the active plugins saved in alphabetical order according to the plugin directory and file name, for example:</p>
<p><span id="more-829"></span>
<pre>Array
(
	[0] =&gt; akismet/akismet.php
	[1] =&gt; example-plugin/index.php
)</pre>
<p>You can however alter the order of the plugins in the array, which will in turn set the order in which the plugins are loaded by WordPress.</p>
<p>The first step towards adjusting the order is to add the following action to your plugin file, which is most likely to be <em>/my-plugin/index.php</em> or <em>/my-plugin/my-plugin.php</em>.</p>
<pre>add_action( 'activated_plugin', 'my_plugin_load_first' );</pre>
<p>Next you need to include the functionality to perform the actual re-ordering. The following function will fetch the existing list, check that your plugin is in the array and if so remove then append it to the beginning, before finally saving the altered list to the database.</p>
<pre>function my_plugin_load_first()
{
	$path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
	if ( $plugins = get_option( 'active_plugins' ) ) {
		if ( $key = array_search( $path, $plugins ) ) {
			array_splice( $plugins, $key, 1 );
			array_unshift( $plugins, $path );
			update_option( 'active_plugins', $plugins );
		}
	}
}</pre>
<p>It should not be necessary for you to adjust anything specified here other than modifying the name of the function used to suit the namespace used by your plugin.</p>
<p>One final thing to consider is only adding this action when the dashboard or administration panels are being displayed, by making use of the <a href="http://codex.wordpress.org/Function_Reference/is_admin" target="_blank">is_admin()</a> conditional tag.</p>
<p><strong>Please note that modifying this option is not something I recommend people do unless absolutely necessary, and it my situation it proved to be very useful.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2011/09/03/forcing-a-wordpress-plugin-to-be-loaded-before-all-other-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding custom columns to the WordPress comments admin page</title>
		<link>http://flav36rs.com/2011/07/27/adding-custom-columns-to-the-wordpress-comments-admin-page/</link>
		<comments>http://flav36rs.com/2011/07/27/adding-custom-columns-to-the-wordpress-comments-admin-page/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 20:24:35 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[custom]]></category>

		<guid isPermaLink="false">http://flav36rs.com/?p=806</guid>
		<description><![CDATA[Adding custom columns to the WordPress admin pages is fairly easy, however not all the filters available to you are displayed on Plugin API Filter Reference page. The following article will take you through the process of adding additional columns &#8230; <a href="http://flav36rs.com/2011/07/27/adding-custom-columns-to-the-wordpress-comments-admin-page/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Adding custom columns to the WordPress admin pages is fairly easy, however not all the filters available to you are displayed on <a title="WordPress.org Filter Reference" href="http://codex.wordpress.org/Plugin_API/Filter_Reference" target="_blank">Plugin API Filter Reference</a> page. The following article will take you through the process of adding additional columns to the <strong>comments admin page</strong> using two undocumented filters.</p>
<p>If you are not a plugin author intending to use this functionality within a plugin, you should place the following code examples into your theme&#8217;s <strong>functions.php</strong> file.</p>
<p><span id="more-806"></span></p>
<p>The first filter &#8220;<em>manage_edit-comments_columns</em>&#8221; is used to adjust the table headings by appending a column called &#8220;<strong>My Custom Column</strong>&#8221; to the end of the table headings.</p>
<pre>function myplugin_comment_columns( $columns )
{
	$columns['my_custom_column'] = __( 'My Custom Column' );
	return $columns;
}
add_filter( 'manage_edit-comments_columns', 'myplugin_comment_columns' );</pre>
<p>The second filter &#8220;<em>manage_comments_custom_column</em>&#8221; will populate each comment row with data. It checks that the column ID matches that set in the function above (&#8220;my_custom_column&#8221;) and outputs &#8220;<strong>Custom Data for ID:</strong>&#8221; followed by the comment ID  for each row.</p>
<pre>function myplugin_comment_column( $column, $comment_ID )
{
	if ( 'my_custom_column' == $column ) {
		echo 'Custom Data for ID: ' . $comment_ID;
	}
}
add_filter( 'manage_comments_custom_column', 'myplugin_comment_column', 10, 2 );</pre>
<p>Outputting this text isn&#8217;t really that useful to anyone, instead you will more likely want to show some actual data related to the comment. One thing you may want to do is adjust the function to display some meta data stored for the comment.</p>
<pre>function myplugin_comment_column( $column, $comment_ID )
{
	if ( 'my_custom_column' == $column ) {
		if ( $meta = get_comment_meta( $comment_ID, $column , true ) ) {
			echo $meta;
		}
	}
}</pre>
<p>The above snippet assumes that meta key is the same as the column ID (&#8220;my_custom_column&#8221;) and you only want to add a single column, but what if you want to add multiple columns and show different data?</p>
<pre>function myplugin_comment_columns( $columns )
{
	return array_merge( $columns, array(
		'custom_column_one' =&gt; __( 'Custom Column One' ),
		'custom_column_two' =&gt; __( 'Custom Column Two' ),
		'custom_column_three' =&gt; __( 'Custom Column Three' )
	) );
}
add_filter( 'manage_edit-comments_columns', 'myplugin_comment_columns' );

function myplugin_comment_column( $column, $comment_ID )
{
	switch ( $column ) {
		case 'custom_column_one':
		case 'custom_column_two':
			if ( $meta = get_comment_meta( $comment_ID, $column , true ) ) {
				echo $meta;
			} else {
				echo '-';
			}
		break;
		case 'custom_column_three':
			echo 'Third Column Data';
		break;
	}
}
add_filter( 'manage_comments_custom_column', 'myplugin_comment_column', 10, 2 );</pre>
<p>The above will add three columns to the edit page, the first two will try to lookup <strong>comment meta data</strong> and the third output the text &#8220;<strong>Third Column Data</strong>&#8221; for the sake of this example.</p>
<p>Similar function and filter combinations can be used for adding columns to the other admin pages. Just adjust the filters used by replacing <em>{type}</em> with either &#8216;<strong>posts</strong>&#8216; or &#8216;<strong>pages</strong>&#8216; in the filters below, however we will not go into further detail here.</p>
<ul>
<li>manage_<strong>{type}</strong>_columns</li>
<li>manage_<strong>{type}</strong>_custom_column</li>
</ul>
<p><strong>Please note</strong> that the above functions have only been tested using WordPress 3.2.1 and cannot guarantee they will work correctly or the same in older versions.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2011/07/27/adding-custom-columns-to-the-wordpress-comments-admin-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress append page slug to body class</title>
		<link>http://flav36rs.com/2011/02/19/wordpress-append-page-slug-to-body-class/</link>
		<comments>http://flav36rs.com/2011/02/19/wordpress-append-page-slug-to-body-class/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 13:53:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[slug]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=775</guid>
		<description><![CDATA[Styling different pages in WordPress is a relatively easy process if you make use of the default body classes that are made available to you, especially the unique page ID class &#8220;page-id-123&#8220;. The problem with using the ID class to &#8230; <a href="http://flav36rs.com/2011/02/19/wordpress-append-page-slug-to-body-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Styling different pages in WordPress is a relatively easy process if you make use of the default <a href="http://codex.wordpress.org/Function_Reference/body_class" target="_blank">body classes</a> that are made available to you, especially the unique page ID class &#8220;<em>page-id-123</em>&#8220;.</p>
<p>The <strong>problem</strong> with using the ID class to identify an individual page is that a page ID can quite easily change when working with a development version or even migrating your blog from one install to another.<span id="more-775"></span></p>
<p>One <strong>solution</strong> to this problem is to append the post type and slug as a class name to the body, e.g. &#8216;<em>page-about</em>&#8216; or &#8216;<em>post-hello-world</em>&#8216;.</p>
<p>Simply add the following to your <a href="http://codex.wordpress.org/Theme_Development#Functions_File" target="_blank">functions.php</a> file to automatically append the classes:</p>
<pre lang="php" escaped="true">function add_body_class( $classes )
{
    global $post;
    if ( isset( $post ) ) {
        $classes[] = $post-&gt;post_type . '-' . $post-&gt;post_name;
    }
    return $classes;
}
add_filter( 'body_class', 'add_body_class' );</pre>
<p><strong>Note: </strong>This method will also apply to individual post pages and custom post types.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2011/02/19/wordpress-append-page-slug-to-body-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to remove the Admin Bar in WordPress 3.1 correctly</title>
		<link>http://flav36rs.com/2011/02/07/how-to-remove-the-admin-bar-in-wordpress-3-1-correctly/</link>
		<comments>http://flav36rs.com/2011/02/07/how-to-remove-the-admin-bar-in-wordpress-3-1-correctly/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 19:05:00 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[bar]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[remove]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=763</guid>
		<description><![CDATA[Although the WordPress Admin Bar can be hidden by a user visiting their profile page in the Admin Panel (Users &#62; Your Profile), there may be a situation where you want to force the removal without instructing the user to &#8230; <a href="http://flav36rs.com/2011/02/07/how-to-remove-the-admin-bar-in-wordpress-3-1-correctly/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Although the WordPress Admin Bar can be hidden by a user visiting their profile page in the Admin Panel (Users &gt; Your Profile), there may be a situation where you want to force the removal without instructing the user to amend their settings or updating their settings automatically.</p>
<p>When the issue of removing the Admin Bar first cropped up, the solution was to remove the associated init action, however this is not the correct method of disabling it and should not be used.<span id="more-763"></span></p>
<p><code><span style="text-decoration: line-through;">remove_action('init', 'wp_admin_bar_init');</span></code></p>
<p>Instead, you either use the show_admin_bar filter and simply return false:</p>
<pre lang="php" escaped="true">function hide_admin_bar() {
    return false;
}
add_filter( 'show_admin_bar', 'hide_admin_bar' );</pre>
<p>Or alternatively call the show_admin_bar function directly:</p>
<pre lang="php" escaped="true">show_admin_bar( false );</pre>
<p>If you are disabling the bar from within an init action it is important that you correctly pass the priority value, otherwise some of the assets may remain (such as the JavaScript file) and cause unwanted behaviour.</p>
<p>Using a priority of 9 seemed to be be the most successful from my experiments, although other possibilities may be used:</p>
<pre lang="php" escaped="true">add_action( 'init', 'my_init_function', 9 );</pre>
<p>There are a number of comments in the source code of 3.1, discouraging you from using the previous method of removing the wp_admin_bar_init action, so encourage anyone to update the method they are using.</p>
<p>All of the methods mentioned here can be used in either your plugin file or functions.php file.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2011/02/07/how-to-remove-the-admin-bar-in-wordpress-3-1-correctly/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WordPress append image dimensions as class names</title>
		<link>http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/</link>
		<comments>http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 11:53:20 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=747</guid>
		<description><![CDATA[When inserting images into post or page content WordPress automatically adds three class name to the image tag along with the other attributes, these are the alignment (alignnone), size (size-full) and the attachment id (wp-image-123). If you need to add &#8230; <a href="http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When inserting images into post or page content WordPress automatically adds three class name to the image tag along with the other attributes, these are the alignment <em>(alignnone)</em>, size <em>(size-full)</em> and the attachment id <em>(wp-image-123)</em>.</p>
<p>If you need to add additional class names to the defaults without having to manually add them every time you insert a new image, you can make use of either the <strong>get_image_tag_class</strong> or <strong>get_image_tag</strong> filters. <span id="more-747"></span></p>
<p>The first of the two filters is <strong>get_image_tag_class</strong>, which allows you to add a value or change the class attribute completely:</p>
<pre lang="php" escaped="true">function add_image_class($class){
	$class .= ' additional-class';
	return $class;
}
add_filter('get_image_tag_class','add_image_class');</pre>
<p>The second function is a little more flexible and provides the ability to alter the image tag completely, thus providing functionality to add the image dimensions to the class names as shown in this example:</p>
<pre lang="php" escaped="true">function add_image_class_dimensions($html, $id, $alt, $title)
{
	if (preg_match('/width="(d+)" height="(d+)"/', $html, $dimensions)) {
		list(,$width, $height) = $dimensions;
		$html = str_replace(
			'class="',
			'class="wp-image-width-'.$width.' wp-image-height-'.$height.' ',
			$html
		);
	}
	return $html;
}
add_filter('get_image_tag', 'add_image_class_dimensions', 10, 4);</pre>
<p>In brief, this function matches the dimensions found within the image tag <em>(width and height)</em> and appends them to the front of the class attribute.</p>
<p>Applying both of these filters will output something similar the following code in the TinyMCE editor:</p>
<pre lang="xhtml" escaped="true">&lt;img class="wp-image-width-200 wp-image-height-100 alignnone size-full wp-image-123" title="Image Title Here" src="/wp-content/uploads/2010/12/my-image.jpg" alt="" width="200" height="100" /&gt;</pre>
<p>To make use of this functionality you will first need to add the filter and function to your theme&#8217;s function.php file. Once this is done, add a new image to your post or page and you will see the custom class names are appended to the image tag. They <strong>will not</strong> be applied to any existing images within your content, you will have to insert them again from the media library for the changes to be applied.</p>
<p>These are only two examples of what results can be achieved, further adjustments and alterations can be easily added using the two get_image_tag filters.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2010/12/05/wordpress-append-image-dimensions-as-class-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable excerpts for pages in WordPress</title>
		<link>http://flav36rs.com/2010/10/11/how-to-enable-excerpts-for-pages-in-wordpress/</link>
		<comments>http://flav36rs.com/2010/10/11/how-to-enable-excerpts-for-pages-in-wordpress/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 18:20:32 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[excerpt]]></category>
		<category><![CDATA[pages]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=731</guid>
		<description><![CDATA[If you are a theme or plugin author, you may require additional functionality to allow for additional page content to be added, managed and displayed. One way this can be achieved, without resorting to custom page meta inputs, is to &#8230; <a href="http://flav36rs.com/2010/10/11/how-to-enable-excerpts-for-pages-in-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are a theme or plugin author, you may require additional functionality to allow for additional page content to be added, managed and displayed.</p>
<p>One way this can be achieved, without resorting to custom page meta inputs, is to simply enable support for <strong>excerpts</strong> on pages.<span id="more-731"></span></p>
<p>The excerpt content section that is visible on the post edit screen will then be displayed on the standard page content editing screen.</p>
<p>This can be achieved very quickly and easily by including the following lines in the theme <strong>functions.php</strong> file:</p>
<pre lang="php" escaped="true">    // Enable excerpts for pages...
add_action('init', 'enable_page_excerpts');
function enable_page_excerpts()
{
    add_post_type_support('page', 'excerpt');
}</pre>
<p>There are a few downsides to using this method, so it is advised that you use with caution.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2010/10/11/how-to-enable-excerpts-for-pages-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress: Prevent auto  tags in page content</title>
		<link>http://flav36rs.com/2010/08/07/wordpress-prevent-auto-br-tags-in-page-content/</link>
		<comments>http://flav36rs.com/2010/08/07/wordpress-prevent-auto-br-tags-in-page-content/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 09:47:53 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[wpautop]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=721</guid>
		<description><![CDATA[If you make use of some basic mark-up in your WordPress page content, you may have encountered an issue where &#60;br /&#62; tags are appearing where they shouldn&#8217;t and are affecting your theme layout. To prevent this happening but leave &#8230; <a href="http://flav36rs.com/2010/08/07/wordpress-prevent-auto-br-tags-in-page-content/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you make use of some basic mark-up in your WordPress page content, you may have encountered an issue where &lt;br /&gt; tags are appearing where they shouldn&#8217;t and are affecting your theme layout.</p>
<p>To prevent this happening but leave the auto conversion of double line-breaks into paragraph tags, I had a dig into the <a href="http://codex.wordpress.org/Function_Reference/wpautop" target="_blank">wpautop</a> function that runs before the content is outputted to the screen.<span id="more-721"></span></p>
<p>This function accepts two parameters, the first is the content to be formatted and the second determines whether to convert remaining line breaks into &lt;br /&gt; tags.</p>
<p>Because the wpautop filter is automatically applied to the content, we first need to remove that by adding the following to our functions.php file:</p>
<pre lang="php" escaped="true">remove_filter('the_content', 'wpautop');</pre>
<p>Then we must apply the formatting function again but this time set the the second parameter to false and prevent the additional &lt;br /&gt; tags appearing.</p>
<pre lang="php" escaped="true">function wpautopnobr($content) {
	return wpautop($content, false);
}
add_filter('the_content', 'wpautopnobr');</pre>
<p>This can be customised further by checking to see if we are on a page rather than a post and only applying the formatting if that is the case. The required code in it&#8217;s entirety is as follows:</p>
<pre lang="php" escaped="true">remove_filter('the_content', 'wpautop');
function wpautopnobr($content) {
	return wpautop($content, (is_page() ? true : false));
}
add_filter('the_content', 'wpautopnobr');</pre>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2010/08/07/wordpress-prevent-auto-br-tags-in-page-content/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WP dbDelta function cannot modify unique keys</title>
		<link>http://flav36rs.com/2010/04/02/wp-dbdelta-function-cannot-modify-unique-keys/</link>
		<comments>http://flav36rs.com/2010/04/02/wp-dbdelta-function-cannot-modify-unique-keys/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 21:12:39 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[dbdelta]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=685</guid>
		<description><![CDATA[Whilst making some updates to one of my WordPress plugins earlier today, I discovered an small issue when trying to make use of the dbDelta function. Although it&#8217;s advised you avoid creating tables unless absolutely necessary, it seemed like the &#8230; <a href="http://flav36rs.com/2010/04/02/wp-dbdelta-function-cannot-modify-unique-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Whilst making some updates to one of my WordPress plugins earlier today, I discovered an small issue when trying to make use of the dbDelta function.</p>
<p>Although it&#8217;s advised you avoid creating tables unless absolutely necessary, it seemed like the correct method to store the data used by this particular plugin.<span id="more-685"></span></p>
<p>This method of storage does have it&#8217;s downsides, especially when it comes to modifying the table structure. Luckily the dbDelta function comes in really handy in aiding the update process.</p>
<p>There is however one issue that I came across, discovering that is unable to modify a unique key (in this situation a composite index).</p>
<p>After browsing through the source code for the dbDelta function I spotted that something was missing. When including an index in the query, it is not dropped before attempting to recreate it and is therefore ignored when performing an update.</p>
<p>Take for example the following code snippet:</p>
<pre lang="php" escaped="true">global $wpdb;
$table = $wpdb-prefix.'mytable';
$sql = "CREATE TABLE $table (
	id mediumint(9) NOT NULL AUTO_INCREMENT,
	calendar varchar(255) NOT NULL default 'default',
	year smallint(5) NOT NULL,
	month tinyint(3) NOT NULL,
	day tinyint(3) NOT NULL,
	PRIMARY KEY (id),
	UNIQUE KEY date (year,month,day)
);";
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);</pre>
<p>If we make some changes to the SQL statement to add an additional column to the unique index, the index would become something like &#8220;<em>UNIQUE KEY date (year,month,day,calendar)</em>&#8220;.</p>
<p>This will work if the the table does not already exist, but if it attempts to update the table then the changes to the unique key are ignored.</p>
<p>The short and simple solution is to simply check the table exists and then drop the index manually before calling the dbDelta function.</p>
<pre lang="php" escaped="true">if ($wpdb-&gt;get_var("SHOW TABLES LIKE $table") == $table) {
	$wpdb-&gt;query("ALTER TABLE $table DROP INDEX date");
}</pre>
<p>I&#8217;m not sure if this is actually a bug with the function or whether it wasn&#8217;t supposed to allow for updates on indexes in the first place, either way the problem can be quite easily resolved.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2010/04/02/wp-dbdelta-function-cannot-modify-unique-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extend WordPress search to include custom post meta</title>
		<link>http://flav36rs.com/2010/03/15/extend-wordpress-search-to-include-custom-post-meta/</link>
		<comments>http://flav36rs.com/2010/03/15/extend-wordpress-search-to-include-custom-post-meta/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 18:50:24 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://36flavours.com/?p=659</guid>
		<description><![CDATA[After receiving numerous requests to allow the SubHeading value in my plugin to be searched when carrying out a default search, I turned my attention to finding a method to achieve this in WordPress 2.9.x. The plugin stores a custom &#8230; <a href="http://flav36rs.com/2010/03/15/extend-wordpress-search-to-include-custom-post-meta/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After receiving numerous requests to allow the <a href="http://wordpress.org/extend/plugins/subheading/" target="_self">SubHeading</a> value in my plugin to be searched when carrying out a default search, I turned my attention to finding a method to achieve this in WordPress 2.9.x.</p>
<p>The plugin stores a custom post meta entry for any post or page that requires a subtitle, in order to append this field to the search query I required the use of two actions.<span id="more-659"></span></p>
<ul>
<li>posts_where_request</li>
<li>posts_join_request</li>
</ul>
<p>Each of my plugins use a class based format, so the following examples will be provided in that format. This could quite easily be changed to regular functions</p>
<p>The first action is called when the class is instantiated:</p>
<pre lang="php" escaped="true">class MyPlugin {
	function MyPlugin()
	{
		add_action('posts_where_request', array(&amp;$this, 'search'));
	}
}</pre>
<p>The first argument passed to this action is a string containing the where clause for the search query.</p>
<p>When the action is called we have also reached a point where we can check whether we are carrying out a blog search &#8220;<strong>is_search()</strong>&#8220;.</p>
<pre lang="php" escaped="true">function search($where)
{
	if (is_search()) {
		global $wpdb, $wp;
		$where = preg_replace(
			"/(wp_posts.post_title (LIKE '%{$wp-&gt;query_vars['s']}%'))/i",
			"$0 OR ($wpdb-&gt;postmeta.meta_key = '_mymetakey' AND $wpdb-&gt;postmeta.meta_value $1)",
			$where
		);
		add_filter('posts_join_request', array(&amp;$this, 'search_join'));
	}
	return $where;
}</pre>
<p>All that we do here is include the meta key search by finding the post_title clause and inserting the meta key clause after it, using the preg_replace() function.</p>
<p><em>(Note: I have used the meta key &#8220;_mymetakey&#8221;, you will need to replace this with the key matching your custom meta data.)</em></p>
<p>The where condition is now in place, but we will need to add on the post_meta table, making use of the second action &#8220;posts_join_request&#8221; included in the function above.</p>
<pre lang="php" escaped="true">function search_join($join)
{
	global $wpdb;
	return $join .= " LEFT JOIN $wpdb-&gt;postmeta ON ($wpdb-&gt;posts.ID = $wpdb-&gt;postmeta.post_id) ";
}</pre>
<p>Putting all the basic functionality together you will have something along the lines of this:</p>
<pre lang="php" escaped="true">class MyPlugin {
	function MyPlugin()
	{
		add_action('posts_where_request', array(&amp;$this, 'search'));
	}
	function search($where)
	{
		if (is_search()) {
			global $wpdb, $wp;
			$where = preg_replace(
				"/(wp_posts.post_title (LIKE '%{$wp-&gt;query_vars['s']}%'))/i",
				"$0 OR ($wpdb-&gt;postmeta.meta_key = '_{$this-&gt;tag}' AND $wpdb-&gt;postmeta.meta_value $1)",
				$where
			);
			add_filter('posts_join_request', array(&amp;$this, 'search_join'));
		}
		return $where;
	}
	function search_join($join)
	{
		global $wpdb;
		return $join .= " LEFT JOIN $wpdb-&gt;postmeta ON ($wpdb-&gt;posts.ID = $wpdb-&gt;postmeta.post_id) ";
	}
}</pre>
<p>There are however a few possible pitfalls that I have yet to address, the main one being that the meta_value field is not indexed.</p>
<p>I&#8217;m not sure whether to try and automatically add an index to the field or add an additional option on my plugin settings page to create the index.</p>
]]></content:encoded>
			<wfw:commentRss>http://flav36rs.com/2010/03/15/extend-wordpress-search-to-include-custom-post-meta/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

