• 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)
  • Plugin Author Rolf Allard van Hagen

    (@ravanh)

    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?

    Yes, absolutely. Thanks for reporting this. I’ll be fixed in the upcoming .1 release!

    Plugin Author Rolf Allard van Hagen

    (@ravanh)

    An update to the dev version has just been uploaded. If you’d like to test, you can download it from https://downloads.wp.xz.cn/plugin/xml-sitemap-feed.zip

    If you do test, let me know the result 🙂

    Thread Starter Michael

    (@mixe)

    Hi Ravan. Thanks for the quick response about this. I did try the version you linked above, but it might have an internal error because it didn’t produce a sitemap. I got this WordPress error:

    ERROR: This is not a valid feed template.

    😕

    Plugin Author Rolf Allard van Hagen

    (@ravanh)

    Strange. I’ll have to test this some more…

    Plugin Author Rolf Allard van Hagen

    (@ravanh)

    OK, found it. There is a new version available on https://downloads.wp.xz.cn/plugin/xml-sitemap-feed.zip

    Thread Starter Michael

    (@mixe)

    I tried this more recent development version linked above, and it produces site maps as normal. Also, this newer version allows me to filter the plugin url. Therefore I would say this new change works for me and the issue can be closed.

    Plugin Author Rolf Allard van Hagen

    (@ravanh)

    Excellent. Thanks again for reporting and pointing out the underlying issue. And for testing 🙂

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

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