Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 789fb1c

Browse files
crockGatsbyJS Bot
and
GatsbyJS Bot
authored
feat(gatsby-source-wordpress): Ability to set a custom rest api route prefix (gatsbyjs#20998)
* ✨ Added configuration option to set a custom wp rest api route prefix * 🐛 Fixed undefined varaible, added to configuration options in README * chore: format * 🐛 Co-authored-by: GatsbyJS Bot <[email protected]>
1 parent 5783cd1 commit 789fb1c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/gatsby-source-wordpress/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ module.exports = {
5858
baseUrl: "live-gatbsyjswp.pantheonsite.io",
5959
// The protocol. This can be http or https.
6060
protocol: "https",
61+
// The rest api route prefix that your WordPress site is using.
62+
// Sometimes this is modified by WordPress plugins.
63+
// If not set, it uses the default of "wp-json"
64+
restApiRoutePrefix: "wp-json",
6165
// Indicates whether the site is hosted on wordpress.com.
6266
// If false, then the assumption is made that the site is self hosted.
6367
// If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.

packages/gatsby-source-wordpress/src/fetch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async function fetch({
5353
_concurrentRequests,
5454
_includedRoutes,
5555
_excludedRoutes,
56+
_restApiRoutePrefix,
5657
typePrefix,
5758
refactoredEntityTypes,
5859
}) {
@@ -65,7 +66,7 @@ async function fetch({
6566
url = `https://public-api.wordpress.com/wp/v2/sites/${baseUrl}`
6667
_accessToken = await getWPCOMAccessToken(_auth)
6768
} else {
68-
url = `${_siteURL}/wp-json`
69+
url = `${_siteURL}/${_restApiRoutePrefix}`
6970
if (shouldUseJwt(_auth)) {
7071
_accessToken = await getJWToken(_auth, url)
7172
}

packages/gatsby-source-wordpress/src/gatsby-node.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let _excludedRoutes
2525
let _normalizer
2626
let _normalizers
2727
let _keepMediaSizes
28+
let _restApiRoutePrefix
2829

2930
exports.sourceNodes = async (
3031
{
@@ -53,6 +54,7 @@ exports.sourceNodes = async (
5354
normalizer,
5455
normalizers,
5556
keepMediaSizes = false,
57+
restApiRoutePrefix = `wp-json`,
5658
}
5759
) => {
5860
const { createNode, touchNode } = actions
@@ -70,6 +72,7 @@ exports.sourceNodes = async (
7072
_includedRoutes = includedRoutes
7173
_excludedRoutes = excludedRoutes
7274
_keepMediaSizes = keepMediaSizes
75+
_restApiRoutePrefix = restApiRoutePrefix
7376
_normalizer = normalizer
7477
_normalizers = normalizers
7578

@@ -87,6 +90,7 @@ exports.sourceNodes = async (
8790
_includedRoutes,
8891
_excludedRoutes,
8992
_keepMediaSizes,
93+
_restApiRoutePrefix,
9094
typePrefix,
9195
refactoredEntityTypes,
9296
})
@@ -240,6 +244,7 @@ exports.sourceNodes = async (
240244
concurrentRequests,
241245
excludedRoutes,
242246
keepMediaSizes,
247+
restApiRoutePrefix,
243248
}
244249

245250
// apply custom normalizer

0 commit comments

Comments
 (0)