Skip to content

Instantly share code, notes, and snippets.

@hayatbiralem
Last active April 17, 2024 17:08
Show Gist options
  • Save hayatbiralem/081c2c89e7a7cb524e1d47c69d74283b to your computer and use it in GitHub Desktop.
Save hayatbiralem/081c2c89e7a7cb524e1d47c69d74283b to your computer and use it in GitHub Desktop.
WP All Export get the image urls from the post content
<?php
function reboot_remove_image_dimensions($str){
$re = '/-\d+x\d+\./m';
return preg_replace($re, '.', $str);
}
function reboot_get_content_images($id){
$p = get_post($id);
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML( $p->post_content );
$xpath = new DOMXPath($doc);
$imgs = $xpath->query("//img");
$urls = [];
for ($i=0; $i < $imgs->length; $i++) {
$img = $imgs->item($i);
$src = $img->getAttribute("src");
if(strpos($src, 'phardon.com') !== false) {
$urls[] = $src;
}
}
$concat_urls = implode('|', $urls);
return reboot_remove_image_dimensions($concat_urls);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment