• Resolved Michael

    (@mixe)


    I think something changed in version 4.4 of this plugin. There is the introduction of the constant XMLSF_PLUGIN_URL, and I think it is the source of my problem.

    I need to run a filter on the plugin URL. But it seems that this new constant is declared in the global scope of the plugin, and so filters cannot reach it. In any case, I am unable to apply a filter to the plugin URL in version 4.4 of xml-sitemap-feed.

    The reason I need to filter the plugin_url, in case you are wondering, is because I’m working on a site that serves most files under a cached subdomain (let’s say ‘www’), but WordPress files are served under a live subdomain (let’s say ‘live’). The sitemap shows up fine at http://www.foo.com/sitemap.xml. But the XSLT file is served as live.foo.com/sitemap.xsl. Now the XSLT is broken because of a same-origin policy within XML. This is easy easy easy to fix if I can just filter the plugin URL.

    Please check out the Notes section of this page:

    http://https://codex.ww.wp.xz.cn/Function_Reference/plugins_url()

    This note is the one that I think describes the problem I am having:

    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).

    In summary, it seems to me the new XMLSF_PLUGIN_URL constant is declared in the global context of the plugin, and that is preventing me from applying a simple filter to it. Does that make sense?

    (P.S. I’m not sury why, but adding a filter to plugins_url() seemed to work with version 4.3.2).

    https://ww.wp.xz.cn/plugins/xml-sitemap-feed/

Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Cannot apply_filters() to plugins_url()’ is closed to new replies.