# 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

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

[acf\_views/container](#container) (Pro)

[acf\_views/twig/custom\_functions](#custom-twig-functions-pro) (Pro)

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

## 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( 'acf_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 (Pro)

Using this hook, you can define a [PHP-DI container](https://php-di.org/), and then use it inside [Custom\_View\_Data](/advanced-views/display-content/php-controller.md) and [Custom\_Card\_Data](/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( 'acf_views/container', function () use ( $container ) {
	return $container;
} );
</code></pre>

### Custom Twig functions (Pro)

{% code overflow="wrap" %}

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

add_filter('acf_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 (Pro)

{% code overflow="wrap" %}

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

add_filter('acf_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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wplake.gitbook.io/advanced-views/customization/filters-and-hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
