Posts: 2,094
Threads: 54
Joined: Jan 2011
2012-04-08, 02:10:16
(This post was last modified: 2012-04-08, 02:11:45 by nime.)
I just wanted to enhance the I18N plugin to create correct sitemaps (with language in URL), but found out that the actions - sitemap-additem
- save-sitemap
are useless, as the relevant variables are neither global nor passed to the action.
For 3.0 it would have been possible to add a admin menu item creating correct sitemaps but now with 3.1 and it's automatic generation of sitemaps this is not possible.
Edit: See also this topic regarding switching off sitemap generation/search engine pinging.
Posts: 2,094
Threads: 54
Joined: Jan 2011
Posts: 6,266
Threads: 181
Joined: Sep 2011
yeah its a known issue, but i dont know that there is an actual issue created for it.
Posts: 3,491
Threads: 106
Joined: Mar 2010
Posts: 3,491
Threads: 106
Joined: Mar 2010
It seems this can be fixed by inserting this in function generate_sitemap()
(admin/inc/template_functions.php)
...at least to fix action sitemap-additem. Those 2 variables are the ones that plugins try to use to add their own elements to the Sitemap.
I've tested this with News Manager (whose posts were added to the Sitemap with GS 3.0). I haven't tested with the I18N plugin, as it has its own patches for GS 3.1+
Any opinions, suggestions? Do you think it should be fixed other way, maybe new different hooks for Sitemap...?
Posts: 2,094
Threads: 54
Joined: Jan 2011
2012-12-06, 03:25:48
(This post was last modified: 2012-12-06, 03:26:20 by mvlcek.)
(2012-12-06, 02:47:49)Carlos Wrote: It seems this can be fixed by inserting this in function generate_sitemap()
...
Any opinions, suggestions? Do you think it should be fixed other way, maybe new different hooks for Sitemap...?
To really solve issues like that I think that the action concept needs to be enhanced: - pass arguments to actions instead of relying on global variables (not needed here)
- evaluate the return parameter
Then three actions (or rather two actions and one filter) can be used to allow for all eventualities:
Code: function generate_sitemap() {
# for special purposes, where the whole sitemap is generated by a plugin
$done = exec_action('output-sitemap');
if ($done) { exec_action('save-sitemap'); return; }
...
foreach ($pagesSorted as $page) {
$page = exec_filter('sitemap-additem', $page);
# filter returns null to have page ignored
# filter may adjust any fields, like private and add 'loc', ... (see below)
if ($page) {
# use $page['loc'], $page['lastmod'], $page['changefreq'], $page['priority'], if set
# otherwise set them as now
...
}
}
...
XMLsave($xml, $file);
exec_action('save-sitemap');
}
Posts: 3,491
Threads: 106
Joined: Mar 2010
2012-12-06, 03:45:02
(This post was last modified: 2012-12-06, 03:45:34 by Carlos.)
Thanks for your suggestion.
Don't you think it might be better to use new hooks/filters (apart from your sitemap-output) instead of reusing sitemap-additem and sitemap-save? (and remove those two so that older plugins don't do strange things...)
Posts: 2,094
Threads: 54
Joined: Jan 2011
(2012-12-06, 03:45:02)Carlos Wrote: Don't you think it might be better to use new hooks/filters (apart from your sitemap-output) instead of reusing sitemap-additem and sitemap-save? (and remove those two so that older plugins don't do strange things...)
Yes, and harmonize the naming - start the name with the functionality/section: e.g. sitemap-output, sitemap-item, sitemap-save (as wrongly described in the wiki - instead of save-sitemap).
Posts: 6,266
Threads: 181
Joined: Sep 2011
What purpose does sitemap-item serve ?
Posts: 2,094
Threads: 54
Joined: Jan 2011
(2012-12-06, 04:53:33)shawn_a Wrote: What purpose does sitemap-item serve ? - set the correct link (e.g. I18N plugin)
- set another update date (e.g. plugins fixing pubDate issues or setting it, because other content that is included on the page has changed - blog/news plugins, Items Manager)
- set frequency and priority (e.g. blog/news plugins)
- do something else for each (or some) pages
Posts: 6,266
Threads: 181
Joined: Sep 2011
I have not been following this nor do I use this functionality.
I apologize this this has been discussed.
I propose removing all sitemap hooks.
we can keep a notification hook for saved.
We use a single filter for sitemap modification.
Filters are made for modifying data.
Posts: 6,266
Threads: 181
Joined: Sep 2011
Posts: 3,491
Threads: 106
Joined: Mar 2010
Since GS 3.3.0 there is a 'sitemap' filter.
|