mirror of
https://ghproxy.net/https://github.com/stingray82/mainwp-plugin-icons.git
synced 2025-10-04 21:54:28 +08:00
Added Theme Support, Added Bricks Icon
This commit is contained in:
parent
055ac5119f
commit
3a1db3d84c
1 changed files with 19 additions and 3 deletions
22
README.md
22
README.md
|
@ -21,18 +21,31 @@ Replace `yourusername` with your actual GitHub username or organization name.
|
|||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ php
|
||||
add_filter('mainwp_before_save_cached_icons', function ($cached_icons, $icon, $slug, $type, $custom_icon, $noexp) {
|
||||
$json_url = 'https://raw.githubusercontent.com/stingray82/mainwp-plugin-icons/main/icons-map.json';
|
||||
$response = wp_remote_get($json_url);
|
||||
|
||||
// Determine correct JSON source based on type
|
||||
$json_url = '';
|
||||
if ($type === 'plugin') {
|
||||
$json_url = 'https://raw.githubusercontent.com/stingray82/mainwp-plugin-icons/main/icons-map.json';
|
||||
} elseif ($type === 'theme') {
|
||||
$json_url = 'https://raw.githubusercontent.com/stingray82/mainwp-plugin-icons/main/themes-icons-map.json';
|
||||
} else {
|
||||
return $cached_icons;
|
||||
}
|
||||
|
||||
// Fetch JSON data
|
||||
$response = wp_remote_get($json_url);
|
||||
if (is_wp_error($response)) {
|
||||
error_log("[MainWP ICONS] Failed to fetch {$type} icon map: " . $response->get_error_message());
|
||||
return $cached_icons;
|
||||
}
|
||||
|
||||
$icons_map = json_decode(wp_remote_retrieve_body($response), true);
|
||||
if (!is_array($icons_map)) {
|
||||
error_log("[MainWP ICONS] Invalid JSON for {$type} icons.");
|
||||
return $cached_icons;
|
||||
}
|
||||
|
||||
// Inject custom icons if not already cached
|
||||
foreach ($icons_map as $custom_slug => $custom_icon_url) {
|
||||
if (!isset($cached_icons[$custom_slug])) {
|
||||
$cached_icons[$custom_slug] = [
|
||||
|
@ -40,13 +53,16 @@ add_filter('mainwp_before_save_cached_icons', function ($cached_icons, $icon, $s
|
|||
'path_custom' => '',
|
||||
'path' => urlencode($custom_icon_url),
|
||||
];
|
||||
|
||||
|
||||
error_log("[MainWP ICONS] Injected {$type} icon for: {$custom_slug}");
|
||||
}
|
||||
}
|
||||
|
||||
return $cached_icons;
|
||||
|
||||
}, 10, 6);
|
||||
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Repository Structure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue