WPUInstaller/inc/base_perfs.php
2023-04-25 18:13:07 +02:00

58 lines
1.7 KiB
PHP

<?php
/*
Plugin Name: [wpuprojectname] Perfs
Description: Website perfs fixes
*/
/* ----------------------------------------------------------
Prefetch domains
---------------------------------------------------------- */
add_action('wp_head', function () {
$domains = array(
//'https://cdn.shopify.com'
);
foreach ($domains as $domain) {
echo '<link rel="preconnect" href="' . esc_url($domain) . '" />';
echo '<link rel="dns-prefetch" href="' . esc_url($domain) . '" />';
}
}, 1);
/* ----------------------------------------------------------
Disable some plugins scripts & styles
---------------------------------------------------------- */
/* Safe SVG
-------------------------- */
add_action('wp_enqueue_scripts', function () {
wp_dequeue_script('safe-svg-block-script');
wp_dequeue_style('safe-svg-block-frontend');
}, 999);
/* ----------------------------------------------------------
Cache oembeds
---------------------------------------------------------- */
/* Actions */
add_filter('pre_oembed_result', function ($content = '', $url = '', $args = array()) {
$url_hash = 'wpuprojectid_oembed_' . md5($url . json_encode($args));
// Return result if available
$cached_content = wpufilecache_get($url_hash);
if (!empty($cached_content) && !is_null($cached_content)) {
return $cached_content;
}
return $content;
}, 10, 3);
add_filter('oembed_result', function ($content = '', $url = '', $args = array()) {
$url_hash = 'wpuprojectid_oembed_' . md5($url . json_encode($args));
// Create cache
wpufilecache_set($url_hash, $content);
// Return content
return $content;
}, 10, 3);