FTP credentials in WordPress

Wordpress Logo

The issue is that when you try to automatically update your WordPress installation you are asked to supply your ftp login credentials. Hopefully just like me you are using unique, complex and hard to remember details. Joost De Valk created a plugin to fix the automatic update issue that some webhosts have here

The plugin (and this alternative) are a way to avoid having to go look up the details before plugging them in every time you wish to update.

In your wp-config.php you can define these values to hopefully end this problem once and for all:

define(‘FS_METHOD’, ‘ftpext’);
define(‘FTP_BASE’, ‘/path/to/wordpress/’);
define(‘FTP_USER’, ‘username’);
define(‘FTP_PASS’, ‘password’);
define(‘FTP_HOST’, ‘host’);
define(‘FTP_SSL’, false);

The codex has a little more to say on the matter here

Renaming WordPress database prefixes

Wordpress Logo

Having non-standard table prefixes can help reduce automated attacks and malicious scripts from compromising your WordPresss database

This is a fairly simple process if you are familiar with the underlying database and principles, but is not recommended unless you are experienced with queries and a sql client such as phpMyAdmin

1) Prepare by making a backup everything, redirect your visitors etc
2) Change the default table prefix in wp-config.php to your required name
3) Rename all WordPress database table prefixes

Here are the necessary SQL commands (remember to change the example to your own table prefix)

RENAME table ‘wp_commentmeta’ TO ‘wp_rand0mstr1ng_commentmeta’;
RENAME table ‘wp_comments’ TO ‘wp_rand0mstr1ng_comments’;
RENAME table ‘wp_links’ TO ‘wp_rand0mstr1ng_links’;
RENAME table ‘wp_options’ TO ‘wp_rand0mstr1ng_options’;
RENAME table ‘wp_postmeta’ TO ‘wp_rand0mstr1ng_postmeta’;
RENAME table ‘wp_posts’ TO ‘wp_rand0mstr1ng_posts’;
RENAME table ‘wp_terms’ TO ‘wp_rand0mstr1ng_terms’;
RENAME table ‘wp_term_relationships’ TO ‘wp_rand0mstr1ng_term_relationships’;
RENAME table ‘wp_term_taxonomy’ TO ‘wp_rand0mstr1ng_term_taxonomy’;
RENAME table ‘wp_usermeta’ TO ‘wp_rand0mstr1ng_usermeta’;
RENAME table ‘wp_users’ TO ‘wp_rand0mstr1ng_users’;

Remember if there are other WordPress related tables created by plugins you will need to rename these as well. ALL table prefixes should be renamed.

4) Search the options table for any instances of the old table prefixes

SELECT * FROM ‘wp_rand0mstr1ng_options’ WHERE ‘option_name’ LIKE ‘%wp_%’

This will return wp_user_roles and any options or configurations created by plugins or custom scripts. Update the fields as appropriate.

5) Edit the usermeta table

Search the usermeta for all instances of the old table prefixes

SELECT * FROM ‘wp_rand0mstr1ng_usermeta’ WHERE ‘meta_key’ LIKE ‘%wp_%’

Again these fields will need to be updated where appropriate

Test everything is working and then set your site to live once again.

PHP URL Shortening

A current Twitter related project involves quite a few URLs and because Twitter limits you to only 140 characters per post shortening a link can be very rewarding.

There are a multitude of URL shortening services on the internet and whilst perhaps not producing the shortest links, TinyURL.com requires no account in order to use it via PHP which makes for a very simple query:
function getTinyUrl($url) {
return file_get_contents(“http://tinyurl.com/api-create.php?url=”.$url);
}

bit.ly is another popular URL shortener, however it does require an easily obtainable API key. The code is below:
function getBitly($url) {
$query = file_get_contents(“http://api.bit.ly/v3/shorten?login=YOUR_LOGIN&;apiKey=YOUR_APIKEY&longUrl=”.$url.”&format=xml”);
$element = new SimpleXmlElement($query);
$bitlyurl = $element->data->url;
if($bitlyurl){
return $bitlyurl;
} else {
return ‘0’;
}
}

Dont forget to change YOUR_LOGIN and YOUR_APIKEY to your own values. I’m sure you dont need any help with usage, but as always comment if you have any issues.

Netgear DG834N dead WiFi

The problem began when both the green WiFi light on the DG834N (v1) ADSL/router stopped functioning and the ability to see the SSID being broadcast ceased. It seemed nothing had changed and during transport from one location to another it had simply died.

To begin with I flashed the latest firmware to the device. It is really important to do this via a wired connection to these devices; often if you perform the operation via wireless the upload of the firmware partially fails and the device ends up becoming a brick. You have been warned!

With new firmware I rebooted the device and at this point the WiFi light turned green. I congratulated myself and expected to find the SSID being broadcast as per normal. It was not to be however, and many hours were about to be spent solving the problem.

I tried many resets – including a hard reset. To perform a hard reset hold the reset button in for 20 seconds with power, continuing to hold the reset button but remove the power for 20 seconds, and finally connect the power while still holding in the reset button. So: 60 seconds holding in the reset button, 20 powered, 20 unpowered, 20 powered. If this reset works properly the power LED will flash between red and green.

After a phenomenal amount of searching the internet I found a few clues to the issue and eventually solved it.

The WiFi component on this model is a plug in module that can sometimes become loose. Open the case, pull the module out, and re-insert firmly. The module is instantly recognisable by the two antenna wires that attach to it.
Note: There are two torx screws that need to be removed underneath at the base and also two underneath the large sticker label at the rear of the unit.

The future:
Apparently the chipset on this model is notorious for heat generation eventually leading to failure. A future mod for this device could be using a dremel to carve out a hole in the chasis and subsequently add a fan to improve airflow.
With the simple plug in antenna arrangement these could also be replaced; however I have had no issues with WiFi performance.
The power supply that comes with these devices are also reputed to be quite underpowered. Mine seemed quite heavy duty so I dont think I will need to replace it unless the addition of a fan increases the current draw too much.