diff --git a/composer.lock b/composer.lock index 76d73d00..571cb1b2 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "doctrine/deprecations", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "4f2d4f2836e7ec4e7a8625e75c6aa916004db931" + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/4f2d4f2836e7ec4e7a8625e75c6aa916004db931", - "reference": "4f2d4f2836e7ec4e7a8625e75c6aa916004db931", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", "shasum": "" }, "require": { @@ -49,27 +49,27 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.2" + "source": "https://github.com/doctrine/deprecations/tree/1.1.3" }, - "time": "2023-09-27T20:04:15+00:00" + "time": "2024-01-30T19:34:25+00:00" }, { "name": "nikic/php-parser", - "version": "v4.17.1", + "version": "v4.19.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" + "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b", + "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.1" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", @@ -105,9 +105,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1" }, - "time": "2023-08-13T19:53:39+00:00" + "time": "2024-03-17T08:10:35+00:00" }, { "name": "phpdocumentor/reflection", @@ -228,28 +228,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", + "version": "5.4.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" + "reference": "9d07b3f7fdcf5efec5d1609cba3c19c5ea2bdc9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9d07b3f7fdcf5efec5d1609cba3c19c5ea2bdc9c", + "reference": "9d07b3f7fdcf5efec5d1609cba3c19c5ea2bdc9c", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.1", "ext-filter": "*", - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", + "phpdocumentor/type-resolver": "^1.7", + "phpstan/phpdoc-parser": "^1.7", "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" + "mockery/mockery": "~1.3.5", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-webmozart-assert": "^1.2", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^5.13" }, "type": "library", "extra": { @@ -273,33 +280,33 @@ }, { "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" + "email": "opensource@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.1" }, - "time": "2021-10-19T17:43:47+00:00" + "time": "2024-05-21T05:55:05+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.3", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419" + "reference": "153ae662783729388a584b4361f2545e4d841e3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", - "php": "^7.4 || ^8.0", + "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", "phpstan/phpdoc-parser": "^1.13" }, @@ -337,22 +344,22 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.3" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" }, - "time": "2023-08-12T11:01:26+00:00" + "time": "2024-02-23T11:10:43+00:00" }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.2", + "version": "1.29.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bcad8d995980440892759db0c32acae7c8e79442" + "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", - "reference": "bcad8d995980440892759db0c32acae7c8e79442", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4", + "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4", "shasum": "" }, "require": { @@ -384,9 +391,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1" }, - "time": "2023-09-26T12:28:12+00:00" + "time": "2024-05-31T08:52:43+00:00" }, { "name": "psr/container", @@ -528,16 +535,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v2.5.2", + "version": "v2.5.3", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" + "reference": "80d075412b557d41002320b96a096ca65aa2c98d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/80d075412b557d41002320b96a096ca65aa2c98d", + "reference": "80d075412b557d41002320b96a096ca65aa2c98d", "shasum": "" }, "require": { @@ -575,7 +582,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.3" }, "funding": [ { @@ -591,7 +598,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:53:40+00:00" + "time": "2023-01-24T14:02:46+00:00" }, { "name": "symfony/filesystem", @@ -658,16 +665,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", + "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", "shasum": "" }, "require": { @@ -681,9 +688,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -720,7 +724,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" }, "funding": [ { @@ -736,20 +740,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -763,9 +767,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -803,7 +804,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" }, "funding": [ { @@ -819,20 +820,20 @@ "type": "tidelift" } ], - "time": "2023-07-28T09:04:16+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5" + "reference": "21bd091060673a1177ae842c0ef8fe30893114d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fe2f306d1d9d346a7fee353d0d5012e401e984b5", - "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/21bd091060673a1177ae842c0ef8fe30893114d2", + "reference": "21bd091060673a1177ae842c0ef8fe30893114d2", "shasum": "" }, "require": { @@ -840,9 +841,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -882,7 +880,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php73/tree/v1.29.0" }, "funding": [ { @@ -898,20 +896,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.28.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", "shasum": "" }, "require": { @@ -919,9 +917,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.28-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -965,7 +960,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" }, "funding": [ { @@ -981,20 +976,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2024-01-29T20:11:03+00:00" }, { "name": "symfony/service-contracts", - "version": "v2.5.2", + "version": "v2.5.3", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "4b426aac47d6427cc1a1d0f7e2ac724627f5966c" + "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/4b426aac47d6427cc1a1d0f7e2ac724627f5966c", - "reference": "4b426aac47d6427cc1a1d0f7e2ac724627f5966c", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/a2329596ddc8fd568900e3fc76cba42489ecc7f3", + "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3", "shasum": "" }, "require": { @@ -1048,7 +1043,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v2.5.2" + "source": "https://github.com/symfony/service-contracts/tree/v2.5.3" }, "funding": [ { @@ -1064,20 +1059,20 @@ "type": "tidelift" } ], - "time": "2022-05-30T19:17:29+00:00" + "time": "2023-04-21T15:04:16+00:00" }, { "name": "timber/teak", - "version": "1.0.5", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/timber/teak.git", - "reference": "a5af1504cadb8e5d2277069165caf948d1d0c012" + "reference": "780977298163b40549d51e8657c1d1b5154284d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/timber/teak/zipball/a5af1504cadb8e5d2277069165caf948d1d0c012", - "reference": "a5af1504cadb8e5d2277069165caf948d1d0c012", + "url": "https://api.github.com/repos/timber/teak/zipball/780977298163b40549d51e8657c1d1b5154284d0", + "reference": "780977298163b40549d51e8657c1d1b5154284d0", "shasum": "" }, "require": { @@ -1114,9 +1109,9 @@ "description": "Generate a Markdown reference documentation for PHP projects (optimized for WordPress)", "support": { "issues": "https://github.com/timber/teak/issues", - "source": "https://github.com/timber/teak/tree/1.0.5" + "source": "https://github.com/timber/teak/tree/1.0.6" }, - "time": "2022-02-07T20:46:57+00:00" + "time": "2024-04-26T12:47:48+00:00" }, { "name": "webmozart/assert", @@ -1187,5 +1182,5 @@ "php": ">=7.4.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/content/v2/hooks/actions.md b/content/v2/hooks/actions.md index c0acc1e4..47ce75f2 100644 --- a/content/v2/hooks/actions.md +++ b/content/v2/hooks/actions.md @@ -3,3 +3,63 @@ title: "Action Hooks" is_reference: true --- +## timber\_{$object\_type}\_get\_meta\_pre + +Filters post meta data before it is fetched from the database. + +**DEPRECATED** since 2.0.0, use `timber/{object_type}/pre_meta` + +## timber/loader/render\_file + +Fires after … + +| Name | Type | Description | +| --- | --- | --- | +| $result | `string` | | + +## timber\_loader\_render\_file + +Fires after … + +**DEPRECATED** since 2.0.0, use `timber/loader/render_file` + +This action is used by the Timber Debug Bar extension. + +## timber/calling\_php\_file + +Fires after the calling PHP file was determined in Timber’s compile +function. + +This action is used by the Timber Debug Bar extension. + +**since** 1.1.2 + +| Name | Type | Description | +| --- | --- | --- | +| $caller_file | `string` or `null` | The calling script file. | + +## timber/compile/done + +Fires after a Twig template was compiled and before the compiled data +is returned. + +This action can be helpful if you need to debug Twig template +compilation. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $output | `string` | The compiled output. | +| $file | `string` | The name of the Twig template that was compiled. | +| $data | `array` | The data that was used to compile the Twig template. | +| $expires | `bool` or `int` or `array` | The expiration time of the cache in seconds, or false to disable cache. | +| $cache_mode | `string` | Any of the cache mode constants defined in Timber\Loader. | + +## timber\_compile\_done + +Fires after a Twig template was compiled and before the compiled data +is returned. + +**DEPRECATED** since 2.0.0, use `timber/compile/done` + diff --git a/content/v2/hooks/filters.md b/content/v2/hooks/filters.md index a1bbbfac..4ea07449 100644 --- a/content/v2/hooks/filters.md +++ b/content/v2/hooks/filters.md @@ -3,3 +3,1619 @@ title: "Filter Hooks" is_reference: true --- +## timber/meta/transform\_value + +Filters whether to transform a meta value. + +If the filter returns `true`, all meta value will be transformed to Timber/standard PHP objects if possible. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $transform_value | `bool` | | + +**PHP** + +```php +// Transforms all meta value. +add_filter( 'timber/meta/transform_value', '__return_true' ); +``` + +## timber/{$object\_type}/pre\_meta + +Filters object meta data before it is fetched from the database. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $object_meta | `string` or `null` | The field value. Default null. Passing a non-null value will skip fetching the value from the database and will use the value from the filter instead. | +| $post_id | `int` | The post ID. | +| $field_name | `string` | The name of the meta field to get the value for. | +| $object | `object` | The Timber object. | +| $args | `array` | An array of arguments. | + +**PHP** + +```php +// Disable fetching meta values. +add_filter( 'timber/post/pre_meta', '__return_false' ); + +// Add your own meta data. +add_filter( 'timber/post/pre_meta', function( $post_meta, $post_id, $post ) { + $post_meta = array_merge( $post_meta, [ + 'custom_data_1' => 73, + 'custom_data_2' => 274, + ] ); + + return $post_meta; +}, 10, 3 ); +``` + +## timber\_{$object\_type}\_get\_meta\_field\_pre + +Filters the value for a post meta field before it is fetched from the database. + +**DEPRECATED** since 2.0.0, use `timber/{object_type}/pre_meta` + +## timber/{$object\_type}/meta + +Filters the value for a post meta field. + +This filter is used by the ACF Integration. + +**see** [Timber\Post::meta()](/docs/reference/timber-post/#meta) + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $post_meta | `string` | The field value. | +| $post_id | `int` | The post ID. | +| $field_name | `string` | The name of the meta field to get the value for. | +| $post | `\CoreEntity` | The post object. | +| $args | `array` | An array of arguments. | + +**PHP** + +```php +add_filter( 'timber/post/meta', function( $post_meta, $post_id, $field_name, $post ) { + if ( 'event' === $post->post_type ) { + // Do something special. + $post_meta['foo'] = $post_meta['foo'] . ' bar'; + } + + return $post_meta; +}, 10, 4 ); +``` + +## timber/term/meta/field + +Filters the value for a term meta field. + +**DEPRECATED** since 2.0.0, use `timber/term/meta` + +## timber\_{$object\_type}\_get\_meta\_field + +Filters the value for an object meta field. + +**DEPRECATED** since 2.0.0, use `timber/{object_type}/meta` + +## timber\_{$object\_type}\_get\_meta + +Filters object meta data fetched from the database. + +**DEPRECATED** since 2.0.0, use `timber/{object_type}/meta` + +## timber/comment/classmap + +Filters the class(es) used for comments linked to different post types. + +The default class is Timber\Comment. You can use this filter to provide your own comment class for specific post types. + +Make sure to merge in your additional classes instead of overwriting the whole Class Map. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $classmap | `array` | The post class(es) to use. An associative array where the key is the post type and the value the name of the class to use for the comments of this post type or a callback that determines the class to use. | + +``` +use Book; + +add_filter( 'timber/post/classmap', function( $classmap ) { + $custom_classmap = [ + 'book' => BookComment::class, + ]; + + return array_merge( $classmap, $custom_classmap ); +} ); +``` + +## timber/comment/class + +Filters the comment class based on your custom criteria. + +Maybe you want to set a custom class based upon the comment type? +This allows you to filter the PHP class, utilizing data from the WP_Comment object. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The class to use. | +| $comment | `\WP_Comment` | The comment object. | + +``` +add_filter( 'timber/comment/class', function( $class, $comment ) { + if ( $comment->comment_type === 'pingback' ) { + return PingBackComment::class; + } + return $class; +}, 10, 2 ); +``` + +## timber/menu/classmap + +Filters the class(es) used for different menus. + +Read more about this in the documentation for [Menu Class Maps](https://timber.github.io/docs/v2/guides/class-maps/#the-menu-class-map). + +The default Menu Class Map will contain class names for locations that map to `Timber\Menu`. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $classmap | `array` | The menu class(es) to use. An associative array where the key is the location and the value the name of the class to use for this menu or a callback that determines the class to use. | + +``` +add_filter( 'timber/menu/classmap', function( $classmap ) { + $custom_classmap = [ + 'primary' => MenuPrimary::class, + 'secondary' => MenuSecondary::class, + ]; + + return array_merge( $classmap, $custom_classmap ); +} ); +``` + +## timber/menu/class + +Filters the menu class based on your custom criteria. + +Maybe the location is not appropriate in some cases. This filter will allow you to filter the class +on whatever data is available. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The class to use. | +| $term | `\WP_Term` | The menu term. | +| $args | `array` | The arguments passed to the menu. | + +``` +add_filter( 'timber/menu/class', function( $class, $term, $args ) { + if ( $args['depth'] === 1 ) { + return SingleLevelMenu::class; + } + + return MultiLevelMenu::class; +}, 10, 3 ); +``` + +## timber/menuitem/classmap + +Filters the class(es) used for different menu items. + +Read more about this in the documentation for [Menu Item Class Maps](https://timber.github.io/docs/v2/guides/class-maps/#the-menu-item-class-map). + +The default Menu Item Class Map will contain class names for locations that map to `Timber\MenuItem`. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $classmap | `array` | The menu item class(es) to use. An associative array where the key is the location and the value the name of the class to use for this menu item or a callback that determines the class to use. | + +``` +add_filter( 'timber/menuitem/classmap', function( $classmap ) { + $custom_classmap = [ + 'primary' => MenuItemFooter::class, + 'secondary' => MenuItemHeader::class, + ]; + + return array_merge( $classmap, $custom_classmap ); +} ); +``` + +## timber/menuitem/class + +Filters the menu item class + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The class to use. | +| $item | `\WP_Post` | The menu item. | +| $menu | `\Menu` | The menu object. | + +``` +add_filter( 'timber/menuitem/class', function( $class, $item, $menu ) { + if ( $item->post_parent ) { + return SubMenuItem::class; + } + + return MenuItem::class; +}, 10, 3 ); +``` + +## timber/pages\_menu/class + +Filters the class used for different menus. + +Read more about this in the documentation for [Pages Menu Class filter](https://timber.github.io/docs/v2/guides/class-maps/#the-pages-menu-class-filter). + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The pages menu class to use. | +| $args | `array` | The arguments passed to `Timber::get_pages_menu()`. | + +``` +add_filter( 'timber/pages_menu/class', function( $class ) { + return ExtendedPagesMenu::class; +} ); +``` + +## timber/post/classmap + +Filters the class(es) used for different post types. + +Read more about this in the documentation for [Post Class Maps](https://timber.github.io/docs/v2/guides/class-maps/#the-post-class-map). + +The default Post Class Map will contain class names for posts, pages that map to +`Timber\Post` and a callback that will map attachments to `Timber\Attachment` and +attachments that are images to `Timber\Image`. + +Make sure to merge in your additional classes instead of overwriting the whole Class Map. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $classmap | `array` | The post class(es) to use. An associative array where the key is the post type and the value the name of the class to use for this post type or a callback that determines the class to use. | + +``` +use Book; +use Page; + +add_filter( 'timber/post/classmap', function( $classmap ) { + $custom_classmap = [ + 'page' => Page::class, + 'book' => Book::class, + ]; + + return array_merge( $classmap, $custom_classmap ); +} ); +``` + +## timber/post/class + +Filters the post class based on your custom criteria. + +Maybe you want to set a custom class based upon how blocks are used? +This allows you to filter the PHP class, utilizing data from the WP_Post object. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The class to use. | +| $post | `\WP_Post` | The post object. | + +``` +add_filter( 'timber/post/class', function( $class, $post ) { + if ( has_blocks($post) ) { + return GutenbergPost::class; + } + + return $class; +}, 10, 2 ); +``` + +## timber/post/image\_extensions + +Filters the list of image extensions that will be used to determine if an attachment is an image. + +You can use this filter to add or remove image extensions to the list of extensions that will be +used to determine if an attachment is an image. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $extensions | `array` | An array of image extensions. | + +## timber/term/classmap + +Filters the class(es) used for terms of different taxonomies. + +The default Term Class Map will contain class names mapped to the build-in post_tag and category taxonomies. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $classmap | `array` | The term class(es) to use. An associative array where the key is the taxonomy name and the value the name of the class to use for this taxonomy or a callback that determines the class to use. | + +``` +add_filter( 'timber/term/classmap', function( $classmap ) { + $custom_classmap = [ + 'expertise' => ExpertiseTerm::class, + ]; + + return array_merge( $classmap, $custom_classmap ); +} ); +``` + +## timber/term/class + +Filters the term class based on your custom criteria. + +Maybe you want to set a custom class based upon a certain category? +This allows you to filter the PHP class, utilizing data from the WP_Term object. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The class to use. | +| $term | `\WP_Term` | The term object. | + +``` +add_filter( 'timber/term/class', function( $class, $term ) { + if ( get_term_meta($term->term_id, 'is_special_category', true) ) { + return MyCustomTermClass::class; + } + + return $class; +}, 10, 2 ); +``` + +## timber/user/class + +Filters the name of the PHP class used to instantiate `Timber\User` objects. + +The User Class Map receives the default `Timber\User` class and a `WP_User` object. You +should be able to decide which class to use based on that user object. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The name of the class. Default `Timber\User`. | +| $user | `\WP_User` | The `WP_User` object that is used as the base for the `Timber\User` object. | + +**PHP** + +```php +use Administrator; +use Editor; + +add_filter( 'timber/user/class', function( $class, \WP_User $user ) { + if ( in_array( 'editor', $user->roles, true ) ) { + return Editor::class; + } elseif ( in_array( 'author', $user->roles, true ) ) { + return Author::class; + } + + return $class; +}, 10, 2 ); +``` + +## timber/transient/slug + +Filters the transient slug. + +This might be useful if you are using a multilingual solution. + +**since** 0.22.6 + +| Name | Type | Description | +| --- | --- | --- | +| $slug | `string` | The slug for the transient. | + +## timber/transient/force\_transients + +Filters whether to force a locked transients to be regenerated. + +If a transient is locked, it means that another process is currently generating the data. +If you want to force the transient to be regenerated, during that process, you can set this +filter to true. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $force | `bool` | Whether to force a locked transient to be regenerated. | + +## timber\_force\_transients + +Filters whether to force a locked transients to be regenerated. + +**DEPRECATED** since 2.0.0, use `timber/transient/force_transients` + +If a transient is locked, it means that another process is currently generating the data. +If you want to force the transient to be regenerated, during that process, you can set this +filter to true. + +## timber/transient/force\_transient\_{$slug} + +Filters whether to force a specific locked transients to be regenerated. + +If a transient is locked, it means that another process is currently generating the data. +If you want to force the transient to be regenerated during that process, you can set this value to true. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $force | `bool` | Whether to force a locked transient to be regenerated. | + +**PHP** + +```php + +add_filter( 'timber/transient/force_transient_mycustumslug', function($force) { + if(false == something_special_has_occurred()){ + return false; + } + + return true; +}, 10 ); +``` + +## timber\_force\_transient\_{$slug} + +Filters whether to force a specific locked transients to be regenerated. + +**DEPRECATED** since 2.0.0, use `timber/transient/force_transient_{$slug}` + +If a transient is locked, it means that another process is currently generating the data. +If you want to force the transient to be regenerated, during that process, you can set this value to true. +`$slug` The transient slug. + +| Name | Type | Description | +| --- | --- | --- | +| $force | `bool` | Whether to force a locked transient to be regenerated. | + +## timber/helper/wp\_title\_separator + +Filters the separator used for the page title. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $separator | `string` | The separator to use. Default `' '`. | + +## timber\_wp\_title\_seperator + +Filters the separator used for the page title. + +**DEPRECATED** since 2.0.0, use `timber/helper/wp_title_separator` + +## timber/image/src + +Filters the src URL for a `Timber\Image`. + +**see** [Timber\Image::src()](/docs/reference/timber-image/#src) + +**since** 0.21.7 + +| Name | Type | Description | +| --- | --- | --- | +| $src | `string` | The image src. | +| $id | `int` | The image ID. | + +## timber\_image\_src + +Filters the src URL for a `Timber\Image`. + +**DEPRECATED** since 2.0.0, use `timber/image/src` + +## timber/sideload\_image/basename + +Filters basename for sideloaded files. + +**since** 2.1.0 + +| Name | Type | Description | +| --- | --- | --- | +| $basename | `string` | Current basename for the sideloaded file. | +| $path_parts | `array` | Array with path info for the sideloaded file. | + +**PHP** + +```php +// Change the basename used for sideloaded images. +add_filter( 'timber/sideload_image/basename', function ($basename, $path_parts) { + return $path_parts['filename'] . '-' . substr($basename, 0, 6); +}, 10, 2) +``` + +## timber/sideload\_image/subdir + +Filters to directory that should be used for sideloaded images. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $subdir | `string` | The subdir name to use for sideloaded images. Return an empty string or a falsey value in order to not use a subfolder. Default `external`. | + +**PHP** + +```php +// Change the subdirectory used for sideloaded images. +add_filter( 'timber/sideload_image/subdir', function( $subdir ) { + return 'sideloaded'; +} ); + +// Disable subdirectory used for sideloaded images. +add_filter( 'timber/sideload_image/subdir', '__return_false' ); +``` + +## timber/image\_helper/pre\_analyze\_url + +Filters whether to short-circuit the ImageHelper::analyze_url() +file path of a URL located in a theme directory. + +Returning a non-null value from the filter will short-circuit +ImageHelper::analyze_url(), returning that value. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $info | `array` or `null` | The URL components array to short-circuit with. Default null. | +| $url | `string` | The URL pointing to an image. | + +## timber/image\_helper/analyze\_url + +Filters the array of analyzed URL components. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $info | `array` | The URL components. | +| $url | `string` | The URL pointing to an image. | + +## timber/image\_helper/pre\_theme\_url\_to\_dir + +Filters whether to short-circuit the ImageHelper::theme_url_to_dir() +file path of a URL located in a theme directory. + +Returning a non-null value from the filter will short-circuit +ImageHelper::theme_url_to_dir(), returning that value. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $path | `string` or `null` | Full path to short-circuit with. Default null. | +| $src | `string` | The URL to be converted. | + +## timber/image\_helper/theme\_url\_to\_dir + +Filters the raw file path of a URL located in a theme directory. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $path | `string` | The resolved full path to $src. | +| $src | `string` | The URL that was converted. | + +## timber/image/new\_url + +Filters the URL for the resized version of a `Timber\Image`. + +You’ll probably need to use this in combination with `timber/image/new_path`. + +**since** 1.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $new_url | `string` | The URL to the resized version of an image. | + +## timber/image/new\_path + +Filters the destination path for the resized version of a `Timber\Image`. + +A possible use case for this would be to store all images generated by Timber in a +separate directory. You’ll probably need to use this in combination with +`timber/image/new_url`. + +**since** 1.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $destination_path | `string` | Full path to the destination of a resized image. | + +## timber/cache/mode + +Filters the cache mode. + +You can read more about Caching in the +[Performance/Caching]({{}}) guide. + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $cache_mode | `string` | The cache mode. Can be one of the following: `Timber\Loader::CACHE_NONE`, `Timber\Loader::CACHE_OBJECT`, `Timber\Loader::CACHE_TRANSIENT`, `Timber\Loader::CACHE_SITE_TRANSIENT`, `Timber\Loader::CACHE_USE_DEFAULT`. Default `Timber\Loader::CACHE_TRANSIENT`. | + +## timber\_cache\_mode + +Filters the cache mode. + +**DEPRECATED** since 2.0.0, use `timber/cache/mode` + +## timber/loader/render\_data + +Filters … + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $data | `array` | | +| $file | `string` | | + +## timber\_loader\_render\_data + +Filters … + +**DEPRECATED** since 2.0.0, use `timber/loader/render_data` + +## timber/output/pre-cache + +Filters $output before it is cached. + +**since** 2.1.0 + +| Name | Type | Description | +| --- | --- | --- | +| $output | `string` | | +| $data | `array` | | +| $file | `string` | | + +## timber/output + +Filters … + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $output | `string` | | +| $data | `array` | | +| $file | `string` | | + +## timber\_output + +Filters … + +**DEPRECATED** since 2.0.0, use `timber/output` + +## timber/loader/paths + +Filters the template paths used by the Loader. + +**DEPRECATED** since 2.0.0, use `timber/locations` + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $paths | `array` | | + +## timber/loader/loader + +Filters … + +**link** + +**since** 1.1.11 + +## timber/twig/environment/options + +Filters the environment options that are used when creating a Twig Environment instance. + +By default, Timber sets the following values: + +- `'debug' => WP_DEBUG` +- `'autoescape' => false` +- `'cache' => false` + +**link** + +**since** 1.9.5 + +| Name | Type | Description | +| --- | --- | --- | +| $environment_options | `array` | An array of Twig environment options. | + +**PHP** + +```php +add_filter( 'timber/twig/environment/options', 'update_twig_environment_options' ); + +/** + * Updates Twig environment options. + * + * @link https://twig.symfony.com/doc/2.x/api.html#environment-options + * + * \@param array $options An array of environment options. + * + * @return array + */ +function update_twig_environment_options( $options ) { + $options['cache'] = true; + $options['auto_reload'] = true; + + return $options; +} +``` + +## timber/cache/location + +Filters the cache location used for Twig. + +**DEPRECATED** since 2.0.0 + +Allows you to set a new cache location for Twig. If the folder doesn’t exist yet, it +will be created automatically. + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $twig_cache_loc | `string` | Full path to the cache location. Default `/cache/twig` in the Timber root folder. | + +## timber/cache/enable\_extension + +Filters the cache extension activation. + +Allows users to disable the cache extension and use their own + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $enable_cache_extension | `bool` | Whether to enable the cache extension. | + +## timber/loader/twig + +Filters … + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $twig | `\Environment` | The Twig environment you can add functionality to. | + +## timber/twig + +Filters the Twig environment used in the global context. + +You can use this filter if you want to add additional functionality to Twig, like global +variables, filters or functions. + +**since** 0.21.9 + +| Name | Type | Description | +| --- | --- | --- | +| $twig | `\Environment` | The Twig environment. | + +**PHP** + +```php +/** + * Adds Twig functionality. + * + * \@param \Twig\Environment $twig The Twig Environment to which you can add additional functionality. + */ +add_filter( 'timber/twig', function( $twig ) { + // Make get_theme_file_uri() usable as {{ theme_file() }} in Twig. + $twig->addFunction( new Twig\TwigFunction( 'theme_file', 'get_theme_file_uri' ) ); + + return $twig; +} ); +``` + +**Twig** + +```twig + + Logo {{ site.title }} + +``` + +## timber/cache/extension/lifetime + +Filters the Twig environment used in the global context. + +**DEPRECATED** since 2.0.0 + +## timber/cache/transient\_key + +Filters the transient key used for caching. + +**since** 2.1.0 + +| Name | Type | Description | +| --- | --- | --- | +| $trans_key | `string` | The transient key. | +| $key | `string` | The cache key. | +| $group | `string` | The cache group. | +| $cache_mode | `string` | The cache mode. | + +``` +add_filter( 'timber/cache/transient_key', function( $trans_key, $key, $group, $cache_mode ) { + return $trans_key . '_my_suffix'; +}, 10, 4 ); +``` + +## timber/cache/transient\_key + +Filters the transient key used for caching. + +**since** 2.1.0 + +| Name | Type | Description | +| --- | --- | --- | +| $trans_key | `string` | The transient key. | +| $key | `string` | The cache key. | +| $group | `string` | The cache group. | +| $cache_mode | `string` | The cache mode. | + +``` +add_filter( 'timber/cache/transient_key', function( $trans_key, $key, $group, $cache_mode ) { + return $trans_key . '_my_suffix'; +}, 10, 4 ); +``` + +## timber/locations + +Filters the filesystem paths to search for Twig templates. + +**since** 0.20.10 + +| Name | Type | Description | +| --- | --- | --- | +| $locs | `array` | An array of filesystem paths to search for Twig templates. | + +``` +add_filter( 'timber/locations', function( $locs ) { + $locs = \array_map(function ($loc) { + \array_unshift($loc, \dirname(__DIR__) . '/my-custom-dir'); + return $loc; + }, $locs); + + return $locs; +} ); +``` + +## timber\_locations + +Filters the filesystem paths to search for Twig templates. + +**DEPRECATED** since 2.0.0, use `timber/locations` + +## timber/menu/item\_objects + +Filters the sorted list of menu item objects before creating the Menu object. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $item | `array` | | +| $menu | `\WP_Term` | | + +``` +add_filter( 'timber/menu/item_objects', function ( $items ) { + return array_map(function ($item) { + if ( is_object( $item ) && ! ( $item instanceof \WP_Post ) ) { + return new \WP_Post( get_object_vars( $item ) ); + } + + return $item; + }, $items); +} ); +``` + +## timber/post/import\_data + +Filters the imported post data. + +Used internally for previews. + +**see** Timber::init() + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $data | `array` | An array of post data to import. | +| $post | `\Post` | The Timber post instance. | + +## timber/post/meta\_object\_field + +Filters field object data from Advanced Custom Fields. + +This filter is used by the ACF Integration. + +**see** [Timber\Post::field_object()](/docs/reference/timber-post/#field_object) + +**since** 1.6.0 + +| Name | Type | Description | +| --- | --- | --- | +| $value | `mixed` | The value. | +| $post_id | `int` or `null` | The post ID. | +| $field_name | `string` | The ACF field name. | +| $post | `\Post` | The post object. | + +## timber/post/authors + +Filters authors for a post. + +This filter is used by the CoAuthorsPlus integration. + +**see** [Timber\Post::authors()](/docs/reference/timber-post/#authors) + +**since** 1.1.4 + +| Name | Type | Description | +| --- | --- | --- | +| $authors | `array` | An array of User objects. Default: User object for `post_author`. | +| $post | `\Post` | The post object. | + +``` +add_filter( 'timber/post/authors', function( $author, $post ) { + foreach ($cauthors as $author) { + // do something with $author + } + + return $authors; +} ); +``` + +## timber/post/children\_args + +Filters the arguments for the query used to get the children of a post. + +This filter is used by the `Timber\Post::children()` method. It allows you to modify the +arguments for the `get_children` function. This way you can change the query to get the +children of a post. + +**see** [Timber\Post::children()](/docs/reference/timber-post/#children) + +**since** 2.1.0 + +| Name | Type | Description | +| --- | --- | --- | +| $arguments | `array` | An array of arguments for the `get_children` function. | +| $post | `\Post` | The post object. | + +``` +add_filter( 'timber/post/children_args', function( $args, $post ) { + + if ( $post->post_type === 'custom_post_type' ) { + $args['post_status'] = 'private'; + } + + return $args; +} ); +``` + +## timber/post/content/show\_password\_form\_for\_protected + +Filters whether the password form should be shown for password protected posts. + +This filter runs only when you call `{{ post.content }}` for a password protected +post. When this filter returns `true`, a password form will be shown instead of the +post content. If you want to modify the form itself, you can use the +`timber/post/content/password_form` filter. + +**since** 1.1.4 + +| Name | Type | Description | +| --- | --- | --- | +| $show_pw | `bool` | Whether the password form should be shown. Default `false`. | + +**PHP** + +```php +// Always show password form for password protected posts. +add_filter( 'timber/post/content/show_password_form_for_protected', '__return_true' ); +``` + +## timber/post/content/password\_form + +Filters the password form output. + +As an alternative to this filter, you could also use WordPress’s `the_password_form` filter. +The difference to this filter is, that you’ll also have the post object available as a second +parameter, in case you need that. + +**since** 1.1.4 + +| Name | Type | Description | +| --- | --- | --- | +| $form | `string` | Form output. Default WordPress password form output generated by `get_the_password_form()`. | +| $post | `\Post` | The post object. | + +**PHP** + +```php +// Modify the password form. +add_filter( 'timber/post/content/password_form', function( $form, $post ) { + return Timber::compile( 'assets/password-form.twig', array( 'post' => $post ) ); +}, 10, 2 ); +``` + +## timber/post/content/remove\_blocks + +Filters whether the content produced by block editor blocks should be removed or not from the content. + +If truthy then block whose content does not belong in the excerpt, will be removed. +This removal is done using WordPress Core `excerpt_remove_blocks` function. + +**see** excerpt_remove_blocks() The WordPress Core function that will handle the block removal from the excerpt. + +**since** 2.1.1 + +| Name | Type | Description | +| --- | --- | --- | +| $remove_blocks | `bool` | Whether blocks whose content should not be part of the excerpt should be removed or not from the excerpt. | + +## timber/post/excerpt/defaults + +Filters the default options used for post excerpts. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $defaults | `array` | An array of default options. You can see which options you can use when you look at the `$options` parameter for [PostExcerpt::__construct()](https://timber.github.io/docs/v2/reference/timber-postexcerpt/#__construct). | + +**PHP** + +```php +add_filter( 'timber/post/excerpt/defaults', function( $defaults ) { + // Only add a read more link if the post content isn’t longer than the excerpt. + $defaults['always_add_read_more'] = false; + + // Set a default character limit. + $defaults['words'] = 240; + + return $defaults; +} ); +``` + +## timber/post/excerpt/read\_more\_class + +Filters the CSS class used for excerpt links. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $class | `string` | The CSS class to use for the excerpt link. Default `read-more`. | + +**PHP** + +```php +// Change the CSS class for excerpt links. +add_filter( 'timber/post/excerpt/read_more_class', function( $class ) { + return 'read-more__link'; +} ); +``` + +## timber/post/preview/read\_more\_class + +Filters the CSS class used for excerpt links. + +**DEPRECATED** since 2.0.0 + +**since** 1.0.4 + +## timber/post/excerpt/read\_more\_link + +Filters the link used for a read more text in an excerpt. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $link | `string` | The HTML link. | +| $post | `\Post` | Post instance. | +| $linktext | `string` | The link text. | +| $read_more_class | `string` | The CSS class name. | + +## timber/post/get\_preview/read\_more\_link + +Filters the link used for a read more text in an excerpt. + +**DEPRECATED** since 2.0.0 + +**since** 1.1.3 + +## timber/site/update\_option + +Filters a value before it is updated in the site options. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $value | `mixed` | The new value. | +| $key | `string` | The option key. | +| $site_id | `int` | The site ID. | +| $site | `\Site` | The site object. | + +## timber\_site\_set\_meta + +Filters a value before it is updated in the site options. + +**DEPRECATED** since 2.0.0, use `timber/site/update_option` + +**since** 0.20.0 + +## timber/term/link + +Filters the link to the term archive page. + +**see** [Timber\Term::link()](/docs/reference/timber-term/#link) + +**since** 0.21.9 + +| Name | Type | Description | +| --- | --- | --- | +| $link | `string` | The link. | +| $term | `\Term` | The term object. | + +## timber\_term\_link + +Filters the link to the term archive page. + +**DEPRECATED** since 0.21.9, use `timber/term/link` + +## timber/term/path + +Filters the relative link (path) to a term archive page. + +``` +add_filter( 'timber/term/path', function( $rel, $term ) { + if ( $term->slug === 'news' ) { + return '/category/modified-url'; + } + + return $rel; +}, 10, 2 ); +``` + +**see** [Timber\Term::path()](/docs/reference/timber-term/#path) + +**since** 0.21.9 + +| Name | Type | Description | +| --- | --- | --- | +| $rel | `string` | The relative link. | +| $term | `\Term` | The term object. | + +## timber\_term\_path + +Filters the relative link (path) to a term archive page. + +**DEPRECATED** since 2.0.0, use `timber/term/path` + +## timber\_term\_set\_meta + +Filters term meta value that is going to be updated. + +**DEPRECATED** since 2.0.0 with no replacement + +## timber/term/meta/set + +Filters term meta value that is going to be updated. + +**DEPRECATED** since 2.0.0, with no replacement + +This filter is used by the ACF Integration. + +## timber/trim\_words/allowed\_tags + +Filters allowed tags for `trim_words()` helper. + +The `trim_words()` helper strips all HTML tags from a text it trims, except for a list of +allowed tags. Instead of passing the allowed tags every time you use `trim_words()` (or `{{ text|truncate }}` +in Twig), you can use this filter to set the allowed tags. + +**see** [Timber\TextHelper::trim_words()](/docs/reference/timber-texthelper/#trim_words) + +**since** 0.21.9 + +| Name | Type | Description | +| --- | --- | --- | +| $allowed_tags | `string` | Allowed tags, separated by one whitespace. Default `p a span b i br blockquote`. | + +## timber/integrations + +Filters the integrations that should be initialized by Timber. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $integrations | `\IntegrationInterface[]` | An array of PHP class names. Default: array of integrations that Timber initializes by default. | + +## timber/context + +Filters the global Timber context. + +By using this filter, you can add custom data to the global Timber context, which +means that this data will be available on every page that is initialized with +`Timber::context()`. + +Be aware that data will be cached as soon as you call `Timber::context()` for the +first time. That’s why you should add this filter before you call +`Timber::context()`. + +**see** [Timber\Timber::context()](/docs/reference/timber-timber/#context) + +**since** 0.21.7 + +| Name | Type | Description | +| --- | --- | --- | +| $context | `array` | The global context. | + +**PHP** + +```php +add_filter( 'timber/context', function( $context ) { + // Example: A custom value + $context['custom_site_value'] = 'Hooray!'; + + // Example: Add a menu to the global context. + $context['menu'] = new \Timber\Menu( 'primary-menu' ); + + // Example: Add all ACF options to global context. + $context['options'] = get_fields( 'options' ); + + return $context; +} ); +``` +**Twig** + +```twig +

{{ custom_site_value|e }}

+ +{% for item in menu.items %} + {# Display menu item #} +{% endfor %} + +
+ {% if options.footer_text is not empty %} + {{ options.footer_text|e }} + {% endif %} +
+``` + +## timber\_context + +Filters the global Timber context. + +**DEPRECATED** since 2.0.0, use `timber/context` + +## timber/render/file + +Filters the Twig template that should be rendered. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $file | `string` | The chosen Twig template name to render. | + +## timber\_render\_file + +Filters the Twig file that should be rendered. + +**DEPRECATED** since 2.0.0, use `timber/render/file` + +## timber/compile/file + +Filters the Twig template that should be compiled. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $file | `string` | The chosen Twig template name to compile. | + +## timber\_compile\_file + +Filters the Twig template that should be compiled. + +**DEPRECATED** since 2.0.0 + +## timber/render/data + +Filters the data that should be passed for rendering a Twig template. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $data | `array` | The data that is used to render the Twig template. | +| $file | `string` | The name of the Twig template to render. | + +## timber\_render\_data + +Filters the data that should be passed for rendering a Twig template. + +**DEPRECATED** since 2.0.0 + +## timber/compile/data + +Filters the data that should be passed for compiling a Twig template. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $data | `array` | The data that is used to compile the Twig template. | +| $file | `string` | The name of the Twig template to compile. | + +## timber\_compile\_data + +Filters the data that should be passed for compiling a Twig template. + +**DEPRECATED** since 2.0.0, use `timber/compile/data` + +## timber/compile/result + +Filters the compiled result before it is returned in `Timber::compile()`. + +It adds the possibility to filter the output ready for render. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $output | `string` or `bool` | the compiled output. | + +## timber\_compile\_result + +Filters the compiled result before it is returned. + +**DEPRECATED** since 2.0.0 use timber/compile/result + +**see** [Timber\Timber::fetch()](/docs/reference/timber-timber/#fetch) + +**since** 0.16.7 + +| Name | Type | Description | +| --- | --- | --- | +| $output | `string` | The compiled output. | + +## timber/twig/functions + +Filters the functions that are added to Twig. + +The `$functions` array is an associative array with the filter name as a key and an +arguments array as the value. In the arguments array, you pass the function to call with +a `callable` entry. + +This is an alternative filter that you can use instead of adding your function in the +`timber/twig` filter. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $functions | `array` | | + +**PHP** + +```php +add_filter( 'timber/twig/functions', function( $functions ) { + // Add your own function. + $functions['url_to_domain'] = [ + 'callable' => 'url_to_domain', + ]; + + // Replace a function. + $functions['get_image'] = [ + 'callable' => 'custom_image_get', + ]; + + // Remove a function. + unset( $functions['bloginfo'] ); + + return $functions; +} ); +``` + +## timber/twig/filters + +Filters the filters that are added to Twig. + +The `$filters` array is an associative array with the filter name as a key and an +arguments array as the value. In the arguments array, you pass the function to call with +a `callable` entry. + +This is an alternative filter that you can use instead of adding your filter in the +`timber/twig` filter. + +**since** 2.0.0 + +| Name | Type | Description | +| --- | --- | --- | +| $filters | `array` | | + +**PHP** + +```php +add_filter( 'timber/twig/default_filters', function( $filters ) { + // Add your own filter. + $filters['price'] = [ + 'callable' => 'format_price', + ]; + + // Replace a filter. + $filters['list'] = [ + 'callable' => 'custom_list_filter', + ]; + + // Remove a filter. + unset( $filters['list'] ); + + return $filters; +} ); +``` + +## timber/twig/escapers + +Filters the escaping filters that are added to Twig. + +The `$escaper_filters` array is an associative array with the filter name as a key and an +arguments array as the value. In the arguments array, you pass the function to call with +a `callable` entry. + +**since** 2.1.0 + +| Name | Type | Description | +| --- | --- | --- | +| $escaper_filters | `array` | | + +**PHP** + +```php +add_filter( 'timber/twig/escapers', function( $escaper_filters ) { + // Add your own filter. + $filters['esc_xml'] = [ + 'callable' => 'esc_xml', + 'options' => [ + 'is_safe' => ['html'], + ], + ]; + + // Remove a filter. + unset( $filters['esc_js'] ); + + return $filters; +} ); +``` + +## timber/url\_helper/url\_to\_file\_system/path + +Filters the path of a parsed URL. + +You can use this filter to alter the returned file system path. +This filter is used by the WPML integration. + +**see** [Timber\URLHelper::url_to_file_system()](/docs/reference/timber-urlhelper/#url_to_file_system) + +**since** 1.3.2 + +| Name | Type | Description | +| --- | --- | --- | +| $path | `string` | The current translated path | + +## timber/URLHelper/url\_to\_file\_system/path + +Filters the path of a parsed URL. + +**DEPRECATED** since 2.0.0, use `timber/url_helper/url_to_file_system/path` + +## timber/url\_helper/file\_system\_to\_url + +Filters the URL in URLHelper::file_system_to_url + +You can use this filter to alter the returned URL. +This filter is used by the WPML integration. + +**see** [Timber\URLHelper::file_system_to_url()](/docs/reference/timber-urlhelper/#file_system_to_url) + +**since** 1.3.2 + +| Name | Type | Description | +| --- | --- | --- | +| $url | `string` | The current translated url | + +## timber/URLHelper/file\_system\_to\_url + +Filters the URL in URLHelper::file_system_to_url + +**DEPRECATED** since 2.0.0, use `timber/url_helper/file_system_to_url` + +You can use this filter to alter the returned URL. +This filter is used by the WPML integration. + +| Name | Type | Description | +| --- | --- | --- | +| $url | `string` | The current url | + +## timber/url\_helper/get\_content\_subdir/home\_url + +Filters the home URL that is used to get the path relative to the content directory. + +**since** 1.3.2 + +| Name | Type | Description | +| --- | --- | --- | +| $home_url | `string` | The URL to use as the base for getting the content subdirectory. Default value of `home_url()`. | + +## timber/URLHelper/get\_content\_subdir/home\_url + +Filters the home URL that is used to get the path relative to the content directory. + +**DEPRECATED** since 2.0.0, use `timber/url_helper/get_content_subdir/home_url` + +## timber/url/schemes-whitelist + +Filters the schemes that are excluded for double slash removal. + +If an url start with one of the schemes in the whitelist, +that scheme will be excluded from the double slash removal. + +**since** 1.16.0 + +| Name | Type | Description | +| --- | --- | --- | +| $schemes_whitelist | `array` | the schemes that are excluded for double slash removal. | + +## timber/user/name + +Filters the name of a user. + +**since** 1.1.4 + +| Name | Type | Description | +| --- | --- | --- | +| $name | `string` | The name of the user. Default `display_name`. | +| $user | `\User` | The user object. | + diff --git a/content/v2/reference/timber-texthelper.md b/content/v2/reference/timber-texthelper.md index 60ea0d1a..11dbd92e 100644 --- a/content/v2/reference/timber-texthelper.md +++ b/content/v2/reference/timber-texthelper.md @@ -70,7 +70,7 @@ take the same amount of space in each post for example | Name | Type | Description | | --- | --- | --- | -| $string | | | +| $string | `mixed` | | | $tags | `array` | | --- diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 6146fae1..4dfc1e79 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,514 +2,514 @@ https://timber.github.io/docs/404.html - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/_index/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/installation/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/getting-started/setup/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/getting-started/setup/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/getting-started/switch-to-composer/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/getting-started/theming/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/getting-started/twig-tools/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/getting-started/video-tutorials/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/acf-cookbook/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/cheatsheet/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/comments/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/cookbook-images/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/cookbook-text/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/cookbook-twig/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/custom-page-templates/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/debugging/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/escapers/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/extending-timber/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/filters/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/functions/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/gutenberg/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/hosts-servers/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/internationalization/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/menus/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/pagination/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/performance/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/routing/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/sidebars/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/template-locations/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/testing/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/woocommerce/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/guides/wp-integration/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-archives/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-comment/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-helper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-image/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-imagehelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-menu/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-menuitem/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-pagination/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-post/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-postpreview/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-postquery/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-site/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-term/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-texthelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-theme/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-urlhelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber-user/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/reference/timber/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v1/upgrade-guides/1.0/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/getting-started/a-post-archive/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/getting-started/a-single-post/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/getting-started/introduction/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/getting-started/template-inheritance-and-includes/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/cheatsheet/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/class-maps/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/comments/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/context/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/cookbook-images/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/cookbook-text/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/custom-fields/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/custom-integrations/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/custom-page-templates/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/date-time/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/debugging/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/escaping/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/extending-timber/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/extending-twig/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/functions/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/gutenberg/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/hosts-servers/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/internationalization/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/menus/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/pagination/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/performance/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/posts/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/routing/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/shortcodes/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/sidebars/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/template-locations/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/terms/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/testing/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/twig-filters/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/twig/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/users/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/widgets/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/woocommerce/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/guides/wp-cli/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/installation/installation/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/installation/intro-to-composer/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/installation/manage-timber-with-composer/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/integrations/advanced-custom-fields/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/upgrade-guides/1.0/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/upgrade-guides/2.0/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/contributing/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-archives/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-attachment/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-cache-cleaner/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-comment/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-datetimehelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-externalimage/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-helper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-image/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-imagedimensions/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-imagehelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-menu/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-menuitem/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-pagesmenu/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-pagination/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-pathhelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-post/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-postarrayobject/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-postexcerpt/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-postquery/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-site/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-term/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-texthelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-theme/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-timber/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-urlhelper/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/reference/timber-user/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/hooks/filters/ - 2024-05-15 + 2024-06-07 https://timber.github.io/docs/v2/hooks/actions/ - 2024-05-15 + 2024-06-07 diff --git a/docs/v2/hooks/actions/index.html b/docs/v2/hooks/actions/index.html index 25c9cb8b..200f4f01 100644 --- a/docs/v2/hooks/actions/index.html +++ b/docs/v2/hooks/actions/index.html @@ -2,7 +2,7 @@ function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); - gtag('config', 'UA-126807198-1');Action Hooks – Timber v2 – Timber Documentation
Timber Logo
Action Hooks – Timber v2 – Timber Documentation
Timber Logo

You are reading the documentation for Timber v2.x. Switch to the documentation for Timber v1.x.

Action Hooks

timber_{$object_type}_get_meta_pre #

Filters post meta data before it is fetched from the database.

DEPRECATED since 2.0.0, use timber/{object_type}/pre_meta

timber/loader/render_file #

Fires after …

NameTypeDescription
$resultstring

timber_loader_render_file #

Fires after …

DEPRECATED since 2.0.0, use timber/loader/render_file

This action is used by the Timber Debug Bar extension.

timber/calling_php_file #

Fires after the calling PHP file was determined in Timber’s compile function.

This action is used by the Timber Debug Bar extension.

since 1.1.2

NameTypeDescription
$caller_filestring or nullThe calling script file.

timber/compile/done #

Fires after a Twig template was compiled and before the compiled data is returned.

This action can be helpful if you need to debug Twig template compilation.

since 2.0.0

NameTypeDescription
$outputstringThe compiled output.
$filestringThe name of the Twig template that was compiled.
$dataarrayThe data that was used to compile the Twig template.
$expiresbool or int or arrayThe expiration time of the cache in seconds, or false to disable cache.
$cache_modestringAny of the cache mode constants defined in Timber\Loader.

timber_compile_done #

Fires after a Twig template was compiled and before the compiled data is returned.

DEPRECATED since 2.0.0, use timber/compile/done

Filter Hooks – Timber v2 – Timber Documentation
Timber Logo
Filter Hooks – Timber v2 – Timber Documentation
Timber Logo

You are reading the documentation for Timber v2.x. Switch to the documentation for Timber v1.x.

Filter Hooks

timber/meta/transform_value #

Filters whether to transform a meta value.

If the filter returns true, all meta value will be transformed to Timber/standard PHP objects if possible.

since 2.0.0

NameTypeDescription
$transform_valuebool

PHP

// Transforms all meta value.
add_filter( 'timber/meta/transform_value', '__return_true' );

timber/{$object_type}/pre_meta #

Filters object meta data before it is fetched from the database.

since 2.0.0

NameTypeDescription
$object_metastring or nullThe field value. Default null. Passing a non-null value will skip fetching the value from the database and will use the value from the filter instead.
$post_idintThe post ID.
$field_namestringThe name of the meta field to get the value for.
$objectobjectThe Timber object.
$argsarrayAn array of arguments.

PHP

// Disable fetching meta values.
add_filter( 'timber/post/pre_meta', '__return_false' );

// Add your own meta data.
add_filter( 'timber/post/pre_meta', function( $post_meta, $post_id, $post ) {
$post_meta = array_merge( $post_meta, [
'custom_data_1' => 73,
'custom_data_2' => 274,
] );

return $post_meta;
}, 10, 3 );

timber_{$object_type}_get_meta_field_pre #

Filters the value for a post meta field before it is fetched from the database.

DEPRECATED since 2.0.0, use timber/{object_type}/pre_meta

timber/{$object_type}/meta #

Filters the value for a post meta field.

This filter is used by the ACF Integration.

see Timber\Post::meta()

since 2.0.0

NameTypeDescription
$post_metastringThe field value.
$post_idintThe post ID.
$field_namestringThe name of the meta field to get the value for.
$post\CoreEntityThe post object.
$argsarrayAn array of arguments.

PHP

add_filter( 'timber/post/meta', function( $post_meta, $post_id, $field_name, $post ) {
if ( 'event' === $post->post_type ) {
// Do something special.
$post_meta['foo'] = $post_meta['foo'] . ' bar';
}

return $post_meta;
}, 10, 4 );

timber/term/meta/field #

Filters the value for a term meta field.

DEPRECATED since 2.0.0, use timber/term/meta

timber_{$object_type}_get_meta_field #

Filters the value for an object meta field.

DEPRECATED since 2.0.0, use timber/{object_type}/meta

timber_{$object_type}_get_meta #

Filters object meta data fetched from the database.

DEPRECATED since 2.0.0, use timber/{object_type}/meta

timber/comment/classmap #

Filters the class(es) used for comments linked to different post types.

The default class is Timber\Comment. You can use this filter to provide your own comment class for specific post types.

Make sure to merge in your additional classes instead of overwriting the whole Class Map.

since 2.0.0

NameTypeDescription
$classmaparrayThe post class(es) to use. An associative array where the key is the post type and the value the name of the class to use for the comments of this post type or a callback that determines the class to use.
use Book;
+
+add_filter( 'timber/post/classmap', function( $classmap ) {
+    $custom_classmap = [
+        'book' => BookComment::class,
+    ];
+
+    return array_merge( $classmap, $custom_classmap );
+} );
+

timber/comment/class #

Filters the comment class based on your custom criteria.

Maybe you want to set a custom class based upon the comment type? This allows you to filter the PHP class, utilizing data from the WP_Comment object.

since 2.0.0

NameTypeDescription
$classstringThe class to use.
$comment\WP_CommentThe comment object.
add_filter( 'timber/comment/class', function( $class, $comment ) {
+    if ( $comment->comment_type === 'pingback' ) {
+        return PingBackComment::class;
+    }
+    return $class;
+}, 10, 2 );
+

timber/menu/classmap #

Filters the class(es) used for different menus.

Read more about this in the documentation for Menu Class Maps.

The default Menu Class Map will contain class names for locations that map to Timber\Menu.

since 2.0.0

NameTypeDescription
$classmaparrayThe menu class(es) to use. An associative array where the key is the location and the value the name of the class to use for this menu or a callback that determines the class to use.
add_filter( 'timber/menu/classmap', function( $classmap ) {
+    $custom_classmap = [
+        'primary'   => MenuPrimary::class,
+        'secondary' => MenuSecondary::class,
+    ];
+
+    return array_merge( $classmap, $custom_classmap );
+} );
+

timber/menu/class #

Filters the menu class based on your custom criteria.

Maybe the location is not appropriate in some cases. This filter will allow you to filter the class on whatever data is available.

since 2.0.0

NameTypeDescription
$classstringThe class to use.
$term\WP_TermThe menu term.
$argsarrayThe arguments passed to the menu.
add_filter( 'timber/menu/class', function( $class, $term, $args ) {
+    if ( $args['depth'] === 1 ) {
+        return SingleLevelMenu::class;
+    }
+
+    return MultiLevelMenu::class;
+}, 10, 3 );
+

timber/menuitem/classmap #

Filters the class(es) used for different menu items.

Read more about this in the documentation for Menu Item Class Maps.

The default Menu Item Class Map will contain class names for locations that map to Timber\MenuItem.

since 2.0.0

NameTypeDescription
$classmaparrayThe menu item class(es) to use. An associative array where the key is the location and the value the name of the class to use for this menu item or a callback that determines the class to use.
add_filter( 'timber/menuitem/classmap', function( $classmap ) {
+    $custom_classmap = [
+        'primary'   => MenuItemFooter::class,
+        'secondary' => MenuItemHeader::class,
+    ];
+
+    return array_merge( $classmap, $custom_classmap );
+} );
+

timber/menuitem/class #

Filters the menu item class

since 2.0.0

NameTypeDescription
$classstringThe class to use.
$item\WP_PostThe menu item.
$menu\MenuThe menu object.
add_filter( 'timber/menuitem/class', function( $class, $item, $menu ) {
+    if ( $item->post_parent ) {
+        return SubMenuItem::class;
+    }
+
+    return MenuItem::class;
+}, 10, 3 );
+

timber/pages_menu/class #

Filters the class used for different menus.

Read more about this in the documentation for Pages Menu Class filter.

since 2.0.0

NameTypeDescription
$classstringThe pages menu class to use.
$argsarrayThe arguments passed to Timber::get_pages_menu().
add_filter( 'timber/pages_menu/class', function( $class ) {
+    return ExtendedPagesMenu::class;
+} );
+

timber/post/classmap #

Filters the class(es) used for different post types.

Read more about this in the documentation for Post Class Maps.

The default Post Class Map will contain class names for posts, pages that map to Timber\Post and a callback that will map attachments to Timber\Attachment and attachments that are images to Timber\Image.

Make sure to merge in your additional classes instead of overwriting the whole Class Map.

since 2.0.0

NameTypeDescription
$classmaparrayThe post class(es) to use. An associative array where the key is the post type and the value the name of the class to use for this post type or a callback that determines the class to use.
use Book;
+use Page;
+
+add_filter( 'timber/post/classmap', function( $classmap ) {
+    $custom_classmap = [
+        'page' => Page::class,
+        'book' => Book::class,
+    ];
+
+    return array_merge( $classmap, $custom_classmap );
+} );
+

timber/post/class #

Filters the post class based on your custom criteria.

Maybe you want to set a custom class based upon how blocks are used? This allows you to filter the PHP class, utilizing data from the WP_Post object.

since 2.0.0

NameTypeDescription
$classstringThe class to use.
$post\WP_PostThe post object.
add_filter( 'timber/post/class', function( $class, $post ) {
+    if ( has_blocks($post) ) {
+        return GutenbergPost::class;
+    }
+
+    return $class;
+}, 10, 2 );
+

timber/post/image_extensions #

Filters the list of image extensions that will be used to determine if an attachment is an image.

You can use this filter to add or remove image extensions to the list of extensions that will be used to determine if an attachment is an image.

since 2.0.0

NameTypeDescription
$extensionsarrayAn array of image extensions.

timber/term/classmap #

Filters the class(es) used for terms of different taxonomies.

The default Term Class Map will contain class names mapped to the build-in post_tag and category taxonomies.

since 2.0.0

NameTypeDescription
$classmaparrayThe term class(es) to use. An associative array where the key is the taxonomy name and the value the name of the class to use for this taxonomy or a callback that determines the class to use.
add_filter( 'timber/term/classmap', function( $classmap ) {
+    $custom_classmap = [
+        'expertise'   => ExpertiseTerm::class,
+    ];
+
+    return array_merge( $classmap, $custom_classmap );
+} );
+

timber/term/class #

Filters the term class based on your custom criteria.

Maybe you want to set a custom class based upon a certain category? This allows you to filter the PHP class, utilizing data from the WP_Term object.

since 2.0.0

NameTypeDescription
$classstringThe class to use.
$term\WP_TermThe term object.
add_filter( 'timber/term/class', function( $class, $term ) {
+    if ( get_term_meta($term->term_id, 'is_special_category', true) ) {
+        return MyCustomTermClass::class;
+    }
+
+    return $class;
+}, 10, 2 );
+

timber/user/class #

Filters the name of the PHP class used to instantiate Timber\User objects.

The User Class Map receives the default Timber\User class and a WP_User object. You should be able to decide which class to use based on that user object.

since 2.0.0

NameTypeDescription
$classstringThe name of the class. Default Timber\User.
$user\WP_UserThe WP_User object that is used as the base for the Timber\User object.

PHP

use Administrator;
use Editor;

add_filter( 'timber/user/class', function( $class, \WP_User $user ) {
if ( in_array( 'editor', $user->roles, true ) ) {
return Editor::class;
} elseif ( in_array( 'author', $user->roles, true ) ) {
return Author::class;
}

return $class;
}, 10, 2 );

timber/transient/slug #

Filters the transient slug.

This might be useful if you are using a multilingual solution.

since 0.22.6

NameTypeDescription
$slugstringThe slug for the transient.

timber/transient/force_transients #

Filters whether to force a locked transients to be regenerated.

If a transient is locked, it means that another process is currently generating the data. If you want to force the transient to be regenerated, during that process, you can set this filter to true.

since 2.0.0

NameTypeDescription
$forceboolWhether to force a locked transient to be regenerated.

timber_force_transients #

Filters whether to force a locked transients to be regenerated.

DEPRECATED since 2.0.0, use timber/transient/force_transients

If a transient is locked, it means that another process is currently generating the data. If you want to force the transient to be regenerated, during that process, you can set this filter to true.

timber/transient/force_transient_{$slug} #

Filters whether to force a specific locked transients to be regenerated.

If a transient is locked, it means that another process is currently generating the data. If you want to force the transient to be regenerated during that process, you can set this value to true.

since 2.0.0

NameTypeDescription
$forceboolWhether to force a locked transient to be regenerated.

PHP


add_filter( 'timber/transient/force_transient_mycustumslug', function($force) {
if(false == something_special_has_occurred()){
return false;
}

return true;
}, 10 );

timber_force_transient_{$slug} #

Filters whether to force a specific locked transients to be regenerated.

DEPRECATED since 2.0.0, use timber/transient/force_transient_{$slug}

If a transient is locked, it means that another process is currently generating the data. If you want to force the transient to be regenerated, during that process, you can set this value to true. $slug The transient slug.

NameTypeDescription
$forceboolWhether to force a locked transient to be regenerated.

timber/helper/wp_title_separator #

Filters the separator used for the page title.

since 2.0.0

NameTypeDescription
$separatorstringThe separator to use. Default ' '.

timber_wp_title_seperator #

Filters the separator used for the page title.

DEPRECATED since 2.0.0, use timber/helper/wp_title_separator

timber/image/src #

Filters the src URL for a Timber\Image.

see Timber\Image::src()

since 0.21.7

NameTypeDescription
$srcstringThe image src.
$idintThe image ID.

timber_image_src #

Filters the src URL for a Timber\Image.

DEPRECATED since 2.0.0, use timber/image/src

timber/sideload_image/basename #

Filters basename for sideloaded files.

since 2.1.0

NameTypeDescription
$basenamestringCurrent basename for the sideloaded file.
$path_partsarrayArray with path info for the sideloaded file.

PHP

// Change the basename used for sideloaded images.
add_filter( 'timber/sideload_image/basename', function ($basename, $path_parts) {
return $path_parts['filename'] . '-' . substr($basename, 0, 6);
}, 10, 2)

timber/sideload_image/subdir #

Filters to directory that should be used for sideloaded images.

since 2.0.0

NameTypeDescription
$subdirstringThe subdir name to use for sideloaded images. Return an empty string or a falsey value in order to not use a subfolder. Default external.

PHP

// Change the subdirectory used for sideloaded images.
add_filter( 'timber/sideload_image/subdir', function( $subdir ) {
return 'sideloaded';
} );

// Disable subdirectory used for sideloaded images.
add_filter( 'timber/sideload_image/subdir', '__return_false' );

timber/image_helper/pre_analyze_url #

Filters whether to short-circuit the ImageHelper::analyze_url() file path of a URL located in a theme directory.

Returning a non-null value from the filter will short-circuit ImageHelper::analyze_url(), returning that value.

since 2.0.0

NameTypeDescription
$infoarray<string,mixed> or nullThe URL components array to short-circuit with. Default null.
$urlstringThe URL pointing to an image.

timber/image_helper/analyze_url #

Filters the array of analyzed URL components.

since 2.0.0

NameTypeDescription
$infoarray<string,mixed>The URL components.
$urlstringThe URL pointing to an image.

timber/image_helper/pre_theme_url_to_dir #

Filters whether to short-circuit the ImageHelper::theme_url_to_dir() file path of a URL located in a theme directory.

Returning a non-null value from the filter will short-circuit ImageHelper::theme_url_to_dir(), returning that value.

since 2.0.0

NameTypeDescription
$pathstring or nullFull path to short-circuit with. Default null.
$srcstringThe URL to be converted.

timber/image_helper/theme_url_to_dir #

Filters the raw file path of a URL located in a theme directory.

since 2.0.0

NameTypeDescription
$pathstringThe resolved full path to $src.
$srcstringThe URL that was converted.

timber/image/new_url #

Filters the URL for the resized version of a Timber\Image.

You’ll probably need to use this in combination with timber/image/new_path.

since 1.0.0

NameTypeDescription
$new_urlstringThe URL to the resized version of an image.

timber/image/new_path #

Filters the destination path for the resized version of a Timber\Image.

A possible use case for this would be to store all images generated by Timber in a separate directory. You’ll probably need to use this in combination with timber/image/new_url.

since 1.0.0

NameTypeDescription
$destination_pathstringFull path to the destination of a resized image.

timber/cache/mode #

Filters the cache mode.

You can read more about Caching in the [Performance/Caching]({{<relref "performance.md" >}}) guide.

since 0.20.10

NameTypeDescription
$cache_modestringThe cache mode. Can be one of the following: Timber\Loader::CACHE_NONE, Timber\Loader::CACHE_OBJECT, Timber\Loader::CACHE_TRANSIENT, Timber\Loader::CACHE_SITE_TRANSIENT, Timber\Loader::CACHE_USE_DEFAULT. Default Timber\Loader::CACHE_TRANSIENT.

timber_cache_mode #

Filters the cache mode.

DEPRECATED since 2.0.0, use timber/cache/mode

timber/loader/render_data #

Filters …

since 0.20.10

NameTypeDescription
$dataarray
$filestring

timber_loader_render_data #

Filters …

DEPRECATED since 2.0.0, use timber/loader/render_data

timber/output/pre-cache #

Filters $output before it is cached.

since 2.1.0

NameTypeDescription
$outputstring
$dataarray
$filestring

timber/output #

Filters …

since 0.20.10

NameTypeDescription
$outputstring
$dataarray
$filestring

timber_output #

Filters …

DEPRECATED since 2.0.0, use timber/output

timber/loader/paths #

Filters the template paths used by the Loader.

DEPRECATED since 2.0.0, use timber/locations

since 0.20.10

NameTypeDescription
$pathsarray

timber/loader/loader #

Filters …

link https://github.com/timber/timber/pull/1254

since 1.1.11

timber/twig/environment/options #

Filters the environment options that are used when creating a Twig Environment instance.

By default, Timber sets the following values:

  • 'debug' => WP_DEBUG
  • 'autoescape' => false
  • 'cache' => false

link https://twig.symfony.com/doc/2.x/api.html#environment-options

since 1.9.5

NameTypeDescription
$environment_optionsarrayAn array of Twig environment options.

PHP

add_filter( 'timber/twig/environment/options', 'update_twig_environment_options' );

/**
* Updates Twig environment options.
*
* @link https://twig.symfony.com/doc/2.x/api.html#environment-options
*
* \@param array $options An array of environment options.
*
* @return array
*/

function update_twig_environment_options( $options ) {
$options['cache'] = true;
$options['auto_reload'] = true;

return $options;
}

timber/cache/location #

Filters the cache location used for Twig.

DEPRECATED since 2.0.0

Allows you to set a new cache location for Twig. If the folder doesn’t exist yet, it will be created automatically.

since 0.20.10

NameTypeDescription
$twig_cache_locstringFull path to the cache location. Default /cache/twig in the Timber root folder.

timber/cache/enable_extension #

Filters the cache extension activation.

Allows users to disable the cache extension and use their own

since 2.0.0

NameTypeDescription
$enable_cache_extensionboolWhether to enable the cache extension.

timber/loader/twig #

Filters …

since 0.20.10

NameTypeDescription
$twig\EnvironmentThe Twig environment you can add functionality to.

timber/twig #

Filters the Twig environment used in the global context.

You can use this filter if you want to add additional functionality to Twig, like global variables, filters or functions.

since 0.21.9

NameTypeDescription
$twig\EnvironmentThe Twig environment.

PHP

/**
* Adds Twig functionality.
*
* \@param \Twig\Environment $twig The Twig Environment to which you can add additional functionality.
*/

add_filter( 'timber/twig', function( $twig ) {
// Make get_theme_file_uri() usable as {{ theme_file() }} in Twig.
$twig->addFunction( new Twig\TwigFunction( 'theme_file', 'get_theme_file_uri' ) );

return $twig;
} );

Twig

<a class="navbar-brand" href="{{ site.url }}">
<img src="{{ theme_file( 'build/img/logo-example.svg' ) }}" alt="Logo {{ site.title }}">
</a>

timber/cache/extension/lifetime #

Filters the Twig environment used in the global context.

DEPRECATED since 2.0.0

timber/cache/transient_key #

Filters the transient key used for caching.

since 2.1.0

NameTypeDescription
$trans_keystringThe transient key.
$keystringThe cache key.
$groupstringThe cache group.
$cache_modestringThe cache mode.
add_filter( 'timber/cache/transient_key', function( $trans_key, $key, $group, $cache_mode ) {
+    return $trans_key . '_my_suffix';
+}, 10, 4 );
+

timber/cache/transient_key #

Filters the transient key used for caching.

since 2.1.0

NameTypeDescription
$trans_keystringThe transient key.
$keystringThe cache key.
$groupstringThe cache group.
$cache_modestringThe cache mode.
add_filter( 'timber/cache/transient_key', function( $trans_key, $key, $group, $cache_mode ) {
+    return $trans_key . '_my_suffix';
+}, 10, 4 );
+

timber/locations #

Filters the filesystem paths to search for Twig templates.

since 0.20.10

NameTypeDescription
$locsarrayAn array of filesystem paths to search for Twig templates.
add_filter( 'timber/locations', function( $locs ) {
+  $locs = \array_map(function ($loc) {
+     \array_unshift($loc, \dirname(__DIR__) . '/my-custom-dir');
+      return $loc;
+  }, $locs);
+
+    return $locs;
+} );
+

timber_locations #

Filters the filesystem paths to search for Twig templates.

DEPRECATED since 2.0.0, use timber/locations

timber/menu/item_objects #

Filters the sorted list of menu item objects before creating the Menu object.

since 2.0.0

NameTypeDescription
$itemarray
$menu\WP_Term
add_filter( 'timber/menu/item_objects', function ( $items ) {
+    return array_map(function ($item) {
+        if ( is_object( $item ) && ! ( $item instanceof \WP_Post ) ) {
+            return new \WP_Post( get_object_vars( $item ) );
+        }
+
+        return $item;
+    }, $items);
+} );
+

timber/post/import_data #

Filters the imported post data.

Used internally for previews.

see Timber::init()

since 2.0.0

NameTypeDescription
$dataarrayAn array of post data to import.
$post\PostThe Timber post instance.

timber/post/meta_object_field #

Filters field object data from Advanced Custom Fields.

This filter is used by the ACF Integration.

see Timber\Post::field_object()

since 1.6.0

NameTypeDescription
$valuemixedThe value.
$post_idint or nullThe post ID.
$field_namestringThe ACF field name.
$post\PostThe post object.

timber/post/authors #

Filters authors for a post.

This filter is used by the CoAuthorsPlus integration.

see Timber\Post::authors()

since 1.1.4

NameTypeDescription
$authorsarrayAn array of User objects. Default: User object for post_author.
$post\PostThe post object.
add_filter( 'timber/post/authors', function( $author, $post ) {
+     foreach ($cauthors as $author) {
+       // do something with $author
+     }
+
+    return $authors;
+} );
+

timber/post/children_args #

Filters the arguments for the query used to get the children of a post.

This filter is used by the Timber\Post::children() method. It allows you to modify the arguments for the get_children function. This way you can change the query to get the children of a post.

see Timber\Post::children()

since 2.1.0

NameTypeDescription
$argumentsarrayAn array of arguments for the get_children function.
$post\PostThe post object.
add_filter( 'timber/post/children_args', function( $args, $post ) {
+
+    if ( $post->post_type === 'custom_post_type' ) {
+       $args['post_status'] = 'private';
+    }
+
+    return $args;
+} );
+

timber/post/content/show_password_form_for_protected #

Filters whether the password form should be shown for password protected posts.

This filter runs only when you call {{ post.content }} for a password protected post. When this filter returns true, a password form will be shown instead of the post content. If you want to modify the form itself, you can use the timber/post/content/password_form filter.

since 1.1.4

NameTypeDescription
$show_pwboolWhether the password form should be shown. Default false.

PHP

// Always show password form for password protected posts.
add_filter( 'timber/post/content/show_password_form_for_protected', '__return_true' );

timber/post/content/password_form #

Filters the password form output.

As an alternative to this filter, you could also use WordPress’s the_password_form filter. The difference to this filter is, that you’ll also have the post object available as a second parameter, in case you need that.

since 1.1.4

NameTypeDescription
$formstringForm output. Default WordPress password form output generated by get_the_password_form().
$post\PostThe post object.

PHP

// Modify the password form.
add_filter( 'timber/post/content/password_form', function( $form, $post ) {
return Timber::compile( 'assets/password-form.twig', array( 'post' => $post ) );
}, 10, 2 );

timber/post/content/remove_blocks #

Filters whether the content produced by block editor blocks should be removed or not from the content.

If truthy then block whose content does not belong in the excerpt, will be removed. This removal is done using WordPress Core excerpt_remove_blocks function.

see excerpt_remove_blocks() The WordPress Core function that will handle the block removal from the excerpt.

since 2.1.1

NameTypeDescription
$remove_blocksboolWhether blocks whose content should not be part of the excerpt should be removed or not from the excerpt.

timber/post/excerpt/defaults #

Filters the default options used for post excerpts.

since 2.0.0

NameTypeDescription
$defaultsarrayAn array of default options. You can see which options you can use when you look at the $options parameter for PostExcerpt::__construct().

PHP

add_filter( 'timber/post/excerpt/defaults', function( $defaults ) {
// Only add a read more link if the post content isn’t longer than the excerpt.
$defaults['always_add_read_more'] = false;

// Set a default character limit.
$defaults['words'] = 240;

return $defaults;
} );

timber/post/excerpt/read_more_class #

Filters the CSS class used for excerpt links.

since 2.0.0

NameTypeDescription
$classstringThe CSS class to use for the excerpt link. Default read-more.

PHP

// Change the CSS class for excerpt links.
add_filter( 'timber/post/excerpt/read_more_class', function( $class ) {
return 'read-more__link';
} );

timber/post/preview/read_more_class #

Filters the CSS class used for excerpt links.

DEPRECATED since 2.0.0

since 1.0.4

Filters the link used for a read more text in an excerpt.

since 2.0.0

NameTypeDescription
$linkstringThe HTML link.
$post\PostPost instance.
$linktextstringThe link text.
$read_more_classstringThe CSS class name.

Filters the link used for a read more text in an excerpt.

DEPRECATED since 2.0.0

since 1.1.3

timber/site/update_option #

Filters a value before it is updated in the site options.

since 2.0.0

NameTypeDescription
$valuemixedThe new value.
$keystringThe option key.
$site_idintThe site ID.
$site\SiteThe site object.

timber_site_set_meta #

Filters a value before it is updated in the site options.

DEPRECATED since 2.0.0, use timber/site/update_option

since 0.20.0

Filters the link to the term archive page.

see Timber\Term::link()

since 0.21.9

NameTypeDescription
$linkstringThe link.
$term\TermThe term object.

Filters the link to the term archive page.

DEPRECATED since 0.21.9, use timber/term/link

timber/term/path #

Filters the relative link (path) to a term archive page.

add_filter( 'timber/term/path', function( $rel, $term ) {
+    if ( $term->slug === 'news' ) {
+       return '/category/modified-url';
+    }
+
+    return $rel;
+}, 10, 2 );
+

see Timber\Term::path()

since 0.21.9

NameTypeDescription
$relstringThe relative link.
$term\TermThe term object.

timber_term_path #

Filters the relative link (path) to a term archive page.

DEPRECATED since 2.0.0, use timber/term/path

timber_term_set_meta #

Filters term meta value that is going to be updated.

DEPRECATED since 2.0.0 with no replacement

timber/term/meta/set #

Filters term meta value that is going to be updated.

DEPRECATED since 2.0.0, with no replacement

This filter is used by the ACF Integration.

timber/trim_words/allowed_tags #

Filters allowed tags for trim_words() helper.

The trim_words() helper strips all HTML tags from a text it trims, except for a list of allowed tags. Instead of passing the allowed tags every time you use trim_words() (or {{ text|truncate }} in Twig), you can use this filter to set the allowed tags.

see Timber\TextHelper::trim_words()

since 0.21.9

NameTypeDescription
$allowed_tagsstringAllowed tags, separated by one whitespace. Default p a span b i br blockquote.

timber/integrations #

Filters the integrations that should be initialized by Timber.

since 2.0.0

NameTypeDescription
$integrations\IntegrationInterface[]An array of PHP class names. Default: array of integrations that Timber initializes by default.

timber/context #

Filters the global Timber context.

By using this filter, you can add custom data to the global Timber context, which means that this data will be available on every page that is initialized with Timber::context().

Be aware that data will be cached as soon as you call Timber::context() for the first time. That’s why you should add this filter before you call Timber::context().

see Timber\Timber::context()

since 0.21.7

NameTypeDescription
$contextarrayThe global context.

PHP

add_filter( 'timber/context', function( $context ) {
// Example: A custom value
$context['custom_site_value'] = 'Hooray!';

// Example: Add a menu to the global context.
$context['menu'] = new \Timber\Menu( 'primary-menu' );

// Example: Add all ACF options to global context.
$context['options'] = get_fields( 'options' );

return $context;
} );

Twig

<h1>{{ custom_site_value|e }}</h1>

{% for item in menu.items %}
{# Display menu item #}
{% endfor %}

<footer>
{% if options.footer_text is not empty %}
{{ options.footer_text|e }}
{% endif %}
</footer>

timber_context #

Filters the global Timber context.

DEPRECATED since 2.0.0, use timber/context

timber/render/file #

Filters the Twig template that should be rendered.

since 2.0.0

NameTypeDescription
$filestringThe chosen Twig template name to render.

timber_render_file #

Filters the Twig file that should be rendered.

DEPRECATED since 2.0.0, use timber/render/file

timber/compile/file #

Filters the Twig template that should be compiled.

since 2.0.0

NameTypeDescription
$filestringThe chosen Twig template name to compile.

timber_compile_file #

Filters the Twig template that should be compiled.

DEPRECATED since 2.0.0

timber/render/data #

Filters the data that should be passed for rendering a Twig template.

since 2.0.0

NameTypeDescription
$dataarrayThe data that is used to render the Twig template.
$filestringThe name of the Twig template to render.

timber_render_data #

Filters the data that should be passed for rendering a Twig template.

DEPRECATED since 2.0.0

timber/compile/data #

Filters the data that should be passed for compiling a Twig template.

since 2.0.0

NameTypeDescription
$dataarrayThe data that is used to compile the Twig template.
$filestringThe name of the Twig template to compile.

timber_compile_data #

Filters the data that should be passed for compiling a Twig template.

DEPRECATED since 2.0.0, use timber/compile/data

timber/compile/result #

Filters the compiled result before it is returned in Timber::compile().

It adds the possibility to filter the output ready for render.

since 2.0.0

NameTypeDescription
$outputstring or boolthe compiled output.

timber_compile_result #

Filters the compiled result before it is returned.

DEPRECATED since 2.0.0 use timber/compile/result

see Timber\Timber::fetch()

since 0.16.7

NameTypeDescription
$outputstringThe compiled output.

timber/twig/functions #

Filters the functions that are added to Twig.

The $functions array is an associative array with the filter name as a key and an arguments array as the value. In the arguments array, you pass the function to call with a callable entry.

This is an alternative filter that you can use instead of adding your function in the timber/twig filter.

since 2.0.0

NameTypeDescription
$functionsarray

PHP

add_filter( 'timber/twig/functions', function( $functions ) {
// Add your own function.
$functions['url_to_domain'] = [
'callable' => 'url_to_domain',
];

// Replace a function.
$functions['get_image'] = [
'callable' => 'custom_image_get',
];

// Remove a function.
unset( $functions['bloginfo'] );

return $functions;
} );

timber/twig/filters #

Filters the filters that are added to Twig.

The $filters array is an associative array with the filter name as a key and an arguments array as the value. In the arguments array, you pass the function to call with a callable entry.

This is an alternative filter that you can use instead of adding your filter in the timber/twig filter.

since 2.0.0

NameTypeDescription
$filtersarray

PHP

add_filter( 'timber/twig/default_filters', function( $filters ) {
// Add your own filter.
$filters['price'] = [
'callable' => 'format_price',
];

// Replace a filter.
$filters['list'] = [
'callable' => 'custom_list_filter',
];

// Remove a filter.
unset( $filters['list'] );

return $filters;
} );

timber/twig/escapers #

Filters the escaping filters that are added to Twig.

The $escaper_filters array is an associative array with the filter name as a key and an arguments array as the value. In the arguments array, you pass the function to call with a callable entry.

since 2.1.0

NameTypeDescription
$escaper_filtersarray

PHP

add_filter( 'timber/twig/escapers', function( $escaper_filters ) {
// Add your own filter.
$filters['esc_xml'] = [
'callable' => 'esc_xml',
'options' => [
'is_safe' => ['html'],
],
];

// Remove a filter.
unset( $filters['esc_js'] );

return $filters;
} );

timber/url_helper/url_to_file_system/path #

Filters the path of a parsed URL.

You can use this filter to alter the returned file system path. This filter is used by the WPML integration.

see Timber\URLHelper::url_to_file_system()

since 1.3.2

NameTypeDescription
$pathstringThe current translated path

timber/URLHelper/url_to_file_system/path #

Filters the path of a parsed URL.

DEPRECATED since 2.0.0, use timber/url_helper/url_to_file_system/path

timber/url_helper/file_system_to_url #

Filters the URL in URLHelper::file_system_to_url

You can use this filter to alter the returned URL. This filter is used by the WPML integration.

see Timber\URLHelper::file_system_to_url()

since 1.3.2

NameTypeDescription
$urlstringThe current translated url

timber/URLHelper/file_system_to_url #

Filters the URL in URLHelper::file_system_to_url

DEPRECATED since 2.0.0, use timber/url_helper/file_system_to_url

You can use this filter to alter the returned URL. This filter is used by the WPML integration.

NameTypeDescription
$urlstringThe current url

timber/url_helper/get_content_subdir/home_url #

Filters the home URL that is used to get the path relative to the content directory.

since 1.3.2

NameTypeDescription
$home_urlstringThe URL to use as the base for getting the content subdirectory. Default value of home_url().

timber/URLHelper/get_content_subdir/home_url #

Filters the home URL that is used to get the path relative to the content directory.

DEPRECATED since 2.0.0, use timber/url_helper/get_content_subdir/home_url

timber/url/schemes-whitelist #

Filters the schemes that are excluded for double slash removal.

If an url start with one of the schemes in the whitelist, that scheme will be excluded from the double slash removal.

since 1.16.0

NameTypeDescription
$schemes_whitelistarraythe schemes that are excluded for double slash removal.

timber/user/name #

Filters the name of a user.

since 1.1.4

NameTypeDescription
$namestringThe name of the user. Default display_name.
$user\UserThe user object.
Timber\​TextHelper – Timber v2 – Timber Documentation
Timber Logo

You are reading the documentation for Timber v2.x. Switch to the documentation for Timber v1.x.

Timber\​TextHelper

Class provides different text-related functions commonly used in WordPress development

Overview #

Methods #

NameReturn TypeSummary/Returns
remove_tags()null or string or string[]
trim_characters()stringTrims text to a certain number of characters.

Returns: trimmed text.
trim_words()string

Class Methods #

trim_characters() #

Trims text to a certain number of characters.

This function can be useful for excerpt of the post As opposed to wp_trim_words trims characters that makes text to take the same amount of space in each post for example

since 1.2.0

trim_characters( string $text, int $num_chars = 60, string $more = '&hellip;' )

Returns: string trimmed text.

NameTypeDescription
$textstringText to trim.
$num_charsintNumber of characters. Default is 60.
$morestringWhat to append if $text needs to be trimmed. Defaults to '…'.

trim_words() #

trim_words( string $text, int $num_words = 55, string|null|false $more = null, string $allowed_tags = 'p a span b i br blockquote' )

Returns: string

NameTypeDescription
$textstring
$num_wordsint
$morestring or null or falsetext to appear in "Read more...". Null to use default, false to hide
$allowed_tagsstring

remove_tags() #

remove_tags( mixed $string, array $tags = [] )

Returns: null|string|string[]

NameTypeDescription
$string
$tagsarray

Timber\​TextHelper – Timber v2 – Timber Documentation
Timber Logo

You are reading the documentation for Timber v2.x. Switch to the documentation for Timber v1.x.

Timber\​TextHelper

Class provides different text-related functions commonly used in WordPress development

Overview #

Methods #

NameReturn TypeSummary/Returns
remove_tags()null or string or string[]
trim_characters()stringTrims text to a certain number of characters.

Returns: trimmed text.
trim_words()string

Class Methods #

trim_characters() #

Trims text to a certain number of characters.

This function can be useful for excerpt of the post As opposed to wp_trim_words trims characters that makes text to take the same amount of space in each post for example

since 1.2.0

trim_characters( string $text, int $num_chars = 60, string $more = '&hellip;' )

Returns: string trimmed text.

NameTypeDescription
$textstringText to trim.
$num_charsintNumber of characters. Default is 60.
$morestringWhat to append if $text needs to be trimmed. Defaults to '…'.

trim_words() #

trim_words( string $text, int $num_words = 55, string|null|false $more = null, string $allowed_tags = 'p a span b i br blockquote' )

Returns: string

NameTypeDescription
$textstring
$num_wordsint
$morestring or null or falsetext to appear in "Read more...". Null to use default, false to hide
$allowed_tagsstring

remove_tags() #

remove_tags( mixed $string, array $tags = [] )

Returns: null|string|string[]

NameTypeDescription
$stringmixed
$tagsarray