]+src=["|\']([^"|\']+)["|\']/i';
$srcset_pattern = '/
]+srcset=["|\']([^"|\']+)["|\']/i';
$sizes_pattern = '/
]+sizes=["|\']([^"|\']+)["|\']/i';
if ( preg_match( $src_pattern, $tag, $matches ) ) {
$src = $matches[1];
}
if ( preg_match( $srcset_pattern, $tag, $matches ) ) {
$srcset = $matches[1];
}
if ( preg_match( $sizes_pattern, $tag, $matches ) ) {
$sizes = $matches[1];
}
if ( OPTML_DEBUG ) {
do_action(
'optml_log',
'preload_tag: ' . print_r(
[
'url' => $src,
'srcset' => $srcset,
'sizes' => $sizes,
'priority' => $priority,
],
true
) . ' ' . $priority
);
}
// Add the preload link to the links array
self::add_link(
[
'url' => $src,
'srcset' => $srcset,
'sizes' => $sizes,
'priority' => $priority,
]
);
}
/**
* Get the links.
*
* @return array The links.
*/
public static function get_links(): array {
return self::$links;
}
/**
* Get the links count.
*
* @return int The links count.
*/
public static function get_links_count(): int {
return count( self::$links );
}
/**
* Get the links html.
*
* @return string The links html.
*/
public static function get_links_html(): string {
// generate image preload links for all links
$links = [];
foreach ( self::$links as $link ) {
$url = esc_url( $link['url'] );
if ( empty( $url ) ) {
continue;
}
$preload = '= self::MAX_LINKS ) {
break;
}
$links[] = $preload;
}
return implode( "\n", $links ) . "\n";
}
}