font management fixes
This commit is contained in:
parent
847ed92c23
commit
d5ecb31dad
8 changed files with 728 additions and 99 deletions
|
|
@ -19,12 +19,14 @@ class MLF_Font_Registry {
|
|||
/**
|
||||
* Register a font family with WordPress Font Library.
|
||||
*
|
||||
* @param string $font_name Display name (e.g., "Open Sans").
|
||||
* @param string $font_slug Slug (e.g., "open-sans").
|
||||
* @param array $files Array of downloaded file data.
|
||||
* @param string $font_name Display name (e.g., "Open Sans").
|
||||
* @param string $font_slug Slug (e.g., "open-sans").
|
||||
* @param array $files Array of downloaded file data.
|
||||
* @param string $font_version Google Fonts version (e.g., "v35").
|
||||
* @param string $last_modified Google Fonts last modified date.
|
||||
* @return int|WP_Error Font family post ID or error.
|
||||
*/
|
||||
public function register_font($font_name, $font_slug, $files) {
|
||||
public function register_font($font_name, $font_slug, $files, $font_version = '', $last_modified = '') {
|
||||
// Check if font already exists
|
||||
$existing = get_posts([
|
||||
'post_type' => 'wp_font_family',
|
||||
|
|
@ -88,6 +90,14 @@ class MLF_Font_Registry {
|
|||
update_post_meta($family_id, '_mlf_imported', '1');
|
||||
update_post_meta($family_id, '_mlf_import_date', current_time('mysql'));
|
||||
|
||||
// Store version info for update checking
|
||||
if (!empty($font_version)) {
|
||||
update_post_meta($family_id, '_mlf_font_version', $font_version);
|
||||
}
|
||||
if (!empty($last_modified)) {
|
||||
update_post_meta($family_id, '_mlf_font_last_modified', $last_modified);
|
||||
}
|
||||
|
||||
// Create font face posts (children) - WordPress also reads these
|
||||
foreach ($files as $file) {
|
||||
$filename = basename($file['path']);
|
||||
|
|
@ -190,6 +200,11 @@ class MLF_Font_Registry {
|
|||
delete_transient('global_styles');
|
||||
delete_transient('global_styles_' . get_stylesheet());
|
||||
|
||||
// Clear WP_Theme_JSON caches
|
||||
if (class_exists('WP_Theme_JSON_Resolver')) {
|
||||
WP_Theme_JSON_Resolver::clean_cached_data();
|
||||
}
|
||||
|
||||
// Clear object cache for post queries
|
||||
wp_cache_flush_group('posts');
|
||||
|
||||
|
|
@ -248,10 +263,14 @@ class MLF_Font_Registry {
|
|||
$faces_by_font[$parent_id][] = $face;
|
||||
}
|
||||
|
||||
// Batch get all import dates in single query
|
||||
// Batch get all metadata
|
||||
$import_dates = [];
|
||||
$font_versions = [];
|
||||
$font_last_modified = [];
|
||||
foreach ($font_ids as $font_id) {
|
||||
$import_dates[$font_id] = get_post_meta($font_id, '_mlf_import_date', true);
|
||||
$font_versions[$font_id] = get_post_meta($font_id, '_mlf_font_version', true);
|
||||
$font_last_modified[$font_id] = get_post_meta($font_id, '_mlf_font_last_modified', true);
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
|
@ -285,11 +304,13 @@ class MLF_Font_Registry {
|
|||
});
|
||||
|
||||
$result[] = [
|
||||
'id' => $font->ID,
|
||||
'name' => $settings['name'] ?? $font->post_title,
|
||||
'slug' => $settings['slug'] ?? $font->post_name,
|
||||
'variants' => $variants,
|
||||
'import_date' => $import_dates[$font->ID] ?? '',
|
||||
'id' => $font->ID,
|
||||
'name' => $settings['name'] ?? $font->post_title,
|
||||
'slug' => $settings['slug'] ?? $font->post_name,
|
||||
'variants' => $variants,
|
||||
'import_date' => $import_dates[$font->ID] ?? '',
|
||||
'version' => $font_versions[$font->ID] ?? '',
|
||||
'last_modified' => $font_last_modified[$font->ID] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue