• Resolved Gerdski

    (@gerdski)


    Hello,

    I have no clue on how arguments work in this plugin.

    I am being told
    “use a JSON-encoded array, like [25], [“asdf”] or [“i”,”want”,25,”cakes”]”,
    but how to use this? Is there a practical example?

    Let’s say I want to pass the parameter howmanycakes=25…what must i put in the arguments box?

    Something like [“howmanycakes”,25] ?
    Or [“howmanycakes=25”] ?
    or something else?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the message. This isn’t an easy thing to figure out because you also need to be aware of how the WP-Cron functions in WordPress core accept arguments.

    The args parameter represents all the parameters passed to the callback function. Each item in the array is a successive parameter. Example:

    [1,2,3] is the equivalent of calling my_function( 1, 2, 3 ).

    If your callback function’s first argument is an associative array then you’ll need something like this:

    [{"howmanycakes":25}] which is the equivalent of calling my_function( array( 'howmanycakes' => 25 ) )

    Hope this helps. I’ve added a TODO for myself to improve this documentation in the plugin.

    Thread Starter Gerdski

    (@gerdski)

    Ah, ok. So in order to set howmanycakes=25, i must enter [25] in the parameter box for this one cronjob, and then set my_function like this:

    my_function ($howmanycakes) {
    echo $howmanycakes;
    }

    which should echo 25 if called by my cronjob…right?

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Correct!

    Thread Starter Gerdski

    (@gerdski)

    Great. Works now.

    I’d suggest putting 1 or 2 lines of explanation to the input field description of the plugin. It is easy to understand but hard to guess. ??

    Thanks!

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