Category Archives: website

technical website

Posting domain mapped permalinks via the wp-to-twitter plugin

A really useful WordPress feature is support for hosting multiple sites from the same core install. I used to run WordPress-MU for this purpose before it was rolled into the main version. If you have control of DNS you can easily have sites as subdomains, or even map a seperate domain to a subsite using a plugin such as WordPress MU Domain Mapping.

Since I use SSL with a wildcard certificate this also means I can securely administer wordpress subsites via https://subsite-example.glenscott.net while having a public non-ssl url of http://subsite-example.tld.

I recently installed the plugin WP-To-Twitter to use on a subsite, and found that when posting updates to twitter, wordpress unfortunately provides it with the http://subsite-example.glenscott.net/link-to-post permalink instead of the http://subsite-example.tld/link-to-post permalink. This doesn’t seem to be the fault of either plugin as MU Domain Mapping is using some smoke and mirrors rewriting to display the mapped http://subsite-example.tld domain while the plugins in the secure wordpress admin URL (including wp-to-twitter) rightly see the site as if it is located at https://subsite-example.glenscott.net. I tried a few combinations of changing the site_url and home_url values in the network admin –> sites panel, but only succeeded in breaking my domain mapping. Until domain mapping is baked into the wordpress core I suspect this will continue to be an issue.

I’m not a wordpress/plugin dev by any stretch but I spent a couple of hours looking through the code for wp-to-twitter and concocted a (temporary) hack which is now posting the correct permalink to twitter. I would have been happy with hardcoding the domain value since the plugin is only being used on one site, but in the end I learned a few things about core wordpress PHP functions and came up with a solution which should work for multiple subsites / domains.

I based part of this solution on the post here:
http://premium.wpmudev.org/forums/topic/permalinks-converted-to-those-domain-based

Here’s the code:

Add the following function to wp-content/plugins/wp-to-twitter/wpt-functions.php

function get_permalink_dom( $id ){
    global $wpdb;
    $linkpath = str_replace(home_url(), '', get_permalink($id));
    $thisblogid = get_current_blog_id();
    $thisblogdomain = $wpdb->get_var( "SELECT domain FROM wp_domain_mapping WHERE blog_id = $thisblogid AND active = 1" );
    return "http://" . $thisblogdomain . $linkpath;
}

Edit the following in wp-content/plugins/wp-to-twitter/wpt-truncate.php

    // comment/remove the below line (15) and replace it with the call to get_permalink_dom
    //$thisposturl = trim($shrink);
    $thisposturl = trim(get_permalink_dom($post_ID));

That’s it; the ‘Tweet Now’ box in the post editor should use the domain mapped link.

technical website

WordPress, the OpenID plugin and “Fatal error: Call to a member function needsSigning() … in Server.php on line 1495”

For many moons I’ve been attempting to get the server functionlity of the OpenID plugin working with my wordpress install and been stumped on the following two errors:

First, any hit on the OpenID /openid/server url (I am using non-default permalinks) generated the following :

Fatal error: Call to undefined function add_options_page() in
/path/to/wp-content/plugins/wp-contact-form/wp-contactform.php on line 200

This was pretty obviously a conflict with WP-Contactform. Disabling this plugin made the above error go away, so I’ll be looking for a replacement for it soon.

Once the contactform error was worked around by disabling the plugin, the following appeared:

Fatal error: Call to a member function needsSigning() on a non-object in
/path/to/wp-content/plugins/openid/Auth/OpenID/Server.php
on line 1495

This would happen when I tried to specify my URL (whether main blog or wordpress author url) as an openid – it would seem to be working, go through the logon process then generate the error and the authentication process would abort.

After much googling (not much out there but this was helpful, sort of) and a good period of waiting and trying new versions of the OpenID plugin as they were released, the solution / workaround turned out to be extremely simple. It was a plugin conflict (doh) and a process of elimination identified the culprit and main show stopper: the cryptographp plugin.

No idea why but once it was disabled things worked fine. I was using this plugin to generate protective captchas for my comment forms. I replaced it with Simple CAPTCHA. (Its worth noting that in the 15 minutes or so I had no CAPTCHA active, I had already received a bot comment spam – and my site isn’t heavily trafficked by any means). I might choose another solution at some point from the plethora available, but for the time being, Simple Captcha gets the job done fine.

So thats about it. In a nutshell, some seemingly unrelated plugins were conflicting, disabling them and replacing with alternatives fixed it.

Now I can use glenscott.net as an OpenID, and my visitors have a nice simple OpenID login option on comments pages =)

technical website

Creating ‘hidden’ pages in wordpress which don’t appear in the navigation menu

Yeah I know theres seventy thousand or so articles out there already talking about modifying

wp_list_pages();

to include and exclude various pages from your wordpress site menus, but I’m going to talk about they way I did it anyway =)

The deal is, I’m wanting to publish stories and other standalone type pieces of writing on this site, and I want to create them as nice friendly text wordpress pages, but I don’t want each and every story to appear as a default pages link. The titles are long, there’ll be a few of them, and they’ll screw up my page layout if included in the pages menu(s), especially in the top nav bar where theres limited space.

To change this behavior, you just need to go into your theme template files and add some parameters to wp_list_pages(). The definitive list of parameters is over here and is worth a read:

http://codex.wordpress.org/Template_Tags/wp_list_pages

The most useful ones for this task are ‘include’, ‘exclude’, and ‘depth’. You can string multiple parameters together using the ampersand & character like so:

wp_list_pages(foobar=1&moobar=2);

Include and exclude will do as they suggest, given a comma delimited list of page numbers. If you use include it will only include the specified pages, if you use exclude it will include all except the specified pages.

I decided a better way to get it done, actually ideal for my purposes, is to create all my ‘hidden’ pages in a subcategory, and set the depth parameter to ‘1’. This means any page created as a subcategory will not appear in the navigation menus, though it can be explicitly linked to, or appear in a list of links for that subcategory (exactly what I want).

The Widgets file

I managed to sort out the top nav bar page listing on my template pretty easily by making the change to the header.php file, but I couldn’t find anything immediately obvious generating the page listing in sidebar.php, or any of the other theme includes. After some bumbling around trying to figure this out, I discovered the sidebar listing was being handled by wordpress widgets . This was pretty easy to fix once I found out where the widgets file is (/wp-includes/widgets.php), although since it uses an array for the parameters its slightly different than the edit above.

You have a few options for changing how the pages display through the wordpress widgets control panel, but sadly no way to exclude sub-pages by default. This would be a cool thing to have available, and I’d write it into the widget file and make my version available, but my php is far too rusty at the moment for this even though its pretty simple.

Ok, how to do it manually. Open up the widgets file for editing and find the section which defines function wp_widget_pages and add to the line which starts as follows:

$out = wp_list_pages (array ('title_li' => '',

etc etc and add to it the parameter ‘depth’ => 1, so it ends up looking something like this:

$out = wp_list_pages( array('title_li' => '', 'depth' => 1,'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) );

Thats it. save the file and your side menu should hide all pages in sub-categories.

Also, there is this plugin I found over here which interferes somehow with

wp_list_pages();

to cause the change everywhere the function is called. Might save having to mess with multiple places in the template / widgets file depending how your theme is set up. (Mine has pages listed in a top nav bar as well as a side menu, for example).