Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Virtual" slugs?
#7
RobA Wrote:Which is preferred then?

The difference is a subtle one and has to do with compatibility. If you want your plugin to support other plugins that use filters — maybe to add certain things in the beginning or the end of the content — you cannot use a filter yourself.

If you use a filter to overwrite the content variable, all previously run filters will have their effects overwritten. By overwriting the content variable before the filters are applied all will stay in effect.

There are also places, such as certain plugins or GetSimple’s own get_header(), that will use $content without running a filter. Again, overwriting the content variable as soon as you can will make sure these are supported.

RobA Wrote:I guess I was thinking of a something in the 404 handler to check "nope, not a real (xml) page", then check to see if any plugins have registered to have a certain slug, and call the registered function to generate content using the default page template, to avoid the need to create a page.

This is probably possible right now. You can let your plugin create an XML file that fakes the one used by pages somewhere on the server. Then run something like the following (untested) code:
Code:
add_action('error-404','notFOF');
function notFOF() {
    global $file, $id;
    if ($id=='contact') {
        $file = GSDATAOTHERPATH.'myplugin/blank.xml';
        add_filter('content','changeContent');
        function changeContent($contents) {
            $my_content = 'My plugin content!';
            return $my_content;
        }
    }
}
Now our fake slug “contact” gets assigned a dummy-file. This is to make sure GetSimple doesn’t give up when it does getXML() on $file. It is also important that we get GetSimple to recognise an URL other than “404” to keep it from sending the Not Found header to the UA. We also add the content rewriting function in there for good merits. Your plugin could, of course, just plant an XML file with the correct content to the server already but creating the content through PHP allows us to use the same dummy XML file for all “virtual pages”.

After this you will still need to add code into the changedata hook to make sure nobody creates a page using your virtual slug. That might even be the hardest part… maybe I’ll look into that tomorrow.

You are right about this being build in to the core would make development way easier!

It’s getting late and I’m tired so I hope I’m still making sense ;-)
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply


Messages In This Thread
"Virtual" slugs? - by RobA - 2011-06-17, 00:49:59
"Virtual" slugs? - by mvlcek - 2011-06-17, 01:07:26
"Virtual" slugs? - by ccagle8 - 2011-06-17, 01:18:35
"Virtual" slugs? - by mvlcek - 2011-06-17, 01:25:59
"Virtual" slugs? - by Zegnåt - 2011-06-17, 01:28:27
"Virtual" slugs? - by RobA - 2011-06-17, 03:52:54
"Virtual" slugs? - by Zegnåt - 2011-06-17, 09:24:05



Users browsing this thread: 1 Guest(s)