admin管理员组

文章数量:1414621

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.

本文标签: Adding user using admin ajax by a user with custom role