最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Adding user using admin ajax by a user with custom role

programmeradmin1浏览0评论

I have a form in which user A with a custom role is able to invite other users. Javascript which handles that looks like this:

 sendNotificationEmail(newUserId) {
      newUserId = parseInt(newUserId);
      $.ajax({
       beforeSend: (xhr) => {
       xhr.setRequestHeader('X-WP-Nonce', ftsData.nonce);
       },
       url: ftsData.root_url + '/wp-admin/admin-ajax.php',
       type: 'POST',
       dataType: 'JSON',
       data: {
        action: 'send_it_bro',
        id : newUserId
       },
       success: (response) => {
        console.log(response);
       },
       error: (response) => {
        console.log(response);
       },
       });
    }

In functions.php I have:

add_action ('wp_ajax_send_it_bro', 'send_it_bro') ;

function send_it_bro(){
    $id = intval($_REQUEST['id']);
    wp_send_new_user_notifications($id, 'both');
    $return_value = $id ;
    wp_send_json_success ($return_value) ;
}

When user with a role "admin" invites new users everything works well, but when a user with custom role invites users, then they don't get welcome e-mail.

发布评论

评论列表(0)

  1. 暂无评论