PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | src/Log/Admin/Logs/api.js +20 -18 4.16.34.16.9 View file →
@@ -1,23 +1,24 @@
1 -import axios from 'axios';
1 +import apiFetch from '@wordpress/api-fetch';
2 2 import useSWR from 'swr';
3 3
4 -const API = axios.create({
5 - baseURL: window.GiveLogs.apiRoot,
6 - headers: {
7 - 'Content-Type': 'application/json',
8 - 'X-WP-Nonce': window.GiveLogs.apiNonce,
9 - },
10 -});
4 +const NAMESPACE = '/give-api/v2/logs';
11 5
6 +/**
7 + * @since 4.16.8 Replaced axios with @wordpress/api-fetch, which resolves with the parsed
8 + * response body and supplies the REST root and nonce from WordPress core.
9 + */
10 +const API = {
11 + get: (endpoint) => apiFetch({path: NAMESPACE + endpoint}),
12 + post: (endpoint, data) => apiFetch({path: NAMESPACE + endpoint, method: 'POST', data}),
13 + delete: (endpoint) => apiFetch({path: NAMESPACE + endpoint, method: 'DELETE'}),
14 +};
15 +
12 16 export default API;
13 17
14 -export const CancelToken = axios.CancelToken.source();
15 -
16 18 // SWR Fetcher
17 19 export const Fetcher = (endpoint) =>
18 - API.get(endpoint).then((res) => {
19 - const {data, ...rest} = res.data;
20 + API.get(endpoint).then(({data, ...rest}) => {
20 21 return {
21 22 data,
22 23 response: rest,
23 24 };
@@ -32,16 +33,17 @@
32 33 response: data ? data.response : undefined,
33 34 };
34 35 };
35 36
36 -// GET endpoint with additional parameters
37 +/**
38 + * GET endpoint with additional parameters.
39 + *
40 + * @since 4.16.8 apiFetch's root URL middleware rewrites the separator on sites without
41 + * pretty permalinks, so the endpoint always uses '?' here.
42 + */
37 43 export const getEndpoint = (endpoint, data) => {
38 44 if (data) {
39 - const queryString = new URLSearchParams(data);
40 - // pretty url?
41 - const separator = window.GiveLogs.apiRoot.indexOf('?') === -1 ? '?' : '&';
42 -
43 - return endpoint + separator + queryString.toString();
45 + return endpoint + '?' + new URLSearchParams(data).toString();
44 46 }
45 47
46 48 return endpoint;
47 49 };