<?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>ANDY STRATTON&#187; Wordpress</title>
	<atom:link href="http://theandystratton.com/category/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://theandystratton.com</link>
	<description>WordPress and PHP Developer</description>
	<lastBuildDate>Wed, 18 Apr 2012 20:49:34 +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>Restrict WordPress Registration to Email&#160;Whitelist</title>
		<link>http://theandystratton.com/2011/restrict-wordpress-registration-to-email-whitelist</link>
		<comments>http://theandystratton.com/2011/restrict-wordpress-registration-to-email-whitelist#comments</comments>
		<pubDate>Tue, 11 Oct 2011 21:33:48 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=590</guid>
		<description><![CDATA[Today I ran into a request with a client that I wanted to document and share: restricting registration to a WordPress site to a whitelist of email address domains. Luckily, there&#8217;s a sweet hook, registration_errors you can get into. It accepts 3 parameters: $errors, which is the WP_Error object; $login, which is the user_login entered [...]]]></description>
			<content:encoded><![CDATA[<p>Today I ran into a request with a client that I wanted to document and share: restricting registration to a WordPress site to a whitelist of email address domains.</p>
<p>Luckily, there&#8217;s a sweet hook, <code>registration_errors</code> you can get into. It accepts 3 parameters: <code>$errors</code>, which is the WP_Error object; <code>$login</code>, which is the <code>user_login</code> entered during registration; and <code>$email</code>, which is the <code>user_email</code> entered during registration.</p>
<p>Here&#8217;s the code:</p>
<pre><code>add_action('registration_errors', 'sizeable_restrict_domains', 10, 3);
function sizeable_restrict_domains( $errors, $login, $email ) {
	$whitelist = array('sizeableinteractive.com', 'theandystratton.com');
	if ( is_email($email) ) {
		$parts = explode('@', $email);
		$domain = $parts[count($parts)-1];
		if ( !in_array(strtolower($domain), $whitelist) ) {
			$errors->add('email_domain', __('<strong>ERROR:</strong> You may only register with an approved email address.'));
		}
	}
	return $errors;
}</code></pre>
<p><strong>Remember</strong> to specify some kind of priority AND how many parameters your callback function will accept when adding actions. I always forget to specify them when coding quickly from scratch and wonder why I&#8217;m getting weird values in my callback functions parameters.</p>
<p>Happy WP&#8217;ing.</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2011/restrict-wordpress-registration-to-email-whitelist/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lost Widgets When Migrating WordPress Domains (dev to production&#160;server)</title>
		<link>http://theandystratton.com/2011/lost-widgets-when-migrating-domains-server</link>
		<comments>http://theandystratton.com/2011/lost-widgets-when-migrating-domains-server#comments</comments>
		<pubDate>Tue, 24 May 2011 03:57:41 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=550</guid>
		<description><![CDATA[This is something I ran into long into working on WordPress sites. Here&#8217;s how what happens: I work locally with a MAMP setup I create virtual hosts per project Each virtual host corresponds to a host name I add to my /etc/hosts file Sometimes I mirror this to a staging server/domain for the client to [...]]]></description>
			<content:encoded><![CDATA[<p>This is something I ran into long into working on WordPress sites. Here&#8217;s how what happens:</p>
<ul>
<li>I work locally with a MAMP setup</li>
<li>I create virtual hosts per project</li>
<li>Each virtual host corresponds to a host name I add to my <code>/etc/hosts</code> file</li>
<li>Sometimes I mirror this to a staging server/domain for the client to prime content before launch</li>
<li>When launching, I take the staging database in a SQL export and import it into the production database and run a query to update the domains</li>
</ul>
<p>Many times, the last item is a query like this (assuming default database prefix):</p>
<pre><code>UPDATE wp_options
SET option_value = REPLACE(option_value, 'http://dev.mycoolwebsite.com', 'http://www.mycoolwebsite.com');</code></pre>
<p>This typically did the trick. I rarely had issues, until one day, I migrated that had a <a rel="external" href="http://codex.wordpress.org/Widgetizing_Themes">widgetized sidebar</a> from my local machine, let&#8217;s say the hostname was <code>localhost</code> and the production domain was <code>www.mycoolsite.com</code>.</p>
<p>Everything worked as planned, but I lost all my widgets.</p>
<h2>¿Por Que, Widgets?</h2>
<p>Here&#8217;s what I figured: WordPress uses a serialized PHP array to store widget settings in the database. This array also contains the site&#8217;s domain, an abbreviated example would be:</p>
<pre><code>a:2:{s:3:"url";s:17:"http://localhost/";s:4:"meta";s:17:"some kind of meta";}</code></pre>
<p><code>a:2</code> represents an array with 2 elements; <code>s:3</code> says <q>this is a string that&#8217;s 3 characters long<!--1--> and so forth. When I run my replace SQL, it changes <code>http://localhost/</code> to <code>http://www.mycoolsite.com/</code> but never updates the string&#8217;s length from <code>s:17</code> to what it <em>should be</em>, which is <code>s:26</code>.</q></p>
<p>This simple inconsistency will invalidate that serialized array, returning <code>false</code> when it is unserialized &#8212; meaning no widgets or settings.</p>
<h2>Any Solution?</h2>
<p>Two solutions I use, short of some make-shiv helper script:</p>
<ol>
<li>Use a development/staging hostname that&#8217;s the same length so you can do a global replace (e.g. dev.mycoolsite.com, stg.mycoolsite.com, etc.)</li>
<li>Run a more target query</li>
</ol>
<p>Target Your Query, Hit the Widgets Page</p>
<p>Now, the following steps have worked for me and seem to be easier for me to be lazy with my organization up front. I recommend option 1 to be safe, but you can try this too:</p>
<pre><code>UPDATE wp_options
SET option_value = REPLACE(option_value, 'http://localhost', 'http://www.mycoolwebsite.com')
<strong>WHERE option_value LIKE 'http://%';</strong></code></pre>
<p>This will restrict the query only to WordPress option records that &lt;strong&gt;start&lt;/strong&gt; with the http:// protocol, thus ignoring serialized arrays. Once this runs, hit your widgets settings page and re-save things, and if you&#8217;re as lucky as me, everything is kosher.</p>
<h2>Yet Another Option</h2>
<p>This may actually be simpler. Go into your dev/staging/etc. site&#8217;s options and change the domain. You&#8217;ll get logged out. Go make your database dump and use that. You&#8217;ll probably need to do the previous steps to fix your dev/staging database though.</p>
<p>Hope this helps a few of you if you&#8217;re in a frustrated panic.</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2011/lost-widgets-when-migrating-domains-server/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>No Magic Bullets &#8211; WordCamp Raleigh&#160;2011</title>
		<link>http://theandystratton.com/2011/no-magic-bullets-wordcamp-raleigh-2011</link>
		<comments>http://theandystratton.com/2011/no-magic-bullets-wordcamp-raleigh-2011#comments</comments>
		<pubDate>Mon, 23 May 2011 18:13:11 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=541</guid>
		<description><![CDATA[I had a blast as WordCamp Raleigh. I re-connected with a ton of great people and met even more new people. My presentation got excellent reception from all attendees and I was quite pleased. I want to issue a huge thank you to Michael Torbert, Steve Mortiboy and the Semper Fi Web Design team for [...]]]></description>
			<content:encoded><![CDATA[<p>I had a blast as <a href="http://www.wordcampraleigh.com" rel="external">WordCamp Raleigh</a>. I re-connected with a ton of great people and met even more new people. My presentation got excellent reception from all attendees and I was quite pleased.</p>
<p>I want to issue a huge thank you to Michael Torbert, Steve Mortiboy and the <a href="http://semperfiwebdesign.com" rel="external">Semper Fi Web Design</a> team for making this happen, and making it happen well.</p>
<h2>The Slides</h2>
<div style="width:600px" id="__ss_8071017"><iframe src="http://www.slideshare.net/slideshow/embed_code/8071017" width="600" height="501" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><strong style="display:block;margin:12px 0 4px"><a href="http://slidesha.re/lLXIIs" rel="external" title="Diet Pills, SEO and Theme Frameworks: There are no magic bullets.">Diet Pills, SEO and Theme Frameworks: There are no magic bullets.</a></strong></div>
<p>You can <a href="/downloads/wcraleigh-preso-theandystratton.pdf">download the PDF</a> or <a href="http://slidesha.re/lLXIIs" rel="external">view the presentation on SlideShare</a>.</p>
<p>I think that the <a href="http://www.wordcampraleigh.com" rel="external">WordCamp Raleigh website</a> will also be posting slides and video(s).</p>
<p>Thanks to all who attended, see you at the next WordCamp!</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2011/no-magic-bullets-wordcamp-raleigh-2011/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Raw HTML Snippets WordPress&#160;Plugin</title>
		<link>http://theandystratton.com/2011/raw-html-snippets-wordpress-plugin</link>
		<comments>http://theandystratton.com/2011/raw-html-snippets-wordpress-plugin#comments</comments>
		<pubDate>Thu, 12 May 2011 15:16:52 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=531</guid>
		<description><![CDATA[Ever since my über vent over fake shortcodes that autoformat the output of real shortcodes, I realized that the intention was good but the execution was bad. So, I wrote a quick plugin that I thought was a more elegant (and that did not affect expected, core WordPress behaviors). Raw HTML Snippets This plugin allows [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since my über vent over <a href="http://theandystratton.com/2011/shortcode-autoformatting-html-with-paragraphs-and-line-breaks">fake shortcodes that autoformat the output of real shortcodes</a>, I realized that the intention was good but the execution was bad.</p>
<p>So, I wrote a quick plugin that I thought was a more elegant (and that did not affect expected, core WordPress behaviors).</p>
<h2>Raw HTML Snippets</h2>
<p>This plugin allows you to create a library of raw HTML snippets you need to embed within post/page content, then uses the native shortcode API to embed them without them being auto-formatted by <code>wpautop</code> or <code>wptexturize</code>.</p>
<p>It may not be as convenient as pasting directly into the HTML tab of the WYSIWYG editor, but it&#8217;s a solution that&#8217;s reusable, clean and does not interfere with the core functionality of WordPress or other possible plugins/shortcodes/content filters.</p>
<p><a herf="http://wordpress.org/extend/plugins/raw-html-snippets/" rel="external">Raw HTML Snippets</a> | <a href="http://downloads.wordpress.org/plugin/raw-html-snippets.zip" rel="external">Download</a></p>
<p>Give it a whirl, and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2011/raw-html-snippets-wordpress-plugin/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Shortcode Autoformatting HTML with Paragraphs and Line&#160;Breaks</title>
		<link>http://theandystratton.com/2011/shortcode-autoformatting-html-with-paragraphs-and-line-breaks</link>
		<comments>http://theandystratton.com/2011/shortcode-autoformatting-html-with-paragraphs-and-line-breaks#comments</comments>
		<pubDate>Tue, 10 May 2011 22:41:50 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=512</guid>
		<description><![CDATA[So, I have been working on a client&#8217;s WP plugin that is relatively linked to their ThemeForest WordPress theme authored by the good folks at ThemeFuse using their theme framework. Now, the easiest way to limit the reliance on the theme for the functionality I am building is to use shortcodes that output conditional content [...]]]></description>
			<content:encoded><![CDATA[<p>So, I have been working on a client&#8217;s WP plugin that is relatively linked to their <a href="http://www.themeforest.com" rel="nofollow external" title="Dear General Public: Stop customizing pre-built themes.">ThemeForest</a> WordPress theme authored by the good folks at <a href="http://www.themefuse.com" rel="external nofollow">ThemeFuse</a> using their <q>theme framework</q>.</p>
<p>Now, the easiest way to limit the reliance on the theme for the functionality I am building is to use shortcodes that output conditional content based on whether a user is logged in, based on user meta data, etc.</p>
<h2>Shortcode Autoformatting Has Helped Doubled My Time</h2>
<p>I have spent twice the amount of estimated time on this project, and at least 50% of that bloat has been this mysterious issue of my shortcode output being mysteriously auto-formatted with paragraph tags (<code>&lt;p&gt;</code>) and line-breaks (<code>&lt;br /&gt;</code>).</p>
<p>I&#8217;ve spent days ripping out the tiny hairs on my head trying to figure out why I&#8217;m such a moron when it comes to WP&#8217;s shortcode API and core content filters (things I&#8217;ve been working with for YEARS).</p>
<h2>I Do Something I Should Do More Often.</h2>
<p>My e-friend <a href="http://twitter.com/carlhancock" rel="external">Carl Hancock</a> of <a href="http://www.rocketgenius.com/" rel="external">Rocket Genius</a>, the company behind the awesomeness of functionality and user-experience that is <a href="http://www.gravityforms.com" rel="external" title="Worth Every Damn Penny + $100">GravityForms</a>, helped shed some light on this problem.</p>
<p>I figured he&#8217;d be the prefect person to reach out to, since the core of displaying a Gravity Form relies on WordPress&#8217; <a href="http://codex.wordpress.org/Shortcode_API" rel="external">Shortcode API</a>.</p>
<p>As we are direct messaging on Twitter, I remember his comments about fixing MANY ThemeForest theme issues for clients using Gravity Forms due to terrible coding standards and overriding core functionality that affect both Gravity Forms and other plugins.</p>
<p>I hunt through some of the 100+ files embedded in this pre-built theme <q>framework</q> and fine this, well, poor code:</p>
<pre><code>//Disable Automatic formatting in WordPress posts
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}
	return $new_content;
}

remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');

add_filter('the_content', 'my_formatter', 99);
</code></pre>
<p>No sooner than I see this code, I get a DM from Carl with a link to a <a href="http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode" rel="external">WP Recipe article</a> with the exact same code.</p>
<p>I&#8217;m not sure WHO this code started with, but I know who used it.</p>
<h2>Why is this a problem?</h2>
<p>It&#8217;s globally removing two very important core content filters that WP has built-in for very good reasons. It is typically assumed by most themes and plugins that these filters are running. I don&#8217;t have a problem turning them off conditionally (i.e. specific post ID&#8217;s, specific page templates in a theme, etc.). Better yet, set this as a setting in a custom field, <em>per page/post</em>, and have it on by default. Give me the option to disable it and even know it exists if I&#8217;m walking into the theme from a distance. </p>
<div style="width:250px;float:right;margin:0 0 1em 1em;background:#f5f5f5;border:1px solid #ccc;padding:1em;font-size:11px;font-style:italic;">At least give it the same priority as the <code>wpautop</code> and <code>wptexturize</code> filters so it does NOT affect shortcode output and behaves as similarly as possible! I realize this is to allow users to have &#8220;raw HTML output,&#8221; but you can do the same thing using it as a content filter and token replacement before/after these core filters are called.</div>
<p>This makes this theme work perfectly and negatively affects ANY and ALL plugins that have shortcodes or possibly filter content after the assumed priority of <code>wpautop</code> and <code>wptexturize</code>.</p>
<p>This is not a solution. It&#8217;s more of a hack that may or may not have cause the earthquake in Haiti, the tsunami in Japan and the tornados in the southern U.S&#8230;</p>
<h2>How the hell do I fix this?</h2>
<p><strong>Don&#8217;t use a theme that poor code in it.</strong> That&#8217;s the optimal solution. Don&#8217;t expect a $36 purchase from a virtual Wal-mart to be stable, secure or provide you with a strong solution for communicating and interacting with your clients.</p>
<h2>Okay, so realistically how do I fix this?</h2>
<ol>
<li>You can comment these lines of code out, including the <code>remove_filter()</code> calls, so that WP behaves as expected.</li>
<li>You can remove this filter in your shortcodes, which is what I did since my client is going to continue to use this theme:
<pre><code>add_shortcode('andy_shortcode', 'andy_shortcode');
function andy_shortcode( $atts, $content = '' ) {
	remove_filter('the_content', 'my_formatter', 99);
	extract(shortcode_atts(array(), $atts));
	$output = '&lt;div class="my_formatter_violated_my_output"&gt;';
	$output .= 'Thanks for using the my theme framework.&lt;/div&gt;';
	return $output;
}</code></pre>
<p>Remeber you MUST <strong>enter their priority value of 99</strong> (or whatever it is set to in your theme, chances are you&#8217;re using a theme from the same authors, or authors of the same mentality).
</li>
<li>You can stop using shortcodes or pray that it doesn&#8217;t affect you.</li>
</ol>
<h2>Final Thoughts</h2>
<p>I understand what the intention of this functionality is. In fact, I think it&#8217;s a good idea, just a poor implementation.</p>
<p>Ultimately, I&#8217;d move away from these themes and check out some stronger theme directories with dedicate WP experts coding, not a hodge-podge marketplace. Being that I&#8217;m kind of against purchasing pre-built themes from both a designer and developer standpoint, I can&#8217;t recommend a good site, but I&#8217;m sure I can keep recommending sites NOT to use.</p>
<p>Good luck and God Speed.</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2011/shortcode-autoformatting-html-with-paragraphs-and-line-breaks/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress 3.1 Admin Bar and I Can&#8217;t See Custom&#160;Fields!</title>
		<link>http://theandystratton.com/2011/wordpress-3-1-admin-bar-and-i-cant-see-custom-fields</link>
		<comments>http://theandystratton.com/2011/wordpress-3-1-admin-bar-and-i-cant-see-custom-fields#comments</comments>
		<pubDate>Thu, 24 Feb 2011 16:42:11 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=496</guid>
		<description><![CDATA[Alright WP junkies, I hope you&#8217;ve been upgrading. I won&#8217;t dive too deep into nerdiness of how the WP core team has answered my prayers and added a lot of things like better support in WP Query for taxonomy queries and Custom Fields/Meta queries, let&#8217;s focus on the Oh, Shit! moments a few of my [...]]]></description>
			<content:encoded><![CDATA[<p>Alright WP junkies, I hope you&#8217;ve been upgrading. I won&#8217;t dive too deep into nerdiness of how the WP core team has answered my prayers and added a lot of things like better support in WP Query for <a href="http://codex.wordpress.org/Function_Reference/query_posts#Taxonomy_Parameters" rel="external">taxonomy queries</a> and <a href="http://codex.wordpress.org/Function_Reference/query_posts#Custom_Field_Parameters" rel="external">Custom Fields/Meta queries</a>, let&#8217;s focus on the <q>Oh, Shit!</q> moments a few of my clients had today when I rolled some updates out.</p>
<h2>I Can&#8217;t See My Custom Fields</h2>
<p>I used custom fields a lot. Sometimes I create custom meta boxes for them, sometimes I have clients use the custom fields meta box directly. When we upgraded one of my client&#8217;s sites, my original administrator account still saw everything but the other accounts only saw the Publish, Page Attributes and title/editor panes in the Add/Edit Page screen.</p>
<p>Not cool. I was freaked. Then I realized (thanks to a <a href="http://wordpress.org/support/topic/wordpress-31-stable-cant-view-post-excerpts-or-custom-fields" rel="external">support post</a> at WordPress.org) that there are screen options there. They could&#8217;ve been there before and I just never paid attention, but now I know:</p>
<p><a target="_blank" href="http://theandystratton.com/wp-content/uploads/2011/02/Screen-shot-2011-02-24-at-11.32.40-AM.png"><img src="http://theandystratton.com/wp-content/uploads/2011/02/Screen-shot-2011-02-24-at-11.32.40-AM-300x79.png" alt="" title="Editor Screen Options" width="300" height="79" class="alignnone size-medium wp-image-500" /></a></p>
<p>Hopefully that helps you out.</p>
<h2>Killing the WordPress 3.1 Update Admin Bar</h2>
<p>Don&#8217;t get me wrong. I get it. I like it. But I have some installs where we are leveraging WP accounts but don&#8217;t want to advertise to the user that we&#8217;re on WP. I&#8217;ve used it for some very interesting applications and customized some installs heavily (not core, of course) and some clients just freaked about it.</p>
<p>My <a href="http://yoast.com/disable-wp-admin-bar/" rel="external">preferred method</a>, thanks to <a href="http://yoast.com" rel="external">Joost de Valk</a>, is to just to turn it off completely:</p>
<pre><code>add_filter('show_admin_bar', '__return_false');</code></pre>
<p>Remember, if you just want to hide it for yourself you can edit your user profile in the admin screens. <a href="http://yoast.com/disable-wp-admin-bar/" rel="external">Check out Joost&#8217;s article</a> for more options. Happy double-you-peeing.</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2011/wordpress-3-1-admin-bar-and-i-cant-see-custom-fields/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>BuddyPress Avatars Not Displaying with WordPress&#160;3.0</title>
		<link>http://theandystratton.com/2010/buddypress-avatars-not-displaying-with-wordpress-3-0</link>
		<comments>http://theandystratton.com/2010/buddypress-avatars-not-displaying-with-wordpress-3-0#comments</comments>
		<pubDate>Thu, 09 Sep 2010 15:13:26 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=488</guid>
		<description><![CDATA[I don&#8217;t work with BuddyPress much if at all, but have been doing a lot more of it lately. Recently, we had an issue where avatars were not displaying on pages using the built-in template tags, like bp_member_avatar() and others. We thought this was a weird environment issue at first, but then I found this [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t work with BuddyPress much if at all, but have been doing a lot more of it lately. Recently, we had an issue where avatars were not displaying on pages using the built-in template tags, like <code>bp_member_avatar()</code> and others.</p>
<p>We thought this was a weird environment issue at first, but then I found <a href="http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/custom-avatars-not-showing-on-multisite-blogs/" rel="external">this post</a> that showed me it&#8217;s a common issue that&#8217;s been reported to their development team.</p>
<p>I continued searching for a solution and got some direction <a href="http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/custom-avatars-arent-shown-on-single-blogs-in-wpmu/" rel="external">from a solution</a> by <a href="http://buddypress.org/community/members/foralien/" rel="external">@foralien</a> on the BuddyPress forums. Her solution did not work for, but I created my own version and had success.</p>
<h2>What was happening?</h2>
<p>Our BuddyPress installation was trying to get avatars from <code>/blogs.dir/1/files/avatars/{$user_id}/{$filename}</code> – which did not eve exist, this was referencing a files directory for the root blog and it didn&#8217;t even exist.</p>
<p>As per <a href="http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/custom-avatars-arent-shown-on-single-blogs-in-wpmu/" rel="external">@foralien&#8217;s solution</a>, I created 2 filters (one for the avatar path, the other for the avatar public URL):</p>
<p><a href="/downloads/bp-avatar-filters.txt"><strong>Download the Code</strong></a></p>
<pre class="brush: php; title: ; notranslate">// Custom filters to clean up issues in WP 3.0 with avatar paths.
// Written by @theandystratton
function sizeable_bp_core_avatar_folder_dir( $path ) {
	$items = explode('/', $path);
	$path = ABSPATH . 'wp-content/uploads/avatars/' . end($items);
	return $path;
}
add_filter('bp_core_avatar_folder_dir', 'sizeable_bp_core_avatar_folder_dir');
function sizeable_bp_core_avatar_folder_url( $url ) {
	$items = explode('/', $url);
	$url = 'http://' . $items[2] . '/wp-content/uploads/avatars/' . end($items);
	return $url;
}
add_filter('bp_core_avatar_folder_url', 'sizeable_bp_core_avatar_folder_url');</pre>
<h2>What it&#8217;s doing</h2>
<p>We&#8217;re filtering the path and the url for avatars to ensure it&#8217;s using the WP 3.0 location, which is the upload_path for the root site followed by <code>/avatars/{$user_id}</code>. This is <em>not</em> a forever fix. I&#8217;d use it as duct tape until they release a BuddyPress update for WP 3.0 fixing the issue.</p>
<p>Hope this helps you guys and saves you some time and frustration.</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2010/buddypress-avatars-not-displaying-with-wordpress-3-0/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Shared Hosting Fix&#8230; Uhm,&#160;fix.</title>
		<link>http://theandystratton.com/2010/shared-hosting-fix-uhm-fix</link>
		<comments>http://theandystratton.com/2010/shared-hosting-fix-uhm-fix#comments</comments>
		<pubDate>Wed, 30 Jun 2010 02:47:30 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=434</guid>
		<description><![CDATA[I highly recommend working with Sucuri.netto fix your hacked site and monitor your site from future hacks. So I&#8217;ve had some reports that the shared hosting hack fix that I wrote as a quick bridge to a real solution left some people with PHP documents that contained a bit of leading whitespace, which can really [...]]]></description>
			<content:encoded><![CDATA[<div style="margin:1em 0;padding:1em;text-align:center;border:1px solid #080;background:lightYellow;"><a href="/sucuri"><img src="http://sucuri.net/images/sucuri-long.png" alt="Fix &#038; Monitor Your Website from Hacks"></a><br />I highly recommend working with <a href="/sucuri">Sucuri.net</a><br />to <a href="/sucuri">fix your hacked site</a> and <a href="/sucuri">monitor your site</a> from future hacks.</a></div>
<p>So I&#8217;ve had some reports that the <a href="http://theandystratton.com/2010/shared-godaddy-hosting-wordpress-malware-hack-fix">shared hosting hack fix</a> that I wrote as a quick bridge to a <a href="http://theandystratton.com/2010/shared-godaddy-hosting-wordpress-malware-hack-fix#do-more">real solution</a> left some people with PHP documents that contained a bit of leading whitespace, which can really b0rk up your WordPress install or any PHP application if it&#8217;s in the right file the wrong way.</p>
<p>So, I give you the cleaner (special thanks to Michael Safovich for requesting and testing).</p>
<h3>What&#8217;s it do</h3>
<p>It recursively looks through it&#8217;s current directory (and subdirectories) for PHP files (by default it&#8217;s looking for <code>php</code>, <code>php4</code>, <code>php5</code> and <code>phtml</code> extensions, but this is customizable) and killing any whitespace in the beginning of the file, turning:</p>
<pre><code>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&lt;?php include_once './wp-blog-header.php'; ?&gt;</code></pre>
<p>into this:</p>
<pre><code>&lt;?php include_once './wp-blog-header.php'; ?&gt;</code></pre>
<p>Make sense? Good, here&#8217;s the <a href="/downloads/cleaner.zip">download link</a>.</p>
<h3>Tips &amp; Customization</h3>
<p>BACK UP YOUR FILES. You agree to take responsibility for running this, because I sure don&#8217;t (though I think you&#8217;ll be fine).</p>
<p>To run on custom file types, edit the <code>$fileTypes</code> array to include the types you want to strip leading whitespace from.</p>
<p>The script will run for the current directory. You will need to set the <code>$directory</code> variable to contain the path you&#8217;d like to recursively clean, in most cases you&#8217;d drop the <code>cleaner.php</code> file in your document root and hit it in the browser.</p>
<p>It will run immediately and output a log. Hope it helps. ¡Hasta luego!</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2010/shared-hosting-fix-uhm-fix/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated: Shared PHP Hosting &amp; WordPress Malware Hack&#160;Fix</title>
		<link>http://theandystratton.com/2010/shared-godaddy-hosting-wordpress-malware-hack-fix</link>
		<comments>http://theandystratton.com/2010/shared-godaddy-hosting-wordpress-malware-hack-fix#comments</comments>
		<pubDate>Tue, 18 May 2010 03:55:47 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=407</guid>
		<description><![CDATA[I highly recommend working with Sucuri.netto fix your hacked site and monitor your site from future hacks. *UPDATE* Reports of leading whitespace being left in the files after the fix script has been ran led me to build the cleaner, a script to, well clean up that leading whitespace. I have also updated the download [...]]]></description>
			<content:encoded><![CDATA[<div style="margin:1em 0;padding:1em;text-align:center;border:1px solid #080;background:lightYellow;"><a href="/sucuri"><img src="http://sucuri.net/images/sucuri-long.png" alt="Fix &#038; Monitor Your Website from Hacks"></a><br />I highly recommend working with <a href="/sucuri">Sucuri.net</a><br />to <a href="/sucuri">fix your hacked site</a> and <a href="/sucuri">monitor your site</a> from future hacks.</a></div>
<p><strong>*UPDATE*</strong> Reports of leading whitespace being left in the files after the fix script has been ran led me to build <a href="http://theandystratton.com/2010/shared-hosting-fix-uhm-fix">the cleaner</a>, a script to, well clean up that leading whitespace.</p>
<p>I have also updated the download of <a href="/downloads/2010-hack/shared-hosting-fix.php.txt">the fix on this page</a> to strip leading white space.</p>
<p>So <a href="http://godaddy.com" rel="external nofollow">GoDaddy</a> wasn&#8217;t the only host attacked by this malware PHP hack. I&#8217;ve found traces on client&#8217;s <a href="http://www.bluehost.com" rel="external nofollow">BlueHost shared Linux hosting</a> as well. Apparently some other hosts, including <a href="http://www.networksolutions.com" rel="external nofollow">Network Solutions</a>. </p>
<p>One host I use (along with multiple clients) who I haven&#8217;t seen or heard about being affected is <a href="http://www.hostgator.com" rel="external nofollow">HostGator</a>. My dedicated box(es) have not been affected either.</p>
<p>This is NOT an issue exclusive to WordPress installs. Tons of WordPress installations have been affected but WordPress is currently the most-installed PHP/MySQL web application on the web today, especially in these shared Linux hosting environments. I&#8217;ve seen this same attack affect sites with basic PHP files using only <code>include</code> statements as well as other PHP/MySQL applications such as <span title="Joomla really">Joomla</span> (<em>*shudder*</em>).</p>
<h2>What the attack seems to be doing</h2>
<ul>
<li>Adding a line of <code>base64</code> encrypted PHP to be evaluated before most PHP scripts run</li>
<li>Common strings in hacked files include:
<ul>
<li><code>&lt;?php eval(base64_decode(</code></li>
<li><code>&lt;?php eval(gzinflate(base64_decode(</code></li>
</ul>
<li>Some of this code is injecting content into your page&#8217;s output for search engines, some redirecting users</li>
<li>I&#8217;ve found some sites commonly have the file <code>./wp-includes/js/tinymce/plugins/inlinepopups/skins/clearlooks2/img/style.css.php</code> which is a lot of <code>eval()</code> wrapped <code>base64</code> encoded strings (it&#8217;s been recursively encrypted and after 15 iterations I needed to get back to client work)</li>
<li>I also found some files without extensions in the <code>./wp-includes/js/tinymce/plugins/inlinepopups/skins/clearlooks2/img/</code> directory (<a href="/downloads/2010-hack/t.txt">t (looks to be a template)</a>, <a href="/downloads/2010-hack/lb.txt">lb (links, link back perhaps?)</a> and <a href="/downloads/2010-hack/kwd.txt">kwd (keywords)</a> &mdash; there was also a file named <code>cnf</code> which looked to be encrypted configuration for the hack as well as another file called <code>csi</code> which contained an IP and Unix timestamp.</li>
</ul>
<h2>Updated Fix for the Hosting Hack</h2>
<p>Please note: this is not an all comprehensive fix. This can help clear out some code very quickly but you should still take some drastic efforts (<a href="#do-more">see below</a>) to clean up your site and protect yourself.</p>
<h3><a href="/downloads/2010-hack/shared-hosting-fix.php.txt">Download Shared Hosting Attack Fix &raquo;</a></h3>
<p><strong>Instructions:</strong></p>
<ol>
<li><strong>Make time <em>this week</em> to figure out and implement a plan for backing up your site and database,</strong> either via your hosting provider, your own shell scripts, or <a href="http://www.vaultpress.com" rel="external nofollow">VaultPress.com</a> is looking very good right now if you&#8217;re on WordPress.</li>
<li><strong>Back up your site files.</strong> Even if they are hacked, get a copy of everything locally just in case.</li>
<li>Download <a href="/downloads/2010-hack/shared-hosting-fix.php.txt"><code>shared-hosting-fix.php.txt</code></a> and rename it <code>shared-hosting-fix.php</code></li>
<li>Place the file somewhere in your document root and visit it in a browser to review what files are <q>infected</q>. If you&#8217;re not seeing affected files here, make sure the contents of the <code>$hack_str</code> variable on line 30 is the same as the beginning of the hack&#8217;s code. Some have been different by a space here and there, which will affect this clean up script.</li>
<li>If you have infected files, you can press the &#8220;Fix Files&#8221; button at the bottom of the page to start the automated task of removing the first line of malicious code</li>
<li>Confirm that you want to make the changes on the popups and you will see a simple log display when all is said and done</li>
<li>Back up your clean(er) files and <a href="#do-more">take more steps to audit your files and database</a> to try to avoid recurrence</li>
</ol>
<h2 id="do-more">Do More to Clean Up and Protect Yourself (WordPress)</h2>
<p>Just a few notes about other things you can (and should) do:</p>
<ul>
<li><strong>Make regular backups</strong> &mdash; Lazy? Checkout <a href="http://vaultpress.com" rel="external">VaultPress</a></li>
<li><strong>Clear any and all cache files on your server.</strong> I&#8217;d literally de-activate the caching plugins, remove them and their associated directories and then download and re-install them</li>
<li>Back up your <code>wp-config.php</code> file and <code>wp-content</code> directory then completely remove all of your WordPress files and directories, then re-upload from a fresh and up-to-date <a href="http://wordpress.org/latest.zip" rel="external nofollow">WordPress install</a>. <strong>Audit your <code>wp-content</code> directories and <code>wp-config.php</code> file</strong> before re-uploading.</li>
<li>Use some WP Security plugins:
<ul>
<li><a href="http://wordpress.org/extend/plugins/wp-security-scan/" rel="external nofollow">WP Security Scan</a></li>
<li><a href="http://wordpress.org/extend/plugins/wordpress-file-monitor/" rel="external nofollow">WordPress File Monitor</a></li>
<li><a href="http://wordpress.org/extend/plugins/exploit-scanner/" rel="external nofollow">WordPress Exploit Scanner</a></li>
</ul>
</li>
<li>Check your database, specifically the <code>wp_options</code> table for suspicious code (see Chris Pearson&#8217;s post below, <a href="http://www.pearsonified.com/2010/04/wordpress-pharma-hack.php" rel="external nofollow">How to Diagnose and Remove the WordPress Pharma Hack</a></li>
</ul>
<h2>WordPress Security Reference Links</h2>
<p>Thanks to some friends at <a href="http://automattic.com" rel="external nofollow">Automattic</a> and in the WordPress community, here are some links for your reference:</p>
<ul>
<li><a href="http://www.slideshare.net/williamsba/wordpress-security-1709496" rel="external nofollow">WordPress Security Presentation</a><br />A great WP security presentation by Brad Williams of <a href="http://webdevstudios.com/" rel="external nofollow">WebDevStudios</a></li>
<li><a href="http://codex.wordpress.org/Hardening_WordPress#Securing_wp-admin" rel="external nofollow">Securing wp-admin</a></li>
<li><a href="http://codex.wordpress.org/Hardening_WordPress#Securing_wp-config.php" rel="external nofollow">Securing wp-config.php</a></li>
<li><a href="http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content" rel="external nofollow">Moving wp-content</a></li>
<li><a href="http://codex.wordpress.org/Installing_WordPress_With_Clean_Subversion_Repositories" rel="external nofollow">Installing WP with Clean SVN Repositories</a></li>
<li>If you&#8217;re a busy, well-to-do, business person who just doesn&#8217;t have the time, you could <a href="/contact?quote">contact and hire</a> a <a href="http://theandystratton.com">outstanding WordPress and PHP developer</a> and occasional blogger&hellip; <code>&lt;/shamless_self_promotion&gt;</code>
</ul>
<h2>Some Reference Posts For Reading:</h2>
<ul>
<li><a href="http://www.wpsecuritylock.com/dangerous-malware-alert-hacked-godaddy-responds/" rel="external nofollow">CONTINUING STORY – Dangerous Malware Alert – Self-Hosted Sites Hack Update –  Go Daddy Responds! | WPSecurityLock</a></li>
<li><a href="http://blog.sucuri.net/2010/05/simple-cleanup-solution-for-latest.html" rel="external nofollow">Simple cleanup solution for the latest WordPress hack</a></li>
<li><a href="http://smackdown.blogsblogsblogs.com/2010/05/13/hosting-with-godaddy-might-want-to-rethink-that-decision/" rel="external nofollow">http://smackdown.blogsblogsblogs.com/2010/05/13/hosting-with-godaddy-might-want-to-rethink-that-decision/</a></li>
<li><a href="http://www.pearsonified.com/2010/04/wordpress-pharma-hack.php" rel="external nofollow">How to Diagnose and Remove the WordPress Pharma Hack</a></li>
<li><a href="http://www.blogtips.org/how-to-cure-your-godaddy-wordpress-hacked-blog/" rel="nofollow external">How to cure your GoDaddy WordPress hacked blog</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2010/shared-godaddy-hosting-wordpress-malware-hack-fix/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>The Permalinker WordPress Plugin: Dynamic&#160;Permalinks</title>
		<link>http://theandystratton.com/2009/the-permalinker-wordpress-plugin-dynamic-permalinks</link>
		<comments>http://theandystratton.com/2009/the-permalinker-wordpress-plugin-dynamic-permalinks#comments</comments>
		<pubDate>Tue, 30 Jun 2009 18:48:21 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://theandystratton.com/?p=181</guid>
		<description><![CDATA[As a developer, I&#8217;ve always found permalinks and directory structures between local, staging, and production environments to be a pain. Creating links within content requires either absolute (http://yourdomain.com/path/to/post/) or a non-domain-specific absolute (/install/directory/path/to/post) URLs. This can prove to be a pain during the development or migration process. It can also make it annoying if you [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer, I&#8217;ve always found permalinks and directory structures between local, staging, and production environments to be a pain. Creating links within content requires either absolute (<code>http://yourdomain.com/path/to/post/</code>) or a non-domain-specific absolute (/install/directory/path/to/post) URLs.</p>
<p>This can prove to be a pain during the development or migration process. It can also make it annoying if you happen to change your permalink structure and have tons of posts.</p>
<p><strong class="header">Introducing dynamically inserted WordPress permalinks with The Permalinker</strong></p>
<p><a href="http://wordpress.org/extend/plugins/the-permalinker/" rel="external">The Permalinker</a> will allow you to use <a href="http://faq.wordpress.com/2008/06/18/what-are-the-wordpress-shortcodes/" rel="external">WordPress short codes</a> to dynamically insert permalinks and permalink URLs into your posts via the content editor.</p>
<p><strong>How it works:</strong></p>
<p>When editing content, simply use the the <code><a href="http://theandystratton.com/2009/the-permalinker-wordpress-plugin-dynamic-permalinks" class="permalinker_link "></code> short code to insert a link:</p>
<pre><code>[permalink]This is a link to the current post</a></code></pre>
<p><strong>Linking to a different post:</strong></p>
<p>You can set the <code>id</code> attribute in the short code to point to a specific page/post:</p>
<pre><code><a href="http://theandystratton.com/2009/9-revision-3" class="permalinker_link ">A link to post 23</a></code></pre>
<p><strong>Supported anchor attributes:</strong></p>
<p>Currently, the following attributes are supported in the <code><a href="http://theandystratton.com/2009/the-permalinker-wordpress-plugin-dynamic-permalinks" class="permalinker_link "></code> short code and will be added to the resulting anchor element: <code>class</code>, <code>rel</code>, and <code>target</code>.</p>
<pre><code>[permalink id=23 class="my_class" rel="self" target="_blank"]Open post 23 in a new window</a></code></pre>
<p><strong>Want more control over your markup?</strong></p>
<p>Using a non-terminating or empty <code>http://theandystratton.com/2009/the-permalinker-wordpress-plugin-dynamic-permalinks</code> short code will simply output the permalink URL:</p>
<pre><code>&lt;a href="http://theandystratton.com/2009/9-revision-3" class="thickbox" id="link_23">Another link to page/post 23&lt;/a&gt;</code></pre>
<p><strong class="header">There&#8217;s more: Dynamically grab your template directory</strong></p>
<p>As a request from fellow WordPress designers and developers, I&#8217;ve included a <code>http://theandystratton.com/wp-content/themes/theandystratton</code> short code as well, allowing you to quickly and dynamically get the full URL to your active template directory from the content editor:</p>
<pre><code>&lt;img src="http://theandystratton.com/wp-content/themes/theandystratton/photos/yoda.gif" alt="A picture of Yoda!" /&gt;</code></pre>
<p><strong class="header">Download Permalinker</strong></p>
<p>You can learn more and <a href="http://wordpress.org/extend/plugins/the-permalinker" rel="external">download The Permalinker</a> from the WordPress plugin repository.</p>
<p>Happy coding ;]</p>
]]></content:encoded>
			<wfw:commentRss>http://theandystratton.com/2009/the-permalinker-wordpress-plugin-dynamic-permalinks/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

