tags with a rel attribute of 'stylesheet' and a href attribute that points to a Google Fonts stylesheet foreach ($html->find('link[rel=stylesheet][href*=fonts.googleapis.com]') as $link) { $url = $link->href; // Generate a local filename for the stylesheet $filename = hash('sha256', $url, false); $filename = substr($filename, 0, 10) . '.css'; if (!file_exists($easyfonts_dir . '/' . $filename)) { $response = wp_remote_get($url, array('user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',)); if (is_wp_error($response)) { add_settings_error('easyfont_process_content_link_tag', 'http_error', $response->get_error_message(), 'error'); return $content; } $css = wp_remote_retrieve_body($response); if (!preg_match_all('/@font-face\s*\{([^}]+)\}/', $css, $matches)) continue; if (preg_match_all('/@font-face\s*\{([^}]+)\}/', $css, $matches)) { foreach ($matches[1] as $match) { if (preg_match_all('/src\s*:\s*([^;]+);/', $match, $srcs)) { foreach ($srcs[1] as $src) { if (preg_match('/url\(([^)]+)\)/', $src, $url_match)) { $font_url = trim($url_match[1], "'\""); $font_filename = hash('sha256', $font_url, false); $font_filename = substr($font_filename, 0, 10) . '.' . pathinfo($font_url, PATHINFO_EXTENSION); if (!file_exists($easyfonts_dir . '/' . $font_filename)) { $font_response = wp_remote_get($font_url, array('user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',)); if (is_wp_error($font_response)) { add_settings_error('easyfont_process_content_link_tag', 'http_error', $font_response->get_error_message(), 'error'); continue; } $font_data = wp_remote_retrieve_body($font_response); // Save the font file to the 'wp-content/uploads/easyfonts' directory file_put_contents($easyfonts_dir . '/' . $font_filename, $font_data); } // Replace the src property with a local reference to the downloaded font file $css = str_replace($src, "url('" . wp_upload_dir() ['baseurl'] . "/easyfonts/" . $font_filename . "')", $css); } } } } } // Save the modified stylesheet to the 'wp-content/uploads/easyfonts' directory file_put_contents($easyfonts_dir . '/' . $filename, $css); } // Replace the href attribute with a local reference to the downloaded stylesheet $link->href = wp_upload_dir() ['baseurl'] . '/easyfonts/' . $filename; } // Return the modified content return $html->save(); } function easyfont_process_content_import($content) { $html = hgfl_str_get_html($content, false, true, 'UTF-8', false, PHP_EOL, ' '); // Check if the 'easyfonts' directory exists and is writable $easyfonts_dir = wp_upload_dir() ['basedir'] . '/easyfonts'; if (!wp_mkdir_p($easyfonts_dir)) { return $content; } // Find all