Your changes have been saved.
The fonts have been removed.
get_session_tokens();
// Add the cookies and headers to the request
$options = array(
'cookies' => $cookies,
'headers' => 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',
),
);
// Append a query string to the homepage URL to visit it as an admin
$home_url = home_url() . '?easyfonts_preload=1';
// Visit the homepage as admin to preload the fonts
wp_remote_get($home_url, $options);
}
}
function easyfonts_preload() {
$current_user = wp_get_current_user();
// Check if the user is an admin
if (user_can($current_user, 'manage_options')) {
// Get the cookies for the current user
$cookies = wp_get_current_user()->get_session_tokens();
// Add the cookies and headers to the request
$options = array(
'cookies' => $cookies,
'headers' => 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',
),
);
// Append a query string to the homepage URL to visit it as an admin
$home_url = home_url() . '?easyfonts_preload=1';
// Visit the homepage as admin to preload the fonts
wp_remote_get($home_url, $options);
}
// Display a success message
?>
The fonts have been preloaded.
isFile()) continue;
if ($file->getExtension() === 'css') {
$css_files[] = $file->getFilename();
}
}
if (!empty($css_files)) {
echo '';
echo '';
echo '';
echo '| Hosted Fonts CSS URL | ';
echo 'Font Families | ';
echo 'Variants | ';
echo '
';
echo '';
echo '';
foreach ($css_files as $file_name) {
// Prevent directory traversal
if (strpos($file_name, '..') !== false) {
continue;
}
$file_url = wp_upload_dir()['baseurl'] . '/easyfonts/' . $file_name;
$file_path = $easyfonts_dir . $file_name;
// Ensure the file is readable
if (!is_readable($file_path)) {
continue;
}
$file_content = file_get_contents($file_path);
$font_family = array();
$variant_italic = array();
$variant_normal = array();
preg_match_all("/@font-face\s*{[^}]+}/", $file_content, $matches);
if (!empty($matches[0])) {
foreach ($matches[0] as $font_face) {
if (preg_match("/font-family:\s*['\"]?([^;'\"]+)['\"]?;/", $font_face, $font_family_match)) {
$font_family[] = trim($font_family_match[1]);
}
if (preg_match("/font-style:\s*([^;]+);/", $font_face, $variant_match)) {
$style = trim($variant_match[1]);
if (preg_match("/font-weight:\s*([^;]+);/", $font_face, $weight_match)) {
$variant = trim($weight_match[1]);
if ($style === 'italic' && !in_array($variant, $variant_italic)) {
$variant_italic[] = $variant;
} elseif ($style === 'normal' && !in_array($variant, $variant_normal)) {
$variant_normal[] = $variant;
}
}
}
}
}
$font_family = array_unique($font_family);
$style_data[] = array(
'file_url' => esc_url($file_url),
'font_families' => esc_attr(implode(',', $font_family)),
'variant' => esc_html('italic ' . implode(',', $variant_italic) . ' | normal ' . implode(',', $variant_normal))
);
}
foreach ($style_data as $style) {
echo '';
echo '| ' . esc_html($style['file_url']) . ' | ';
echo '' . esc_html($style['font_families']) . ' | ';
echo '' . esc_html($style['variant']) . ' | ';
echo '
';
}
echo '';
echo '
';
} else {
if (get_option('easyfonts_host_google_fonts_locally_link', false) || get_option('easyfonts_host_google_fonts_locally_import', false)) {
echo esc_html__('Fonts styles are not found. Preload the font first or visit the homepage.', 'easyfonts');
}
}
} catch (Exception $e) {
echo '' . esc_html__('Error: ', 'easyfonts') . esc_html($e->getMessage()) . '
';
}
}