4
OCT
11:11

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
24
SEP
18:10

WordPress snippets

I’ve added a page here for some WordPress snippets I’ve created recently. Just for fun. They are small pieces of code where I doesn’t really feel the need to put them into plugins. The plugins feature in WordPress is great. Obviously. But sometimes when you do themes it’s nice to skip the initial fifteen odd plugins that all do one or two, small things. I’ve added the code to my Github repository. I’m a Github newbie. But it’s a lot easier to keep the code there, and make sure it’s updated, instead of posting it on the blog. And you can follow me there as well to see when I post updates… ;)

  • WPSettings — a set of classes to create a WordPress settings page for a Theme or a plugin.
  • WPCustomPostTypeArchive — add archive functionality to custom post types.
  • WPGetLatestTweet — a simple lib to get and cache the latest tweet for a username.
Posted by David
6
SEP
11:18

Small Twitter Tools extension to exclude twitter posts in feed

I’ve been using an old and modified version of Twitter Tools on my blog to import my tweets. They are imported as blog posts and then viewed on the Lifestream sidebar. I had to modify it cause the version I downloaded had a bug and a missing feature. It included @-replies, even though I told it in the settings not to. And I wanted to be able to exclude all twitter posts in the feed for any RSS subscribers.

A couple of days ago the old version of Twitter Tools stopped working though. It was missing oAuth. I downloaded the latest version and the bug had been fixed, it ignored @-reply like it where suppose to, but I still couldn’t remove the posts from the feed. (Which I had forgotten all about when my girlfriend asked me why all my tweets where appearing in her NetNewsWire all of a sudden).

This time thought, instead of hacking the plugin to fix my feature, I’ve created a small plugin extension. If you also uses Twitter Tools and wishes to exclude the twitter posts in your feed, you can check it out here or go straight to the download page.

Posted by David
1
JUL
15:58

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
6
MAR
17:50

Nya Feed Me A Stray Cat

I andan av Web Två Punkt Noll så tänkte jag, efter förslag från iThomas, dela med mig av nya Feed Me A Stray Cat-designen i dess beta-form. Kom gärna med förslag på förändringar och förbättringar. Eller buggar. Mycket är inte klart. Men förhoppningsvis kan det i alla fall inte skada … :)

Så nyfikna besökare gör bäst i att peka om webbläsaren till http://beta.feedmeastraycat.net/ … PEACE!

Posted by David
17
FEB
20:20

Västtrafik för iPhone delvis lagad

Efter mailet jag fick från Västtrafik så har jag nu äntligen fått lite tid att försöka laga appen. Det har gått. Delvis. Tyvärr lyckas jag inte få fram information om vart till exempel en spårvagn är på väg. Till exempel att man ska åka 5:an, men åt Torp? Eller andra hållet. Tyvärr saknas också möjlighet att få fram Nästa avgång. Så den funktionen är temporärt avstängd.

Eventuellt kommer jag fortsätta testa och utveckla appen. Det finns mycket nytt roligt i den nya webservicen. Men framförallt så berättade den snälla mannen från Västtrafik att de tydligen utvecklar en riktigt iPhone-app. Förhoppningsvis kommer den om ca två månader. Får hoppas det är riktig tid, och inte Västtrafik-tid! ;)

Posted by David
16
FEB
22:56

Vittene

Sitter i Vittene och gör inte så mycket. Tittar på Dirty Jobs och leker med Zend. Detta inlägget är faktiskt mest en test för det jag leker med. Så. Om det inte verkar vara ett så intressant inlägg … Så … Ja … Det är det inte!

Posted by David
5
FEB
21:16

Bloggy till WordPress

För WordPress och Bloggy-användare. Har gjort en liten Bloggy till WordPress-plugin som importerar Bloggy-inläggen till din blogg. Så som jag kör med Twitter här…

Posted by David
4
FEB
20:22

Uppdatering till Västtrafik för iPhone

