Blogroll Autolinker: Conflict with Bird Feeder WP

If you happen to use the Blogroll Autolinker along with BirdFeederWP, you’ll probably notice something bad like this show up in your feeds:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1 AND link_visible = 'Y' ORDER BY link_name ASC' at line 1]
SELECT * , IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated FROM WHERE 1=1 AND link_visible = 'Y' ORDER BY link_name ASC

I did, anyway. It turns out it’s because BirdFeederWP needs to reestablish the connection to the WordPress database, and it does so in a way that wipes out all the $wpdb->table_name variables that WordPress uses internally to refer to its database tables. So when the Blogroll Autolinker calls a function to get all your links from the database, it can’t because it doesn’t know what the links table is called! I contacted the author of the plugin about that, and in the meantime I think you can fix the problem by copying the following code into BirdFeederWP.php just after line 113:

$wpdb->prefix = $table_prefix;
if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
    wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
$wpdb->posts          = $wpdb->prefix . 'posts';
$wpdb->users          = $wpdb->prefix . 'users';
$wpdb->categories     = $wpdb->prefix . 'categories';
$wpdb->post2cat       = $wpdb->prefix . 'post2cat';
$wpdb->comments       = $wpdb->prefix . 'comments';
$wpdb->link2cat       = $wpdb->prefix . 'link2cat';
$wpdb->links          = $wpdb->prefix . 'links';
$wpdb->options        = $wpdb->prefix . 'options';
$wpdb->postmeta       = $wpdb->prefix . 'postmeta';
$wpdb->usermeta       = $wpdb->prefix . 'usermeta';
$wpdb->terms          = $wpdb->prefix . 'terms';
$wpdb->term_taxonomy  = $wpdb->prefix . 'term_taxonomy';
$wpdb->term_relationships = $wpdb->prefix . 'term_relationships';
if ( defined('CUSTOM_USER_TABLE') )
    $wpdb->users = CUSTOM_USER_TABLE;
if ( defined('CUSTOM_USER_META_TABLE') )
    $wpdb->usermeta = CUSTOM_USER_META_TABLE;

Then find line 111 and change it so it looks like this:

global $wpdb, $table_prefix;

This worked for me, at least.

Comments

  1. The fix as described above is exactly what I would suggest as a quick workaround. I’ll try to look into the problem and release a version that behaves better. Please note, that you need this fix only in case your Mint installation resides in another database than WordPress.

  2. Update 01.10.2007

    WordPress 2.3 has been released. I had to enroll further tests with this version of WordPress. And everything looks fine. As stevenberg.net has pointed out I also had to change the way the plugin reconnects to the WordPress DB in cases where Mint resides in another DB than WordPress. This problem should be solved by version 1.0.4.

  3. […] BirdFeederWP 1.0.4 fixes the problem with its re-initialization of the WordPress database. Now it’s no longer necessary to hack the plugin as I described in my earlier post. […]

Leave a comment

Comments are formatted with Markdown.