Allowing periods in wordpress permalinks

John Resig tweeted the following:

Trying to get periods in Wordpress permalinks to work, but failing. How can I force WP to allow: http://example.com/foo.bar/


I was curious so I watched replies to him. There were many deeply misguided answers, my favorite being:

I’m not sure, but it seems like it might likely be a server configuration issue.


There was a reference to this: http://firsttube.com/read/hacking-wordpress-day-two/, but hacking the core is a pretty poor solution, and will be overwritten the next time you upgrade.

The periods get dropped by sanitize_title_with_dashes, and there is no clean way to hook into it and fix the problem, so you can just use remove_filter to drop it, and replace it with a very similar function that allows for periods:

remove_filter('sanitize_title', 'sanitize_title_with_dashes');
add_filter('sanitize_title', 'sanitize_title_with_dashes_allow_periods');
 
function sanitize_title_with_dashes_allow_periods($title){
        // same as sanitize_title_with_dashes minus the line replacing periods, 
        // and an alteration to the final catch all regex to allow periods
        // please note, might be dangerous for some reason?  i don't rightly know.
        $title = strip_tags($title);
        // Preserve escaped octets.
        $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
        // Remove percent signs that are not part of an octet.
        $title = str_replace('%', '', $title);
        // Restore octets.
        $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
 
        $title = remove_accents($title);
        if (seems_utf8($title)) {
                if (function_exists('mb_strtolower')) {
                        $title = mb_strtolower($title, 'UTF-8');
                }
                $title = utf8_uri_encode($title, 200);
        }
 
        $title = strtolower($title);
        $title = preg_replace('/&.+?;/', '', $title); // kill entities
        //$title = str_replace('.', '-', $title);
        $title = preg_replace('/[^\.%a-z0-9 _-]/', '', $title); // allow for periods
        $title = preg_replace('/\s+/', '-', $title);
        $title = preg_replace('|-+|', '-', $title);
        $title = trim($title, '-');
 
        return $title;
}

Please note that this could be dangerous, they might be removing periods for a good reason

trackback

Tags: , 2 responses »
  1. Bilal Bhatti's gravatar

    Hi, i successfully enabled periods in my WordPress POSTS permalinks but now i have encountered with an other problem. All of my TAGS permalinks with are in the following format

    http://example.com/tag/hello-1.1/

    is now giving 404, when i change it to

    http://example.com/tag/hello-1-1/

    It gives the right results.

    Why this happened? Please help me.

  2. atom's gravatar

    I guess the title of this is slightly misleading, the above only affects “titles”. In order for it to do what you want, you would need to adapt it for whatever they use to sanitize tags.

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

WPMU, why you gotta be like that?

I have a long and tension filled past with WPMU (Wordpress multi-user).

My first major beef was that they forcibly eliminated ‘www’ from your site url. It was hard coded in the source to tear it out and redirect, even if you went well out of your way to define it with the ‘www’. This was part of their general participation in the following bullshit: http://no-www.org/

I had an ssl certificate on www. Lots of stuff blew up, and there were a few infinite loop redirects. I wasn’t happy, and this eventually led to some core edits. This has since been changed, you can read some of the complaints here: http://mu.wordpress.org/forums/topic.php?id=7593

My next problem was that lots of language shit was hardcoded, including emails. This is generally improving over time, however I still have problems translating everything, as there are now emails stored in the database as options, which leaves me with difficult translations. More core edits to sort this out.

The next issue that I encountered was that my term id’s were very quickly getting larger and larger, with no reasonable explanation. This is still the case, and I have no idea why. Refer to the following forum thread (with no replies or acknowledgement), which explains this issue in more detail: http://mu.wordpress.org/forums/topic.php?id=3308 and my solution: http://mu.wordpress.org/forums/topic.php?id=6759

The next issue is that the admin does not gracefully handle many users. For pages where it is displaying users, no pagination is used. So if you get a few thousand subscribers, you better believe your browser is in for a crash when even attempting to load any of those pages.

The most recent issue I have experienced is that you can no longer register subpages to the plugins.php page, unless you don’t want anyone but the admin to be able to use them. I have no problem with this in theory, but historically this has never been the case. Now you have to be an admin to even load the plugins page, so if you have a tool you want editors to use, it better be somewhere else. This is because the variables that handle the menu generation declare that you need to be able to install plugins, edit plugins, or activate plugins in order to see the page, which only admins are capable of doing. This was also a hell of a thing to figure out. I had to crawl through include after include with ‘die(‘made it here!’);’

I still very much appreciate the software. It is a huge piece of impressive, and its not something that they needed to share or support (It was developed for use with wordpress.com). I am sure is a bear and a half to work on and test.

I just need to vent sometimes.

trackback

Tags: , , 1 response »
  1. Andrea_R's gravatar

    As much as I love it, I feel your pain. :D

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

Wordpress 2.5, a half-assed review.

wordpress 2.5 admin

Good:

  • The design has been updated and is much less offensive to the eyes.
  • The dashboard has better information at first glance.
  • Dashboard widgets will probably be pretty cool.
  • The new flash uploader is a big improvement.
  • The new gallery feature seems pretty cute, although it isn’t the sort of thing I usually go in for.
  • Full screen post writing is nice if you have a lot to write.
  • Tag management / tag filling is handy.
  • The ability to define permalinks on the fly when writing a post is neat.

Bad:

  • The admin has a max-width that is very noticeable (annoying) on a widescreen monitor, especially because it is not centered.
  • I miss the categories being on the sidebar on the post pages.
  • Tags still are not searchable. Why are tags not searchable?
  • There is even more Javascript in the admin than before, for an impressive total of 324Kb, ~2 second load.

TBD:

  • Whether or not any of the cute little enhancements break the hell out of plugins that I don’t feel like updating.
  • Whether or not nightmarish new vulnerabilities have been introduced. With an update this big, it is almost a sure thing.

Watch Matt’s screencast for a quick overview, I have to update the rest of my sites.

trackback

