Skip to content

Commit 5f4e148

Browse files
doc: Add a doc entry for Wordpress support (#922)
Closes #880. --------- Co-authored-by: Calvin Alkan <[email protected]>
1 parent dd0a672 commit 5f4e148

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
5959
- [Class aliases](docs/further-reading.md#class-aliases)
6060
- [Function aliases](docs/further-reading.md#function-aliases)
6161
- [Symfony support](docs/further-reading.md#symfony-support)
62+
- [Wordpress support](docs/further-reading.md#wordpress-support)
6263
- [Limitations](docs/limitations.md#limitations)
6364
- [Dynamic symbols](docs/limitations.md#dynamic-symbols)
6465
- [Date symbols](docs/limitations.md#date-symbols)

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,6 @@ namespace Humbug\Acme;
468468

469469

470470
[box]: https://github.com/box-project/box
471-
[symfony_finder]: https://symfony.com/doc/current/components/finder.html
472471
[php-scoper-integration]: https://github.com/humbug/box#isolating-the-phar
473472
[phpstorm-stubs]: https://github.com/JetBrains/phpstorm-stubs
473+
[symfony_finder]: https://symfony.com/doc/current/components/finder.html

docs/further-reading.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Class aliases](#class-aliases)
66
- [Function aliases](#function-aliases)
77
- [Symfony support](#symfony-support)
8+
- [Wordpress support](#wordpress-support)
89

910

1011
### How to deal with unknown third-party symbols
@@ -111,6 +112,44 @@ return [
111112
Note that the path is the "regular path(s)" that can be passed to patchers.
112113

113114

115+
### Wordpress Support
116+
117+
When writing a Wordpress plugin, you need to [exclude Wordpress' symbols](#excluded-symbols). To facilitate
118+
this task, [Snicco] created a third-party CLI tool [php-scoper-excludes] that can be used to generate
119+
PHP-Scoper compatible symbol lists for any PHP codebase you point it.
120+
121+
### Example for WordPress Core
122+
123+
```shell
124+
composer require sniccowp/php-scoper-wordpress-excludes
125+
```
126+
127+
```php
128+
// scoper.inc.php
129+
130+
function getWpExcludedSymbols(string $fileName): array
131+
{
132+
$filePath = __DIR__.'/vendor/sniccowp/php-scoper-wordpress-excludes/generated/'.$fileName;
133+
134+
return json_decode(
135+
file_get_contents($filePath),
136+
true,
137+
);
138+
}
139+
140+
$wp_classes = getWpExcludedSymbols('exclude-wordpress-classes.json');
141+
$wp_functions = getWpExcludedSymbols('exclude-wordpress-functions.json');
142+
$wp_constants = getWpExcludedSymbols('exclude-wordpress-constants.json');
143+
144+
return [
145+
'exclude-classes' => $wp_classes,
146+
'exclude-constants' => $wp_functions,
147+
'exclude-functions' => $wp_constants,
148+
// ...
149+
];
150+
```
151+
152+
114153
<br />
115154
<hr />
116155

@@ -123,5 +162,7 @@ Note that the path is the "regular path(s)" that can be passed to patchers.
123162
[exposing a class]: configuration.md#exposing-classes
124163
[exposing a function]: configuration.md#exposing-functions
125164
[#706]: https://github.com/humbug/php-scoper/pull/706
126-
[patchers]: ./configuration.md#patchers
165+
[Snicco]: https://github.com/snicco
127166
[symfony-php-config]: https://symfony.com/doc/current/service_container.html#explicitly-configuring-services-and-arguments
167+
[patchers]: ./configuration.md#patchers
168+
[php-scoper-excludes]: https://github.com/snicco/php-scoper-excludes

0 commit comments

Comments
 (0)