Fall Conferences – PHP Madison and WordCamp NYC

Today I get to announce two conferences that I’m speaking at this fall. The first is here in NYC and is the 2015 WordCamp NYC.  I’ll be giving a talk entitled:
Lessons from Science Fiction and Fantasy we can use in Creating Websites.  Here is a short synopsis.

Science Fiction and Fantasy can teach web creators many valuable lessons. From seeing how Daleks with too narrow of a goal always fail to understanding the Klingons value of honor, to hundreds of other we can become better web creators by borrowing lessons from Science Fiction and Fantasy.

Next, I’ll be traveling to Madison, Wisconsin for the first time in almost 10 years to present “How Not To Build A WordPress Plugin” at Madison PHP.  A short synopsis of this talk is

WordPress has a powerful plugin architecture that enables you to build almost anything on top of WordPress. This power though can lead to anti-patterns that slow down sites, confuse users, and make it hard to scale. Let’s look at the wrong way of building plugins so you can avoid these traps.

Tickets for both events are on sale.  If you are either one, make sure to say hi!

Following up on WordPress in a Next Generation PHP World

In April, just as WordPress 4.3 was beginning development, I started a conversation about WordPress, PHP7, and HHVM. Now that WordPress 4.3 has been released, I’m glad to say WordPress is looking great as far as PHP7 goes.

I’m planning on spending some time during the 4.3 development cycle focused on these next generation platforms.

The PHP core team did a solid job of not introducing many breaking changes with this release, which really helped to make the transition easier. The two major changes that WordPress needed to make in order to have passing unit tests on PHP7 were to deprecate PHP4 style constructors and updating some variable variables.

Screenshot of Travis-CI showing WordPress tests passing on PHP7
The final commit of WordPress 4.3 has PHP7 tests passing and running faster then any of the other PHP versions.

In 4.4, I intend to continue to focus on PHP7.  The release schedule targets Mid October 2015. I hope to move PHP7 out of the Allowed Failures bucket on Travis-CI the day it is released.

Next up is getting the unit tests passing on HHVM. Onward!

WordPress in a next generation PHP world

My elephant tattoo

HHVM has now released it’s second long term support release and PHP 7 is in the final stages of implementing changes. It’s an exciting time for PHP and to be a PHP developer which means it is also an exciting time to be a WordPress developer since it creates an opportunity for WordPress to once again embrace forwards compatibility.

While I was at PHPUK, one of the most common conversations I had was people being critical of WordPress for supporting PHP 5.2 as a minimum.  Many of those same people became less critical once they find out WordPress runs great on PHP 5.6 and that many people run it on HHVM.

For the last several weeks, WordPress has been running it’s unit tests on PHP7 nightly builds. They’ve been running on HHVM for months. Right now, the unit tests are not passing for either one and as far as I know, have never passed for either one.  This is a problem.

I’m planning on spending some time during the 4.3 development cycle focused on these next generation platforms. Rasmus has put together a php7 vagrant box and JJJ created an addon to Varying Vagrant Vagrants to enable HHVM there. WP engine also has it’s own WordPress HHVM vagrant box. I intend to use all three of these to help.

Davey Shafik has put together a great two part series on the changes coming in PHP 7.  The two changes that are most likely to cause issues for WordPress sites are the removal of all deprecated features and the deprecation of PHP4 style constructors. This is going to affect many widgets along with all sorts of other code.

It’s exciting to see PHP moving forward.  The competition between HHVM and PHP runtimes is making PHP faster and is only going to push the language forward. It’s a great time to be writing PHP.

Adding a twitter box to the Profile page in WordPress

I haven’t used AIM in years and I haven’t used Yahoo Messager in even longer.  What I do use is twitter.  Therefore, having a box in the WordPress admin for twitter name is better and with some code I wrote for the , super easy.

[php]
add_filter(‘user_contactmethods’, ‘jorbin_user_contactmethods’);

/**
* Removes AIM, YAHOO, and Jabber boxes from profile page and adds Twitter in it’s place
*
*/
function jorbin_user_contactmethods($user_contactmethods){
$new_user_contactmethods[‘twitter’] = __(‘Twitter’);

return $new_user_contactmethods;
}
[/php]

Filtering user_contactmethods is one of the easiest things you can do. All you need to do is return an array where the key is the code based name you want and the value is the public facing name. Easy. As. Pie.

WordPress Shortcodes for Users and Non Users

One of the plugins I wrote for the DC WordPress group’s meeting on Users / Roles / Capabilities demonstrates how to create shortcode that makes some content only visable by users with a certain capability and other content only visable to non logged in viewers.  You can download Shortcodes for Discrimination (along with the other three ) from google code.  Beyond the jump, I go over the code and an explanation of how it works.

Continue reading WordPress Shortcodes for Users and Non Users

How to remove a nav menu location in WordPress 3.0.0

This function is in WordPress 3.0.1. You can now just call unregister_nav_menu and don’t need to put it in your child theme

One of the great additions to WordPress 3.0 is navigation menus.  One of the aspects that it contains is the ability for a theme to register a nav menu location and for the user to assign any menu they want to that location.  GREAT!  Except that a missing piece of functionality is the ability for Child Themes to remove a location that it might no longer want.  I’ve created a ticket and submitted a patch, but if you need that functionality now, just add the code below to you child theme’s functions.php file:
[php]
if (! function_exists(‘unregister_nav_menu’) ):
function unregister_nav_menu( $location ) {
global $_wp_registered_nav_menus;

if (is_array($_wp_registered_nav_menus) && array_key_exists( $location, $_wp_registered_nav_menus ) ){
unset( $_wp_registered_nav_menus[$location] );
return true;
}

return false;

}
endif;
[/php]

