Identify mass uploads of the same file in WordPress

Been hit by the WPML – WP 4.0 bug (Mostly caused by Media translation) and stuck with MANY corrupted uploads in your database? And having massive amounts of duplicate images?

Note: this assumes you have the wp_ DB table prefix
This will identify file uploads with the same filename, having over 300 uploads in the same second

Warning: Make a database backup first!

Query to identify the uploads:

Code:
 SELECT * FROM `wp_posts` WHERE
 ID IN (SELECT ID FROM
 (SELECT post_title, post_modified, count(post_title) AS ttlcount FROM `wp_posts` 
WHERE `post_type` = 'attachment' 
AND post_name LIKE('%-2-%') group by post_title, post_modified HAVING ttlcount > 300)
 AS SUB1
 )
 AND
 post_modified IN (SELECT post_modified FROM
 (SELECT post_title, post_modified, count(post_title) AS ttlcount FROM `wp_posts` 
WHERE `post_type` = 'attachment' 
AND post_name LIKE('%-2-%') group by post_title, post_modified HAVING ttlcount > 300)
 AS SUB2
 )
AND
 `post_type` = 'attachment'
 AND
 post_name LIKE('%-2-%')

Query to mark the uploads as deleted
Note: They will not be auto-deleted as that also needs an insert into the postmeta table. They are kept and there for you to restore.

Code:
 UPDATE wp_posts SET post_status = 'trash', post_type = 'attachment_trash'
 WHERE
 ID IN (SELECT ID FROM
 (SELECT post_title, post_modified, count(post_title) AS ttlcount FROM `wp_posts` 
WHERE `post_type` = 'attachment' 
AND post_name LIKE('%-2-%') group by post_title, post_modified HAVING ttlcount > 300)
 AS SUB1
 )
 AND
 post_modified IN (SELECT post_modified FROM
 (SELECT post_title, post_modified, count(post_title) AS ttlcount FROM `wp_posts` 
WHERE `post_type` = 'attachment' 
AND post_name LIKE('%-2-%') group by post_title, post_modified HAVING ttlcount > 300)
 AS SUB2
 )
AND
 `post_type` = 'attachment'
 AND
 post_name LIKE('%-2-%')

Fix to make NextGen Gallery work again using the theme Interio by Tohid Golkar

/**
*Fix to make NGG work again using the theme Interio by Tohid Golkar
*/
function mp_ngg($out) {
if(strpos($out,'ngg') !== false) {
remove_action( 'wp_footer', 'interio_lightbox',99 );
}
return $out;
}
add_filter('the_content', 'mp_ngg',99);


Login LockDown and Varnish

Seeing "Too much IP attempts" but it wasn't you?

 

Add this to your wp-config.php

 

if ( isset( $_SERVER[ "HTTP_X_FORWARDED_FOR" ] ) ) {
$_SERVER[ 'REMOTE_ADDR' ] = $_SERVER[ "HTTP_X_FORWARDED_FOR" ];
}


A thing or two you need to know about Genesis breadcrumbs

This PHP code should do all the talking ..

if ( function_exists( 'bcn_display' ) ) {
echo '<div class="breadcrumb" itemprop="breadcrumb">';
bcn_display();
echo '</div>';
}
elseif ( function_exists( 'yoast_breadcrumb' ) ) {
yoast_breadcrumb( '<div class="breadcrumb">', '</div>' );
}
elseif ( function_exists( 'breadcrumbs' ) ) {
breadcrumbs();
}
elseif ( function_exists( 'crumbs' ) ) {
crumbs();
}
else {
genesis_breadcrumb();
}

Meaning .. there are many functions that may or may not display breadcrumbs. In our case the client had enabled Genesis breadcrumbs and used Yoast SEO plugin. The only problem was .. Yoast's breadcrumb settings were set to OFF, resulting in non functional breadcrumbtrails ..


GravityForms field translations

Using Gravityforms ? Nice !

GravityForms itself can be translated, see for instance http://wordpress.org/plugins/gravityforms-nl/
(more…)


