Support » Plugin: PHP Snippets » Passing Arguments

Viewing 4 replies - 1 through 4 (of 4 total)
  • Using WP from the command line is not well supported — I’ve looked into it for a number of projects and although it’s possible, the degree of skill it requires and the insane workarounds required to actually pull it off are not for the faint of heart – WP just was not built with that in mind and you can’t retroactively fix architectural shortcomings.

    PHP Snippets can pass arguments TO the command line if your code uses exec(), system(), passthru() etc, just make sure you escape the command and its arguments thoroughly (http://www.php.net/manual/en/function.escapeshellcmd.php and http://www.php.net/manual/en/function.escapeshellarg.php).

    However passing arguments FROM the command line to a PHP Snippet here would definitely be flying off the radar — PHP Snippets is designed to support one thing only: WP shortcodes, and shortcodes exist entirely as a by-product of having a simplified GUI manager. If you’re needing to do a lot of command-line stuff, I would recommend a framework like Laravel and against WP entirely. Hope that helps.

    Thread Starter Pastor Walt Mayhew

    (@wmayhewwalnuthillccorg)

    I guess I must have misrepresented what I’m trying to do and used improper terminology. Let me describe my project.

    I am a pastor with 30+ years IT experience on a number of platforms and am learning PHP to interact with WordPress to provide a Bible Reading Plan site that users can also discuss their daily reading.

    I have written snippets to provide users with various Bible passages from their daily reading plan. The code is so similar between plans that I could use one snippet if I could pass a parameter/argument/variable (whatever the right terminology is) indicating the reading plan. I was looking through all kinds of sites to find the right terminology, method, etc, which is where I got the terminology I used.

    Given what I’ve explained, can it be done using PHP Snippet and if so how.

    Thanks in advance.

    Ah… well, if you’re just passing a value to the snippet, just set it as an argument in your shortcode:

    [lesson_plan x="123"]

    The variables used correspond to the variables available in your snippet:

    print $x; // prints 123

    WP has caveats as to the names of the variables (e.g. keep them all lowercase).

    Some examples are on the wiki: https://code.google.com/p/wordpress-php-snippets/

    Other than that, the only way to “pass” values to your snippets would be via globals or super-globals (e.g. url parameters passed in the $_GET array). How you react to that variable depends on your code I suppose … e.g. including a file depending on the value passed, etc.

    Hope that clarifies.

    Thread Starter Pastor Walt Mayhew

    (@wmayhewwalnuthillccorg)

    Worked great. Thanks for the assist.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Passing Arguments’ is closed to new replies.