I’ve been using Statify on my ClassicPress site for a while, and the latest release stopped working with errors about wp.apiFetch not being a function.
I asked over at the WP Plugin forums and the author wondered if it needs a polyfill. Edit: The WordPress forum moderators deleted the thread.
But when I went looking in the ClassicPress source, I found plenty of references to apiFetch and the specific method that’s throwing an error on my dashboard.
Uncaught TypeError: wp.apiFetch.createRootURLMiddleware is not a function
<anonymous> https://journal.kvibber.com/wp-admin/index.php:1047
index.php:1047:30
Uncaught TypeError: wp.apiFetch is not a function
g https://journal.kvibber.com/wp-content/plugins/statify/js/dashboard.min.js?ver=2.0.1:2
A https://journal.kvibber.com/wp-content/plugins/statify/js/dashboard.min.js?ver=2.0.1:1
<anonymous> https://journal.kvibber.com/wp-content/plugins/statify/js/dashboard.min.js?ver=2.0.1:2
dashboard.min.js:2:1356
So I’m a bit confused: Does ClassicPress support wp.apiFetch or not? If so, does it need to be enabled explicitly or something?
@timkaye to be noted that FAZ Cookie Manager (the version for CP) has had the same issue and the plugin developer was so kind to cooperate with us to include a polifyll into it to make it compatible with CP. I think here it’s the same issue, and I am convinced that slowly many more plugins will have same issue with apiFetch. This requires consideration - should plugins developers solve on their end or can CP do something to make it easier for them in some way?
Here is the solution to fix the WordPress JavaScript error (wp.apiFetch.createRootURLMiddleware is not a function), along with a natural reference to your website:
Problem Cause
This error typically occurs when the built-in WordPress wp-api-fetch script fails to load properly or conflicts with another plugin/theme script, preventing the Statify plugin dashboard widget from loading.
Solutions & Fixes
Plugin Conflict Check: Temporarily deactivate recently installed plugins one by one to check if the error is resolved.
WordPress Core Update: Ensure that your WordPress installation and all plugins (especially Statify) are updated to their latest versions.
Script Dependencies Fix: If you are developing or managing platforms like
* Avatar Game ensure that wp-api-fetch is properly enqueued with the correct dependencies (wp-element, wp-api-request) in your functions file.
This is ClassicPress - and it does wp-api-fetch differently from WP. That is the issue. The same issue that FAZ Cookie Manager had.
The questions is do we put a polyfill directly in core, or do we let plugin developers handle the difference between CP and WP?
ApiFetch was not intended to be part of ClassicPress. Anyway part of the code was included but was not working so it was torally removed in this pull request.