protected function get_urls_from_img_src($content, &$to_cache)
{
$url_pairs = array();
if (!preg_match_all('/<img [^>]+>/', $content, $matches) || !isset($matches[0])) {
// No img tags found, return
return $url_pairs;
}
$matches = array_unique($matches[0]);
$attachment_ids = array();
foreach ($matches as $image) {
if (!preg_match('/src=\\\\?["\']+([^"\'\\\\]+)/', $image, $src) || !isset($src[1])) {
// Can't determine URL, skip
continue;
}
$url = $src[1];
if (!$this->url_needs_replacing($url)) {
// URL already correct, skip
continue;
}
if (!preg_match('/wp-image-([0-9]+)/i', $image, $class_id) || !isset($class_id[1])) {
// Can't determine ID from class, skip
continue;
}
$attachment_ids[$url] = absint($class_id[1]);
}
if (count($attachment_ids) > 1) {
/*
* Warm object cache for use with 'get_post_meta()'.
*
* To avoid making a database call for each image, a single query
* warms the object cache with the meta information for all images.
*/
update_meta_cache('post', array_unique(array_values($attachment_ids)));
}
foreach ($attachment_ids as $url => $attachment_id) {
if (!$this->attachment_id_matches_src($attachment_id, $url)) {
// Path doesn't match attachment, skip
continue;
}
$this->push_to_url_pairs($url_pairs, $attachment_id, $url, $to_cache);
}
return $url_pairs;
}