> For the complete documentation index, see [llms.txt](https://wplake.gitbook.io/advanced-views/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wplake.gitbook.io/advanced-views/customization/filters-and-hooks.md).

# Filters and Hooks

Please make sure you've installed the latest version of the plugin before using these filters.

Some filters are common and available in both the Lite and Pro plugin versions, where some are only available in the Pro version, these have been labelled as **(Pro)**.

This page lists hooks that are common for both *Layouts* and *Post Selections*. Check the child pages to see hooks related to *Layouts* and *Post Selections*.

## Common hooks list

[advanced\_views/manage\_capability](#manage-capability)

[advanced\_views/container](#container)

[advanced\_views/twig/custom\_functions](#custom-twig-functions)

[advanced\_views/twig/custom\_filters](#custom-twig-filters)

## Common hooks description

### Manage capability

By default, *Layout* and *Post Selection* management (menu items, lists, etc.) is available only to administrators (or custom roles with the `manage_options` capability). \
\
To change the default capability use this hook:

```php
add_filter( 'advanced_views/manage_capability', function (string $manage_capability): string {
    // Allow management for anyone who can edit posts, e.g. authors.
    return "edit_posts";
} );
```

{% hint style="info" %}
You can read more [about roles and capabilities](https://wordpress.org/documentation/article/roles-and-capabilities/) in the WordPress Docs.&#x20;
{% endhint %}

### Container

Using this hook, you can define a [PHP-DI container](https://php-di.org/), and then use it inside [Layout PHP Controlller](/advanced-views/display-content/php-controller.md) and [Selection PHP Controller](/advanced-views/query-content/php-controller.md) classes. [Read more](https://docs.advanced-views.com/display-content/custom-data-pro#php-di-support)

<pre class="language-php"><code class="lang-php">use DI\Container;

<strong>$container = new Container();
</strong>
add_filter( 'advanced_views/container', function () use ( $container ) {
	return $container;
} );
</code></pre>

### Custom Twig functions

{% code overflow="wrap" %}

```php
add_filter('advanced_views/twig/custom_functions', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixer',
            function ($firstArg) {
                return 'prefix2' . $firstArg;
            }
        ]
    ]);
});

add_filter('advanced_views/twig/custom_functions', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixerWithHtml',
            function ($firstArg) {
                return '<strong>prefix</strong>' . $firstArg;
            },
            ['is_safe' => ['html',],]
        ]
    ]);
});
```

{% endcode %}

{% hint style="info" %}
Note: every item of the array represents the custom function. First argument is the function name, second is the callback. Third argument is optional, here you can pass any [function settings](https://twig.symfony.com/doc/3.x/advanced.html) supported by Twig.

For the function callback, you can define as many arguments as you need.&#x20;
{% endhint %}

Now you can call your functions in twig templates of your *Layouts* and *Post Selections*.

```twig
{{ prefixer(myVar) }}
{{ prefixerWithHtml(myVar) }}
```

### Custom Twig filters

{% code overflow="wrap" %}

```php
add_filter('advanced_views/twig/custom_filters', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixer',
            function ($value, $firstArg) {
                return $firstArg . $value;
            }
        ]
    ]);
});

add_filter('advanced_views/twig/custom_filters', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixerWithHtml',
            function ($value, $firstArg) {
                return '<strong>'.$firstArg.'</strong>' . $value;
            },
            ['is_safe' => ['html',],]
        ]
    ]);
});
```

{% endcode %}

{% hint style="info" %}
Note: every item of the array represents the custom filter. First argument is the filter name, second is the callback. Third argument is optional, here you can pass any [filter settings](https://twig.symfony.com/doc/3.x/advanced.html) supported by Twig.

For the filter callback, you can define as many arguments as you need.&#x20;
{% endhint %}

Now you can call your filters in twig templates of your *Layouts* and *Post Selection*.

```twig
{{ myVar|prefixer("prefix") }}
{{ myVar|prefixer("prefix") }}
```

{% hint style="success" %}
Do you need to customize something but a filter isn't available?&#x20;

Then [Contact us](https://advanced-views.com/support/) and we'll try to add it as soon as possible.
{% endhint %}
