original_string: public static function delete_message($messageid, $userid, $read = true) {
          global $CFG;
  
          // Check if private messaging between users is allowed.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          // Warnings array, it can be empty at the end but is mandatory.
          $warnings = array();
  
          // Validate params.
          $params = array(
              'messageid' => $messageid,
              'userid' => $userid,
              'read' => $read
          );
          $params = self::validate_parameters(self::delete_message_parameters(), $params);
  
          // Validate context.
          $context = context_system::instance();
          self::validate_context($context);
  
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
          if (\core_message\api::can_delete_message($user->id, $params['messageid'])) {
              $status = \core_message\api::delete_message($user->id, $params['messageid']);
          } else {
              throw new moodle_exception('You do not have permission to delete this message');
          }
  
          $results = array(
              'status' => $status,
              'warnings' => $warnings
          );
          return $results;
      }
code: public static function delete_message($messageid, $userid, $read = true) {
          global $CFG;
  
          // Check if private messaging between users is allowed.
          if (empty($CFG->messaging)) {
              throw new moodle_exception('disabled', 'message');
          }
  
          // Warnings array, it can be empty at the end but is mandatory.
          $warnings = array();
  
          // Validate params.
          $params = array(
              'messageid' => $messageid,
              'userid' => $userid,
              'read' => $read
          );
          $params = self::validate_parameters(self::delete_message_parameters(), $params);
  
          // Validate context.
          $context = context_system::instance();
          self::validate_context($context);
  
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
          if (\core_message\api::can_delete_message($user->id, $params['messageid'])) {
              $status = \core_message\api::delete_message($user->id, $params['messageid']);
          } else {
              throw new moodle_exception('You do not have permission to delete this message');
          }
  
          $results = array(
              'status' => $status,
              'warnings' => $warnings
          );
          return $results;
      }
code_tokens: public static function delete_message ( $ messageid , $ userid , $ read = true ) { global $ CFG ; // Check if private messaging between users is allowed. if ( empty ( $ CFG -> messaging ) ) { throw new moodle_exception ( 'disabled' , 'message' ) ; } // Warnings array, it can be empty at the end but is mandatory. $ warnings = array ( ) ; // Validate params. $ params = array ( 'messageid' => $ messageid , 'userid' => $ userid , 'read' => $ read ) ; $ params = self :: validate_parameters ( self :: delete_message_parameters ( ) , $ params ) ; // Validate context. $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; $ user = core_user :: get_user ( $ params [ 'userid' ] , '*' , MUST_EXIST ) ; core_user :: require_active_user ( $ user ) ; if ( \ core_message \ api :: can_delete_message ( $ user -> id , $ params [ 'messageid' ] ) ) { $ status = \ core_message \ api :: delete_message ( $ user -> id , $ params [ 'messageid' ] ) ; } else { throw new moodle_exception ( 'You do not have permission to delete this message' ) ; } $ results = array ( 'status' => $ status , 'warnings' => $ warnings ) ; return $ results ; }
docstring: Deletes a message
  
  @param  int $messageid the message id
  @param  int $userid the user id of who we want to delete the message for
  @param  bool $read if is a message read (default to true)
  @return external_description
  @throws moodle_exception
  @since 3.1
docstring_tokens: Deletes a message