Then all you need to do is call:
[php]
//Remove Twenty Ten Default Menu Location
unregister_nav_menu(‘primary’);[/php]
At some point after the nav menu is registered. I like to use the init hook.

Constructing my new theme with Thematic

EDIT: I’ve switched to a Twenty Ten Child Theme

When I heard Ian Stewart’s announcement that he become an Automattician I figured it was a good idea to take a look at Thematic and see what it could do. I’ve mostly built my themes from scratch, but Thematic looked like it could streamline my work and hasten the development of sites. I figured if I’m going to try it out, I might as well give my site some love an a new theme. Thus Aaron.Jorb.In 3.0 was born.

I couldn’t believe how easy it was. Essentially Thematic makes theme development as easy as plugin development. Find the appropriate hook/filter and make the changes needed. For example, I wanted a slightly different loop for My Clients Category Page that also doubles as my Portfolio. By adding an action to wp_head, I am able to check if it is the My-Clients Category, and if so I can remove the default loop, add my own, and also add a notice to appear above the loop.

It’s also super easy to remove the sidebar. All I had to do was add an action to thematic_sidebar that returned false. Essentially Thematic has removed my need to make custom page templates when I want to keep 90% of the page the same.

Overall, redoing my site took about a third of the time that it took me to construct the last version. I would encourage anyone familiar with the plugin architecture of WordPress to take a look at Thematic. And the best part about it? It’s 100% gpl compatible and doesn’t cost a penny.

If you have any question how I added or did anything on here, please comment below.

More Twitter Shortcodes for WordPress

Building on my WordPress Shortcode How To, here are two more Twitter shortcodes. I’ve also added a new project on google code to track all of my shortcodes.

The first new shortcode is for twitter search. It’s logically enough

 [twitter-search phrase='#haikufriday']

Like my last twitter shortcode, it caches the results for two minutes. It also includes some other options. You can specify the number of tweets using the number attribute. There is a default of 20. You can also specify a max and min tweet id using max_id and since_id . Finally, you can specify the language with the lang attribute. This defaults to English.
[sourcecode language=”php”]
function jorbin_firestream_search($atts){
extract(shortcode_atts(array(
‘phrase’ => false,
‘lang’ => ‘en’,
‘max_id’ => false,
‘since_id’ => false,
‘number’ => ’20’
), $atts));
if (‘phrase’ == false){
return false;
}
//*/ Build our search url and transient name
$transient = ‘tweet-‘. esc_sql($phrase) . ‘&l=’ . esc_sql($lang);
$url = ‘http://search.twitter.com/search.json?q=’. urlencode($phrase) . ‘&show_user=true〈=’. urlencode($lang) .’&rpp=’ . $number;

if ($max_id != false){
$url .= ‘&max_id=’ . (int) $max_id;
$transient .= ‘&m=’ . (int) $max_id;
}
if ($since_id != false){
$url .= ‘&since_id=’ . (int) $since_id;
$transient .= ‘&s=’ . (int) $since_id;
}

if ( $tweet_display = get_transient($transient) ){
// It’s allready been brought
}
else {

if ($search = wp_remote_get( $url ) ){

$results = json_decode($search[‘body’]);

ob_start();
$tweets = $results->results;
//*/
foreach ( (array) $tweets as $tweet){
$tweetcontent = $tweet->text;
$newcontent = preg_replace(‘%@([^\s]*)%’, "<a href="http://twitter.com/\\1">@\\1</a>", $tweetcontent);
echo "<div class="twitter_shortcode"><p>
<img class="twitter_shortcode_image" src="&quot;.esc_url($tweet-&gt;profile_image_url).&quot;"><span class="twitter_shotcode_username"><a href="http://twitter.com/&quot;.$tweet-&gt;from_user.&quot;">".$tweet-&gt;from_user."</a>&nbsp;—&nbsp;</span>". $newcontent ."</p>
</div>";

}
$tweet_display = ob_get_clean();
set_transient($transient, $tweet_display, 300);
}
else
{
$tweet_display = "I’m sorry, no tweets are availailable at this time";
}
}
return apply_filters(‘jorbin_tweet_content’, $tweet_display) ;
}
add_filter(‘jorbin_tweet_content’, ‘make_clickable’ );
add_shortcode(‘twitter-search’, ‘jorbin_firestream_search’);

[/sourcecode]
Like before, there are some classes for you to work with that should make it easy for you to theme these shortcodes. If you want for me to add more, comment below.

The second shortcode allows you to get and display a list of the most recent trends on twitter using the shortcode:

[twitter-trends]

This one doesn’t have any attribute. The output is in an unordered list with the class of twitter-trends.
[sourcecode language=”php”]
function jorbin_twitter_trends(){

$transient=’twitter-trends’;
$url = ‘http://search.twitter.com/trends.json’;

if ( $tweet_display = get_transient($transient) ){

}
else{
$search = wp_remote_get( $url );

$results = json_decode($search[‘body’]);
$trends = $results-&gt;trends;
ob_start();
echo "<ul class="twitter-trends">";
foreach ($trends as $trend){
echo ‘<li><a href="’ . esc_url($trend-&gt;url) . ‘"> ‘. esc_html($trend-&gt;name) . ‘</a></li>’;
}
echo "</ul>";
$tweet_display = ob_get_clean();
set_transient($transient, $tweet_display, 120);
}
return $tweet_display;
}

add_shortcode(‘twitter-trends’, ‘jorbin_twitter_trends’);

[/sourcecode]
If you use any of these, let me know. If there are any improvements or more you want to see, comment below.