Auch wenn es meines Erachtens kein Mensch braucht, hier ein kleines Script, dass die Google Fonts aus dem wp_head parsed, auf den Server lädt und dann von dort aus der „betroffenen Person“ liefert. Damit musst du nicht selber das ganze Prozedere durchmachen und, was eigentlich das Blöde ist, es aus dem Theme rausnehmen.

Keine Gewähr, kein irgendwas, ist ein Proove of Concept, denn ich weiß nicht mal, ob man das laut Google überhaupt so machen darf 😛

Erwähnungen wären nett 😉

Direkter Download für den Upload bei den WP-Plugins

 

<?php

/**
 * @package Rent-a-Ninja DSGVO Google Fonts WordPress Fix
 * @version 1.0
 */
/*
Plugin Name: DSGVO Google Fonts WordPress Fix
Plugin URI: https://archive.rent-a-ninja.org/
Description: Dies ist eine vereinfachte Variante, die Google Fonts "lokal" auf den Server lädt und der betroffenen Person die Fonts  nicht über Google bereitstellt.
Author: Alexander Herzog
Version: 1.1
License: Nimm es wie es ist, wenn was hin werden sollte (was ich mir nicht vorstellen kann) dann ist das nicht mein Problem. Es kostet nix, aber du darfst den Source nicht als deinen ausgeben.
Author URI:https://archive.rent-a-ninja.org/
*/

function start_wp_head_buffer() {
        ob_start();
}
add_action('wp_head','start_wp_head_buffer',0);

function end_wp_head_buffer() {
        $in = ob_get_clean();
        if(preg_match_all('/https:\/\/fonts.googleapis.com\/[^\'"]*/', $in, $matches)) {
            foreach($matches[0] as $match) {
                $key = md5($match . '@'. $_SERVER['HTTP_USER_AGENT']);
                $targetdir = WP_CONTENT_DIR . '/cache/gfonts/';
                wp_mkdir_p($targetdir);
                $targetfile = $targetdir.$key.'.css';
                if (!file_exists($targetfile)) {
                        $opts = array('http' =>
                                array(
                                        'method'  => 'GET',
                                        'user_agent'  =>  $_SERVER['HTTP_USER_AGENT']
                                )
                        );
                        $context  = stream_context_create($opts);
                        $gfontdata = file_get_contents($match, false, $context);
                        preg_match_all('/https:\/\/[^)]*/', $gfontdata, $fontmatches);
                        foreach($fontmatches[0] as $fontmatch) {
                                $fontfile = $targetdir . basename($fontmatch);
                                if (!file_exists($fontfile)) {
                                        file_put_contents($fontfile, file_get_contents($fontmatch));
                                }
                                $fontfileurl = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $fontfile);
                                $gfontdata = str_replace($fontmatch, $fontfileurl, $gfontdata);
                        }
                        file_put_contents($targetfile, $gfontdata);
                }
                $fontscss = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $targetfile);
                $in = str_replace($match, $fontscss, $in);
            }
        }
        echo $in;
}
add_action('wp_head','end_wp_head_buffer', PHP_INT_MAX);
Programming PHP Entwicklung Google Fonts DSGVO Plugin für WordPress und jedes Theme
%d Bloggern gefällt das: