Wednesday, December 26, 2007

WordPress Plugin: SimpleTags Modification

WordPress SimpleTags is a WordPress plugin that will allow you to easily manage tags of your blog. However, I found some of bugs of WordPress SimpleTags, here is my modification.

1. Search terms problem:

SimpleTags use of the full text of the search, as long as the article contains the keyword matching, which can lead to large errors match, I modify it only match of the headlines.

Open file simple-tags\inc\simple-tags.admin.php, in line 1466, replace:

$search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_content LIKE '%{$search}%') )";

to:

$search_sql = "AND ( (post_title LIKE '%{$search}%') OR (post_title LIKE '%{$search}%') )";

2. Untagged only problem:

When blog have large numbers of the article, the untagged only function will return errors, I change some of original code in the SQL statement , greatly improving the efficiency of search and speed.

Open file simple-tags\inc\simple-tags.admin.php, in line 1475, replace:

$p_id_used = $wpdb->get_col("
SELECT DISTINCT term_relationships.object_id
FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
WHERE term_taxonomy.taxonomy = 'post_tag'
AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
AND term_relationships.object_id = posts.ID
AND posts.post_type = '{$type}'");
$filter_sql = 'AND ID NOT IN ("'.implode( '", "', $p_id_used ).'")';


to:

$p_id_used = "SELECT DISTINCT term_relationships.object_id
FROM {$wpdb->term_taxonomy} term_taxonomy, {$wpdb->term_relationships} term_relationships, {$wpdb->posts} posts
WHERE term_taxonomy.taxonomy = 'post_tag'
AND term_taxonomy.term_taxonomy_id = term_relationships.term_taxonomy_id
AND term_relationships.object_id = posts.ID
AND posts.post_type = '{$type}'";
$filter_sql = 'AND ID NOT IN ('.$p_id_used.')';

Saturday, December 22, 2007

WordPress Plugin: Post2Mail, Send Post to Email

Some of WordPress user needed a plugin to send an e-mail to a mailing list whenever a post was published to the blog. Here is a modified version of the "Post2Mail" plugin which can email the post to a mailing list or email address.

WordPress Post2Mail plugin allows you to automatically e-mail selected people when a post is published on your blog. Also useful for alerting an administrator when a post has been published on the blog. Configuration is done in the post2mail.config.php file which has comments to get you started.

This modified plugin have the following Features:

1. Support Far East Characters (such as Chinese Characters). Use base64 to encode email title to support Chinese Characters.

2. Fix some Security bug.

Installation / Configuration Instructions:

1. Edit post2mail.config.php to add the email address or mailing list address.

2. Upload post2mail.php and post2mail.config.php to your WordPress plugin directory.

3. Activate the plugin.

Download Latest:

Click here to download the latest version of WordPress Post2Mail Plugin.

Monday, December 17, 2007

WordPress Plugin: WP-PostViews JavaScript Edition

Lester Chan develop a greate WordPress plugin - WP-PostViews, can enable user to display how many times a post/page had been viewed. It's base on PHP. But if you active WP-Cache plugin, you will found that  WP-PostViews not working. So I develop a new javascript version of WP-PostViews, that can work fine with WP-Cache or WP Super Cache plugin.

Installation / Configuration Instructions:

1. Install normal version of WP-PostViews 1.20.

2. Upload postviews.php to your WordPress plugin directory(wp-content\plugins\postviews).

3. Upload wp-counter.php to your WordPress root directory.

4. Activate the WP-PostViews plugin.

Download Latest:

Click here to download the latest version of WP-PostViews JavaScript Version plugin.

Saturday, December 15, 2007

How To Turning Off WordPress Autosave

WordPress autosave is the best features which I hate in WordPress. My WordPress hosting is very slow, when I post new article, sometimes I got two saved post. The autosave features almost make me crazy. How can I turn off the autosave?

I finally patched core program post_new.php to disable autosave for a "new" post and the problem went away. Do not know if this will help you or not. My patch for v.2.3.1 follows. Newer versions might be around the same location.

Edit the file wp-admin/post_new.php WP v2.3.1 and insert "//" (without the quotes) at the beginning of this line (currently line 8):

wp_enqueue_script('autosave');

Save and upload the file post_new.php, and the WordPress autosave features is now disable.

Sunday, December 9, 2007

WordPress Robots.txt For SEO

The robots.txt file is used to instruct search engine robots about what pages on your website should be crawled and consequently indexed. Most websites have files and folders that are not relevant for search engines (like images or admin files) therefore creating a robots.txt file can actually improve your website indexation.

Implementing an effective SEO robots.txt file for WordPress will help your blog to rank higher in Search Engines, receive higher paying relevant Ads, and increase your blog traffic.

Here is my robots.txt files, which can further protect WordPress from this duplicate content issue.

User-agent: *
Disallow: /wp-
Disallow: /feed/
Disallow: /trackback/
Disallow: /comments/feed/
Disallow: /page/
Disallow: /comments/


After you created the robots.txt file just upload it to your root directory and you are done!

Friday, December 7, 2007

WordPress MU AdSense Plugin

WordPress MU AdSense Plugin is an easy-to-use plugin for WordPress MU 1.3+ (also including WordPress 2.3+) for quickly inserting Google or Yahoo! ads into all of the WordPress multi-user's blog posts. Wordpress MU allows webmasters to easily integrate Google Adsense inside wordpress using this plugins. Google Adsense has become the most popular online contextual advertising program and proper custom integration with Wordpress can help to increase Adsense earnings.

Installation / Configuration Instructions:

1. Edit wp-adsense.php, replace the Google AdSense code in the plugin with your own customized Google Adsense code.

2. Upload wp-adsense.php to your WordPress plugin directory(not the mu-plugins directory).

3. Download and install a WordPress MU Plugin - Plugin Commander, upload Plugin Commander to mu-plugins directory.

4. Login WordPress MU's Site Admin, click Plugin Commander, find WordPress Adsense plugin and click "Activate all" to mass activate the wordpress adsense plugin.

Download Latest:

Click here to download the latest version of WordPress MU AdSense plugin.

WordPress MU AdSense plugin can display AdSense ads inline with blog posts. Wish you would like this plugin.

Monday, December 3, 2007

WordPress Plugin: MySQL Server Crash Monitor

Since end of October our MySQL Server crashed on or two times a day. We don't no exactly why. Maybe the Databases are to big. We run several WordPress system on this MySQL Server. but the MySQL services often crashed, then my WordPress can't connect to MySQL server and show the error. So I develop this program to monitor the WordPress MySQL server, when the server is down, WordPress will auto send me an e-mail and write to a text log file in a recorded. We can look trough the log file to analysis the MySQL server databse, in order to cantact the host administrators to fix the error.

Here is the source code of the MySQL Server Crash Monitor.


// Change the e-mail address below .
$from = "[email protected]";
$to = "[email protected]";
$subject = "MySQL Crashed!";
$body = date("Y-m-d H:i:s");
$headers = 'From: '.$from . "\r\n"
.'Reply-To: '.$from . "\r\n"
.'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
// Log to file
$filename = 'log.txt';
$somecontent = date("Y-m-d H:i:s");
$somecontent = $somecontent . "\r\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
exit;
}
if (!fwrite($handle, $somecontent)) {
exit;
}
fclose($handle);
}


First, upload a file named log.txt to the WordPress root directory, chmod it to 666.

Second, replace the e-mail address of the code to your own e-mail.

Then,opening wp-includes/wp-db.php, find "if (! $ This-> dbh)", 66 lines in WordPress 2.3.1, paste the code after that. Save and upload the file.

Now, When the database lost connection or get problems, WordPress will automatically mail the error message to your mailbox, at the same time the message will be recorded in log.txt document.