Tags: , , , 4 responses »
  1. nocash's gravatar

    They have a list of compatible plugins. I only glanced through, but the only one that jumped out at me was Twitter Tools, which loses the ability to post from the sidebar. With twhirl, though, I doubt it matters.

    I bet it breaks the hell out of Hello Ninja, though :(

  2. cliff's gravatar

    How about that one-click plugin updating? I thought that was pretty sweet.

  3. atom's gravatar

    @cliff

    yeah, it will be cool when all plugins comply to it, and they change it so you don’t have to de/reactivate any plugin that is updated.

  4. Jacob Kennedy's gravatar

    I’m with you on the categories point. It was very handy on the sidebar.

    I love the media handling now. Major improvement.

    Why doesn’t the basic editor have some basic HTML formatting though. A quick dropdown for formatting a line as an h1 or an h2 would be usable for every level of user.

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

sxsw day two

The second day was difficult to start, we had quite a first night. Did not manage to make it to anything before noon. Anywho…

attended the contextual web

This was not quite what I expected, I was hoping that this would be more about data portability, but it ended up just being an iPhone orgy. I did however realize that I was in the non-iPhone possessing sxsw minority.

attended ExpressionEngine 2.0 Sneak Peak

This was awesome. I am and have been a big fan of Ellislab, not because of ExpressionEngine, but because of CodeIgniter. Learning about ExpressionEngine was very interesting, especially when they announced that ExpressionEngine 2.0 has been rewritten to run on top of CodeIgniter. This is very pleasant news. This has gotten me all atwitter about the possibilities of a cms running on-top of my most favoritest PHP framework. Also everyone was very nice, and I desired to be friends with them. This panel was something I talked about throughout the rest of my trip.

attended 10 Things We’ve Learned at 37signals

This was another highpoint. CEO Jason Fried is an excellent speaker. Everything he said made sense, and he answered all questions asked were answered very well. At one point Anil Dash of six apart asked a question that seemed like more of an insult than anything.

attended Behind the Scenes at the Onion News Network

This was pretty fun, it being the Onion and all (which had quite a presence in Austin). I was hoping that it was going to be more about the site backend, and not the actual production of the show / a bunch of clips I have already seen.

went to the Google Party

The SXSWi Google Party

Wacky google action, got lots of saucy google swag, including pens, flashing plastic pins, and the best thing I have to keep a secret, because it is a present for my buddy Wes. The bar was kinda downtowny and lame, but I also got to meet Dustin Diaz, and tell him that I love him. His girlfriend liked my hair, and took a picture of us.

went to the EllisLab party at Moonshine Grill

This is the CodeIgniter / Expression engine core team trying to eat while I stalk them.
This was a wonderful event. Tons of bad ass food, free shirts (I nabbed a bunch and wear them all the time). The highlight of this was definitely hanging out with and talking to Derek Allard. Derek is a development beast, and is responsible for alot of the awesomeness in and around ExpressionEngine and CodeIgniter. You should go to his site, it is awesome.

went to the frog design / SXSW Interactive Opening Party

This was a hell of a thing. There seemed to be thousands of people spread throughout a very large area, lots of loud techno music and so forth. The beer line was long, and the beer was green. I think we only managed to stay there for about an hour.

went to the 16 Bit: SXSWi’s Opening Night Afterparty

16 bit: SXSWi Opening Night Afterparty

This was an amazing party, with an equally amazing line to get in. There was a band / freakshow, which eventually turned into silly 80’s music that made me feel like I was playing Vice City. It was good stuff all around, lots of cool excited people and lots of free drinks.

999 eyes: band / freakshow playing at 16bit

Towards the end of the party, I met Matt Mullenweg. I have always been amazed by Wordpress, and generally the stuff he gets into. I got to spend some time talking to him about the future of Wordpress, and vented a little bit about the problems I have had with WordpressMU, chiefly the forced support of the no-www.org agenda. I am not even going to link to it because of how much arrogant bullshit I think it is. It should be noted that normal Wordpress does not enforce this. When I was done going off about that, I launched into a drunken rant about how awesome CodeIgniter and ExpressionEngine were going to get. We were talking until the bar closed, and were yelled at to leave by a scruffy bouncer, and then continued to talk outside until his girlfriend got pissed. Anyhow, Matt was awesome, and much funnier than I expected.

ended up at Kerbey Lane Cafe

We stood outside of Scoot Inn (where the last party was) bullshitting with people for about an hour and suddenly found ourselves among the last few there. Me and Cliff (big bad boss) ended up going to breakfast with two complete strangers. One was a local Austin lady who was recently single (which she repeatedly and proudly exclaimed) and a gentleman who, to me, was the epitome of the apple fanboy. I was later informed that I may have been too rough on him regarding this, but I was drunk and he was a friendly stranger.

I don’t remember what I ate (aside from sweet potato fries), and I don’t remember the stranger’s names. If you are one of the strangers: please excuse me, and leave a comment to say hi.

trackback

Tags: , , , , , , , 4 responses »
  1. Anil's gravatar

    I apologize if my question to Jason seemed disrespectful, but he and I have been friends for years and have had that exact debate many times. I suspect that the reverence many people in the room felt for Jason and 37s might have made what was a fairly straightforward question seem like more of a challenge than it actually was.

  2. atom's gravatar

    @Anil, it is true that the crowd was fawning over him, and prior knowledge of your friendship would have made it seem less of an attack.

    I think more than anything, it was that you didn’t seem to accept his answer.

  3. Bryce's gravatar

    Now my curiosity is piqued. What was Anil’s question?

  4. atom's gravatar

    @Bryce

    Hopefully Anil will be back through to let us know.

    I will not be able to quote this verbatim, so I won’t try very hard.

    From where I was sitting (quite a ways back), the general gist of it was:

    “You are not ambitious enough.”

    P.S.: I have been planning on attending the co-work one of these days for a few kicks.

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.

situational Javascript based on body ID

I know that this is not anything revolutionary or anything, but I found it very helpful when making this site, so I thought I would share.

By assigning the body element an ID, you can check it with Javascript, and then execute what you need to based on this condition, like so(wordpress example):

Some php, for the Wordpress template (in header.php):

<?php
 
if(is_home()) //if we are at the wordpress "home"
	$location = 'home';
elseif(is_single() || is_page()) // if it is a single post or page
	$location = 'single';
elseif(is_some_strange_situation()) // a user function that test for something strange
	$location = 'strange';
else // otherwise, nothing special
	$location = 'default';
 
?>
<body id="<?php echo $location ?>">

Then some Javascript:

<script type="text/javascript">
	switch(document.body.id){
		case 'home':
			runAtHomeOnly();
			break;
		case 'single':
			runOnSingleOnly();
			break;
		case 'strange':
			runOnStrangeOnly();
		default:
			runOtherwise();
			break;
	}
	runThisAlways();
 
	function runAtHomeOnly(){
		alert('You are home.');
	}
 
	function runOnSingleOnly(){
		alert('You are on a single post or page.');
	}
 
	function runOnStrangeOnly(){
		alert('You are somewhere strange.');
	}
 
	function runOtherwise(){
		alert('You are not home, at a single post or page, and you are not somewhere strange.');
	}
 
	function runThisAlways(){
		alert('I always run.');
	}
</script>

The example is a little verbose I know, but wanted to make sure my point was gotten ;-)

trackback

Tags: , , no responses »

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.