Posts Tagged ‘wordpress’

Last Modified Posts in WordPress

Saturday, March 8th, 2008
Posted in Web Apps • Tags:

Want to show the last posts you updated in WordPress? This shows the posts you went back and updated or modified, which is different than your recent posts.


<?php
query_posts('showposts=10&orderby=modified&order=DESC');
if (have_posts())
{
echo '<h3>Last Modified Posts</h3>';
echo '<ul>' . "\n";
while (have_posts()) : the_post();
echo '<li>';
echo '<a href="' . get_permalink() . '">' . the_title('','', false) . '</a>';
echo '</li>' . "\n";
endwhile;
echo '</ul>';
}
?>

WordPress Spam Prevention Hack

Sunday, February 10th, 2008
Posted in Web Apps • Tags: ,

Akismet catches a lot of spam, but there is a lot it won’t catch. Therefore I decided to put together a hack to catch some more. The hack has 2 options:

  • One for you to put in spam words that if they are in the comment, the whole comment will be considered spam. Just be careful, if you add cialis you will block the word specialist also.
  • The other option lets you set the maximum number of links you will allow in a comment.

It will catch links that start with http://, https://, http://www., https://www. and www.. WordPress doesn’t convert text like example.com into a link.

The hack also checks to see if there is more content in the comment than just A tag(s), if there isn’t it’s considered spam. I recommend to use this with the Akismet plugin because it won’t prevent all spam. Keep in mind this hack may not work with other spam prevention plugins.

Open up wp-comments-post.php and after these lines

if ( '' == $comment_content )
wp_die( __('Error: please type a comment.') );

Add the following:

else /*MODIFIED - added this else to filter strings and count links*/
{
//OPTIONS
$link_limit = 3;//set the maximum number of links we allow
$disallowed_strings = array('[url', '[/url]', 'zithromax', 'levaquin');//add any strings you wont allow, make them lowercase, we test for case insensitivity later
//END OPTIONS
$temp_comment = strtolower($comment_content);//lowercase text so we can be case insensitive, php4 doesnt have stripos
$total_disallowed_strings = count($disallowed_strings);
//look for disallowed strings
for ($temp_counter = 0; $temp_counter < $total_disallowed_strings; $temp_counter++)
{
if (strpos($temp_comment, $disallowed_strings[$temp_counter]) !== false)
{
wp_die( __('Sorry, that looks like spam.') );
}
}
$comment_links = 0;
//regex would be better
$link_strings = array('http://www.', 'https://www.', 'http://', 'https://', 'www.');//order is important here
$temp_comment = str_replace($link_strings, '[LINK]', $temp_comment);
$comment_links = substr_count($temp_comment, '[LINK]');
//test for number of links
if ($comment_links > $link_limit)
{
wp_die( __('Sorry, that looks like spam.') );
}
//weed out all A tags and see if anything is left
$temp_comment = preg_replace('/<a[^\<]{1,}\<\/a\>/', '', $temp_comment);
$temp_comment = trim($temp_comment);
//see if the comment is nothing but links
if (empty($temp_comment))
{
wp_die( __('Sorry, that looks like spam.') );
}
}

Flat File Based WordPress

Friday, January 4th, 2008
Posted in Web Apps • Tags: ,

I ran into this the other day while browsing Scripts.com, which is much better than Hotscripts, because they have filters for the scripts so you can view only free ones or high ranking ones. The only problem is that it does that using POST (no bookmarkable filters) and resets your filter on each page load.

Anyway, back to the flat file based WordPress, it’s called Dayfox. This should be lighter weight and faster than regular WP, but its still in beta.

In case your not sure what flat file based means, it means they use text files to hold the data, rather than a real database like MySQL.

reCAPTCHA Plugin for WordPress

Monday, August 27th, 2007
Posted in Web Apps • Tags:

The reCAPTCHA plugin for WordPress is very easy to install. All you have to do is register on their site, get your keys and download the plugin. Then you just upload it, put activate it and put in your keys in WordPress. The code seems to be maintained by Carnegie Mellon University. reCAPTCHA works with JavaScript enabled or disabled, has a audio reading option and is free.
reCAPTCHA for WordPress
If you already use Akismet, this will help reduce the amount of spam you will have to moderate.

You can also change the theme that it uses, in case the default red and yellow clashes with your site.

Inside recaptcha.php look for these lines

<script type='text/javascript'>
var RecaptchaOptions = { theme : 'red', tabindex : 5 };
</script>

The only theme I know that works for sure is ‘red’ and ‘white’, they don’t seem to have a black theme yet.

WordPress Popularity Contest Plugin Review

Thursday, May 24th, 2007
Posted in Web • Tags:

I just setup the Popularity Contest plugin for WordPress. It was real simple to setup, upload it, enable it, pick your settings and put it in the sidebar or somewhere “outside the wordpress loop”. It only added 2 more queries to the home page. It seems to work well with version 2.2 also. There is an option to show the popularity of each blog on the post itself at the bottom, personally I think this is more of a debug feature (so you can figure out why something is ranking higher than something else) and not really something readers will care to see. You can also adjust the ranking weights. It has several samples of “template tags” to put in also.

Popularity Contest Options Popularity Contest Rankings Popularity Contest in the Sidebar