Posts

Exporting Announcements from WHMCS

Doing some integration work with WHMCS, I found the need to export some of the announcements into WordPress. Since there isn’t any native implementation of this, I found the best way is to export it directly from the database. The PHP code to do this is fairly easy:

[cc lang=”php”]include(“/path/to/whmcs/configuration.php”);
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);
$query = “SELECT * FROM tblannouncements WHERE published=’on’ ORDER BY date DESC LIMIT 0,3”;
$result=mysql_query($query);
while($data = mysql_fetch_array($result)) {
$id = $data[“id”];
$date = $data[“date”];
$title = $data[“title”];
$announcement = $data[“announcement”];
echo(“$title“);
}

If you wanted to make it more than 3 posts, just change the limit to 5 or 10 or whatever you wish. You can also change the ordering and add additional filters via more SQL statements. If you wanted to do a list, encapulate the code with <ul> and just make them <li> entries.

I’m using this code in a WordPress template but it would work equally as well in any other PHP based application.

A Twitter Search WordPress Plugin

Ok, this is not really a plugin per se, but WordPress already has the capability of displaying a Twitter search stream via it’s RSS feed widget.

It is dirt simple to set up.

Go into Appearance -> Widgets and select the widget area you wish to add the twitter search stream to;

Add “RSS” and position the widget accordingly.

Click “Edit” and “Enter the RSS feed URL here:”. This is the link from search.twitter.com where it says “Feed for this query”.

Twitter Search RSS Feed

Enter a title, if appropriate.

Thats it! You will see an area on the site such as the one below:

Twitter Search Plugin

To summarize: There is no Twitter Search Plugin but WordPress’s RSS feature works just fine!

Password Protected Folder Gives 404 Not Found in WordPress Installation Sub-folder.

Wordpress

Came across this little maddening issue again today after fixing it a few months back. I created a directory that is password protected using a .htaccess file. However, when trying to access this folder or anything under this directory, a File Not Found 404 error from WordPress is displayed before it even prompts you for the password. The problem here lays within the main WordPress .htaccess file

The default .htaccess file for WordPress is:

# BEGIN wordpress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END wordpress

This means that if a file is requested from the server, if it is not a file that exists in the server’s folder directory (!-f) and if it is not a directory that exists in the server’s folder directories (!-d) then pass the request onto index.php. This way, WordPress will handle both customized URLs (such as those used for SEO) and also 404 File Not Found errors.

If you set up a password protected folder in a directory included in a WordPress install, all of a sudden WordPress takes over that folder and returns a 404 page, like the file doesn’t exist.

This happens because of a little ‘gotcha’ in the apache configuration. Luckily it is an easy fix.

In the password protected folder’s .htaccess file, you may already have the entries to ask for password access. Before all of that, place the following line:

ErrorDocument 401 /401.html

Then create a 401.html in the main folder, with any text, for example:

PASSWORD PROTECTED FOLDER - Please enter the correct username/password.

Voila, you can now enter your password protected folder again.

There is another workaround this little error, but since it involves editing the main wordpress .htaccess file, it can be overridden during an upgrade.

Solution found on: http://www.webmasterworld.com/apache/3688208.htm

Installatron WordPress Upgrade Disables Plugins

I just found a quick tip on the Installatron forums.

By default Installatron disables all WordPress plugins when doing an upgrade. This is due to the WordPress best practices for upgrading the version of their system. When you have a lot of WordPress installs to go through this is a big pain because it usually breaks the site.

According to this post, you disable the disabling of the plugins by creating a file named .dont_disable_plugins in the directory that wordpress is installed to.

Via command line it is as simple as this:

touch /path/to/wordpress/.dont_disable_plugins

Execute that command on the command line (or upload an empty file via FTP/SCP) and the plugins will remain enabled. There is also an option in the installatron settings to enable this file creation upon install.

Note that if you have a plugin that is not compatible with a new version of WordPress, it may break your install!

Last Modified Date or Time on WordPress Template Page

I couldn’t readily find an answer to this question via the google. So here it is: If you want to insert a ‘last updated’ or ‘last modified’ date on your wordpress page, then there is a simple bit of PHP code you can use for this:

And via Ardamis’s Blog, there is a great way to only display this information if it has been modified after the original post date. This is a good way to let people know if there have been updates since the original post:

= $u_time + 86400) {
echo "and last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo ", "; } ?>

This will display the last modified date and time if it is more than 86400 seconds after the creation date – that is 24 hours.