<?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>WPStorm &#187; Coding</title>
	<atom:link href="http://wpstorm.net/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpstorm.net</link>
	<description>Coding, Wordpress and Plugin Development</description>
	<lastBuildDate>Mon, 30 Jan 2012 00:25:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Editor Styles for Custom Post Types in WordPress 3.0</title>
		<link>http://wpstorm.net/2010/04/editor-styles-custom-post-types-wordpress-3-0/</link>
		<comments>http://wpstorm.net/2010/04/editor-styles-custom-post-types-wordpress-3-0/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 16:27:51 +0000</pubDate>
		<dc:creator>Lotta</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tweak]]></category>
		<category><![CDATA[WordPress 3.0]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=333</guid>
		<description><![CDATA[I&#8217;ve had some fun playing around with the recently released WordPress 3.0, Beta 1. One of my new favorite additions is the add_editor_style() which allows you to assign a CSS file for the TinyMCE when editing posts, pages and the new custom post types. This is very handy to get closer to a WYSIWYG experience ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had some fun playing around with the recently released <a href="http://wordpress.org/development/2010/04/wordpress-3-0-beta-1/">WordPress 3.0, Beta 1</a>. One of my new favorite additions is the add_editor_style() which allows you to assign a CSS file for the TinyMCE when editing posts, pages and the new custom post types. This is very handy to get closer to a WYSIWYG experience in WordPress&#8217; editor and not having to preview the posts all the times while writing, to check where line breaks end up and so on (if you care about those things).</p>
<p>I&#8217;m also loving the new Custom Post Types, and on one of my sites, I have setup a few different post types. On the frontend I have different widths for posts, pages and my new WordPress 3.0 custom post type &#8216;portfolio. I wanted to reflect the different widths in my admin editor style sheet as well. The posts are the narrowest ones, while pages are wider and my custom post type portfolio is the widest, so I have made 3 style sheets which are pretty much the same, with the exception of the</p>
<pre class="brush: css; title: ; notranslate">
html .mceContentBody {
	max-width:640px;
}
</pre>
<p>which sets the width for the editor. My style sheets are named; editor-style-post.css, editor-style-page.css and editor-style-portfolio.css.<br />
To be able to decide which post type I&#8217;m editing I check post_type in the $current_screen variable and then set the correct CSS according to that.</p>
<p>The code I end up with adding to my <em>functions.php</em> file looks something like this.</p>
<pre class="brush: php; title: ; notranslate">
function my_editor_style() {
	global $current_screen;
	switch ($current_screen-&gt;post_type) {
	case 'post':
		add_editor_style('editor-style-post.css');
		break;
	case 'page':
		add_editor_style('editor-style-page.css');
		break;
	case 'portfolio':
		add_editor_style('editor-style-portfolio.css');
		break;
	}
}
add_action( 'admin_head', 'my_editor_style' );
</pre>
<p>By expanding on the code above you can continue defining stylesheets for any custom post types you might end up with in WordPress 3.0.</p>
<p>That&#8217;s it folks, cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2010/04/editor-styles-custom-post-types-wordpress-3-0/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Optimize and style Contact Form 7 for WordPress</title>
		<link>http://wpstorm.net/2009/06/optimize-style-contact-form-7-wordpress/</link>
		<comments>http://wpstorm.net/2009/06/optimize-style-contact-form-7-wordpress/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 12:52:04 +0000</pubDate>
		<dc:creator>Lotta</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Contact]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Tweak]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=244</guid>
		<description><![CDATA[One of my favorite WordPress plugins is Contact Form 7 which I use on several of my WordPress based sites. Even though it&#8217;s highly customizable and configurable I have a few gripes with some hard coded functions in it. You can always edit the plugin file, which I did at first, but then you have ...]]></description>
			<content:encoded><![CDATA[<p>One of my favorite WordPress plugins is <a title="Contact Form for WordPress" href="http://ideasilo.wordpress.com/2007/04/30/contact-form-7/">Contact Form 7</a> which I use on several of my WordPress based sites. Even though it&#8217;s highly customizable and configurable I have a few gripes with some hard coded functions in it. You can always edit the plugin file, which I did at first, but then you have to reapply your edits every time the plugin gets updated, which can be cumbersome as this plugin gets updated quite often. So instead of keep editing the plugin file on every update I created some overrides instead.</p>
<h3>The Issues</h3>
<ul>
<li>The url to the AJAX loader symbol is hardcoded into the plugin, so if you don&#8217;t use a white background in your theme the loading symbol looks quite ugly. If you replace the default icon with your own it gets overwritten on each plugin update.</li>
<li>The javascripts for the plugin gets loaded on every single page of the site no matter if the plugin is used or not on that page, which adds unnecessary loading time where it&#8217;s not needed.</li>
<li>The path to the stylesheet for the validation and submit messages is also hardcoded into the plugin, and if you edit the stylesheet to fit your theme, the edits gets lost on each update, and you have to reupload your custom stylesheet for the plugin.</li>
</ul>
<h3>The Solutions</h3>
<p>So to not have to edit the plugin file, I added a few overrides in my theme&#8217;s functions.php file instead to change the behaviour of the plugin where needed.</p>
<p>Let&#8217;s start by taking care of the AJAX loading symbol. To change the path to the gif file I use a regular expression to update the url.</p>
<pre class="brush: php; title: ; notranslate">// Change the URL to the ajax-loader image
function change_wpcf7_ajax_loader($content) {
	if ( is_page('contact') ) {
		$string = $content;
		$pattern = '/(&lt;img class=&quot;ajax-loader&quot; style=&quot;visibility: hidden;&quot; alt=&quot;ajax loader&quot; src=&quot;)(.*)(&quot; \/&gt;)/i';
		$replacement = &quot;$1&quot;.get_template_directory_uri().&quot;/images/ajax-loader.gif$3&quot;;
		$content =  preg_replace($pattern, $replacement, $string);
	}
	return $content;
}
add_filter( 'the_content', 'change_wpcf7_ajax_loader', 100 );</pre>
<p>This function filters the content, tracks down the AJAX loader tag and replaces the URL with a path to the current {theme folder}/images/ajax-loader.gif. So you can have your own custom AJAX loader stored in your theme folder instead, untouched on each plugin update. I added the if( is_page(contact) ) {} to the function to make sure the filter only runs on pages where needed, to not waste CPU cycles on pages where the plugin is not used. Contact is the name of the page where I use the form, change it to the name, or names of pages where you use the plugin.</p>
<p>Okay, now let&#8217;s see take care of the script loading on each page of the site.</p>
<pre class="brush: php; title: ; notranslate">// Add the Contact Form 7 scripts on selected pages
function add_wpcf7_scripts() {
	if ( is_page('contact') )
		wpcf7_enqueue_scripts();
}
if ( ! is_admin() &amp;&amp; WPCF7_LOAD_JS )
	remove_action( 'init', 'wpcf7_enqueue_scripts' );
add_action( 'wp', 'add_wpcf7_scripts' );</pre>
<p>This function removes the call to add the Contact Form 7 scripts on every page, and then adds back the call where needed, in my case I add them back at the page called contact, but change that to whatever works for you.</p>
<p>And finally, let&#8217;s deal with the stylesheet.</p>
<pre class="brush: php; title: ; notranslate">function remove_wpcf7_stylesheet() {
	remove_action( 'wp_head', 'wpcf7_wp_head' );
}
add_action( 'init' , 'remove_wpcf7_stylesheet' );</pre>
<p>Here I actually remove the call to the stylesheet completely. As I have made my own style that fits my theme, I don&#8217;t use the default stylings. If you use the default stylings but just want it to load where needed, you could use an is_page condition like on the loading of the scripts. I could have put the Contact Form 7 Stylesheet in the theme folder using the same technique as on the AJAX loader to leave it untouched on a plugin update, but as I like to keep the calls to external files to a minimum to have the site load as fast as possible, I just put the WPCF7 CSS styles directly in my default style.css of my theme instead and got rid of the plugin stylesheet loading.</p>
<h3>The Final Code</h3>
<p>And here is what the final code looks like, ready to get pasted into the functions.php file in the theme you are using.</p>
<pre class="brush: php; title: ; notranslate">/**
 * Functions:	Optimize and style Contact Form 7 - WPCF7
 *
 */
// Remove the default Contact Form 7 Stylesheet
function remove_wpcf7_stylesheet() {
	remove_action( 'wp_head', 'wpcf7_wp_head' );
}

// Add the Contact Form 7 scripts on selected pages
function add_wpcf7_scripts() {
	if ( is_page('contact') )
		wpcf7_enqueue_scripts();
}

// Change the URL to the ajax-loader image
function change_wpcf7_ajax_loader($content) {
	if ( is_page('contact') ) {
		$string = $content;
		$pattern = '/(&lt;img class=&quot;ajax-loader&quot; style=&quot;visibility: hidden;&quot; alt=&quot;ajax loader&quot; src=&quot;)(.*)(&quot; \/&gt;)/i';
		$replacement = &quot;$1&quot;.get_template_directory_uri().&quot;/images/ajax-loader.gif$3&quot;;
		$content =  preg_replace($pattern, $replacement, $string);
	}
	return $content;
}

// If the Contact Form 7 Exists, do the tweaks
if ( function_exists('wpcf7_contact_form') ) {
	if ( ! is_admin() &amp;&amp; WPCF7_LOAD_JS )
		remove_action( 'init', 'wpcf7_enqueue_scripts' );

	add_action( 'wp', 'add_wpcf7_scripts' );
	add_action( 'init' , 'remove_wpcf7_stylesheet' );
	add_filter( 'the_content', 'change_wpcf7_ajax_loader', 100 );
}</pre>
<p>This tweak was published when Contact Form 7 was at version 1.10, and should continue to work just fine as long as no major changes is made to the inner workings of the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2009/06/optimize-style-contact-form-7-wordpress/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>Email log messages library in CodeIgniter</title>
		<link>http://wpstorm.net/2009/05/email-log-messages-library-codeigniter/</link>
		<comments>http://wpstorm.net/2009/05/email-log-messages-library-codeigniter/#comments</comments>
		<pubDate>Sun, 31 May 2009 16:53:08 +0000</pubDate>
		<dc:creator>Lotta</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=231</guid>
		<description><![CDATA[When working with CodeIgniter, I&#8217;ve found the log message functionality built into the framework very helpful. The other day I noticed in my log of one of my CodeIgniter based sites that I&#8217;ve had some 404 errors going on for some time. As I don&#8217;t have the time to check my logs daily, I hadn&#8217;t ...]]></description>
			<content:encoded><![CDATA[<p>When working with CodeIgniter, I&#8217;ve found the log message functionality built into the framework very helpful. The other day I noticed in my log of one of my CodeIgniter based sites that I&#8217;ve had some 404 errors going on for some time. As I don&#8217;t have the time to check my logs daily, I hadn&#8217;t noticed this problem until now.</p>
<p>This led me to think that it would be real handy to get the log messages sent out by email as well, so you don&#8217;t risk to have a problem going on at the site unnoticed for days or even weeks.</p>
<p>So I wrote an extension to the native Log class in CodeIgniter which adds this functionality. Below is the code for MY_Log.php which extends the CI_Log class. MY_Log calls the native Log functions so the log file still gets generated, and if a log message was executed it also gets sent out by email afterward.</p>
<p>Change the email address in the code to the one you want to receive the log messages to, and then save the file in your application/libraries/ folder as MY_Log.php. This assumes that your Class Extension Prefix is set to MY_ in your config file.</p>
<p>I hope some of you find this class extension useful, and feel free to improve upon it. Cheers!</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * MY_Log Class
 *
 * This library extends the native Log library.
 * It adds the function to have the log messages being emailed when they have been outputted to the log file.
 *
 * @package		CodeIgniter
 * @subpackage		Libraries
 * @category		Logging
 * @author		Johan Steen
 * @link		http://wpstorm.net/
 */
class MY_Log extends CI_Log {
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function MY_Log()
	{
		parent::CI_Log();
	}

	/**
	 * Write Log File
	 *
	 * Calls the native write_log() method and then sends an email if a log message was generated.
	 *
	 * @access	public
	 * @param	string	the error level
	 * @param	string	the error message
	 * @param	bool	whether the error is a native PHP error
	 * @return	bool
	 */
	function write_log($level = 'error', $msg, $php_error = FALSE)
	{
		$result = parent::write_log($level, $msg, $php_error);

		if ($result == TRUE &amp;&amp; strtoupper($level) == 'ERROR') {
			$message = &quot;An error occurred: \n\n&quot;;
			$message .= $level.' - '.date($this-&gt;_date_fmt). ' --&gt; '.$msg.&quot;\n&quot;;

			$to = 'someone@example.com';
			$subject = 'An error has occured';
			$headers = 'From: Example Name &lt;no-reply@example.com&gt;' . &quot;\r\n&quot;;
			$headers .= 'Content-type: text/plain; charset=utf-8\r\n';

			mail($to, $subject, $message, $headers);
		}
		return $result;
	}
}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2009/05/email-log-messages-library-codeigniter/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Coding for Fun&#8230; Code n&#039; Play</title>
		<link>http://wpstorm.net/2009/05/coding-for-fun-codeplay/</link>
		<comments>http://wpstorm.net/2009/05/coding-for-fun-codeplay/#comments</comments>
		<pubDate>Sun, 24 May 2009 00:03:23 +0000</pubDate>
		<dc:creator>Lotta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=177</guid>
		<description><![CDATA[I rebranded the site&#8230; to Code n&#8217; Play. When I set this site up, about two months ago, I didn&#8217;t really have any plans where I wanted to go with it, so I just named it Coding for Fun and downloaded a free WordPress theme to get it started so I had a place to ...]]></description>
			<content:encoded><![CDATA[<p>I rebranded the site&#8230; to Code n&#8217; Play.</p>
<p>When I set this site up, about two months ago, I didn&#8217;t really have any plans where I wanted to go with it, so I just named it Coding for Fun and downloaded a free WordPress theme to get it started so I had a place to host my Post Snippets plugin for WordPress.</p>
<p>Well, I&#8217;ve really enjoyed all the positive response I got from that plugin, and the ambition to make something good out of this site has come as a result of that. So I decided to make my own WordPress theme and rebrand it &#8211; to make the site a tad more serious. The theme is done (you&#8217;re looking at it right now) except some minor tweaks with the commenting styling, which I&#8217;ll do as soon as time permits.</p>
<p>I&#8217;ll continue posting updates to my WordPress plugins, as well as releasing new ones. And also I have some articles planned that will surface down the road. Both around WordPress and PHP as well as some other coding platforms that I am working with.</p>
<p>Still, this is just something I do for fun, I have my daytime (and sometimes evening and nighttime) job which takes a decent amount of time, so articles, new plugins and updates will come when they come. But things are cooking!</p>
<p>Cheers, and hope to see you around!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2009/05/coding-for-fun-codeplay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A site about Coding</title>
		<link>http://wpstorm.net/2009/03/a-site-about-coding/</link>
		<comments>http://wpstorm.net/2009/03/a-site-about-coding/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 10:48:40 +0000</pubDate>
		<dc:creator>Lotta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://wpstorm.net/?p=6</guid>
		<description><![CDATA[Welcome to my new site about coding. I&#8217;m a CG artist, but I have a past as a coder since the Commodore 64 and Amiga days. I still dabble around with coding in my spare time now and then, developing what I find interesting or fun. It can be anything from writing assembler code on ...]]></description>
			<content:encoded><![CDATA[<p>Welcome to my new site about coding. I&#8217;m a CG artist, but I have a past as a coder since the Commodore 64 and Amiga days. I still dabble around with coding in my spare time now and then, developing what I find interesting or fun.</p>
<p>It can be anything from writing assembler code on the Amiga to a C++ plugin for the LightWave 3D platform.</p>
<p>As I&#8217;ve been coding for a long time, since the end of the 1980&#8242;s, I&#8217;ve had time to explore tons of different programming languages during the years. Here I&#8217;ll write about the languages I use today like C++, Actionscript, Assembler, Python, LScript and PHP.</p>
<p>Oh well, I&#8217;ll see what I make out of it, but expect to see code snippets, algorithms and different projects surfacing here. This is something I do for fun, so just don&#8217;t expect to see updates daily here. I won&#8217;t be as active as I am on my other sites about 3D work, but I hope in time there will be some interesting things posted here to read about.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpstorm.net/2009/03/a-site-about-coding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

