18
JAN
17:01

Kenza behöver en ny WordPress-general

Den 16:e Februari 2010 skrev jag att Kenza hade flyttat från blogg.se till en egen server och med en WordPress-installation. Jag klagade dock på att hon inte hade uppdaterat till senaste versionen, som då var 2.9.2. På grund utav en kommentar så såg jag att det ser ut som Kenza fortfarande kör 2.9.2. Det är ju inte så bra. Hon behöver uppdatera till 3.3.1.

(Jag behöver uppdatera till 3.3.1 också, kör just nu 3.3. Sten. Glashus. Ni vet).

Jag kan hjälpa dig uppdatera Kenza. Jag gör det i utbyte mot lite modetips.

Posted by David
8
JAN
00:48

On the road to a WordPress core patch

One of my goals for 2012 is to to get credit for a patch in the WordPress core. It feels like it would be neat. Nerdy… But neat.

This vacation week, when I was going to play Skyrim, but ended up watching all Alien movies on Bluray and coding some WordPress, I might have found my bug. A user in a WordPress dev Facebook group asked if anyone had received pingbacks on custom post types. He hadn’t and was starting to believe something was wrong within WP. I thought it sounded like a fun thing to investigate. So I did. And it turns out it is… I think.

The reason seams to be that the XML-RCP server uses a function called url_to_postid() to get the post ID from the pinged URL. So if the ping is for a regular post and the site is using permalinks it might be something like feedmeastraycat.net/2012/01/08/on-the-road-to-a-wordpress-core-patch/ in which case /2012/01/08/on-the-road-to-a-wordpress-core-patch/ is sent in and the post id is returned. The problem seams to be that it doesn’t handle custom post type urls.

If there is a CPT named “products” and you have a post with the slug/name “macbook” you might have the url test.com/products/macbook/. The url_to_postid() function goes through the rewrite rules and tries to find a match. Which it should do. It then creates a query for that match, which in this case looks like this:

Array
(
    [products] => macbook
    [page] => 
)

The problem here is that this query will fail. WP_Query requires a ‘post_type’ => CPT_Name parameter as well. It should look like this:

Array
(
    [post_type] => products
    [name] => macbook
)

During a regular page call, this is made in WP->parse_request() (here). Not in WP_Query.

Well. I created a ticket and I’ve also added a suggested patch. In a comment. Cause I don’t know how to do it as a real patch… I hope that I haven’t missed anything. And that the higher up:ers like my patch suggestion. It would be nice to get a patch in early and free up 2012 for new goals.

Posted by David
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
30
DEC
11:24

Uppdatera WordPress till 3.0.4!

Viktig säkerhetsuppdatering ute nu. That is all… Tråkig bloggpost? You bet!

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
18
JUN
09:07

WordPress 3.0

Just updated to WordPress 3.0. It is nice. Thank you WordPress team!

Posted by David
13
JUN
21:26

Notes PostWidgets

My newest plugin has just been submitted and accepted at WordPress.org. The idea of the plugin took form in talks between me and TDH who is the creator of the Notes Core WordPress theme and the writer of Smashing WordPress: Beyong the blog. The plugin is called Notes PostWidgets and this is the description from the readme file.

Notes PostWidgets is a plugin which adds a custom post type (“Post Widgets”) that you can use to create text widgets with. This way you can use the built in WYSIWYG (What You See Is What You Get) editor to set the mark up on your widgets. You can set a custom CSS class name for each widget for more specific mark up.

You can read more about Notes and the Notes Core WordPress theme over at NotesBlog.com. Download Notes PostWidgets at WordPress.org or checkout my project page where I will post update notes.

Posted by David
27
MAY
08:00

Internet – 10 år in the making … by me … sort of.

The Creation of Halflife.nu

Upptäckte i förra veckan att tiden har gått fort. Det är idag 10 år sedan första versionen av Halflife.nu gick live. Sidan som fick mig intresserad av att skapa Internet. Eller i alla fall att skapa Internetsidor…

Click here to read the rest of this post…

Posted by David
16
FEB
13:57

Kenza flyttar in hos WordPress

Den stora svenska flick-mode-grejs-bloggaren Kenza har flyttat till WordPress. På egen server. Någon har dock kämpat rejält för att behålla sidans risiga blogg.se-design. Men det kanske bara är för att slippa få så mycket förändring på en gång. Läsarna kanske inte skulle klara det!

Välkommen till WordPress i alla fall Kenza!

Update: Hon/de verkar dock inte ha uppdaterat till senaste 2.9.2 än … ;)

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
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
12
JAN
17:51

Den är här!

Den har kommit nu. Min iPhone! Äntligen! Detta inlägg skrevs med WordPress-applikationen! *nörd*

Posted by David
9
OCT
19:52

Mera Carl Bildt

Nu kanske ni tycker jag har fastnat lite i Carl Bildts värld. Men tyckte bara hans val av WordPress-tema var ganska mysigt!

Posted by David
17
SEP
18:13

Halflife.nu tillbaka

Den äldsta sidan som jag har “hållt på med”, Halflife.nu är tillbaka. Började med den tillsammans med Anders under gymnasietiden (år 2000) och har sedan dess haft upp och nedgångar. Massa versioner, massa olika folk. Senaste tiden har vi vart sponsrade av FZ, men nu står vi på egna fötter och nya versionen (5) är en WordPress-blogg-version. Anyway. Check it out, if ya want to!

Posted by David