What is the use case for the EP Mask in CustomPress

CustomPress is very powerful and I am trying to understand how best to use it.

I have read the WordPress documentation on the EP Mask. The example they give is appending "/JSON" to cause a different version of a page to be rendered.

This does not seem to apply to CustomPress. Can you please explain the intended use of this feature.

Please explain. For example

* What effect does clicking "EP_Permalink" have for a custom post?
* What effect does clicking "EP_TAGS" have for a custom taxonomy?

James

  • Jack Kitterhing

    Hi there @James Bayley on WPMU,

    Hope you're well today and thanks for your question.

    I have flagged the developer to provide his insight into how this exactly works with it's intended use :slight_smile:

    From testing, it appears to be that you can append your custom endpoint mask to the end of the permalink for the EP Permalink, but to get a solid answer on this, I've notified the developer.

    Thanks for your patience here. :slight_smile:

    Thanks!

    Kind Regards
    Jack.

  • Arnold

    You have to add the endpoint so the ep_mask has something to mask. For example.

    // add endpoints for front end special pages
    add_rewrite_endpoint('edit', EP_PAGES);
    add_rewrite_endpoint('contact', EP_PAGES);

    This adds to your rewrite rules so you can pick out any url that has a trailing /edit/ or /contact/. The EP_PAGES ep_mask means that this will be triggered on any Post Type that has the EP_PAGES mask bit set. The mask in the post_type has to match at least one mask in the end point for it create the query var.

    The mask is a bit mask. so you can use multiple masks by using
    "EP_PAGES | EP_ATTACHMENTS".

    Now you have a rewrite rule that will add a query var "edit" or "contact" if that appears at the end of a "normal" url.

    So this could be used for displaying an Edit page for a post when you add /edit/ to the end of the posts normal URL.

    /blogs/johns-post/ shows the post.
    /blogs/johns-post/edit/ shows an edit screen for that post
    /blogs/johns-post/contact/ displays an email contact form for that post.

    That just sets up the rewrite. To intercept the endpoints you have to do two things.

    One: The query vars are created but they have no value which makes them hard to interpret. so in the 'request' filter hook give them a value.

    function on_request($vars){
    
      //Make sure something is actually set
      if(isset($vars['edit']) ) $vars['edit'] = true;
      if(isset($vars['contact']) ) $vars['contact'] = true;
    
      return $vars;

    Two: Hook either "template_redirect" or "template_include" } to decide what template you are going to use to display the alternate template. Something like.

    if( is_singular('your_post_type') && get_query_var('contact') ){
      return "a different template name for contact form";
    }

    Doesn't have to change a template. For example the endpoint could be "delete". You would still intercept at "template_include" and delete whatever you want and redirect to a confirmation of deletion page.

    See not so tough.

    More reading.

    https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/

  • Josh

    I know I'm late to the party, but can someone explain the explanation?

    /blogs/johns-post/ shows the post.
    /blogs/johns-post/edit/ shows an edit screen for that post
    /blogs/johns-post/contact/ displays an email contact form for that post.

    The 3rd would go to a different page or display "johns-post" in a different way?

    What's the benefit of this compared to using a vanilla hyperlink?

  • Michael Bissett

    Hey @Josh,

    The 3rd would go to a different page or display "johns-post" in a different way?

    It would display "johns-post" in a different way, if you had a separate template, as Arnold had mentioned here:

    Two: Hook either "template_redirect" or "template_include" } to decide what template you are going to use to display the alternate template. Something like.

    if( is_singular('your_post_type') && get_query_var('contact') ){
      return "a different template name for contact form";
    }

    What's the benefit of this compared to using a vanilla hyperlink?

    It would depend upon the use case, but to throw up another example (as the front end page & contact form page were examples of how this could be used)...

    Say you had a website that offered various online tools for folks to use (e.g. a calculator, a stopwatch, and a calendar), and you had coded up a template for each tool.

    But let's also assume that instead of having each tool be on a separate page of it's own, like this:

    example.com/calculator
    example.com/stopwatch
    example.com/calendar

    You want to have them be subpages of the main tools page:

    example.com/tools/

    Using the methods above, you could have a URL for each tool, like this:

    example.com/tools/calculator
    example.com/tools/stopwatch
    example.com/tools/calendar

    Granted, this is a rather simple example, there's other ways that could be invented to use this functionality, but I do hope that this sheds a bit more light on the "why" for using this.

    Kind Regards,
    Michael