7studio / acf-svg-icon

Add a new ACF field type: "SVG Icon" which allows you to select icon(s) from a SVG sprite.
37 stars 10 forks source link

svg files fixed for theme path #3

Open badabingbreda opened 5 years ago

badabingbreda commented 5 years ago

Hi 7studio, great work!

One thing I noticed is that it assumes that the svg icons are in (a subfolder of) the theme folder. I was trying to add them packaged as a plugin but the str_replace() on the load_field() callback was preventing my icons from displaying.

I added two extra filters as a workaround to be able to set both search and replace parameters, now my svg can be located in that plugin-folder too.

7studio commented 5 years ago

Hi @badabingbreda,

You are totally right and it's a stupid restriction. But it was out of my scope/need when I created the plugin :sweat_smile:

The problem comes from the line 202 in fields/class-swp-acf-svg-icon-v5.php.

We can resolve the problem in two steps :

  1. Replace the current wrong line/behaviour by: $field['file']['url'] = str_replace( get_home_path(), home_url( '/' ), $field['file']['path'] );. This change should solve your problem.
  2. Offer three filters like acf/fields/svg_icon/file_path for the file URL (e.g.: acf/fields/svg_icon/file_url) to allow the use of an SVG file from a rewrited URL for example.

I hope you will appreciate this solution. I will try to fix this issue during the week.