WC_API_Server::check_authentication PHP Method

check_authentication() public method

Check authentication for the request
Since: 2.1
public check_authentication ( ) : WP_User | WP_Error
return WP_User | WP_Error WP_User object indicates successful login, WP_Error indicates unsuccessful login
    public function check_authentication()
    {
        // allow plugins to remove default authentication or add their own authentication
        $user = apply_filters('woocommerce_api_check_authentication', null, $this);
        // API requests run under the context of the authenticated user
        if (is_a($user, 'WP_User')) {
            wp_set_current_user($user->ID);
        } elseif (!is_wp_error($user)) {
            $user = new WP_Error('woocommerce_api_authentication_error', __('Invalid authentication method', 'woocommerce'), array('code' => 500));
        }
        return $user;
    }