• Resolved apicedda

    (@apicedda)


    I was wondering if there is a way to use shortcodes inside the plugin templates content instead of writing mere html. And if it’s not there yet, is it technically possible and maybe added in a future update? Thanks a lot

    P.S. if you need a logo for the plugin i could try and make you one

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author paulstuttard

    (@paulstuttard)

    Hi,

    Not sure could you give me an example of what you might like to do?

    Cheers,

    Paul

    Thread Starter apicedda

    (@apicedda)

    Sure. Let’s say i have a plugin which lets me create a button using a shortcode like:
    [fancy_button link=”url:SOME_URL” size=”large”]BUTTON TEXT[/fancy_button]

    i would like to use that shortcode inside a template, so something like this:
    [fancy_button link=”url:%URL%” size=”large”]%TITLE% – %PRICE%[/fancy_button]

    Let me know if it wasn’t clear and thanks for the reply.

    Plugin Author paulstuttard

    (@paulstuttard)

    Got it,

    Hmmm… I think the plugin used to support this. However to support ‘Table Press’ I changed the order that things happen (other shortcodes processed first then Amazon Link processed).

    Basically to support this then Amazon Link needs to run first, then other shortcodes processed.

    This is controlled by the ‘priority’ of one of the filters, for a quick fix you could change this in your copy of the plugin.

    In the file:

    plugins/amazon-link/amazon.php

    Line 144 should look like this:

    
             add_filter( 'the_content', array( $this, 'content_filter' ),15,1 );
    

    Change the ’15’ to ’10’ and that should change the order that things happen, e.g.:

    
             add_filter( 'the_content', array( $this, 'content_filter' ),10,1 );
    

    If this does work then let me know and I try and add an ‘extra’ plugin that does this automatically.

    Hope this helps,

    Paul

    Thread Starter apicedda

    (@apicedda)

    That worked, thanks a lot. Unfortunatelly i’m now facing a problem. The urls inside a shortcode needs to be encoded, so an url like:
    https://www.amazon.it/
    (which is what the %URL% tag is replaced by)

    needs to be encoded to:
    https%3A%2F%2Fwww.amazon.it

    is there anything built inside the plugin to work this out? otherwise i’ll look for another solution

    Thanks for the help so far!

    Plugin Author paulstuttard

    (@paulstuttard)

    Tricky,

    Depends on how much you need escaping, if you append “S#” to the keyword (e.g. ‘e.g. %URL%S#‘ it will escape some characters, specifically:

    ( '"', "'", '&', "\r", "\n" ) => ( '%22', "%27", '%26', ' ',' ' )

    For URL’s you could create your own function that takes a string and returns an escaped string and add the line:

    
    add_filter( 'amazon_link_url', array( $this, 'my_escape_function' ), 21, 1 );
    
    function my_escape_function($string) {
       //do some escaping
       return $escaped_string;
    }
    

    If this is too technical then I can can create an extra plugin to do this.

    It is also possible to do this to any keyword (but you have to do each one in turn), e.g.

    
    add_filter( 'amazon_link_template_process_title', array( $this, 'my_escape_function' ), 21, 1 );
    add_filter( 'amazon_link_template_process_artist', array( $this, 'my_escape_function' ), 21, 1 );
    

    To escape the %TITLE% and %ARTIST% keyword.

    Paul

    Thread Starter apicedda

    (@apicedda)

    Ok, i added a filter like this:
    add_filter( 'amazon_link_url', array( $this, 'apply_url_encode' ), 21, 1 );
    and then the actual function:

    function apply_url_encode($string) {
       return rawurlencode($string);
    }

    and it works as it should.

    Now what about adding a new keyword like %URL_ENCODED%?
    would it be too complicated?

    Thank you

    Thread Starter apicedda

    (@apicedda)

    or actually a more versatile %ENCODE_OPEN% %ENCODE_CLOSE% type of thing

    Plugin Author paulstuttard

    (@paulstuttard)

    Hi,

    Sorry for the late reply!

    The problem is the plugin is already insanely complicated and can be a drag on page load times so I’m always reluctant to add features that affect this.

    I’ve created a separate plugin that changes the priority of the ‘the_content’ filter above, and adds an ‘esc’ tag that can be used anywhere in a post or in the amazon-link templates it takes the form:

    <esc>Stuff to escape</esc>

    I have not added the ‘apply_url_encode’ stuff above, but feel free to add this if you always want to encode your urls.

    You can download a copy here:

    https://www.lazyfox.org.uk/pydio/data/public/amazon-link-escape

    This means that on any update of the Amazon Link plugin you do not have to edit that line again.

    Paul

    Thread Starter apicedda

    (@apicedda)

    Thanks a lot, you are doing much more than you should.
    I quickly tested it and looks like it’s working as intended.
    And again, thank you for your awesome work

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Use Shortcodes in templates’ is closed to new replies.