original_string: public static function create_contacts($userids, $userid = 0) {
          global $CFG, $USER;
  
          // Check if messaging is enabled.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          if (empty($userid)) {
              $userid = $USER->id;
          }
  
          // Validate context.
          $context = context_system::instance();
          self::validate_context($context);
  
          $params = array('userids' => $userids, 'userid' => $userid);
          $params = self::validate_parameters(self::create_contacts_parameters(), $params);
  
          $capability = 'moodle/site:manageallmessaging';
          if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
          $warnings = array();
          foreach ($params['userids'] as $id) {
              if (!message_add_contact($id, 0, $params['userid'])) {
                  $warnings[] = array(
                      'item' => 'user',
                      'itemid' => $id,
                      'warningcode' => 'contactnotcreated',
                      'message' => 'The contact could not be created'
                  );
              }
          }
          return $warnings;
      }
code: public static function create_contacts($userids, $userid = 0) {
          global $CFG, $USER;
  
          // Check if messaging is enabled.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          if (empty($userid)) {
              $userid = $USER->id;
          }
  
          // Validate context.
          $context = context_system::instance();
          self::validate_context($context);
  
          $params = array('userids' => $userids, 'userid' => $userid);
          $params = self::validate_parameters(self::create_contacts_parameters(), $params);
  
          $capability = 'moodle/site:manageallmessaging';
          if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
          $warnings = array();
          foreach ($params['userids'] as $id) {
              if (!message_add_contact($id, 0, $params['userid'])) {
                  $warnings[] = array(
                      'item' => 'user',
                      'itemid' => $id,
                      'warningcode' => 'contactnotcreated',
                      'message' => 'The contact could not be created'
                  );
              }
          }
          return $warnings;
      }
code_tokens: public static function create_contacts ( $ userids , $ userid = 0 ) { global $ CFG , $ USER ; // Check if messaging is enabled. if ( empty ( $ CFG -> messaging ) ) { throw new moodle_exception ( 'disabled' , 'message' ) ; } if ( empty ( $ userid ) ) { $ userid = $ USER -> id ; } // Validate context. $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; $ params = array ( 'userids' => $ userids , 'userid' => $ userid ) ; $ params = self :: validate_parameters ( self :: create_contacts_parameters ( ) , $ params ) ; $ capability = 'moodle/site:manageallmessaging' ; if ( ( $ USER -> id != $ params [ 'userid' ] ) && ! has_capability ( $ capability , $ context ) ) { throw new required_capability_exception ( $ context , $ capability , 'nopermissions' , '' ) ; } $ warnings = array ( ) ; foreach ( $ params [ 'userids' ] as $ id ) { if ( ! message_add_contact ( $ id , 0 , $ params [ 'userid' ] ) ) { $ warnings [ ] = array ( 'item' => 'user' , 'itemid' => $ id , 'warningcode' => 'contactnotcreated' , 'message' => 'The contact could not be created' ) ; } } return $ warnings ; }
docstring: Create contacts.
  
  @deprecated since Moodle 3.6
  @param array $userids array of user IDs.
  @param int $userid The id of the user we are creating the contacts for
  @return external_description
  @since Moodle 2.5
docstring_tokens: Create contacts .