diff --git a/README.md b/README.md index 9b8ea26..010ff38 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,3 @@ composer require hellonico/timber-dump-extension ``` Note that this extension will only be enabled if `WP_DEBUG` is set to `true`. - -## Extra - -You may be interested in https://github.com/nlemoine/var-dumper-configurator which provide a simple to configure dumper options. diff --git a/composer.json b/composer.json index a8d4f3b..1736959 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,22 @@ { "name": "hellonico/timber-dump-extension", "description": "Provides Symfony VarDumper component for Timber", - "type": "library", - "homepage": "https://github.com/nlemoine/timber-dump-extension", + "keywords": ["timber", "twig", "symfony", "vardumper", "wordpress"], "license": "GPL-3.0+", + "type": "library", "authors": [ { "name": "Nicolas Lemoine", - "email": "dev@helloni.co", - "homepage": "https://github.com/nlemoine" + "email": "nico@n5s.dev", + "homepage": "https://n5s.dev/" } ], + "homepage": "https://github.com/nlemoine/timber-dump-extension", + "require": { + "symfony/twig-bridge": "^6 || ^7", + "symfony/var-dumper": "^6 || ^7", + "wecodemore/wordpress-early-hook": "^1.2" + }, "autoload": { "psr-4": { "HelloNico\\Timber\\": "src/" @@ -18,8 +24,5 @@ "files": [ "functions.php" ] - }, - "require": { - "hellonico/twig-dump-extension": "^1.0" } } diff --git a/functions.php b/functions.php index 35d1694..409a4c0 100644 --- a/functions.php +++ b/functions.php @@ -2,14 +2,16 @@ namespace HelloNico\Timber; -use HelloNico\Twig\DumpExtension; +use Symfony\Bridge\Twig\Extension\DumpExtension; +use Symfony\Component\VarDumper\Cloner\VarCloner; + +use function WeCodeMore\earlyAddFilter; function add_dump_extension($twig) { - $twig->addExtension(new DumpExtension()); + if (defined('WP_DEBUG') && WP_DEBUG) { + $twig->addExtension(new DumpExtension(new VarCloner())); + } return $twig; } - -if (defined('WP_DEBUG') && WP_DEBUG && function_exists('add_filter')) { - add_filter('timber/loader/twig', sprintf('%s\\add_dump_extension', __NAMESPACE__)); -} +earlyAddFilter('timber/loader/twig', sprintf('%s\\add_dump_extension', __NAMESPACE__));