WordPress 3.4.1 upgrade stopped Media Library working

I recently upgraded one of my WordPress websites to version 3.4.1. As soon as I did this I started experiencing issues with my media library.

Whenever I uploaded an image to the library I would be hit with a 404 error. I also got the same when I tried inserting an image into a post.

I searched the net extensively and tried many possible fixes but none of them worked. I tried altering my .htacces file (http://wordpress.org/support/topic/file-upload-link-error-404), I tried re uploading my wp-admin and wp-includes folders. I made sure my permissions were correct for the uploads folder and also the wp-content folder. I switched to the WordPress TwentyEleven theme but still the same issue was there. I even created a new site on the same host and was experiencing the same issue so decided it was something to do with my host.

I contacted my hosting company and explained the problem to them and with a couple minutes they had rectified the issue. Apparently the mod_security module was causing the conflict. They disabled it and just like that my site was working again.

A lot of the blog posts I found while searching for this had said that it was something to do with mod_security but none of the things I added to the .htaccess file seemed to be effective. 

I hope this helps someone having the same I had.

Exclude Featured image from WordPress gallery

I needed to add the default wordpress gallery to page with a featured image but found that the featured image was also included in this gallery.

The best way I found to exclude this is to add the code below to your site

function exclude_thumbnail_from_gallery($null, $attr)
    if (!$thumbnail_ID = get_post_thumbnail_id())
        return $null; // no point carrying on if no thumbnail ID
    // temporarily remove the filter, otherwise endless loop!
    remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
    // pop in our excluded thumbnail
    if (!isset($attr['exclude']) || empty($attr['exclude']))
        $attr['exclude'] = array($thumbnail_ID);
    elseif (is_array($attr['exclude']))
        $attr['exclude'][] = $thumbnail_ID;
    // now manually invoke the shortcode handler
    $gallery = gallery_shortcode($attr);
    // add the filter back
    add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
    // return output to the calling instance of gallery_shortcode()
    return $gallery;
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);

I found this solution here: http://stackoverflow.com/a/4347635. Its an old post but still works.

WordPress site redirects to costabrava.bee.pl

I have just finished cleaning a wordpress website that had been hacked. The site would redirect to costabrava.bee.pl which is a malicious website.

Due to this Google began showing a warning page whenever someone navigates to that site, informing them that the site is infected.

I had to go through the site and locate all of the instances of code that looked like this:


This code had been inserted in lots of the files on the site. It can be very time consuming to find the offending files. I cleaned the site by using Adobe Dreamweaver, downloading the whole site, including all the WordPress files, not just the theme files and ran a Find All for “eval” on the entire local site. From there I could see all the files that had the offending code and I was able to delete them and re-upload the cleaned file.

Obviously, cleaning the site isn’t the only thing that needs to be done, change all your passwords for the site and ensure they are very secure. Also make sure your WordPress is up-to-date and any plugins you are using.

Some images return 404 error on wordpress site

I recently ran into an issue on a wordpress site I maintain. Images randomly stopped showing up on the site.
On further investigation I found that the images were just returning a 404 error.
After some searching the internet, I came across this article which basically said that it had something to do with the plugin ‘User Access Manager’.
The plugin adds a .htaccess file to the wp-content/uploads folder which stopped images being retrieved correctly.
The .htaccess file contains the following code

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) /index.php?uamfiletype=attachment&uamgetfile=$1 [L]
 Scroll to top