Support » Plugin: Woody code snippets - Insert Header Footer Code, AdSense Ads » Can you explain how the new Snippets Work

  • nwalker

    (@nwalker)


    Hi ,
    I’ve been using [insert_php] successfully on my site. I have a functions file where I store all my PHP routines and I just call the routine i want to use it within the [Insert_php].
    Can I still call the Functions PHP Routines using the new short code. If so, how do i do that?
    If not, what do i have to do with the code and then what will be the line i enter on the web page.

    I’ve never used Snippets before so don’t really understand what I need to do.

    Could you clarify please?

    Thanks
    Neil.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter nwalker

    (@nwalker)

    Sorry just want to clairy.

    At the moment i run this [insert_php]create_games_table (“football”);[/insert_php]

    So this runs a php script from my functions.php file called create_games_table and passes a parameter into it of “football”

    How do I do this with the new Snippets?

    Plugin Author webcraftic

    (@webcraftic)

    Hi,

    Step 1. You placed your function in the function.php file

    Step 2. Call this function in the snippet.

    Step 3. Place the shortcode of the snippet in the post.

    Step 4. See result

    Best regards, Alex

    Thread Starter nwalker

    (@nwalker)

    Thank you, that has helped, but i still don’t quite understand how i can pass a paranter into a snippet at the time of calling it.

    I need to pass a different parameter each time I call the create_games_table script.

    can i have one snippet for create_games_table and when i call it I can add a different parameter each time?. I have 30 possible parameters to chose from each time i use the code depending on where it’s placed on my site. I want to avoid having 30 individually coded snippets as at the moment i have one script that will take a variable paramter.

    Plugin Author webcraftic

    (@webcraftic)

    How do you pass parameters in the old plugin? You can show an example of the code that you used before.

    Best regards, Alex

    Thread Starter nwalker

    (@nwalker)

    sure

    [insert_php]create_games_table (“football”);[/insert_php]

    Plugin Author webcraftic

    (@webcraftic)

    Use the same code in the snippet. It will work.

    if(function_exists('create_games_table')) {  
      create_games_table("football");
    }

    If you do not want to do many snippets. Then pass the function parameter in the addres string.

    For example, you have such a page:
    http://site.dev/my-tables/

    Add to the address, the variable table_type
    http://site.dev/my-tables/?table_type=football

    To display a table with a parameter “football”. We use this code

    if(function_exists('create_games_table')) {  
      $table_type = isset($_GET['table_type']) ? sanitize_text($_GET['table_type']) : null;
      if(!empty($table_type)) {
    	 create_games_table ($table_type);
      } 
    }

    You will need php knowledge to better understand how this works.
    Best regards, Alex

    Thread Starter nwalker

    (@nwalker)

    Ok thanks Alex for looking at this and coming up with some alternatives. Sadly they just won’t work for me.

    I use the same script multiple times on a page each with different parameters.

    I also have scripts that need multiple parameters.

    I need to control the parameters at the point where i run the Snippet, not at the page level.

    The only way to do that is take the 5 scripts I have and create approx 500 snippets to cater for each parameter type, which quite honestly is a massive backward step for me and not something I can do. The overhead of making changes to 500 individual scripts on an ongoing basis is also not something I want to take on.

    It would be great if you could take parameters into the snippets for people running their own functions.php files, but if you have no plans to do this, i’ll look around for an alternative. The Insert_php worked very well for me.

    Regards
    Neil.

    Plugin Author webcraftic

    (@webcraftic)

    You mean, pass parameters through the shortcode?
    [wbcr_php_snippet id=”445″ my_custom_attribute=”football”]

    
    if(function_exists('create_games_table')) { 
      create_games_table($my_custom_attribute);
    }
    

    I need to think about how to solve your problem.

    You can always use the old version of the plugin, if you do not go the new version. We will not force you to change all shortcodes.

    Best regards, Alex

    Thread Starter nwalker

    (@nwalker)

    Yep, something like that on the page would be perfect.

    [wbcr_php_snippet id=”445″ my_custom_attribute=”football”]

    so it calls the create_game_table from my Functions.php file and passes it “football” as the parameter.

    Perhaps also allowing multiple parameters to be passed like “Football” & “Womens” & “Premier” would run my create_games_table(“football”,”Womens”, “Premier”).

    I have some scripts that need multiple parameters.

    Something to think on 🙂 I’ll continue using insert_php for now.

    Thanks Alex.

    Plugin Author webcraftic

    (@webcraftic)

    I’ll figure out how to do this in a new update. Idea in principle can be useful.

    Best regards, Alex

    IIIiW

    (@iiiiw)

    Following @nwalker issue I’ve to point out that I’ve been working a lot with custom short_codes as well. Passing different parameters etc. translating all of them in the new version without being 100% sure that will be working properly will cause a lot of issues.
    I am strongly proposing to reconsider your decision not to support the old version in following updates, if it is not absolutely necessary.
    Best regards,
    Isidoros

    Plugin Author webcraftic

    (@webcraftic)

    @nwalker
    Hi,

    In the new version of the plugin I made it possible to pass the value through shortcodes. You can get the values of the variables from the shortcode attributes. For example, if you set the my_type attribute for the shortcode [wbcr_php_snippet id=”2864″ my_type=”button”], you can get the value of the my_type attribute in the snippet by calling $my_type var.

    Best regards, Alex

    Plugin Author webcraftic

    (@webcraftic)

    @iiiiw
    Hi,
    You can continue to use the old version or versions with support for old shortcodes.
    Best regards, Alex

    IIIiW

    (@iiiiw)

    Thank you for the swift response 🙂

    Following the explanation by Alex above, I created the following snippet:
    insertBlurb($imageCode);
    where insertBlurb is a function defined in custom.php using the Thesis theme.
    When I place the shortcode in a page as follows;
    [wbcr_php_snippet id=”8931″ imageCode=”AA”]
    the function does not execute properly — nothing appears,
    HOWEVER, if I change the snippet like this:
    insertBlurb(‘AA’);
    and place this shortcode in a page:
    [wbcr_php_snippet id=”8931″]
    the function executes properly and places the appropriate text in the page.
    What is the problem with the first method. I want to be able to define a single snippet that can accept parameters since the second method would require an inordinate number of snippets.
    Timothy Binkley

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Can you explain how the new Snippets Work’ is closed to new replies.