diff --git a/docs/usage/wordpress.md b/docs/usage/wordpress.md index 7f3fc2e..28684d3 100644 --- a/docs/usage/wordpress.md +++ b/docs/usage/wordpress.md @@ -509,3 +509,13 @@ This is just a directive version of [`wp_footer`](https://developer.wordpress.or ## @wpbodyopen This is a directive version of [`wp_body_open`](https://developer.wordpress.org/reference/functions/wp_body_open/) except that it will work on WordPress versions below 5.2. + +## @postclass + +`@postclass` functions the same as `[post_class](https://developer.wordpress.org/reference/functions/post_class/)` accepting an optional class and post ID. + +```php +@postclass +@postclass('bg-white') +@postclass('bg-white', $post->ID) +``` diff --git a/src/Directives/WordPress.php b/src/Directives/WordPress.php index 2483767..fac24aa 100644 --- a/src/Directives/WordPress.php +++ b/src/Directives/WordPress.php @@ -572,6 +572,16 @@ return ""; }, + /* + |--------------------------------------------------------------------- + | @postclass + |--------------------------------------------------------------------- + */ + + 'postclass' => function ($expression) { + return ""; + }, + /* |--------------------------------------------------------------------- | @__ diff --git a/tests/Unit/WordPressTest.php b/tests/Unit/WordPressTest.php index 19926f1..c176943 100644 --- a/tests/Unit/WordPressTest.php +++ b/tests/Unit/WordPressTest.php @@ -738,6 +738,32 @@ }); }); +describe('@postclass', function () { + it('compiles correctly', function () { + $directive = '@postclass'; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(''); + }); + + it('compiles correctly with a custom class', function () { + $directive = "@postclass('custom-class')"; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe(""); + }); + + it('compiles correctly with a custom class and post', function () { + $directive = "@postclass('custom-class', \$post->ID)"; + + $compiled = $this->compile($directive); + + expect($compiled)->toBe("ID); ?>"); + }); +}); + describe('@__', function () { it('compiles correctly', function () { $directive = "@__('Hello World', 'sage')";