Slow BrowserSync in OS X with apache or nginx?

I’ve been testing out gulp.js some with BrowserSync for front end development on a new project. I saw a nice a video about it and got the feeling it would be a really nice workflow. But my BrowserSync proxy setup towards my local Apache site (php+mysql) was for some reason really really slow. The video showed an example using Node.js which was instant so to test that out I created a Node.js site and started gulp towards it. And the difference was like a really slow night and a really fast day. It was instant.

After much search and many Google I found this thread on Stack Overflow about someone having an issue with slow localhost/virtualhost load/resolve. And this reply:

I had the exact same problem and it was driving me crazy!

Put all your hosts file entries for localhost into one line like so: localhost myproject.dev myotherproject.dev
::1 localhost
fe80::1%lo0 localhost

Worked like a charm for me. Seems like a bug in Lion.

Because of my many web projects and my fondness of local development I have a lot of different virtual hosts. All pointing to All on different rows. So I went in to my /etc/hosts file and changed it. And behold. It worked. So now I can do my BrowserSync, sass powered, js minifying, gulp induced, front end development without coffee breaks in between changes. Which is really nice. I don’t even drink coffee.

Posted by David

WP: get_author_posts_url() in MU with sub-directories

Just a little tip here. We did a project with a multi site setup with sub directories. There was a photo blog on blogs.example.com/photo/, a food blog on blogs.example.com/food/ and the main/default site gets blogs.example.com/blog/ by default by WordPress. On the main site we wanted a list of the latest posts across the network. A couple of UNION SELECTs solved the data fetching. A loop with switch_to_blog() solved The Loop. But we had a problem with get_author_posts_url(). For some reason it added the default /blog/ sub-directory to all blogs. So instead of blogs.example.com/photo/author/feedmeastraycat/ we got blogs.example.com/blog/photo/author/feedmeastraycat/.

I guess the “problem” here is that switch_to_blog() doesn’t change the WP_Rewrite object. So when get_author_posts_url() calls $wp_rewrite->get_author_permastruct() it get’s the permalink for the main site blog plus the permalink for the selected blog.

Not sure if this is a bug. Or just a way that it have to work. Either way, I created a filter for author_link which solved the problem for us.

function my_author_link($link, $author_id, $author_nicename) {
	global $blog_id;
	if (is_main_site($blog_id)) {
		return $link;
	else {
		return str_replace("/blog/author/", "/author/", $link);
add_filter('author_link', 'my_author_link', 11, 3);

What we do here is getting the global $blog_id variable which contains the current blog’s id number. We run it through is_main_site() to see if this is for example the photo blog, or the food blog, or if it is the main site. If isn’t the main site, we do a string replace on /blog/author/ to just be /author/. But if it’s any other site we return the $link parameter as it is, unchanged.

Disclaimer: Not sure if the problem exists if you don’t have permalink structure. Haven’t even tested. :)

Posted by David

Uppdatera WordPress till 3.0.4!

Viktig s√§kerhetsuppdatering ute nu. That is all… Tr√•kig bloggpost? You bet!

Posted by David

Update Services in WPMU and WordPress 3 Multisite

I heard that WordPress, for some reason, removes the ability to change the ping sites through the Update Services form under Settings > Writing in the admin area. I dug around a bit, I asked a WordPress developer and I found out that you can add a filter to get it back. It was westi who showed me the way. And said:

@westi: @DMRsweden The best thing to do is to use the add_filter but with priority 11 that way it will run after the default filter and win

So basically this is all the plugin needs to do:

add_filter(‘enable_update_services_configuration’, ‘__return_true’, 11);

But you can check for yourself. Download it here.

Update: It was brought to my attention that the plugin didn’t work as expected. The Update Services form was shown, but the data was never saved. Obviously I thought that I had tested it. But I worked on two different solutions and rather quickly… I guess I worked to quickly. :) Anyway, I found out that I needed a second filter, whitelist_options, to add the ping_sites form to the whitelist when saving the form data.

Now I only need a confirmation on that all the sites you add actually gets pinged to … Check out the source code here.

Update 2: @jonasbjork have reported that it seams to work. :)

Posted by David

Tiny Twitter Tools Patch

I use Twitter Tools to import my twitters to my WordPress blog. I also use twitter to update my Facebook status. But I also use Simplaris Blogcast to update my Facebook feed with my blog posts. Social Web Geek. I know. This caused some double posts at Facebook. If I posted a twitt it updated my Facebook status, then my blog got updated, and my blog sent a ping with the Update Service to Simplaris Blogcast and updated my Facebook feed. So every twitter post got posted twice at Facebook. Not the best thing since sliced bread.

I was searching like mad to find where in the WordPress code the Update Service was sent. I found a posts at the WordPress.org forum from someone with the same problem. Kinda. But no solution.

However. At last, by mostly by chance and after a tip from TDH I found out that if I removed all twitter posts from my feeds. The update service didn’t send them to my ping services. This might be common knowledge for everyone. But for you who didn’t know this. This is the patch I made to my Twitter Tools to remove them from my feeds and, ergo, they was removed from my Facebook Simplaris Blogcast Feed updates…

function aktt_pre_get_posts($wp_query) {
	global $bloggy;
	if ($wp_query->is_feed) {
		$wp_query->query_vars['category__not_in'][] = get_option('aktt_blog_post_category');
add_action('pre_get_posts', 'aktt_pre_get_posts');
Posted by David