Composer autoload order in bedrock

Hello,

I try to use the php library https://github.com/Shelob9/jp-rest-cache
It´s not a plugin, it`s just a PHP Library

I added

"shelob9/jp-rest-cache": "dev-master"

to my composer.json file and it was installed in vendor.

But I get the error:

Fatal error: Call to undefined function add_filter() in /srv/www/myproject.dev/current/vendor/shelob9/jp-rest-cache/jp-rest-cache.php on line 27

So I think, it is included too early, so that the wordpress function “add_filter” has not yet been defined.

When I uncomment the line

add_filter( 'json_pre_dispatch', 'jp_rest_cache_get', 10, 2 );

in jp-rest-cache.php and add the line to the functions.php from my theme, everything works fine.

So my question is: Where are the files from composer installed php librarys included to my code, and how can I change the order?

Did you search for it in the code?

It’s called at the top of the main config: https://github.com/roots/bedrock/blob/b0a6278af1ab005628664e0644979ffeb34bddc3/web/wp-config.php#L7

You can try moving that later on in the loading process.