original_string: public static function is_user_non_contact_blocked($recipient, $sender = null) {
          debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER);
  
          global $USER, $CFG;
  
          if (is_null($sender)) {
              // The message is from the logged in user, unless otherwise specified.
              $sender = $USER;
          }
  
          $privacypreference = self::get_user_privacy_messaging_preference($recipient->id);
          switch ($privacypreference) {
              case self::MESSAGE_PRIVACY_SITE:
                  if (!empty($CFG->messagingallusers)) {
                      // Users can be messaged without being contacts or members of the same course.
                      break;
                  }
                  // When the $CFG->messagingallusers privacy setting is disabled, continue with the next
                  // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER.
              case self::MESSAGE_PRIVACY_COURSEMEMBER:
                  // Confirm the sender and the recipient are both members of the same course.
                  if (enrol_sharing_course($recipient, $sender)) {
                      // All good, the recipient and the sender are members of the same course.
                      return false;
                  }
              case self::MESSAGE_PRIVACY_ONLYCONTACTS:
                  // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise.
                  return !self::is_contact($sender->id, $recipient->id);
          }
  
          return false;
      }
code: public static function is_user_non_contact_blocked($recipient, $sender = null) {
          debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER);
  
          global $USER, $CFG;
  
          if (is_null($sender)) {
              // The message is from the logged in user, unless otherwise specified.
              $sender = $USER;
          }
  
          $privacypreference = self::get_user_privacy_messaging_preference($recipient->id);
          switch ($privacypreference) {
              case self::MESSAGE_PRIVACY_SITE:
                  if (!empty($CFG->messagingallusers)) {
                      // Users can be messaged without being contacts or members of the same course.
                      break;
                  }
                  // When the $CFG->messagingallusers privacy setting is disabled, continue with the next
                  // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER.
              case self::MESSAGE_PRIVACY_COURSEMEMBER:
                  // Confirm the sender and the recipient are both members of the same course.
                  if (enrol_sharing_course($recipient, $sender)) {
                      // All good, the recipient and the sender are members of the same course.
                      return false;
                  }
              case self::MESSAGE_PRIVACY_ONLYCONTACTS:
                  // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise.
                  return !self::is_contact($sender->id, $recipient->id);
          }
  
          return false;
      }
code_tokens: public static function is_user_non_contact_blocked ( $ recipient , $ sender = null ) { debugging ( '\core_message\api::is_user_non_contact_blocked() is deprecated' , DEBUG_DEVELOPER ) ; global $ USER , $ CFG ; if ( is_null ( $ sender ) ) { // The message is from the logged in user, unless otherwise specified. $ sender = $ USER ; } $ privacypreference = self :: get_user_privacy_messaging_preference ( $ recipient -> id ) ; switch ( $ privacypreference ) { case self :: MESSAGE_PRIVACY_SITE : if ( ! empty ( $ CFG -> messagingallusers ) ) { // Users can be messaged without being contacts or members of the same course. break ; } // When the $CFG->messagingallusers privacy setting is disabled, continue with the next // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER. case self :: MESSAGE_PRIVACY_COURSEMEMBER : // Confirm the sender and the recipient are both members of the same course. if ( enrol_sharing_course ( $ recipient , $ sender ) ) { // All good, the recipient and the sender are members of the same course. return false ; } case self :: MESSAGE_PRIVACY_ONLYCONTACTS : // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise. return ! self :: is_contact ( $ sender -> id , $ recipient -> id ) ; } return false ; }
docstring: Checks if the recipient is allowing messages from users that aren't a
  contact. If not then it checks to make sure the sender is in the
  recipient's contacts.
  
  @deprecated since 3.6
  @param \stdClass $recipient The user object.
  @param \stdClass|null $sender The user object.
  @return bool true if $sender is blocked, false otherwise.
docstring_tokens: Checks if the recipient is allowing messages from users that aren t a contact . If not then it checks to make sure the sender is in the recipient s contacts .