Skip to content

Commit

Permalink
upd/svg/add-filter/svg-icon-library-icons (#190)
Browse files Browse the repository at this point in the history
* upd/svg/add-filter/svg-icon-library-icons

* update the SVG component README
  • Loading branch information
ckanitz authored Oct 31, 2024
1 parent 8384db3 commit d1ba8da
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
49 changes: 49 additions & 0 deletions plugin/inc/SVG/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,55 @@ current plugin. The component first looks into the theme folder to find the file
and then in the plugin folder.


## Filters

### `lhagentur_svg_icon_library_icons`
Filters the array of `<Icon>`s passed to the `<Icon_Library>`.

#### Parameters
* `(array) $icons` - An array of `<Icon>`s.

#### Returns
* `(array) $icons` - The updated / created array of `<Icon>`s

#### Example
```PHP
use WpMunich\basics\plugin\SVG\Icon;

# ...
add_filter( 'lhagentur_svg_icons_library_icons', 'my_svg_icons_library_icons' );

# ...
function my_svg_icons_library_icons( array $icons ): array {
// If there's some case in which no icons should be registered.
if (some_other_condition) {
return $icons;
}

$img_path = 'my/img/path/';
$my_icons = array(
new Icon(
$icon_path . 'icons/my-icon.svg',
'my-icon--slug',
__( 'My Icon Label', 'textdomain' )
),
# ...
);

// If you want to add icons.
if ( some_condition ) {
return array_merge(
$icons,
$my_icons
);
}

// If you want to override icons.
return $my_icons;
}
```


## Functions

### get_svg( (sting) $path, (array) $arguments )
Expand Down
8 changes: 5 additions & 3 deletions plugin/inc/SVG/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ protected function must_run() {}
public function get_icon_library() {
if ( ! $this->icon_library instanceof Icon_Library ) {
$base_path = plugin()->get_plugin_path();

$this->icon_library = new Icon_Library();
$this->icon_library->set_icons(
$icons = apply_filters(
'lhagentur_svg_icon_library_icons',
array(
new Icon(
$base_path . 'img/icons/slashes.svg',
Expand All @@ -86,6 +85,9 @@ public function get_icon_library() {
),
)
);

$this->icon_library = new Icon_Library();
$this->icon_library->set_icons( $icons );
}
return $this->icon_library;
}
Expand Down

0 comments on commit d1ba8da

Please sign in to comment.