Adding user using admin ajax by a user with custom role

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745190862a4615856.html

相关推荐

  • Adding user using admin ajax by a user with custom role

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

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信