Skip to content

Instantly share code, notes, and snippets.

@wbaxterh
Created October 21, 2022 12:13
Show Gist options
  • Save wbaxterh/8da62e5832b3884e003994011f4164dd to your computer and use it in GitHub Desktop.
Save wbaxterh/8da62e5832b3884e003994011f4164dd to your computer and use it in GitHub Desktop.
ReactJS with Wordpress API
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