Category: WordPress

Plugin developer, Core contributor and support volunteer. Yeah, I’m a WordPress fan!

  • WordPress 2.9 and my pages!

    I updated to WordPress 2.9 yesterday. All appeared fine.

    That is, until I went to update a page today and found the Edit button didn’t work any more. Neither was the URL shortening for the page. And then I noticed that all the comments were missing.

    It appeared that the URL for the page was not being returned correctly. At first I thought this to be a potential WordPress fault but after installing the default page.php into my theme it worked! So I’m slowly converting my pages using them default theme page as a template. So, bear with me as it will take a while to do this (work, Christmas, etc, all getting in the way!).

    It’s strange that I haven’t found any reference to any of this functionality being changed…

    Update

    I found the fault. It was this line…

    if (function_exists('simple_social_bookmarks'))

     
    ..which I use to detect if the current user has editing rights – if so, the edit option is displayed. I’ve now modified the edit_post_link parameter to do this instead.

    No mention of this being changed in this way in any of the documentation and it works fine with posts. Weird.

  • Add Twitter links to your WordPress posts

    Want an easier way to add links to Twitter user pages? Here’s a quick solution.

    Add the following code to your functions.php file within your theme folder…

    add_filter('the_content', 'link_to_twitter');
    function link_to_twitter($content) {
        $start=strpos($content,"[@");
        while ($start!=0) {
            $code=substr($content,$start+2,strpos($content,"]",$start)-$start-2);
            $content=str_replace("[@".$code."]",'<a href="http://twitter.com/'.$code.'" target="_blank">@'.$code.'</a>',$content);
            $start=strpos($content,"[@",$end);
        }
        return $content;
    }

    Now, you simply need to simply specify a Twitter username within square brackets and it will be replaced with the same username, but now with a link to Twitter.

    For example, add [@dartiss] to your post and it will display as @dartiss.

  • Decoding a WordPress Post Title

    By default, get_the_title and the_title will return the title of the current post. It’s stored in the database in plain text, however, when returned using the aforementioned functions if appears to be encoded. This means that characters such as ampersands and apostrophes will be converted to equivalents that are more HTML friendly.

    Unfortunately, passing, say, this title to Twitter, via the URL, causes problems. First you have to URL encode and the mixture of the HTML encoding and the URL encoding produces a mess that Twitter simply doesn’t cope with very well.

    However, the standard HTML decoding in PHP didn’t seem to work 100% with, for example, apostrophes not being decoded. After much head scratching and some frustration I found that this was due to the parameters that I was using.

    The following line will correctly decode the post title to plain text…

    html_entity_decode(get_the_title($post->ID),ENT_QUOTES,'UTF-8');

    To then encode is to be passed via URL, then simply use this…

    urlencode(html_entity_decode(get_the_title($post->ID),ENT_QUOTES,'UTF-8'));

    It seems obvious now 😉

  • Displaying Code in WordPress

    I often have the need to display code within this blog – whether it’s JavaScript, PHP, XHTML or something else.

    There are many plugins available that will display any such code in a nice manner – usually with syntax highlighting – but, as yet, I’ve been unable to find one that doesn’t fulfil my requirements. And personally, I don’t think my requirements are that much.

    Showing the code in a fixed font, with a decent line wrapping facility and the ability to display spaces and/or tabs, I don’t think, is a big list of needs. That list doesn’t even include the ubiquitous syntax highlighting.

    In the end I created a half-arsed version of my own. In fact, it’s not even a plugin – just simply some CSS for displaying the code in reasonable manner. Unfortunately, it doesn’t get around the line wrapping problem.

    So, imagine my surprise to come across a plugin the other day that seemed to resolve all these problems. And it does Syntax Highlighting. I had some initial problems, which involved me having to move my aforementioned CSS, and then, with no further testing, I started busily converting my posts to the new system. Note, me specifically mentioning my lack of testing. Because, yes, after changing lots of pages and posts, I realised that it wouldn’t work with spaced or tabs, so all lines of code were aligned down the left hand side of the screen. Bah. And I can’t find a solution, so I’m in the process of putting it all back to how it was.

    If ANYBODY knows a plugin that will do what I’m after, then please let me know!

  • WordPress Plugins and File Fetching

    A number of my recent plugins have provided a facility to read files from other sites. However, errors were being reported by some users and so I attempted a change in one such plugin to address this.

    Unfortunately, that didn’t quite work as I intended. Kind of. In this case, I swapped to using a different file routine, but one which now only works with PHP 5. So I’ve now published a newer version of the same plugin using another new method, and one that should now be compatible with PHP 4.

    The problem here is that there are security implications with reading files externally, so there is a way for hosts to turn this ability off.

    My new plugin, I suspect, doesn’t actually resolve this and there isn’t a great amount I can do about this – if your host has decided to prevent you from reading external files then, well, you’re stuffed. My host doesn’t, which might explain why I didn’t recognise the problem at first.

    The file system I’ve used now, however, should allow you to specify local file names – at least that way files hosted by yourself should be readable. I’ve not tested it though, so feel free to provide feedback.

    I’m now going to upgrade my other plugins with the same code process.