Wednesday, 14 May 2014

Automatically spam comments with a very long url

[Wordpress hack]

Spam is definitely a problem for bloggers and most of you probably receive more than 100 spam comments per hour. Here is a simple recipe to automatically mark as spam all comments with an url longer than 50 characters.

Open your functions.php file and paste the code below in it. This code will automatically mark as spam all comments with an url longer than 50 chars. This can be changed on line 4.

function rkv_url_spamcheck( $approved , $commentdata ) {
    return ( strlen( $commentdata['comment_author_url'] ) > 50 ) ? 'spam' : $approved;
  }

  add_filter( 'pre_comment_approved', 'rkv_url_spamcheck', 99, 2 );

Automatically link Twitter usernames in WordPress

[Wordpress hack]
Are you using Twitter a lot? Today’s recipe is a cool piece of code to automatically link Twitter usernames on your posts, pages, and comments.

Paste the code below into your functions.php file:
function twtreplace($content) {
 $twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1@$2",$content);
 return $twtreplace;
}

add_filter('the_content', 'twtreplace');   
add_filter('comment_text', 'twtreplace');

WordPress 3.9.1 Released

After three weeks of WordPress 3.9 release, WordPress 3.9.1 is now available to download and update. This maintenance release fixed 34 bugs. This includes bugs fixes for multisite network, customizing widgets, and the updated TinyMCE editor. You can check the full list of tickets fixed in this blog at this link, and the changelog at this link.
Here’s a list of some major bugs fixes:
  • Fixes a bug with theme preview which empties sidebar widget on active theme. See#27897
  • Fixes PHP warnings in Customizer if theme has set a default image for custom header. See #27850
  • Fixes a bug with multisite where subdirectory install breaks if network path has uppercase letters. See #27866
  • TinyMCE now allows you to drag & drop text straight to the visual editor to paste it. See#27880
  • Fixes a bug which makes header image disappear after removing background image in Customizer. See #28046
You can download the WordPress 3.9.1 from this link, or head over to Dashboard > Updates and simply click “Update Now” button.

Sunday, 8 September 2013

Wordpress Tip: Limit Search Results to Specific Post Types

This short tutorial will show you how to limit WordPress search results to specific post types when creating WordPress sites that have multiple custom post types added. To acheive this functionality we will use the WordPress pre_get_posts filter to hook into the default WordPress search query.

Add this code below to your themes functions.php to limit your search query to the post types of Post and Page only.

function wpshock_search_filter( $query ) {
    if ( $query->is_search ) {
        $query->set( 'post_type', array('post','page') );
    }
    return $query;
}
add_filter('pre_get_posts','wpshock_search_filter');

The important part of the code above where you an add or remove post types is below.

array('post','page')


If for example you created a custom WordPress post type with the name of books and wanted this post type to be included in the search results you would alter the code like this example below.

array('post','page', 'books')

Wordpress: Completely exclude Sticky posts from the Loop

When you are displaying most recent posts in a tab, you do not want the sticky posts to stay sticky. If you do not remove the sticky feature, the recent posts area would be useless as all your sticky posts will crowd this area. This is where query_posts feature comes in handy.

To do this you will need to change your loop to something like this:

<?php
$args = array(
'posts_per_page' => 10,
'ignore_sticky_posts' => 1
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>


This code ignores that a post is sticky and shows the posts in the normal order. Using this code your sticky posts will appear in the loop, however they will not be placed on the top.

Completely exclude Sticky posts from the Loop


If you are using sticky posts in a slider, then sometimes you might want to completely exclude your sticky posts from the loop. All what you have to do is edit your custom loop to match with this:

<?php
$the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>

Sunday, 3 March 2013

[Update] List of Ping Services 2013

Ping Services (Update Services) are tools you can use to let other people know you've updated your blog. WordPress automatically notifies popular Update Services that you've updated your blog by sending a XML-RPC ping each time you create or update a post. In turn, Update Services process the ping and updates their proprietary indices with your update. Now people browsing sites like Technorati or Sphere can find your most recent posts!

http://rpc.pingomatic.com
http://rpc.twingly.com
http://api.feedster.com/ping
http://api.moreover.com/RPC2
http://api.moreover.com/ping
http://www.blogdigger.com/RPC2
http://www.blogshares.com/rpc.php
http://www.blogsnow.com/ping
http://www.blogstreet.com/xrbin/xmlrpc.cgi
http://bulkfeeds.net/rpc
http://www.newsisfree.com/xmlrpctest.php
http://ping.blo.gs/
http://ping.feedburner.com
http://ping.syndic8.com/xmlrpc.php
http://ping.weblogalot.com/rpc.php
http://rpc.blogrolling.com/pinger/
http://rpc.technorati.com/rpc/ping
http://rpc.weblogs.com/RPC2
http://www.feedsubmitter.com
http://blo.gs/ping.php
http://www.pingerati.net
http://www.pingmyblog.com
http://geourl.org/ping
http://ipings.com
http://www.weblogalot.com/ping

Thursday, 24 January 2013

Wordpress Update: 3.5.1 Maintenance and Security Release

WordPress 3.5.1 is now available. Version 3.5.1 is the first maintenance release of 3.5, fixing 37 bugs. It is also a security release for all previous WordPress versions. For a full list of changes, consult the list of tickets and the changelog, which include:

  •     Editor: Prevent certain HTML elements from being unexpectedly removed or modified in rare cases.
  •     Media: Fix a collection of minor workflow and compatibility issues in the new media manager.
  •     Networks: Suggest proper rewrite rules when creating a new network.
  •     Prevent scheduled posts from being stripped of certain HTML, such as video embeds, when they are published.
  •     Work around some misconfigurations that may have caused some JavaScript in the WordPress admin area to fail.
  •     Suppress some warnings that could occur when a plugin misused the database or user APIs.

Additionally, a bug affecting Windows servers running IIS can prevent updating from 3.5 to 3.5.1. If you receive the error “Destination directory for file streaming does not exist or is not writable,” you will need to follow the steps outlined on the Codex.

WordPress 3.5.1 also addresses the following security issues:

  •     A server-side request forgery vulnerability and remote port scanning using pingbacks. This vulnerability, which could potentially be used to expose information and compromise a site, affects all previous WordPress versions. This was fixed by the WordPress security team. We’d like to thank security researchers Gennady Kovshenin and Ryan Dewhurst for reviewing our work.
  •     Two instances of cross-site scripting via shortcodes and post content. These issues were discovered by Jon Cave of the WordPress security team.
  •     A cross-site scripting vulnerability in the external library Plupload. Thanks to the Moxiecode team for working with us on this, and for releasing Plupload 1.5.5 to address this issue.