> 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/features/wordpress-hooks.md).

# WordPress hooks of Advanced Views

Advanced Views includes a set of WordPress hooks, allowing you to customize the plugin behavior from your theme (or code snippets).

{% hint style="info" %}
This page focuses only on the generic plugin hooks; check [Layout hooks](/advanced-views/layouts/component-options/wordpress-hooks.md) and [Post Selection hooks](/advanced-views/post-selections/component-options/wordpress-hooks.md) to see specific entity hooks.
{% endhint %}

## 1. Generic hooks list

{% hint style="info" %}
Please make sure you've installed the latest version of the plugin before using these filters.

If you need to customize something, but a filter or hook is unavailable, then [contact us](https://advanced-views.com/support/), and we will try to add it as soon as possible.
{% endhint %}

[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)

## 2. Generic hook descriptions

#### 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/layouts/code-fields/layout-controller.md) and [Selection PHP Controller](/advanced-views/post-selections/code-fields/selection-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") }}
```
