Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Virtual" slugs?
#5
RobA Wrote:I need to […] put in a plugin hook using some short code like (% whatever %).
No you don’t.
Code:
add_action('index-pretemplate','changeContent');
function changeContent() {
    global $content;
    $content = 'My plugin content!';
}
Will use “My plugin content!” as the page’s content instead of whatever content is saved in the XML file.
RobA Wrote:This means my plugin parse gets called every page.
Not necessarily. When your plugin file is being loaded the current page slug is already accessible.

Normally the slug is figured out with the following code (from index.php):
Code:
if (isset($_GET['id'])){
    $id = str_replace ('..','',$_GET['id']);
    $id = str_replace ('/','',$id);
    $id = lowercase($id);
} else {
    $id = "index";
}
Using this and the previous content overwrite in your plugin file you could easily build something like:
Code:
if (isset($_GET['id'])){
    $id = str_replace ('..','',$_GET['id']);
    $id = str_replace ('/','',$id);
    $id = lowercase($id);
} else {
    $id = "index";
}
if ($id=='mypluginslug') {
    add_action('index-pretemplate','changeContent');
    function changeContent() {
        global $content;
        $content = 'My plugin content!';
    }
}
Now this action will only be used when the current page has the slug “mypluginslug”. You can exchange the add_action() for add_filter() if that’s what you want to use of course.

ccagle8 Wrote:Couldn’t you use a check with return_page_slug()
return_page_slug() is not available to plugins until inside the index-pretemplate hook. So if you are concerned about adding a filter to pages where the filter should not be executed that won’t work. (Or it will, but it will be a very roundabout kind of way.)
“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)