Removing a plugin, but only on frontend

Do you have a plugin that is heavy or unneccesary on the frontend?

Use this mu-plugin code to stop this plugin from loading on your website ( it will still be working on your wp-admin backend ! )

This example stops 1 plugin from loading, feel free to adjust the $remove_plugins array according to your needs.

<?php
/**
* @author: Ramon Fincken, MijnPress.nl RamonFincken.com
* http://www.mijnpress.nl/2014/removing-a-plugin-but-only-on-frontend
*/

// Remove plugins from frontend, this may not work on multisite
function remove_plugins_frontend($plugins)
{
$remove_plugins = array('simple-add-pages-or-posts/simple_add_pages_or_posts.php');

if(is_array($remove_plugins) && count($remove_plugins) > 0)
{
foreach($remove_plugins as $del_val)
{

if(($key = array_search($del_val, $plugins)) !== false) {
unset($plugins[$key]);
}
}
}

return $plugins;
}
if(!is_admin())
{
add_filter('option_active_plugins','remove_plugins_frontend');
}
?>


Uploads by proxy – 302 redirect instead of force download to local directory

I stumbled upon http://wordpress.org/plugins/uploads-by-proxy/ a great plugin to fetch remote uploads from your live server when using a staging/dev/local server.

However .. it will fetch all files to your development uploads dir. This may be not suitable for everyone as it needs storage.

The default year 2017 version will also do a host/ip lookup, this patch/version will bypass that as it is not needed anymore.

 

Version 1.1.2 (year 2017) instructions

DIY

Download (or clone) this repo: https://github.com/ramonfincken/uploads-by-proxy/tree/feature/redirect_instead_of_download

DIY

Define the following in your wp-config.php to 302 to the source instead of downloading the uploads.

define('UBP_REDIRECT', true);

 

 

Year 2013 instructions

Here is a "patch" to allow a 302 (temp redirect) to the source image.

OPEN
class-404-template.php

FIND

		$url = 'http://' . $ip . $this->get_remote_path();

AFTER, ADD

		// Redirect to original url?
		// Ramon Fincken, MijnPress.nl
		if(defined('UBP_REDIRECT') && UBP_REDIRECT == TRUE)
		{
			$redirect_url = UBP_SITEURL.$this->get_remote_path();
			wp_redirect( $redirect_url, 302 );
			exit;
		}
		// Falltrough to download file to local storage

DIY

Define the following in your wp-config.php to 302 to the source instead of downloading the uploads.

define('UBP_REDIRECT', true);


Has_post_thumbnail() fix for non existing files

Having problems with missing files/attachments?

When calling has_post_thumbnail() WP will return TRUE if a meta value is set, but this function does NOT check the fysical presence/availability of the attachment file.

To avoid this, swap the function call for the following code:

wp_get_attachment_url((get_post_thumbnail_id()))

this will return the string path of the file OR nothing.


GravityForms Euro teken aan de goede kant

Gravityforms heeft de vreemde afwijking het euro teken aan de verkeerde kant te zetten, de volgende code lost dit probleem op:

add_filter("gform_currencies", "mp_update_currency");
function mp_update_currency($currencies) {
$currencies['EUR'] = array("name" => __("Euro", "gravityforms"), "symbol_left" => "&#8364;", "symbol_right" => "", "symbol_padding" => " ", "thousand_separator" => '.', "decimal_separator" => ',', "decimals" => 2);
return $currencies;
}


Mollie Ideal payment fix for Shopp 1.2.x

If you have the Ideal payment gateway for Shopp you encounter that even if paid, .. the order status does not change to paid and an error is shown to the end user.

Browsing the web, the answer is to apply this fix:

http://ivaldi.nl/2012/03/mollie-laten-werken-met-shopp-1-2/


Samenwerken doen we graag!

We werken graag op freelance basis. Ook voor andere web-bureau's en ontwikkelaars.
En dat mag ook op whitelabel basis. Doen we niet moeilijk over.

Bekijk de informatie pagina.