Har gjort tre lite mindre förändringar. Först och främst så orsakade flip-animeringen problem. Och det var jobbigt att fixa. Så jag ändrade till en slide-animering som ser mer lik ut övriga iPhone-program. Tyvärr så laggar det otroligt mycket när man kör det i iPhone (fungerar bra i iPhone Simulator dock). Så den är pausad och för närvarande och appen bara “switchar” blad utan animering. Har även uppdaterat och fixat Sök nästa avgång-sidan. Den färgkodar nu spårvagnar och bussar samt hämtar ut en resa av varje linje, åt vardera håll, när man söker.

Hojta om ni hittar några buggar!

vtip.kontent.se (bokmärk och lägg som ikon på hemskärmen)

Klicka här för mer information.

vasttrafik-iphone-beta1-6
Posted by David
3
FEB
17:54

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
27
JAN
18:53

Västtrafik för iPhone beta 1

Idag är jag lite stolt att presentera ett litet projekt jag vill kalla Västtrafik för iPhone. Det är (ska bli) en samling av alla de Västtrafik-tjänster man kan tänkas behöva för att hitta runt i lokaltrafiken lätt tillgängligt via din iPhone.

Än så länge så går det bara dock bara att söka resa. Man söker upp en från-station och en till-station (med en autocomplete-sök-funktion), klickar på Sök och får upp tre förslag. Det går att klicka Tidigare och Senare för att få fler förslag och man kan få fram detaljerad information om varje resa.

Fler saker ska dock till. Men har du en iPhone så testa att surfa till http://vtip.kontent.se/ och prova på! Det går fint att lägga till ett bokmärke och skapa ikon på “hemskärmen” för en snygg och snabb genväg!

Tack till TDH för sponsring av serverplats och tack till Emil Hesslow för kodhjälp.

Läs mer här.

Posted by David
28
NOV
22:33

Hello, World!

Jag leker iPhone-utvecklare. Fast jag har ju ingen iPhone då … Men som tur är så finns ju iPhone Simulator.

Posted by David
8
OCT
23:42

Apache2, PHP5 and environment variables in OSX

Ok. So I’ve been sitting here with this problem for the last four hours. And finally I found the solution with the help of Jim the Jimbo. Anyway. I’ve been trying to get ImageMagick to work on my OSX/Apache2/PHP-thingy. But I could not figure out how to pass on the PATH variable I added. After a couple of hours Jim found this here page with the solution.

That’s it! I added the following lines to /System/Library/LaunchDaemons/org.apache.httpd.plist:

    <key>EnvironmentVariables</key>
    <dic>
        <key>FOO</key>
        <string>/bar</string>
    </dict>

and got the following results from exec(“export”):

Array
(
    [0] => export FOO="/bar"
    [1] => export OLDPWD
    [2] => export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
    [3] => export PWD="/Library/WebServer/Documents"
    [4] => export SHLVL="1"
)

Case solved! Thanks all, thanks Axel.
Burt.

So that’s what I did. My /System/Library/LaunchDaemons/org.apache.httpd.plist file now looks alittle something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>EnvironmentVariables</key>
	<dict>
		<key>DYLD_LIBRARY_PATH</key>
		<string>/Applications/ImageMagick-6.4.4/lib</string>
		<key>MAGICK_HOME</key>
		<string>/Applications/ImageMagick-6.4.4</string>
		<key>PATH</key>
		<string>/Applications/ImageMagick-6.4.4/bin:/usr/bin:/bin:...</string>
	</dict>
	<key>Label</key>
	<string>org.apache.httpd</string>
	<key>OnDemand</key>
	<false/>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/sbin/httpd</string>
		<string>-D</string>
		<string>FOREGROUND</string>
	</array>
	<key>SHAuthorizationRight</key>
	<string>system.preferences</string>
</dict>
</plist>

Thanks! I can finally go to sleep! :-)

<Swedish>

Men när jag försökte berätta för S vad jag har lyckats med så sa hon …

du är nördigare än vad man tror. glömmer ibland bort det.

… euhm … tack?!!

</Swedish>

Posted by David