0

I'm using wordpress wp-api to create some endpoints and I have this call:

    register_rest_route('1.00', '/trial/confirm', array(
        'methods' => 'POST',
        'callback' => array($trial_service, 'callback_confirm'),
        'permission_callback' => array($this, 'check_permission_master'),
        'args' => array(
            'token' => array(
                'required' => true,
                'sanitize_callback' => 'esc_attr'
            )
        )
    ));

I would like to know how to pass arguments beyond just $request to the permission_callback function. Any help would be much appreciated.

zag2010
  • 439
  • 2
  • 4
  • 10

1 Answers1

0

You can not send more arguments to that function, but you can create a class which holds the method check_permission_master. Then pass all arguments that you need to that class (for example on construct). And later use them inside check_permission_master. For example:

class Permissions
{
    protected $param1;
    protected $param2;

    public function __construct($param1, $param2)
    {
        $this->param1 = $param1;
        $this->param2 = $param2;
    }

    public function check_permission_master($request)
    {
        ...
    }
}

And then use it in your code:

$permissions = new Permissions(...);
...

   'permission_callback' => array($permissions, 'check_permission_master'),

...