<?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>Bring Your Own Terms Of Service &#187; Code Sample</title> <atom:link href="http://byotos.com/tag/code-sample/feed/" rel="self" type="application/rss+xml" /><link>http://byotos.com</link> <description></description> <lastBuildDate>Sat, 24 Jul 2010 21:29:37 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>Hijacking WordPress Internationalisation</title><link>http://byotos.com/2010/04/hijacking-wordpress-internationalisation/</link> <comments>http://byotos.com/2010/04/hijacking-wordpress-internationalisation/#comments</comments> <pubDate>Thu, 08 Apr 2010 19:27:20 +0000</pubDate> <dc:creator>Paul Gibbs</dc:creator> <category><![CDATA[BuddyPress]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[Code Sample]]></category><guid
isPermaLink="false">http://byotos.com/?p=129</guid> <description><![CDATA[As part of a new feature I am developing for the next release of my Welcome Pack plugin for BuddyPress, I needed a really smart way of dynamically adding my own translations for strings at page-load time; creating a stand-alone &#8230; <a
href="http://byotos.com/2010/04/hijacking-wordpress-internationalisation/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>As part of a new feature I am developing for the next release of my <a
href="http://wordpress.org/extend/plugins/welcome-pack/" target="_blank">Welcome Pack</a> plugin for <a
href="http://buddypress.org/" target="_blank">BuddyPress</a>, I needed a really smart way of dynamically adding my own translations for strings at page-load time; creating a stand-alone <a
href="http://codex.wordpress.org/Translating_WordPress#gettext_files" target="_blank">.mo </a>file to load the strings wasn&#8217;t a great solution, for reasons of requiring people to know how to configure file permissions on the server, having to figure out how to write a .mo file (I wish they were as easy as XML, but they aren&#8217;t), and &#8212; honestly &#8212; doing it that way feels like such a hack.</p><p><span
id="more-129"></span>Here&#8217;s how. Be warned that this will overwrite any translation loaded by a .mo file, but that&#8217;s exactly what I needed to do.</p><p>To add a new string into the localisation table:</p><pre class="brush: php; gutter: false;">
function example() {
global $l10n;

$mo = new MO();
$mo-&amp;gt;add_entry( array( 'singular' =&amp;gt; 'Spongebob', 'translations' =&amp;gt; array( 'Squarepants' ) ) );
if ( isset( $l10n['buddypress'] ) )  //buddypress is the textdomain
$mo-&amp;gt;merge_with( $l10n['buddypress'] );

$l10n['buddypress'] = &amp;amp;$mo;
}

_e( 'Spongebob', 'buddypress' );  // This will return &quot;Squarepants&quot;.
</pre><p>To change an existing string:</p><pre class="brush: php; gutter: false;">
function example() {
global $l10n;

if ( isset( $l10n['buddypress'] ) &amp;amp;&amp;amp; isset( $l10n['buddypress']-&amp;gt;entries['%s posted an update:'] ) )
$l10n['buddypress']-&amp;gt;entries['%s posted an update:']-&amp;gt;translations[0] = '%s posted a monkey:';
}
</pre><p>Post a comment if you use this technique for anything interesting</p> ]]></content:encoded> <wfw:commentRss>http://byotos.com/2010/04/hijacking-wordpress-internationalisation/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>SVN is now public</title><link>http://byotos.com/2009/09/svn-is-now-public/</link> <comments>http://byotos.com/2009/09/svn-is-now-public/#comments</comments> <pubDate>Thu, 03 Sep 2009 17:42:37 +0000</pubDate> <dc:creator>Paul Gibbs</dc:creator> <category><![CDATA[BuddyPress]]></category> <category><![CDATA[Plugins]]></category> <category><![CDATA[Code Sample]]></category><guid
isPermaLink="false">http://metabiscuits.com/?p=27</guid> <description><![CDATA[I made my SVN repository public which I use for my BuddyPress plugins (Welcome Pack and Achievements). It is at http://svn.dangerous-minds.com/djpaul/. For example, to get the latest trunk (development) version of Achievements  — which requires BuddyPress trunk/1.1 — use http://svn.dangerous-minds.com/djpaul/achievements/trunk/.]]></description> <content:encoded><![CDATA[<p>I made my SVN repository public which I use for my BuddyPress plugins (<a
href="http://wordpress.org/extend/plugins/welcome-pack/">Welcome Pack</a> and <a
href="http://wordpress.org/extend/plugins/achievements/">Achievements</a>).  It is at http://svn.dangerous-minds.com/djpaul/.</p><p>For example, to get the latest trunk (development) version of Achievements  — which requires BuddyPress trunk/1.1 — use http://svn.dangerous-minds.com/djpaul/achievements/trunk/.</p> ]]></content:encoded> <wfw:commentRss>http://byotos.com/2009/09/svn-is-now-public/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Improving custom component installation</title><link>http://byotos.com/2009/07/improving-custom-component-installation/</link> <comments>http://byotos.com/2009/07/improving-custom-component-installation/#comments</comments> <pubDate>Sat, 25 Jul 2009 18:53:08 +0000</pubDate> <dc:creator>Paul Gibbs</dc:creator> <category><![CDATA[BuddyPress]]></category> <category><![CDATA[Code Sample]]></category> <category><![CDATA[Component]]></category> <category><![CDATA[WPMU]]></category><guid
isPermaLink="false">http://metabiscuits.com/?p=9</guid> <description><![CDATA[When implementing a custom component in BuddyPress, you will often have additions for the member theme. Member themes live in their own folder, /wp-content/bp-themes/. To render a member theme template, your component will call dpa_load_template() which takes an argument of &#8230; <a
href="http://byotos.com/2009/07/improving-custom-component-installation/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>When implementing a <a
href="http://codex.buddypress.org/how-to-guides/creating-a-custom-buddypress-component/">custom component</a> in <a
href="http://buddypress.org/">BuddyPress</a>, you will often have additions for the member theme. Member themes live in their own folder, <code>/wp-content/bp-themes/</code>.</p><p>To render a member theme template, your component will call <code>dpa_load_template()</code> which takes an argument of the name of the template to load. The path is hardcoded to the <code>/wp-content/bp-themes/</code> folder.</p><p>The problem with this is that after installation of a custom component, the site administrator will need to move the relevant member theme files (bundled with your component) into <code>/wp-content/bp-themes/</code>. This is an annoyance to site administrator, and it may end up being a frequent support request (&#8220;why is X not working?&#8221;).  This very first hurdle may even stop people trying out your component.</p><p>Something else I&#8217;ve seen is that when installing future updates, people may forget that they need to move the updated member theme files into place; this can cause incompatibility issues between versions of your software, something we&#8217;ve seen with recent versions of BuddyPress.</p><p>For my upcoming &#8220;Achievements&#8221; plugin (think a cross between forum points and <a
href="http://en.wikipedia.org/wiki/Xbox_Live">Xbox Live</a>), I decided all that I wanted the site administrator to do would be to download it from the Plugins admin panel &#8211; no moving files into the member theme.</p><p>So, I present to you my code: (06/01/10 &#8211; updated for BP 1.1.3+)</p><pre class="brush: php;">
bp_core_load_template( 'yourcomponent_theme_filename' );  // loads /plugins/your_plugin/filename.php

function yourcomponent_screen_filter_template( $located_template, $template_name ) {
	if ( !empty( $located_template ) )
		return $located_template;

	if ( $bp-&amp;gt;current_component != $bp-&amp;gt;your_component-&amp;gt;slug )
		return false;

	if ( false !== strpos( $template_name[0], 'yourcomponent_theme_' ) ) {
		$prefix = strlen( 'yourcomponent_theme_' );
		$template_name = substr( $template_name[0], $prefix, strlen( $template_name[0] ) - $prefix );
		$template_path = WP_PLUGIN_DIR . &amp;quot;/your_plugin/$template_name&amp;quot;;

		if ( file_exists( $template_path ) )
			return $template_path;
	}

	return false;
}
add_filter( 'bp_located_template', 'yourcomponent_screen_filter_template', 10, 2 );
</pre>]]></content:encoded> <wfw:commentRss>http://byotos.com/2009/07/improving-custom-component-installation/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc (user agent is rejected)
Database Caching 2/9 queries in 0.001 seconds using apc
Object Caching 522/529 objects using apc
Content Delivery Network via Amazon Web Services: CloudFront: Amazon Web Services: S3: media1.byotos.com

Served from: byotos.com @ 2010-07-29 18:37:27 -->