Created
October 21, 2022 12:13
-
-
Save wbaxterh/8da62e5832b3884e003994011f4164dd to your computer and use it in GitHub Desktop.
ReactJS with Wordpress API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getTimezone = async () => { | |
let get_url = "https://your-domain/wp-json/wp/v2/users/" + userId; | |
axios.get(get_url, { | |
headers: { | |
'X-WP-Nonce': nonce, | |
} | |
}).then((response) => { | |
console.log(response.data.timezone); | |
}) | |
} | |
const updateTimezone = async() => { | |
let timezone = myContext.timezone.toString(); | |
let post_url = "https://your-domain/wp-json/wp/v2/users/" + userId + "?timezone=" + myContext.timezone; | |
let postTimezone = { | |
"timezone" : timezone | |
} | |
axios.post(post_url, postTimezone, { | |
headers: { | |
'X-WP-Nonce': nonce, | |
'content-type': 'application/json' | |
} | |
}).then((response) => { | |
console.log(response); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment