• Resolved andrekelling

    (@andrekelling)


    Hi Prakhar,

    Fatal error: Uncaught Error: Call to a member function get_data() on array in /path-to-my-wp/wp-content/plugins/hungry-rest-api-monitor/includes/trackers/class-rest-tracker.php:236 

    there is:

    /**
    * Get response body size.
    *
    * @param WP_REST_Response|WP_Error $response Response object.
    * @return int Size in bytes.
    */
    private static function get_response_size($response)
    {
    if (is_wp_error($response)) {
    return 0;
    }

    $data = $response->get_data();
    return strlen(wp_json_encode($data));
    }

    and as it seems the class ‘WP_REST_Response’ really do not has that method get_data()

    https://developer.ww.wp.xz.cn/reference/classes/wp_rest_response/#methods

    —-
    BTW as you marked your plugin as licence “GPLv2 or later”.

    so it is meant to be open source.

    Is there a public repo where one could join in and suggest contributions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Prakhar Bhatia

    (@prakharb88)

    I have added a fix for that

    Before: Called $response->get_data() blindly after only ruling out WP_Error, so any non-object response (raw array, null) caused a fatal “call to member function on non-object.”

    After: Added an instanceof WP_REST_Response guard — if it’s a proper response object call ->get_data(), otherwise use the value as-is.

    private static function get_response_size($response)
    {
    if (is_wp_error($response)) {
    return 0;
    }
    $data = ($response instanceof WP_REST_Response) ? $response->get_data() : $response;
    return strlen((string) wp_json_encode($data));
    }

    Thank you for bringing this to my notice !

    Thread Starter andrekelling

    (@andrekelling)

    just great!

    works now on my side.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.