Wordpress Rest API-添加用户功能
是否有任何方法可以使用RESTAPI向用户添加功能 我通过以下方式创建用户:Wordpress Rest API-添加用户功能,wordpress,wordpress-rest-api,Wordpress,Wordpress Rest Api,是否有任何方法可以使用RESTAPI向用户添加功能 我通过以下方式创建用户: $.ajax( { url: Slug_API_Settings.root + ‘wp/v2/users/’, method: ‘POST’, beforeSend: function ( xhr ) { xhr.setRequestHeader( ‘X-WP-Nonce’, Slug_API_Settings.nonce ); }, data:{
$.ajax( {
url: Slug_API_Settings.root + ‘wp/v2/users/’,
method: ‘POST’,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( ‘X-WP-Nonce’, Slug_API_Settings.nonce );
},
data:{
email: ‘someone@somewhere.net’,
username: ‘someone’,
password: Math.random().toString(36).substring(7)
}
})
.done( function ( response ) {
console.log( response );
})
然后我需要将该功能分配给新用户。有人举过这样的例子吗
非常感谢 您可以通过WordPress REST API向新用户添加用户角色和功能,如下代码所示:
$.ajax( {
url: Slug_API_Settings.root + ‘wp/v2/users/’,
method: ‘POST’,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( ‘X-WP-Nonce’, Slug_API_Settings.nonce );
},
data:{
email: ‘someone@somewhere.net’,
username: ‘someone’,
password: Math.random().toString(36).substring(7),
roles: ‘contributor’
}
})
.done( function ( response ) {
console.log( response );
})
角色conotributor
具有delete_posts
、edit_posts
和read
等功能。您还可以使用extra_capabilities
参数为用户分配额外功能
您也可以参考WordPressAPI官方文档
请同时参阅角色和功能非常感谢您的帮助!我会试试的。让我知道这里。。!如果你要面对任何问题。