Tips & Tricks
WordPress Security Hacks
Hi guys this is my first post on wpcult the great site Austin built. Hope you guys find it usefull.
If you run a blog using the wordpress software then your blog is a target to hackers. Below I will list some hacks and just how they can help you keep your business/site safe.
The following is code to Block Bad Queries and protect your blog from malicious URL Requests.
Place the following code into a text file and name it what ever you like for example blockbadqueries.php upload it to your plugin folder and activate it in your wordpress admin just as you would any other Plugin
<?php
/*
Plugin Name: Block Bad Queries
Plugin URI: http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/
Description: Protect WordPress Against Malicious URL Requests
Author URI: http://perishablepress.com/
Author: Perishable Press
Version: 1.0
*/
global $user_ID; if($user_ID) {
if(!current_user_can(‘level_10’)) {
if (strlen($_SERVER[‘REQUEST_URI’]) > 255 ||
strpos($_SERVER[‘REQUEST_URI’], “eval(“) ||
strpos($_SERVER[‘REQUEST_URI’], “CONCAT”) ||
strpos($_SERVER[‘REQUEST_URI’], “UNION+SELECT”) ||
strpos($_SERVER[‘REQUEST_URI’], “base64”)) {
@header(“HTTP/1.1 414 Request-URI Too Long”);
@header(“Status: 414 Request-URI Too Long”);
@header(“Connection: Close”);
@exit;
}
}
}
?>
This Great plugin was made by Jeff Starr of Digging into WordPress
Protecting your blog with .htaccess
.htaccess files have lots of possibilities. below is some code that will help protect your wordpress from modification of _REQUEST and/or GLOBALS and scripts injection.
This is real simple just paste the following code into your .htaccess file. Always make a backup of your .htaccess before editing, better to be safe.
Options +FollowSymLinks RewriteEngine On RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR] RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) RewriteRule ^(.*)$ index.php [F,L]
Thanks to Oussama for this great hack
Tips & Tricks
Can′t add pagination on WooThemes Thick Theme
Everything I have tried has led to nothing. And I have tried six way’s from Sunday to get my main posts to paginate.
example one:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('offset=1&showposts=' . get_option('woo_other_entries') . '&cat=-' . $GLOBALS['ex_asides'] . '&paged=$paged' ); ?>
example two:
<?php global $myOffset; global $wp_query; $myOffset = 1; $paged = intval(get_query_var('paged')) ? get_query_var('paged') : 1; $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(array( 'offset' => $myOffset, 'category__not_in' => array($GLOBALS['ex_asides'],7,84), 'paged' => $paged, 'showposts' => get_option('woo_other_entries'), )); ?>
example three:
<?php global $myOffset; $myOffset = 1; $wp_query = new WP_Query(); $wp_query->query(array( 'offset' => $myOffset, 'category__not_in' => array($GLOBALS['ex_asides'],7,84), 'paged' => $paged, 'showposts' => get_option('woo_other_entries'), )); ?>
And after those tries, I just can’t get more pages beyond the option’s that I choose, and can only pull an archive via the browse more link.
Any suggestions or anything?
Tips & Tricks
Pulling custom fields from outside the loop
In the last post “Creating a custom widget” I showed you how to create a custom widget. Well in this post I will show you how I used my custom widget to display all post with a certain custom field from outside the WordPress loop.
In the last post I used this tag:
<?php include(TEMPLATEPATH . '/includes/showcase.php'); ?>
Now I will show you what the file showcase.php
has:
<ul> <?php global $wpdb; $sql = "SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'gallery-url' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wposts.post_date DESC LIMIT 8"; $pageposts = $wpdb->get_results($sql, OBJECT); $output = $pre_HTML; foreach ($pageposts as $post) : setup_postdata($post); ?> <li><a href="<?php echo get_post_meta($post->ID, "gallery-url", $single = true); ?>" title="Link to <?php the_title(); ?>"> <img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" alt="<?php the_title(); ?>" /></a></li> <?php endforeach; ?> </ul>
That’s it! The most important item you may want to change for your own custom field is the line : AND wpostmeta.meta_key = 'gallery-url'
. Where you would change the text in bold to match your own custom field value.
Update:
Check out Austin from PressedWords comment below.
With his great advise I was able to figure out why all my attempts to use the query_post weren’t working. it came down to this line of code: <?php echo get_post_meta($post->ID, "gallery-url", $single = true); ?>
, that was what I had in my code, and the $post->ID
is the reason my code would not echo or print the custom field’s value. Solution? replace $post->ID
with get_the_ID()
. HA, so simple.
Tips & Tricks
Creating a custom widget
Today let’s learn a simple quick trick on how to create a custom widget. For my example I will show you how I created my Showcase widget located in the middle, to the right of the posts.
First under your functions.php
file type in the following:
<?php // Custom Widget function MyCustomWidget() { ?> <li class="widget"> <h2 class="heading">Latest Showcase</h2> <ul> <?php include(TEMPLATEPATH . '/includes/showcase.php'); ?> </ul> </li> <?php } register_sidebar_widget('The Custom Widget for Showcase', 'MyCustomWidget'); ?>
- Always make sure your code is between the
<?php
and?>
for it to work. - Once we call the function, the rest is assuming html code that you may or may not need.
- For instance, you may just put in a picture and call it a day. But my code starts with
<li<
because my sidebar’s start and end with<ul<
. - Any way, once your done, just set the final “
register_sidebar_widget('the widget title', 'the name of the function');
“
That’s it! Now you have a custom widget with what ever you want!
-
Pages5 months ago
Write For Us – Guest Post
-
Showcase4 hours ago
StylizedWeb.com
-
News5 months ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks4 months ago
Remove the title attribute using jQuery
-
Tips & Tricks1 month ago
How to: show/hide a widget in WordPress with jQuery
-
Plugins1 month ago
Top Membership plugins
-
Tips & Tricks5 months ago
Limit the characters that display on the_title
-
Tips & Tricks3 months ago
Remove spaces when echoing the_title
Tina @ Female Hair Transplant
September 2, 2010 at 3:02 am
For a first time post the article is lucid and very useful.
Oliver Mack
September 5, 2010 at 4:49 pm
Thanks for sharing this tip with us, it is very helpful, running online businesses we have to consider taking precautions procedures in order to work safer.
landscape prints
September 12, 2010 at 4:51 am
It’s not a very secure place, the internet, is it?! I can’t believe how much trouble I have to go to as a blogger to ensure everything is a) working and b) secure!
Ah well!
Henri Labelle
September 13, 2010 at 8:05 am
Thanks for the information! I’ll secure my blog right now!
Great blog by the way 🙂
Taylor
September 17, 2010 at 4:44 pm
Great job on your first post!
budi wadud
September 17, 2010 at 10:52 pm
nice blogg , I Learn and I’ve read, this is a good news, the boss ……… may be an invaluable experience and additional knowledge for me, as well as an introduction from me and thank you
SBI Websites
September 18, 2010 at 9:09 pm
GREAT POST! Seriously.. I recently had a few sites down due to very similar issues. I think it was automated SQL Injections from the looks of things.. Anyhow – strong first post and good information to boot.
Magento ecommerce
September 21, 2010 at 11:30 pm
Thanks for that very useful information. I was looking for some security method for my blog ever since I started my blog. I think my search has come to an end now. I will surely try this.
Translation Agency
September 23, 2010 at 3:11 am
Congrats on becoming a new site owner! And thanks for the great first post 🙂
Werbeagentur Bodensee
September 23, 2010 at 6:15 am
Thanks for sharing these tips. We are setting up a blog right now and I was concerned about security issues. Really helpful!
Regards
Fabian
Debra
September 23, 2010 at 6:26 am
Thanks for that! I always appreciate not having to upload another plugin
Powerfull by UspLabs
September 23, 2010 at 11:48 am
That seems like that code will work and doesn’t look to complicated to install. Thank you!
jocuri
September 24, 2010 at 3:36 am
I have some problems with my wordpress .. I hope this plugin is ok
Chris Wheeler
September 25, 2010 at 5:07 am
Nice first blog post. Internet security in general is often overlooked as unneccesary. This is a fatal mistake, and WordPress users can fall foul of prey!
fantasy books
September 25, 2010 at 10:54 pm
More people need to know how to configure their .htaccess files. As a matter of fact, I just compared your recommended settings to my own – I need to make a few tweaks. Thanks for the informative article.
Opal
September 30, 2010 at 9:24 pm
Wow.. useful to know, I had no idea that there was this kind of issue with WP. I once had a script injection attack on a regular html web site I was running, and my web host gave me a javascript to put in the site which would protect it from those kinds of events in the future. I don’t quite understand all the terms you use – what’s a ‘malicious URL request’? Is that an automated request sent by a bot?
Kizie
October 11, 2010 at 7:59 am
Thanks for advice I used your practine on my page.
peter
October 13, 2010 at 6:36 am
Its really so alarming for those like me having their blogs in the wordpress, I wonder why everyone is saying thanks to you in their comments, are these all hackers?
joe brown
October 14, 2010 at 2:01 am
You have written very well in your post. Good job.
Vin Diesel
October 21, 2010 at 1:12 am
This is something dangerous and can be very harmful for the wordpress users. I think wordpress should be careful about it otherwise it can have serious security problem.
TheAffairLady
October 27, 2010 at 8:16 am
I’m constantly worried about securing my wordpress. I use the bad behavior plugin which I think is similar to the plugin in your post. I see hack attempts in my log files all the time but so far I think so good.
cricket broadband
October 28, 2010 at 2:35 am
Your post is very useful to me. Many thanks to you!
Management Consulting Firm
October 29, 2010 at 11:18 am
Hi nice information for the word press and thanks for sharing WordPress Security Hacks system.
WhatLiveToday
November 6, 2010 at 1:30 am
Good post .. I like this article, very useful for me .. if you have a little time, you can visit my website.. thanks for sharing .. 🙂
Vetement Grossesse
November 9, 2010 at 1:37 am
WordPress needs no introduction because it is currently creating lots of waves on the internet at the moment. Some people had gotten their fingers burnt by activities of some online criminals that specialize in stealing information that are in other peoples’ sites and blogs.
creare site
November 9, 2010 at 3:53 am
You must have the latest version of WordPress if you want to be protected. This plugin seems to be very easy to use. However I prefer the protection made from the .htaccess file, exactly like in this tutorial.
u10
November 19, 2010 at 4:10 am
well thats looks good u10 article to read, but anyway i like it as much as u10 games
Britt Phillips
November 20, 2010 at 8:47 am
Great useful WordPress blog information. WordPress security is something every blog owner should be aware of and NOT take lightly.
Jim
November 28, 2010 at 2:09 am
Good information on how to make a blog more secure. Thanks.
Anite @ learn cloud living
November 28, 2010 at 3:00 pm
I will add this protection for my blogs. It’s been awhile since you wrote your first blog… hope you will come back and write some more useful information!
Why My Country Sucks
December 6, 2010 at 11:03 pm
wow, I shall give wordpress a second look before I continue building my site!!
Bold Reports
December 7, 2010 at 4:54 am
I will follow the instruction written here. They are awesome and much needed for newbie’s like me
jocuri cu bile
December 9, 2010 at 3:22 am
GREAT POST! Seriously.. I recently had a few sites down due to very similar issues.
Apple
December 9, 2010 at 4:29 am
Hey thanks for this post. It’s been helpful and enjoyable to read. Great work. Keep posting.
web development
December 13, 2010 at 9:47 pm
i was looking for such type of informative news and i get it through your blog so i am very much thankful to you for sharing.
web development
December 13, 2010 at 10:05 pm
really very nice information sharing and i am looking for such type of informative news and i get through this blog so i am very much thankful to you.
Shailender from India Darshan
December 15, 2010 at 12:31 am
Many wordpress user would be benefited from this post. Good information is shared in the first blog…Keep it up.
Optometrist Reno NV
December 21, 2010 at 4:44 pm
Yikes! Good to know…
Worlds Headlines
December 27, 2010 at 5:20 am
Thanks I have a wordpress blog and I do not want it to be hacked. Really nice and thanks for your kind help.
SamiParker
December 29, 2010 at 6:24 am
Its really a pleasure to be here at this site. I feel like visiting it again and again. samiparker09@gmail.com
Alert 1
January 6, 2011 at 8:31 am
You state that this code is to “block bad queries”. What exactly does that mean? How do you define a “bad query”?
Sami Parker
January 6, 2011 at 10:01 am
Well its really a wonderful and sort of unique one, I like the way it has shown the things, its really nice. Thanks a lot for sharing it. I would love to recommend it to others.
Finally Fast
January 7, 2011 at 1:39 pm
Thank you for the useful information. I will use this method to secure my blog!
Pferdehaftpflicht
January 11, 2011 at 9:02 am
nice blogg (Pferdehaftpflicht) , I Learn and I’ve read, this is a good news, the boss ……… may be an invaluable experience and additional knowledge for me, as well as an introduction from me and thank you
Jetski
January 12, 2011 at 7:35 am
Congrats on becoming a new site owner! And thanks for the great first post 🙂
Uzair
January 12, 2011 at 9:43 am
Nic post thanks for sharing
Web Design Preston
January 12, 2011 at 11:23 am
I know this thread is getting old now but WordPress hacking is still a real issue. We have a large number of sites built on WordPress and many of them have been hacked as recent as the last 2 weeks. Real bad hacks as well with the database wiped and everything. It’s a pain because WordPress is such a great platform to use and very popular with our clients – they love the easy CMS. Wish we could fix WordPress hacking once and for all…!
Daniel @ PHP Programmer Philippines
January 13, 2011 at 8:09 am
Thanks for sharing this, i just used the .htaccess method to protect my wordpress blog, I was searching for a way to protect my blog from hackers and i got into this page. 🙂
Regards,
Daniel
E Learning Online
January 27, 2011 at 4:32 am
Miguel
Thanks, I will look at the second option
I am using these plugins on my blogs:
Firewall
Block Bad Queries (!) using it already
Chap Secure Login
highly recommended
thanks
Jack
Vienna Souvenirs
January 27, 2011 at 11:21 pm
I recently came across your blog and have been reading along. I thought I would leave
my first comment. I don’t know what to say except that I have enjoyed reading. Nice
blog, I will keep visiting this blog very often. Take a piece of Vienna back to your home