Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions acf-svg-icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
define( 'ACF_SVG_ICON_VER', '2.1.3' );
define( 'ACF_SVG_ICON_URL', plugin_dir_url( __FILE__ ) );
define( 'ACF_SVG_ICON_DIR', plugin_dir_path( __FILE__ ) );
define( 'ACF_SVG_ICON_CACHE_KEY', 'acf_svg_icon_files' );

class acf_field_svg_icon_plugin {

Expand All @@ -50,6 +51,10 @@ public function __construct() {

// Register ACF fields
add_action( 'acf/include_field_types', array( __CLASS__, 'register_field_v5' ) );

// Allow to flush the SVG cached data.
add_action( 'admin_bar_menu', array( __CLASS__, 'add_action_button_in_admin_bar' ), 120 );
add_action( 'init', array( __CLASS__, 'handle_flush_action' ) );
}

/**
Expand Down Expand Up @@ -82,6 +87,66 @@ public static function register_field_v5() {
new $klass();
}
}

/**
* Add a button in the WordPress admin bar to flush the cache for the SVG.
*
* @param \WP_Admin_Bar $admin_bar
*
* @return void
*/
public static function add_action_button_in_admin_bar( $admin_bar ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}

$admin_bar->add_node(
array(
'id' => 'acf_svg_icon_flush_cache',
'parent' => null,
'group' => null,
'title' => esc_html__( 'Flush ACF SVG Icon cache', 'acf-svg-icon' ),
'href' => add_query_arg(
[
'action' => 'acf_svg_icon_flush_cache',
'_wpnonce' => wp_create_nonce( 'flush_cache' )
]
),
'meta' => [
'title' => esc_html__( "If some SVG are missing or not up to date this could help resolve the issue.", 'acf-svg-icon' ),
]
)
);
}

/**
* Handle the cache flush action.
*
* @return void
*/
public static function handle_flush_action() {
if ( ! isset( $_GET['action'] ) || 'acf_svg_icon_flush_cache' !== $_GET['action'] ) {
return;
}

if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to execute this action.', 'acf-svg-icon' ) );
}

$nonce = sanitize_text_field( $_GET['_wpnonce'] );
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'flush_cache' ) ) {
wp_die( __( "Security error. Action couldn't be verified.", 'acf-svg-icon' ) );
}

delete_transient( ACF_SVG_ICON_CACHE_KEY );

$referer = wp_get_referer();
if ( ! $referer ) {
$referer = home_url( '/' );
}
wp_safe_redirect( $referer );
exit;
}
}

/**
Expand Down
22 changes: 16 additions & 6 deletions fields/acf-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ class acf_field_svg_icon extends acf_field {
*/
public $defaults = array();

/**
* Name of the cache key used to store SVG data after processing.
*
* @deprecated This as been replaced by the constant {@see ACF_SVG_ICON_CACHE_KEY} and
* will be removed in the next version.
*
* @var string
*/
public $cache_key = 'acf_svg_icon_files';

