• Resolved MarioKnight

    (@marioknight)


    With the old system, I was using the following to generate my own gallery solution within pages as such:

    [insert_php]
    $aid = 1234;
    include('/path/to/script.php');
    [/insert_php]

    This new system appears to want me to make a separate snipped for each possible one, and then change the above in pages to the new format. Already having to change 100s of pages will be cumbersome (I do intend to be re-doing this site with CPTs and custom-made plugins at some point, but this will be a long process), and this looks to be doubled having two places to manage code instead of just one. Is there a way to have a single snippet created with the variable passed in the shortcode within the page? Or am I better off sticking with the old system as I work to re-do a lot of this site?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author webcraftic

    (@webcraftic)

    Hi,

    I plan in the new version to make it possible to pass the value of the variable inside the shortcode so that you do not duplicate the snippets. Expect this decision, I think it has already appeared tomorrow.

    Best regards, Alex

    Plugin Author webcraftic

    (@webcraftic)

    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

    Thread Starter MarioKnight

    (@marioknight)

    Hello,

    Thank you for that quick turnaround. I’ve tested this on my dev instance, and it works with no issues I can see. I’ll still need to decide if I want to do this sort of switch or not given the scale and future dev work mentioned above, but at least this new system to your plugin works and is an option now, so I’ll mark this as resolved. Thank you!

    This does not seem to be working for me. What does “calling $my_type var” mean?

    In my snippet I do
    echo (“Price is {” . $thePrice . “}”);
    This yields an empty string in $thePrice. I.e., it prints Price is {}

    The snippet is called by
    [wbcr_php_snippet id=”635″ thePrice=”32″]

    I assume I need to do something else? I am running version 2.0.6 of PHP code snippets.

    Plugin Author webcraftic

    (@webcraftic)

    @sybok
    Try to use variables without camelcase. It is better to separate the variable with a lower underscore.

    echo "Price is {" . $theprice . "}";

    [wbcr_php_snippet id="2901" title="Echo test" theprice="32"]

    Best regards, Alex

    OK, that seems to work. I don’t know why you would need to massage the attribute names, but OK. So underscores will work – do dashes?

    You also seem to be doing some massaging of the value string. I am trying to pass in a file name (image for a PayPal sales item). The file is something like abc.jpg. Took me awhile to realize you change the period to a dash, so the file becomes abc-jpg. Obnoxious that I have to write code to convert back to the correct file name. Is there a way to escape the period in the filename?

    I found that the massaging of the values is happening because of the line:
    $attr = array_map('sanitize_title', $attr);
    in wp-content/plugins/insert-php/includes/shortcodes.php. You can comment that line out, and the custom attribute values will not be changed.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Reusing code/snippets w/ variables’ is closed to new replies.