Version: 1.0
Author: Cameron Stephen
Description: A WordPress plugin that optimises the get_attached_file
function for remote SVGs by caching them locally. This improves performance, enables CSS styling through inline SVGs, and ensures flexibility for developers to extend functionality.
- Automatically caches remote SVG files locally by hooking into WordPress’s
get_attached_file
function. - Ensures cached files are served locally, improving performance and reducing network requests.
- Serves SVGs inline in the DOM when developers call custom logic (e.g., using helper functions).
- Allows full CSS styling and animations directly on SVG content.
- Use the
SVG_CACHE_HOURS
environment variable to set the duration (in hours) for how long SVG files are cached. - Defaults to 72 hours if the variable is not set.
- Use the
SVG_CACHE_PATH
environment variable to define a custom directory for storing cached SVGs. - Defaults to
wp-content/uploads/cached_svgs/
if not set.
- Clears the cache when WordPress Customizer settings are saved, ensuring updates are reflected immediately.
- Designed to modify only the
get_attached_file
function. - Offers a helper function,
get_inline_svg
, to enable developers to build custom rendering logic.
-
Default Behavior:
- The plugin automatically caches remote SVG files when WordPress uses
get_attached_file
.
- The plugin automatically caches remote SVG files when WordPress uses
-
Developer Integration:
- Developers can extend or customize how SVGs are handled by building their own logic.
- Use the helper function
get_inline_svg($attachment_id)
to fetch and render inline SVG content in themes or plugins.
<div class="icon">
<?= get_inline_svg($attachment_id); ?>
</div>
- Defines how long cached SVG files are stored before being refreshed.
- Default: 72 hours.
- Specifies a custom directory for cached SVG files.
- Default:
wp-content/uploads/cached_svgs/
.
SVG_CACHE_PATH=/path/to/custom/cache/directory
SVG_CACHE_HOURS=72