Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/message/ -> lib.php (source)

Functions that are not part of a class:

message_count_unread_messages($user1=null, $user2=null)   X-Ref
Returns the count of unread messages for user. Either from a specific user or from all users.

param: object $user1 the first user. Defaults to $USER
param: object $user2 the second user. If null this function will count all of user 1's unread messages.
return: int the count of $user1's unread messages

message_format_message_text($message, $forcetexttohtml = false)   X-Ref
Try to guess how to convert the message to html.

param: stdClass $message
param: bool $forcetexttohtml
return: string html fragment

message_search_users($courseids, $searchtext, $sort='', $exceptions='')   X-Ref
Search through course users.

If $courseids contains the site course then this function searches
through all undeleted and confirmed users.

param: int|array $courseids Course ID or array of course IDs.
param: string $searchtext the text to search for.
param: string $sort the column name to order by.
param: string|array $exceptions comma separated list or array of user IDs to exclude.
return: array An array of {@link $USER} records.

message_format_message($message, $format='', $keywords='', $class='other')   X-Ref
Format a message for display in the message history

param: object $message the message object
param: string $format optional date format
param: string $keywords keywords to highlight
param: string $class CSS class to apply to the div around the message
return: string the formatted message

message_format_contexturl($message)   X-Ref
Format a the context url and context url name of a message for display

param: object $message the message object
return: string the formatted string

message_post_message($userfrom, $userto, $message, $format)   X-Ref
Send a message from one user to another. Will be delivered according to the message recipients messaging preferences

param: object $userfrom the message sender
param: object $userto the message recipient
param: string $message the message
param: int $format message format such as FORMAT_PLAIN or FORMAT_HTML
return: int|false the ID of the new message or false

get_message_processors($ready = false, $reset = false, $resetonly = false)   X-Ref
Get all message processors, validate corresponding plugin existance and
system configuration

param: bool $ready only return ready-to-use processors
param: bool $reset Reset list of message processors (used in unit tests)
param: bool $resetonly Just reset, then exit
return: mixed $processors array of objects containing information on message processors

get_message_providers()   X-Ref
Get all message providers, validate their plugin existance and
system configuration

return: mixed $processors array of objects containing information on message processors

get_message_processor($type)   X-Ref
Get an instance of the message_output class for one of the output plugins.

param: string $type the message output type. E.g. 'email' or 'jabber'.
return: message_output message_output the requested class.

get_message_output_default_preferences()   X-Ref
Get messaging outputs default (site) preferences

return: object $processors object containing information on message processors

translate_message_default_setting($plugindefault, $processorname)   X-Ref
Translate message default settings from binary value to the array of string
representing the settings to be stored. Also validate the provided value and
use default if it is malformed.

param: int    $plugindefault Default setting suggested by plugin
param: string $processorname The name of processor
return: array  $settings array of strings in the order: $permitted, $loggedin, $loggedoff.

message_get_messages($useridto, $useridfrom = 0, $notifications = -1, $read = true,$sort = 'mr.timecreated DESC', $limitfrom = 0, $limitnum = 0)   X-Ref
Get messages sent or/and received by the specified users.
Please note that this function return deleted messages too. Besides, only individual conversation messages
are returned to maintain backwards compatibility.

param: int      $useridto       the user id who received the message
param: int      $useridfrom     the user id who sent the message. -10 or -20 for no-reply or support user
param: int      $notifications  1 for retrieving notifications, 0 for messages, -1 for both
param: bool     $read           true for retrieving read messages, false for unread
param: string   $sort           the column name to order by including optionally direction
param: int      $limitfrom      limit from
param: int      $limitnum       limit num
return: external_description

message_output_fragment_processor_settings($args = [])   X-Ref
Handles displaying processor settings in a fragment.

param: array $args
return: bool|string

core_message_can_edit_message_profile($user)   X-Ref
Checks if current user is allowed to edit messaging preferences of another user

param: stdClass $user user whose preferences we are updating
return: bool

core_message_user_preferences()   X-Ref
Implements callback user_preferences, whitelists preferences that users are allowed to update directly

Used in {@see core_user::fill_preferences_cache()}, see also {@see useredit_update_user_preference()}

return: array

core_message_standard_after_main_region_html()   X-Ref
Render the message drawer to be included in the top of the body of each page.

return: string HTML