| Server IP : 87.98.154.146 / Your IP : 216.73.216.165 Web Server : Apache System : Linux webm004.cluster126.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : ohklomafyi ( 52085) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/ohklomafyi/www/wp-content/plugins/wp-seopress/src/Services/Metas/ |
Upload File : |
<?php
namespace SEOPress\Services\Metas;
class GetImageInContent
{
public function getThumbnailInContentByPostId($postId) {
//Get post content
$content = get_post_field('post_content', $postId);
if(empty($content)){
return;
}
//DomDocument
$dom = new \DOMDocument();
$internalErrors = libxml_use_internal_errors(true);
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
$dom->preserveWhiteSpace = false;
if ('' != $dom->getElementsByTagName('img')) {
$images = $dom->getElementsByTagName('img');
}
if (isset($images) && ! empty($images)) {
if ($images->length >= 1) {
foreach ($images as $img) {
$url = $img->getAttribute('src');
//Exclude Base64 img
if (false === strpos($url, 'data:image/')) {
if (true === seopress_is_absolute($url)) {
//do nothing
} else {
$url = get_home_url() . $url;
}
//cleaning url
$url = htmlspecialchars(esc_attr(wp_filter_nohtml_kses($url)));
//remove query strings
$parse_url = wp_parse_url($url);
if ( ! empty($parse_url['scheme']) && ! empty($parse_url['host']) && ! empty($parse_url['path'])) {
return $parse_url['scheme'] . '://' . $parse_url['host'] . $parse_url['path'];
} else {
return $url;
}
}
}
}
}
libxml_use_internal_errors($internalErrors);
}
}