Closed MichelleBlanchette closed 8 months ago
I believe this is a non-issue because you should be able to hook earlier from within an mu-plugin. This should be confirmed before closing this issue.
The problem here is that the initial call to plugins_url()
is executed in Completionist's main file, so the timing sequence is "random" for other plugins trying to hook into it. At least, that's my hypothesis. As stated, this needs to be confirmed.
Oh, that's funny. WordPress's documentation actually notes this (source):
The plugins_url() function should not be called in the global context of plugins, but rather in a hook like “init” or “admin_init” to ensure that the “plugins_url” filters are already hooked at the time the function is called. This is vital for many site configurations to work, and if plugins_url() is called in the global context of a plugin file it cannot be filtered by other plugins (though mu-plugins are able to filter it because they run before any other plugins).
Regardless, I did confirm the usage of an mu-plugin catches it appropriately:
<?php
// wp-content/mu-plugins/test.php
add_filter(
'plugins_url',
function ( $url ) {
error_log( '*** ' . $url );
return $url;
}
);
Original https://github.com/PurpleTurtleCreative/completionist-pro/issues/23
As expected, using the cached constant avoids filters applied to
plugins_url
such as when wanting to map to a different host name.I believe it'd be like this: