Changing the case of the paths without changing the file names themselves could break your links, depending on the server and its configuration.
But to get to the question directly, you may be able to do this with SQL using MySQL's REPLACE
and LOWER
, but I would advise against it. MySQL has some regex functionality but not much. PHP's regex is better by far.
Pull your posts, loop over them, and fix the links. Run something like this:
function replace_cb($matches) {
if (!empty($matches[1])) {
return 'src="'.strtolower($matches[1]).'"';
} else {
return $matches[0];
}
}
function reset_paths() {
global $wpdb;
// debug using a specific post ID
// $posts = $wpdb->get_results("SELECT ID,post_content FROM {$wpdb->posts} WHERE ID = 128");
// remove the where for a real run over all posts
$posts = $wpdb->get_results("SELECT ID,post_content FROM {$wpdb->posts}");
$pattern = '|src="([^"]+)"|';
foreach ($posts as $p) {
define( 'DOING_AUTOSAVE', true );
$p->post_content = preg_replace_callback($pattern,'replace_cb',$p->post_content);
wp_update_post($p);
}
}
reset_paths(); // run the function
reset_paths();
beneath the function definition is what triggers it-- what actually runs the function.
But make a backup and test that thoroughly on a dev server with disposable data before you try it in production.
If you have a lot of posts you may have timeout or memory issues so watch that. If you do have problems you will have to run the function incrementally.
The assumption is that your markup is consistent. That will now replace image `URL's where the attribute is surrounded by single quotes.