Skip to content

Instantly share code, notes, and snippets.

@CaesarOG
Created January 3, 2017 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaesarOG/f75735379fd22548a0723cbff25a7233 to your computer and use it in GitHub Desktop.
Save CaesarOG/f75735379fd22548a0723cbff25a7233 to your computer and use it in GitHub Desktop.
jQuery ajax to update user
jQuery(document).ready(function($) {
$.ajax( {
url: Slug_API_Settings.root + 'wp/v2/users/' + Slug_API_Settings.current_user_id,
method: 'POST',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', Slug_API_Settings.nonce );
//Slug_API_Settings comes from script I enqueued in theme's functions.php which makes some vals available from PHP to the JS
},
data:JSON.stringify( { roles: ["Free"] } )
} ).done( function ( response ) {
console.log( response );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment