0

I’m attempting to call a PHP function via the WordPress RestAPI and for the life of me cannot figure out how to pass a JSON variable to the following function:

    function update_user_status_to_pending_from_api (WP_REST_Request $ID){
    $userID = $ID->get_json_params();
    wp_set_object_terms( $userID, array( 'pending' ), 'user_status', false );
    clean_object_term_cache( $userID, 'user_status' );
    return $ID;
    return $userID;
    }

I’d like to pass the ID variable via the JSON body at the time of the rest API request and the function fires when I call it via my make.com RestAPI module and I have ID in the JSON body, but the script does not consume the value. Even if I append ?ID=3 to the URL the script ignores the value.

I enabled PHP debugging both in WP and PHP which displays nothing when the function is called. When I use curl, I receive a response of 200, but I receive no $ID or $userID output as stated in the function.

1 Answer 1

0

After some exhaustive research I found that you must specify the JSON value you want the variable to consume

function update_user_status_to_pending_from_api (\WP_REST_Request $request){
        $parameters = $request->get_json_params();
        $userID = $parameters["id"];
        wp_set_object_terms( $userID, array( 'pending' ), 'user_status', false );
   clean_object_term_cache( $userID, 'user_status' );
  }

I can call this successfully via a curl command and passing {"id":value} in the string

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.