public function __construct() {
Expand All @@ -24,7 +32,9 @@ public function __construct() {
parent::__construct();

// Hooks !
add_action( 'save_post_attachment', array( $this, 'save_post_attachment' ) );
add_action( 'add_attachment', array( $this, 'flush_cache_for_attachments' ) );
add_action( 'edit_attachment', array( $this, 'flush_cache_for_attachments' ) );
add_action( 'delete_attachment', array( $this, 'flush_cache_for_attachments' ) );
}

/**
Expand Down Expand Up @@ -97,7 +107,7 @@ private function get_svg_files_path() {
*/
public function get_all_svg_files() {
// First try to load files list from the cache.
$files = get_transient( $this->cache_key );
$files = get_transient( ACF_SVG_ICON_CACHE_KEY );
if ( ! empty( $files ) ) {
return $files;
}
Expand All @@ -119,7 +129,7 @@ public function get_all_svg_files() {
$files = array_merge( $media_svg_files, $custom_svg_files );

// Cache 24 hours.
set_transient( $this->cache_key, $files, HOUR_IN_SECONDS * 24 );
set_transient( ACF_SVG_ICON_CACHE_KEY, $files, HOUR_IN_SECONDS * 24 );

return $files;
}
Expand Down Expand Up @@ -327,20 +337,20 @@ public function input_admin_footer() {
}

/**
* Flush cache on new SVG added to medias
* Flush cache when an SVG is added, update or removed from the medias
*
* @param $post_ID
*
* @since 2.0.0
*
*/
public function save_post_attachment( $post_ID ) {
public function flush_cache_for_attachments( $post_ID ) {
$mime_type = get_post_mime_type( $post_ID );
if ( 'image/svg+xml' !== $mime_type ) {
return;
}

delete_transient( $this->cache_key );
delete_transient( ACF_SVG_ICON_CACHE_KEY );
}

/**
Expand Down
Binary file modified languages/acf-svg-icon-fr_FR.mo
Binary file not shown.
49 changes: 40 additions & 9 deletions languages/acf-svg-icon-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,80 @@ msgid ""
msgstr ""
"Project-Id-Version: Advanced Custom Fields: SVG Icon 2.1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/acf-svg-icon\n"
"POT-Creation-Date: 2023-04-11T15:36:45+00:00\n"
"PO-Revision-Date: 2023-04-11 17:47+0200\n"
"POT-Creation-Date: 2025-05-16T16:54:00+00:00\n"
"PO-Revision-Date: 2025-05-16 18:54+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr_FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.1.1\n"
"X-Generator: Poedit 3.6\n"
"X-Domain: acf-svg-icon\n"

#. Plugin Name of the plugin
#: acf-svg-icon.php
msgid "Advanced Custom Fields: SVG Icon"
msgstr "Advanced Custom Fields: SVG Icon"

#. Plugin URI of the plugin
#: acf-svg-icon.php
msgid "http://www.beapi.fr"
msgstr "http://www.beapi.fr"

#. Description of the plugin
#: acf-svg-icon.php
msgid "Add an ACF SVG icon selector."
msgstr "Ajoute un sélecteur d’icône SVG."

#. Author of the plugin
#: acf-svg-icon.php
msgid "BE API Technical team"
msgstr "BE API Technical team"

#. Author URI of the plugin
#: acf-svg-icon.php
msgid "https://www.beapi.fr"
msgstr "https://www.beapi.fr"

#: fields/acf-base.php:17
#: acf-svg-icon.php:108
msgid "Flush ACF SVG Icon cache"
msgstr "Vider le cache de ACF SVG Icon"

#: acf-svg-icon.php:116
msgid ""
"If some SVG are missing or not up to date this could help resolve the issue."
msgstr ""
"Si certains SVG sont manquant ou ne sont pas à jour, cela pourrait résoudre "
"le problème."

#: acf-svg-icon.php:133
msgid "You do not have sufficient permissions to execute this action."
msgstr "Vous n'avez pas les droits nécessaire pour réaliser cette action."

#: acf-svg-icon.php:138
msgid "Security error. Action couldn't be verified."
msgstr "Erreur de sécurité. L'action n'a pas pu être vérifiée."

#: fields/acf-base.php:15
msgid "SVG Icon selector"
msgstr "Sélecteur d’icône SVG"

#: fields/acf-base.php:44
#: fields/acf-base.php:42
msgid "Select an icon"
msgstr "Veuillez sélectionner une icône"

#: fields/acf-base.php:66
#: fields/acf-base.php:64
msgid "Display clear button?"
msgstr "Afficher le bouton Effacer ?"

#: fields/acf-base.php:67
msgid "Whether or not a clear button is displayed when the select box has a selection."
msgstr "Indique si un bouton Effacer doit s’afficher lorsqu’une sélection est ajoutée."
#: fields/acf-base.php:65
msgid ""
"Whether or not a clear button is displayed when the select box has a "
"selection."
msgstr ""
"Indique si un bouton Effacer doit s’afficher lorsqu’une sélection est "
"ajoutée."

#~ msgid "Cannot verify the action."
#~ msgstr "Impossible de vérifier cette action."
37 changes: 29 additions & 8 deletions languages/acf-svg-icon.pot
Original file line number Diff line number Diff line change
@@ -1,51 +1,72 @@
# Copyright (C) 2023 BE API Technical team
# Copyright (C) 2025 BE API Technical team
# This file is distributed under the same license as the Advanced Custom Fields: SVG Icon plugin.
msgid ""
msgstr ""
"Project-Id-Version: Advanced Custom Fields: SVG Icon 2.1.0\n"
"Project-Id-Version: Advanced Custom Fields: SVG Icon 2.1.3\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/acf-svg-icon\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-04-11T15:36:45+00:00\n"
"POT-Creation-Date: 2025-05-16T16:54:00+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"
"X-Generator: WP-CLI 2.11.0\n"
"X-Domain: acf-svg-icon\n"

#. Plugin Name of the plugin
#: acf-svg-icon.php
msgid "Advanced Custom Fields: SVG Icon"
msgstr ""

#. Plugin URI of the plugin
#: acf-svg-icon.php
msgid "http://www.beapi.fr"
msgstr ""

#. Description of the plugin
#: acf-svg-icon.php
msgid "Add an ACF SVG icon selector."
msgstr ""

#. Author of the plugin
#: acf-svg-icon.php
msgid "BE API Technical team"
msgstr ""

#. Author URI of the plugin
#: acf-svg-icon.php
msgid "https://www.beapi.fr"
msgstr ""

#: fields/acf-base.php:17
#: acf-svg-icon.php:108
msgid "Flush ACF SVG Icon cache"
msgstr ""

#: acf-svg-icon.php:116
msgid "If some SVG are missing or not up to date this could help resolve the issue."
msgstr ""

#: acf-svg-icon.php:133
msgid "You do not have sufficient permissions to execute this action."
msgstr ""

#: acf-svg-icon.php:138
msgid "Security error. Action couldn't be verified."
msgstr ""

#: fields/acf-base.php:15
msgid "SVG Icon selector"
msgstr ""

#: fields/acf-base.php:44
#: fields/acf-base.php:42
msgid "Select an icon"
msgstr ""

#: fields/acf-base.php:66
#: fields/acf-base.php:64
msgid "Display clear button?"
msgstr ""

#: fields/acf-base.php:67
#: fields/acf-base.php:65
msgid "Whether or not a clear button is displayed when the select box has a selection."
msgstr ""