• I’m working on a plugin that needs to add the ability to append /outputxml/ to all WP URLs, and have those URLs resolve as if they did not have /outputxml/ on them.

    I have this working for Permalinks to posts, but I get a 404 error whenever I use any other type of URL. You can see what I did to get this working on permalinks here: http://johnbeales.com/20090824/endpoints-a-little-secret-for-url-manipulation-in-wordpress/

    It seems that in my register_activation_hook function, when I call add_rewrite_endpoint() it only adds the endpoint to permalinks, not to category views, archives, the root, (blog home URL), or anything else that I’ve discovered. I have passing an array of all different URL types that exist as my $places variable. I have also tried just using, for example, EP_MONTH. In both situations the endpoint only resolves for permalinks, but not for any archives or any other URLs. I have also tried EP_ALL with the same result.

    I am deactivating and reactivating my plugin after every change.

    Does anyone out there know what I should be doing to make my endpoints work on all URL types, (well, maybe except for attachments)?

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter johnnyb

    (@johnnyb)

    So, I think I figured it out. Apparently I shouldn’t give an array as $places, as the in-code docs say. It works if I set EP_ALL, with no array.

    It’s a mistake to use add_endpoint in activation hook cuz if other plugin which uses WP_Rewrite will be activated/deactivated and flush rules so other plugins will not add own rules so you should add rules at activation hook + flush call and at init action for the case if other plugin will be deactivated and flush rules.

    Example:

    (looks bad, but works)

    function on_activate()
    {
     global $wp_rewrite;
    
     $wp_rewrite->add_endpoint('my_point', EP_ALL);
     $wp_rewrite->flush_rules();
    }
    
    function on_deactivate()
    {
     global $wp_rewrite;
    
     $wp_rewrite->flush_rules();
    }
    
    function on_init()
    {
     global $wp_rewrite;
    
     $wp_rewrite->add_endpoint('my_point', EP_ALL);
    }

    Well, I’ve written a bullshit 😀

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_rewrite_endpint() / WP_rewrite::add_endpoint don’t seem to honour $places’ is closed to new replies.