diff --git a/docs/usage/wordpress.md b/docs/usage/wordpress.md index 2e2f57c..4b34121 100644 --- a/docs/usage/wordpress.md +++ b/docs/usage/wordpress.md @@ -535,3 +535,12 @@ It comes with two assisting directives `@hassidebar` and `@endhassidebar` that c @sidebar('sidebar-primary') @endhassidebar ``` + +## @thememod + +`@thememod` echoes the result of [`get_theme_mod`](https://developer.wordpress.org/reference/functions/get_theme_mod/) function accepting theme modification name and optional default value + +```php +@thememod('header-bg-color') +@thememod('header-bg-color', '#fff') +``` diff --git a/src/Directives/WordPress.php b/src/Directives/WordPress.php index 4b91002..fc518a5 100644 --- a/src/Directives/WordPress.php +++ b/src/Directives/WordPress.php @@ -618,4 +618,23 @@ return ""; }, + + /* + |--------------------------------------------------------------------- + | @thememod + |--------------------------------------------------------------------- + */ + + 'thememod' => function ($expression) { + $expression = Util::parse($expression); + + $mod = $expression->get(0); + $default = $expression->get(1); + + if (! empty($default)) { + return ""; + } + + return ""; + }, ]; diff --git a/tests/Unit/WordPressTest.php b/tests/Unit/WordPressTest.php index c22a6e8..c68c120 100644 --- a/tests/Unit/WordPressTest.php +++ b/tests/Unit/WordPressTest.php @@ -827,3 +827,21 @@ expect($compiled)->toBe(""); }); }); + +describe('@thememod', function () { + it('compiles correctly', function () { + $directive = "@thememod('mod')"; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(""); + }); + + it('compiles correctly with default value', function () { + $directive = "@thememod('mod', 'default')"; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(""); + }); +});