Archive for January 1st, 2015

A workaround for an error with the WordPress Blix 0.9.1 theme under PHP 5.5

At this point in time, this blog is running a theme which it has been running since I first moved it to a WordPress installation in 2005. I have modified the theme a little bit over the years to make the colours more suit tastes and adjust a few functions to work a bit better for my needs. All that said, it is an ancient set of PHP scripts designed to work under an equally ancient version of PHP, and given how much has changed in PHP over the years it could be considered a miracle that the Blix theme still works at all.

Recently I came across a problem which I couldn’t make heads or tails of. Out of the blue, errors started appearing on this blog about failed login attempts where a script on this blog had tried to login to the database as the chief administrative user without a password:

Warning: mysql_query(): Access denied for user ‘root’@’localhost’ (using password: NO) in /home/samuelgo/wp-content/themes/blix/BX_functions.php on line 44
Warning: mysql_query(): A link to the server could not be established in /home/samuelgo/public_html/wp-content/themes/blix/BX_functions.php on line 44
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/samuelgo/public_html/wp-content/themes/blix/BX_functions.php on line 45

I first noticed this problem just after I fixed an issue where the WordPress installation couldn’t login to MySQL and thought it was related and possibly a sign of a very poorly implemented hacking of this blog, but it turned out to be unrelated. The reason WordPress was unable to login to the database was that this site was moved from one server to another and a file with login details was slightly corrupted in the process, and this was easily corrected.

The above errors are related to a function which, on the Archives page, shows the number of comments on each post. Previously the “mysql_query” function in the BX_functions file used the login details which WordPress uses, but the “mysql” function has been deprecated as of PHP 5.5 and, while it still works, now seems to need to be explicitly told which login details to use, or it just assumes it should login as “root” without a password (which is possibly the dumbest login details I can think of as it has almost no chance of working on anything but the most insecure of servers). This error, consequently, appears next to each and every post on the archives page, often multiple times. I was able to suppress these errors from displaying until I could get around to figuring out what the problem was, but this still caused the error to be dumped in to an error log many thousands of times per day, causing the error log to grow by hundreds of megabytes each day until I would delete it before it could use up all of the disk space available to this website.

A Google search for the error message shows a lot of blogs running the Blix theme and related themes, but no solution to the problem, so now that I have figured out a workaround, I’ll post it here for the benefit of everyone.

The solution is a tad cumbersome in that it requires the WordPress database username and password to be added to the BX_functions.php file. In reality it is only a workaround as the “mysql” function has been deprecated in favour of other functions and, as such, it will probably exhibit increasingly bizarre behaviour in future version of PHP until support for it is completely removed. This solution works for now, but the only long-term solution is to change to a more modern WordPress theme…I’m still trying to find one that I like as much as Blix.

The solution is to edit your Blix theme’s BX_functions.php file. I would recommend making a backup copy of the file first. This file can usually be found in the /wp-content/themes/blix directory of your website, but if you have a version of Blix which is installed in a different location, then you’ll need to find BX_functions.php in whatever directory the theme is installed in.

You should see a section which looks like this, starting around line 43 (again this may vary if you have a customised version of Blix):

echo "<li>".get_archives_link($url, $text, '');
$comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID);
$comments_count = mysql_num_rows($comments);
if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo ' ('.$comments_count.')';
echo "</li>\n";

You will need to add a couple lines as follows below the line starting with “echo” and above the line starting with “$comments = mysql_query”.

mysql_connect("server", "username", "password");
mysql_select_db("databasename");

Naturally you need to change these details so that
“server” is the address of your MySQL server (this is often “localhost”)
“username” is the username of your MySQL user
“password” is the password of your MySQL user
“databasename” is the name of the MySQL database used for your WordPress installation.
Do not remove the quotation marks from around these details.

If you’re not sure of any of these details, you should be able to find them in the wp-config.php file in the root directory of your WordPress installation.

Once you’re done, the above section of the BX_functions.php should look something like this:


echo "<li>".get_archives_link($url, $text, '');
mysql_connect("server", "username", "password");
mysql_select_db("databasename");
$comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID);
$comments_count = mysql_num_rows($comments);
if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo ' ('.$comments_count.')';
echo "</li>\n";

And the errors should go away.

It’s an annoying issue, but it’s nice to have a solution, even if it is only really a temporary workaround in lieu of upgrading to a theme designed for a modern version of PHP.

Samuel

January 1st, 2015 at 08:38pm

If you’re donating to Heritage Foundation with a non-US credit card, do it by phone or PayPal, not on their website

The Heritage Foundation, like most US organisations which can accept tax-deductible donations, is in the last stages of their end-of-year appeal. This is an important time of year for such US organisations as it is the end of the tax year for donation purposes, just like in Australia at the end of June when our tax year ends. Of course, being an Australian, I’m not eligible for any tax rebate for donating to a US organisation.

Like most organisations, Heritage is flooding supporters with email requests for donations, and including a link to the donation form on their website. Unfortunately this form has a bug which causes it to not handle transactions involving non-US credit cards properly. The transaction will succeed, but the page will claim it was declined and advise you to check the address you entered. It wasn’t until the third attempt that I worked this out…so yes, silly me did just give them triple the donation I meant to give.

The good news is that Heritage believe they can reverse the unintended payments…but not until Monday morning their time when some of their senior staff are back on deck, and by then I figure it will cost them extra in fees because my bank will have finished processing the payments, so I won’t bother and instead will just not donate to them for a while. I will call them back on Monday to make sure their senior staff are aware of the issue though.

So, if you’re using a non-US credit card and want to donate to The Heritage Foundation, their website buries a contact number ((800) 546-2843) and a link to a PayPal page (to which I won’t link…if you want to use it, go via the above link to the Heritage website rather than trusting a direct link to PayPal from my site) half way down an FAQ page. If only I’d seen that earlier.

Meanwhile I was also going to donate to Hillsdale College’s end-of-year campaign, but their website doesn’t accept non-US postal addresses (due to the same problems which Heritage have, perhaps?) and they have to be called by phone. Unfortunately they went home before 5PM eastern time, so that will have to wait until next week.

I did, however, donate to the Institute Of Public Affairs‘ end-of-year campaign (although why they have one at the end of the year, apart from it being a nice date, escapes me).

It is nice to start 2015 on a conservative note by supporting these organisations, even if it is requiring more effort than I was expecting.

Samuel

2 comments January 1st, 2015 at 08:46am


Calendar

January 2015
S M T W T F S
« Dec   Apr »
 123
45678910
11121314151617
18192021222324
25262728293031

Posts by Month

Posts by Category

Search Blog or Web

Login/Logout

Ads By Google


Blix Theme by Sebastian Schmieg and modified for Samuel's Blog by Samuel Gordon-Stewart.
Printing CSS with the help of Martin Pot's guide to Web Page Printability With CSS.
Icons by Kevin Potts.
Powered by WordPress.
Log in