- run
wp --allow-root db query "select post_content from wp_posts where post_content like '%<img src%';" --skip-column-names --silent | grep -oP "<img\s+.*?src=['\"](.*?)['\"].*?>" | grep -oP "https?://[^\"]*" | sort | uniq
- using
parse_url()
, create a PHP function* to find unique hosts and add first occurence of each to an array of links. - Itterate through new list of links and run through a CURL function** to determine
- Add links with 200-300 status to an array
- Produce Search & Replace script based of returned values
** Gather assets by unique host name
function get_assets_by_unique_host( $links = [] ) {
$temp = [];
$links = [];
foreach ( $links as $link ) {
$parsed = parse_url( $link );
$host = $parsed['host'];
if ( ! in_array( $host, $temp ) ) {
array_push( $temp, $host );
array_push( $links, $link );
}
}
unset( $temp );
return $links;
}
** Get Status via CURL
function get_status( $ur l) {
$c = curl_init();
curl_setopt( $c, CURLOPT_CONNECTTIMEOUT , 5);
curl_setopt( $c, CURLOPT_TIMEOUT, 30 ); //timeout in seconds
curl_setopt( $c, CURLOPT_HEADER, true );
curl_setopt( $c, CURLOPT_NOBODY, true );
curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $c, CURLOPT_SSL_VERIFYHOST, true );
curl_setopt( $c, CURLOPT_URL, $url);
curl_exec( $c );
$status = curl_getinfo( $c, CURLINFO_HTTP_CODE );
curl_close($c);
return $status;
}
because I'm a crazy person